mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
02a7b4ebdf
Allow-list all Python code in tree for use with the black linter, and re-format all code in-tree accordingly. To produce this patch I did all of the following: 1. Make changes to tools/lint/black.yml to remove include: stanza and update list of source extensions. 2. Run ./mach lint --linter black --fix 3. Make some ad-hoc manual updates to python/mozbuild/mozbuild/test/configure/test_configure.py -- it has some hard-coded line numbers that the reformat breaks. 4. Make some ad-hoc manual updates to `testing/marionette/client/setup.py`, `testing/marionette/harness/setup.py`, and `testing/firefox-ui/harness/setup.py`, which have hard-coded regexes that break after the reformat. 5. Add a set of exclusions to black.yml. These will be deleted in a follow-up bug (1672023). # ignore-this-changeset Differential Revision: https://phabricator.services.mozilla.com/D94045
98 lines
3.0 KiB
Python
98 lines
3.0 KiB
Python
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
from argparse import (
|
|
Action,
|
|
ArgumentParser,
|
|
)
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
import buildconfig
|
|
|
|
|
|
class CPPFlag(Action):
|
|
all_flags = []
|
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
|
if "windres" in buildconfig.substs["RC"].lower():
|
|
if option_string == "-U":
|
|
return
|
|
if option_string == "-I":
|
|
option_string = "--include-dir"
|
|
|
|
self.all_flags.extend((option_string, values))
|
|
|
|
|
|
def generate_res():
|
|
parser = ArgumentParser()
|
|
parser.add_argument(
|
|
"-D", action=CPPFlag, metavar="VAR[=VAL]", help="Define a variable"
|
|
)
|
|
parser.add_argument("-U", action=CPPFlag, metavar="VAR", help="Undefine a variable")
|
|
parser.add_argument(
|
|
"-I", action=CPPFlag, metavar="DIR", help="Search path for includes"
|
|
)
|
|
parser.add_argument("-o", dest="output", metavar="OUTPUT", help="Output file")
|
|
parser.add_argument("input", help="Input file")
|
|
args = parser.parse_args()
|
|
|
|
is_windres = "windres" in buildconfig.substs["RC"].lower()
|
|
|
|
verbose = os.environ.get("BUILD_VERBOSE_LOG")
|
|
|
|
# llvm-rc doesn't preprocess on its own, so preprocess manually
|
|
# Theoretically, not windres could be rc.exe, but configure won't use it
|
|
# unless you really ask for it, and it will still work with preprocessed
|
|
# output.
|
|
try:
|
|
if not is_windres:
|
|
fd, path = tempfile.mkstemp(suffix=".rc")
|
|
command = buildconfig.substs["CXXCPP"] + CPPFlag.all_flags
|
|
command.extend(("-DRC_INVOKED", args.input))
|
|
if verbose:
|
|
print("Executing:", " ".join(command))
|
|
with os.fdopen(fd, "wb") as fh:
|
|
retcode = subprocess.run(command, stdout=fh).returncode
|
|
if retcode:
|
|
# Rely on the subprocess printing out any relevant error
|
|
return retcode
|
|
else:
|
|
path = args.input
|
|
|
|
command = [buildconfig.substs["RC"]]
|
|
if is_windres:
|
|
command.extend(("-O", "coff"))
|
|
|
|
# Even though llvm-rc doesn't preprocess, we still need to pass at least
|
|
# the -I flags.
|
|
command.extend(CPPFlag.all_flags)
|
|
|
|
if args.output:
|
|
if is_windres:
|
|
command.extend(("-o", args.output))
|
|
else:
|
|
# Use win1252 code page for the input.
|
|
command.extend(("-c", "1252", "-Fo" + args.output))
|
|
|
|
command.append(path)
|
|
|
|
if verbose:
|
|
print("Executing:", " ".join(command))
|
|
retcode = subprocess.run(command).returncode
|
|
if retcode:
|
|
# Rely on the subprocess printing out any relevant error
|
|
return retcode
|
|
finally:
|
|
if path != args.input:
|
|
os.remove(path)
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(generate_res())
|