diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-07-16 11:45:35 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-07-17 08:59:23 +0000 |
commit | 552906b0f222c5d5dd11b9fd73829d510980461a (patch) | |
tree | 3a11e6ed0538a81dd83b20cf3a4783e297f26d91 /chromium/build/android/gyp/util/build_utils.py | |
parent | 1b05827804eaf047779b597718c03e7d38344261 (diff) |
BASELINE: Update Chromium to 83.0.4103.122
Change-Id: Ie3a82f5bb0076eec2a7c6a6162326b4301ee291e
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/build/android/gyp/util/build_utils.py')
-rw-r--r-- | chromium/build/android/gyp/util/build_utils.py | 123 |
1 files changed, 55 insertions, 68 deletions
diff --git a/chromium/build/android/gyp/util/build_utils.py b/chromium/build/android/gyp/util/build_utils.py index 41b3a483849..bc15fbb61f2 100644 --- a/chromium/build/android/gyp/util/build_utils.py +++ b/chromium/build/android/gyp/util/build_utils.py @@ -4,11 +4,13 @@ """Contains common helpers for GN action()s.""" +import atexit import collections import contextlib import filecmp import fnmatch import json +import logging import os import pipes import re @@ -19,22 +21,21 @@ import sys import tempfile import zipfile -# Any new non-system import must be added to: -# //build/config/android/internal_rules.gni - -from util import md5_check - sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir)) import gn_helpers -# Definition copied from pylib/constants/__init__.py to avoid adding -# a dependency on pylib. -DIR_SOURCE_ROOT = os.environ.get('CHECKOUT_SOURCE_ROOT', - os.path.abspath(os.path.join(os.path.dirname(__file__), - os.pardir, os.pardir, os.pardir, os.pardir))) -JAVA_PATH = os.path.join(DIR_SOURCE_ROOT, 'third_party', 'jdk', 'current', - 'bin', 'java') +# Use relative paths to improved hermetic property of build scripts. +DIR_SOURCE_ROOT = os.path.relpath( + os.environ.get( + 'CHECKOUT_SOURCE_ROOT', + os.path.join( + os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, + os.pardir))) +JAVA_HOME = os.path.join(DIR_SOURCE_ROOT, 'third_party', 'jdk', 'current') +JAVA_PATH = os.path.join(JAVA_HOME, 'bin', 'java') +JAVAC_PATH = os.path.join(JAVA_HOME, 'bin', 'javac') +JAVAP_PATH = os.path.join(JAVA_HOME, 'bin', 'javap') RT_JAR_PATH = os.path.join(DIR_SOURCE_ROOT, 'third_party', 'jdk', 'extras', 'java_8', 'jre', 'lib', 'rt.jar') @@ -45,8 +46,8 @@ except NameError: @contextlib.contextmanager -def TempDir(): - dirname = tempfile.mkdtemp() +def TempDir(**kwargs): + dirname = tempfile.mkdtemp(**kwargs) try: yield dirname finally: @@ -207,7 +208,7 @@ def FilterLines(output, filter_string): """ re_filter = re.compile(filter_string) return '\n'.join( - line for line in output.splitlines() if not re_filter.search(line)) + line for line in output.split('\n') if not re_filter.search(line)) def FilterReflectiveAccessJavaWarnings(output): @@ -418,6 +419,8 @@ def DoZip(inputs, output, base_dir=None, compress_fn=None, for tup in inputs: if isinstance(tup, string_types): tup = (os.path.relpath(tup, base_dir), tup) + if tup[0].startswith('..'): + raise Exception('Invalid zip_path: ' + tup[0]) input_tuples.append(tup) # Sort by zip path to ensure stable zip ordering. @@ -445,8 +448,20 @@ def ZipDir(output, base_dir, compress_fn=None, zip_prefix_path=None): for f in files: inputs.append(os.path.join(root, f)) - with AtomicOutput(output) as f: - DoZip(inputs, f, base_dir, compress_fn=compress_fn, + if isinstance(output, zipfile.ZipFile): + DoZip( + inputs, + output, + base_dir, + compress_fn=compress_fn, + zip_prefix_path=zip_prefix_path) + else: + with AtomicOutput(output) as f: + DoZip( + inputs, + f, + base_dir, + compress_fn=compress_fn, zip_prefix_path=zip_prefix_path) @@ -526,7 +541,7 @@ def GetSortedTransitiveDependencies(top, deps_func): return list(deps_map) -def _ComputePythonDependencies(): +def ComputePythonDependencies(): """Gets the paths of imported non-system python modules. A path is assumed to be a "system" import if it is outside of chromium's @@ -537,9 +552,11 @@ def _ComputePythonDependencies(): if m is not None and hasattr(m, '__file__')) abs_module_paths = map(os.path.abspath, module_paths) - assert os.path.isabs(DIR_SOURCE_ROOT) + abs_dir_source_root = os.path.abspath(DIR_SOURCE_ROOT) non_system_module_paths = [ - p for p in abs_module_paths if p.startswith(DIR_SOURCE_ROOT)] + p for p in abs_module_paths if p.startswith(abs_dir_source_root) + ] + def ConvertPycToPy(s): if s.endswith('.pyc'): return s[:-1] @@ -567,6 +584,23 @@ def _ForceLazyModulesToLoad(): break +def InitLogging(enabling_env): + logging.basicConfig( + level=logging.DEBUG if os.environ.get(enabling_env) else logging.WARNING, + format='%(levelname).1s %(process)d %(relativeCreated)6d %(message)s') + script_name = os.path.basename(sys.argv[0]) + logging.info('Started (%s)', script_name) + + my_pid = os.getpid() + + def log_exit(): + # Do not log for fork'ed processes. + if os.getpid() == my_pid: + logging.info("Job's done (%s)", script_name) + + atexit.register(log_exit) + + def AddDepfileOption(parser): # TODO(agrieve): Get rid of this once we've moved to argparse. if hasattr(parser, 'add_option'): @@ -582,7 +616,7 @@ def WriteDepfile(depfile_path, first_gn_output, inputs=None, add_pydeps=True): assert not isinstance(inputs, string_types) # Easy mistake to make inputs = inputs or [] if add_pydeps: - inputs = _ComputePythonDependencies() + inputs + inputs = ComputePythonDependencies() + inputs MakeDirectory(os.path.dirname(depfile_path)) # Ninja does not support multiple outputs in depfiles. with open(depfile_path, 'w') as depfile: @@ -654,50 +688,3 @@ def ReadSourcesList(sources_list_file_name): """ with open(sources_list_file_name) as f: return [file_name.strip() for file_name in f] - - -def CallAndWriteDepfileIfStale(on_stale_md5, - options, - record_path=None, - input_paths=None, - input_strings=None, - output_paths=None, - force=False, - pass_changes=False, - track_subpaths_whitelist=None, - depfile_deps=None): - """Wraps md5_check.CallAndRecordIfStale() and writes a depfile if applicable. - - Depfiles are automatically added to output_paths when present in the |options| - argument. They are then created after |on_stale_md5| is called. - - By default, only python dependencies are added to the depfile. If there are - other input paths that are not captured by GN deps, then they should be listed - in depfile_deps. It's important to write paths to the depfile that are already - captured by GN deps since GN args can cause GN deps to change, and such - changes are not immediately reflected in depfiles (http://crbug.com/589311). - """ - if not output_paths: - raise Exception('At least one output_path must be specified.') - input_paths = list(input_paths or []) - input_strings = list(input_strings or []) - output_paths = list(output_paths or []) - - input_paths += _ComputePythonDependencies() - - md5_check.CallAndRecordIfStale( - on_stale_md5, - record_path=record_path, - input_paths=input_paths, - input_strings=input_strings, - output_paths=output_paths, - force=force, - pass_changes=pass_changes, - track_subpaths_whitelist=track_subpaths_whitelist) - - # Write depfile even when inputs have not changed to ensure build correctness - # on bots that build with & without patch, and the patch changes the depfile - # location. - if hasattr(options, 'depfile') and options.depfile: - WriteDepfile( - options.depfile, output_paths[0], depfile_deps, add_pydeps=False) |