diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2023-10-27 17:02:53 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2023-10-27 17:04:08 +0200 |
commit | 3dce9b5818576f04ce21cec4b3686eda012e5b65 (patch) | |
tree | fe3d59c6da3e62c74563710ba63996585293c743 /chromium/build/android/gyp | |
parent | 5a424f4a7b188b75da63eb697f63558af0b17f6f (diff) |
BASELINE: Update Chromium to 118.0.5993.24
Change-Id: I8373334b8ea8225ab4d934dc676aabc6a85a7efa
Diffstat (limited to 'chromium/build/android/gyp')
-rwxr-xr-x | chromium/build/android/gyp/binary_baseline_profile.py | 10 | ||||
-rwxr-xr-x | chromium/build/android/gyp/bytecode_processor.py | 134 | ||||
-rwxr-xr-x | chromium/build/android/gyp/compile_java.py | 3 | ||||
-rwxr-xr-x | chromium/build/android/gyp/create_java_binary_script.py | 11 | ||||
-rwxr-xr-x | chromium/build/android/gyp/dex.py | 7 | ||||
-rwxr-xr-x | chromium/build/android/gyp/java_cpp_enum.py | 2 | ||||
-rwxr-xr-x | chromium/build/android/gyp/java_cpp_enum_tests.py | 2 | ||||
-rwxr-xr-x | chromium/build/android/gyp/java_cpp_strings.py | 2 | ||||
-rwxr-xr-x | chromium/build/android/gyp/lint.py | 1 | ||||
-rwxr-xr-x | chromium/build/android/gyp/proguard.py | 33 | ||||
-rw-r--r-- | chromium/build/android/gyp/util/build_utils.py | 9 | ||||
-rw-r--r-- | chromium/build/android/gyp/util/dep_utils.py | 6 | ||||
-rw-r--r-- | chromium/build/android/gyp/util/jar_utils.py | 105 | ||||
-rwxr-xr-x | chromium/build/android/gyp/write_build_config.py | 28 | ||||
-rwxr-xr-x | chromium/build/android/gyp/write_native_libraries_java.py | 12 |
15 files changed, 179 insertions, 186 deletions
diff --git a/chromium/build/android/gyp/binary_baseline_profile.py b/chromium/build/android/gyp/binary_baseline_profile.py index 40498050a61..545e63b475e 100755 --- a/chromium/build/android/gyp/binary_baseline_profile.py +++ b/chromium/build/android/gyp/binary_baseline_profile.py @@ -27,7 +27,6 @@ def main(args): required=True, help='Path to a zip containing release dex files.') parser.add_argument('--proguard-mapping', - required=True, help='Path to proguard mapping for release dex.') parser.add_argument('--input-profile-path', required=True, @@ -44,9 +43,14 @@ def main(args): options.output_metadata, '-a', options.dex, - '-m', - options.proguard_mapping, ] + + if options.proguard_mapping: + cmd += [ + '-m', + options.proguard_mapping, + ] + build_utils.CheckOutput(cmd, env={'JAVA_HOME': build_utils.JAVA_HOME}) action_helpers.write_depfile(options.depfile, options.output_profile, diff --git a/chromium/build/android/gyp/bytecode_processor.py b/chromium/build/android/gyp/bytecode_processor.py index 127e2187754..620ae5458d3 100755 --- a/chromium/build/android/gyp/bytecode_processor.py +++ b/chromium/build/android/gyp/bytecode_processor.py @@ -7,11 +7,12 @@ import argparse import collections +import json import logging import os import pathlib import sys -from typing import Dict, List +from typing import Dict, List, Tuple from util import build_utils from util import dep_utils @@ -24,15 +25,23 @@ sys.path.append(str(_SRC_PATH / 'tools/android/modularization/gn')) from dep_operations import NO_VALID_GN_STR +# This is a temporary constant to make reverts easier (if necessary). +# TODO(crbug.com/1099522): Remove this and make jdeps on by default. +_USE_JDEPS = True + +# This is temporary in case another revert & debug session is necessary. +# TODO(crbug.com/1099522): Remove this when jdeps is on by default. +_DEBUG = False + + def _ShouldIgnoreDep(dep_name: str): if 'gen.base_module.R' in dep_name: return True return False -def _ParseDepGraph(jar_path: str, output_dir: str): - output = jar_utils.run_jdeps(build_output_dir=pathlib.Path(output_dir), - filepath=pathlib.Path(jar_path)) +def _ParseDepGraph(jar_path: str): + output = jar_utils.run_jdeps(pathlib.Path(jar_path)) assert output is not None, f'Unable to parse jdep for {jar_path}' dep_graph = collections.defaultdict(set) # pylint: disable=line-too-long @@ -57,7 +66,7 @@ def _ParseDepGraph(jar_path: str, output_dir: str): dep_from = parsed[0] dep_to = parsed[2] dep_graph[dep_from].add(dep_to) - return dep_graph + return dep_graph, output def _GnTargetToBuildFilePath(gn_target: str): @@ -83,35 +92,33 @@ def _EnsureDirectClasspathIsComplete( full_classpath_jars: List[str], full_classpath_gn_targets: List[str], warnings_as_errors: bool, + auto_add_deps: bool, ): logging.info('Parsing %d direct classpath jars', len(sdk_classpath_jars)) sdk_classpath_deps = set() for jar in sdk_classpath_jars: - deps = jar_utils.extract_full_class_names_from_jar( - build_output_dir=pathlib.Path(output_dir), jar_path=pathlib.Path(jar)) + deps = jar_utils.extract_full_class_names_from_jar(jar) sdk_classpath_deps.update(deps) logging.info('Parsing %d direct classpath jars', len(direct_classpath_jars)) direct_classpath_deps = set() for jar in direct_classpath_jars: - deps = jar_utils.extract_full_class_names_from_jar( - build_output_dir=pathlib.Path(output_dir), jar_path=pathlib.Path(jar)) + deps = jar_utils.extract_full_class_names_from_jar(jar) direct_classpath_deps.update(deps) logging.info('Parsing %d full classpath jars', len(full_classpath_jars)) full_classpath_deps = set() dep_to_target = collections.defaultdict(set) for jar, target in zip(full_classpath_jars, full_classpath_gn_targets): - deps = jar_utils.extract_full_class_names_from_jar( - build_output_dir=pathlib.Path(output_dir), jar_path=pathlib.Path(jar)) + deps = jar_utils.extract_full_class_names_from_jar(jar) full_classpath_deps.update(deps) for dep in deps: dep_to_target[dep].add(target) transitive_deps = full_classpath_deps - direct_classpath_deps - missing_targets: Dict[tuple, Dict[str, str]] = collections.defaultdict(dict) - dep_graph = _ParseDepGraph(input_jar, output_dir) + missing_classes: Dict[str, str] = {} + dep_graph, output = _ParseDepGraph(input_jar) logging.info('Finding missing deps from %d classes', len(dep_graph)) # dep_graph.keys() is a list of all the classes in the current input_jar. Skip # all of these to avoid checking dependencies in the same target (e.g. A @@ -125,55 +132,93 @@ def _EnsureDirectClasspathIsComplete( continue seen_deps.add(dep_to) if dep_to in transitive_deps: - missing_target_names = tuple(sorted(dep_to_target[dep_to])) - missing_targets[missing_target_names][dep_to] = dep_from + # Allow clobbering since it doesn't matter which specific class depends + # on |dep_to|. + missing_classes[dep_to] = dep_from - if missing_targets: + # missing_target_names = tuple(sorted(dep_to_target[dep_to])) + # missing_targets[missing_target_names][dep_to] = dep_from + if missing_classes: def print_and_maybe_exit(): + missing_targets: Dict[Tuple, List[str]] = collections.defaultdict(list) + for dep_to, dep_from in missing_classes.items(): + missing_target_names = tuple(sorted(dep_to_target[dep_to])) + missing_targets[missing_target_names].append(dep_to) print('=' * 30 + ' Dependency Checks Failed ' + '=' * 30) print(f'Target: {gn_target}') print('Direct classpath is incomplete. To fix, add deps on:') - for missing_target_names, data in missing_targets.items(): + for missing_target_names, deps_to in missing_targets.items(): if len(missing_target_names) > 1: print(f' * One of {", ".join(missing_target_names)}') else: print(f' * {missing_target_names[0]}') - for missing_class, used_by in data.items(): - print(f' ** {missing_class} (needed by {used_by})') + for dep_to in deps_to: + dep_from = missing_classes[dep_to] + print(f' ** {dep_to} (needed by {dep_from})') + if _DEBUG: + gn_target_name = gn_target.split(':', 1)[-1] + debug_fname = f'/tmp/bytecode_processor_debug_{gn_target_name}.json' + with open(debug_fname, 'w') as f: + print(gn_target, file=f) + print(input_jar, file=f) + print(json.dumps(sorted(sdk_classpath_deps), indent=4), file=f) + print(json.dumps(sorted(direct_classpath_deps), indent=4), file=f) + print(json.dumps(sorted(full_classpath_deps), indent=4), file=f) + print(json.dumps(sorted(transitive_deps), indent=4), file=f) + print(json.dumps(missing_classes, sort_keys=True, indent=4), file=f) + print(output, file=f) + print(f'DEBUG FILE: {debug_fname}') if warnings_as_errors: sys.exit(1) - # TODO(https://crbug.com/1099522): This is better as a GN arg. - if os.environ.get('AUTO_ADD_MISSING_DEPS') != '1': + if not auto_add_deps: print_and_maybe_exit() else: + # Normalize chrome_public_apk__java to chrome_public_apk. + gn_target = gn_target.split('__', 1)[0] + # TODO(https://crbug.com/1099522): This should be generalized into util. build_file_path = _GnTargetToBuildFilePath(gn_target) cmd = [ 'tools/android/modularization/gn/dep_operations.py', 'add', '--quiet', '--file', build_file_path, '--target', gn_target, '--deps' ] - # For simplicity, always pick the first suggested target. - # TODO(https://crbug.com/1099522): Swap deps with preferred deps. - missing_deps = [names[0] for names in missing_targets.keys()] + class_lookup_index = dep_utils.ClassLookupIndex(pathlib.Path(output_dir), + should_build=False) + + missing_deps = set() + for dep_to in missing_classes: + # Using dep_utils.ClassLookupIndex ensures we respect the preferred dep + # if any exists for the missing deps. + suggested_deps = class_lookup_index.match(dep_to) + assert suggested_deps, f'Unable to find target for {dep_to}' + suggested_deps = dep_utils.DisambiguateDeps(suggested_deps) + missing_deps.add(suggested_deps[0].target) cmd += missing_deps + failed = False + try: - build_utils.CheckOutput(cmd, cwd=build_utils.DIR_SOURCE_ROOT) + stdout = build_utils.CheckOutput(cmd, + cwd=build_utils.DIR_SOURCE_ROOT, + fail_on_output=warnings_as_errors) + if f'Unable to find {gn_target}' in stdout: + # This can happen if a target's deps are stored in a variable instead + # of a list and then simply assigned: `deps = deps_variable`. These + # need to be manually added to the `deps_variable`. + failed = True except build_utils.CalledProcessError as e: if NO_VALID_GN_STR in e.output: - print(f'Unable to add missing dep(s) to {build_file_path}.') - print_and_maybe_exit() + failed = True else: raise + if failed: + print(f'Unable to auto-add missing dep(s) to {build_file_path}.') + print_and_maybe_exit() else: - print(f'Successfully updated {build_file_path} with missing direct ' - f'deps: {missing_deps}') - - -def _AddSwitch(parser, val): - parser.add_argument( - val, action='store_const', default='--disabled', const=val) + gn_target_name = gn_target.split(':', 1)[-1] + print(f'Successfully updated "{gn_target_name}" in {build_file_path} ' + f'with missing direct deps: {missing_deps}') def main(argv): @@ -199,7 +244,11 @@ def main(argv): parser.add_argument('--warnings-as-errors', action='store_true', help='Treat all warnings as errors.') - _AddSwitch(parser, '--is-prebuilt') + parser.add_argument( + '--auto-add-deps', + action='store_true', + help='Attempt to automatically add missing deps to the corresponding ' + 'BUILD.gn file.') args = parser.parse_args(argv) if server_utils.MaybeRunCommand(name=args.target_name, @@ -223,9 +272,8 @@ def main(argv): verbose = '--verbose' if args.verbose else '--not-verbose' - # TODO(https://crbug.com/1099522): Make jdeps the default. - if os.environ.get('BYTECODE_PROCESSOR_USE_JDEPS'): + if _USE_JDEPS: logging.info('Processed args for %s, starting direct classpath check.', args.target_name) _EnsureDirectClasspathIsComplete( @@ -237,11 +285,12 @@ def main(argv): full_classpath_jars=args.full_classpath_jars, full_classpath_gn_targets=args.full_classpath_gn_targets, warnings_as_errors=args.warnings_as_errors, + auto_add_deps=args.auto_add_deps, ) logging.info('Check completed.') else: cmd = [ - args.script, args.gn_target, args.input_jar, verbose, args.is_prebuilt + args.script, args.gn_target, args.input_jar, verbose, '--not-prebuilt' ] cmd += [str(len(args.missing_classes_allowlist))] cmd += args.missing_classes_allowlist @@ -254,10 +303,11 @@ def main(argv): cmd += [str(len(args.full_classpath_gn_targets))] cmd += args.full_classpath_gn_targets try: - build_utils.CheckOutput(cmd, - print_stdout=True, - fail_func=None, - fail_on_output=args.warnings_as_errors) + build_utils.CheckOutput( + cmd, + print_stdout=True, + fail_func=None, # type: ignore + fail_on_output=args.warnings_as_errors) except build_utils.CalledProcessError as e: # Do not output command line because it is massive and makes the actual # error message hard to find. diff --git a/chromium/build/android/gyp/compile_java.py b/chromium/build/android/gyp/compile_java.py index 5fee0d77c3e..56d251033f2 100755 --- a/chromium/build/android/gyp/compile_java.py +++ b/chromium/build/android/gyp/compile_java.py @@ -837,7 +837,8 @@ def main(argv): depfile_deps = classpath_inputs # Files that are already inputs in GN should go in input_paths. - input_paths = depfile_deps + options.java_srcjars + java_files + kt_files + input_paths = ([build_utils.JAVAC_PATH] + depfile_deps + + options.java_srcjars + java_files + kt_files) if options.header_jar: input_paths.append(options.header_jar) input_paths += [x[0] for x in options.additional_jar_files] diff --git a/chromium/build/android/gyp/create_java_binary_script.py b/chromium/build/android/gyp/create_java_binary_script.py index b6adf6b0b75..51c2d94e146 100755 --- a/chromium/build/android/gyp/create_java_binary_script.py +++ b/chromium/build/android/gyp/create_java_binary_script.py @@ -40,20 +40,19 @@ if os.getcwd() != self_dir: classpath = [fix_path(p) for p in classpath] java_path = fix_path(java_path) java_cmd = [java_path] + +# https://github.com/iBotPeaches/Apktool/issues/3174 +# https://chromium-review.googlesource.com/c/chromium/src/+/4697557/3 +java_cmd += ['-Djdk.util.zip.disableZip64ExtraFieldValidation=true'] + # This is a simple argparser for jvm, jar, and classpath arguments. parser = argparse.ArgumentParser(add_help=False) parser.add_argument('--jar-args') parser.add_argument('--jvm-args') parser.add_argument('--classpath') # Test_runner parses the classpath for sharding junit tests. -parser.add_argument('--print-classpath', action='store_true', - help='Prints the classpass. Used by test_runner.') known_args, unknown_args = parser.parse_known_args(sys.argv[1:]) -if known_args.print_classpath: - sys.stdout.write(':'.join(classpath)) - sys.exit(0) - if known_args.jvm_args: jvm_arguments = known_args.jvm_args.strip('"').split() java_cmd.extend(jvm_arguments) diff --git a/chromium/build/android/gyp/dex.py b/chromium/build/android/gyp/dex.py index ce91b38b1ae..221b3fd50c7 100755 --- a/chromium/build/android/gyp/dex.py +++ b/chromium/build/android/gyp/dex.py @@ -425,9 +425,10 @@ def main(args): options.class_inputs += options.class_inputs_filearg options.dex_inputs += options.dex_inputs_filearg - input_paths = options.class_inputs + options.dex_inputs - input_paths.append(options.r8_jar_path) - input_paths.append(options.custom_d8_jar_path) + input_paths = ([ + build_utils.JAVA_PATH_FOR_INPUTS, options.r8_jar_path, + options.custom_d8_jar_path + ] + options.class_inputs + options.dex_inputs) if options.main_dex_rules_path: input_paths.extend(options.main_dex_rules_path) diff --git a/chromium/build/android/gyp/java_cpp_enum.py b/chromium/build/android/gyp/java_cpp_enum.py index 9098cfc82b1..5225b89b36b 100755 --- a/chromium/build/android/gyp/java_cpp_enum.py +++ b/chromium/build/android/gyp/java_cpp_enum.py @@ -349,7 +349,7 @@ def DoParseHeaderFile(path): def GenerateOutput(source_path, enum_definition): template = Template(""" -// Copyright ${YEAR} The Chromium Authors. All rights reserved. +// Copyright ${YEAR} The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/build/android/gyp/java_cpp_enum_tests.py b/chromium/build/android/gyp/java_cpp_enum_tests.py index c14f2a085ed..6103b583996 100755 --- a/chromium/build/android/gyp/java_cpp_enum_tests.py +++ b/chromium/build/android/gyp/java_cpp_enum_tests.py @@ -31,7 +31,7 @@ class TestPreprocess(unittest.TestCase): 'really long.')]) output = GenerateOutput('path/to/file', definition) expected = """ -// Copyright %d The Chromium Authors. All rights reserved. +// Copyright %d The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/build/android/gyp/java_cpp_strings.py b/chromium/build/android/gyp/java_cpp_strings.py index c3d05de6c64..60de019214a 100755 --- a/chromium/build/android/gyp/java_cpp_strings.py +++ b/chromium/build/android/gyp/java_cpp_strings.py @@ -17,7 +17,7 @@ import zip_helpers class StringParserDelegate(java_cpp_utils.CppConstantParser.Delegate): - STRING_RE = re.compile(r'\s*const char k(.*)\[\]\s*=') + STRING_RE = re.compile(r'\s*(?:inline )?const(?:expr)? char k(.*)\[\]\s*=') VALUE_RE = re.compile(r'\s*("(?:\"|[^"])*")\s*;') def ExtractConstantName(self, line): diff --git a/chromium/build/android/gyp/lint.py b/chromium/build/android/gyp/lint.py index ae26a18085d..95892023355 100755 --- a/chromium/build/android/gyp/lint.py +++ b/chromium/build/android/gyp/lint.py @@ -33,6 +33,7 @@ _DISABLED_ALWAYS = [ "ObsoleteLintCustomCheck", # We have no control over custom lint checks. "SwitchIntDef", # Many C++ enums are not used at all in java. "Typos", # Strings are committed in English first and later translated. + "VisibleForTests", # Does not recognize "ForTesting" methods. "UniqueConstants", # Chromium enums allow aliases. "UnusedAttribute", # Chromium apks have various minSdkVersion values. ] diff --git a/chromium/build/android/gyp/proguard.py b/chromium/build/android/gyp/proguard.py index 20f66723836..89a1b2dd3df 100755 --- a/chromium/build/android/gyp/proguard.py +++ b/chromium/build/android/gyp/proguard.py @@ -142,6 +142,14 @@ def _ParseOptions(): action='append', help='List of name pairs separated by : mapping a feature module to a ' 'dependent feature module.') + parser.add_argument('--input-art-profile', + help='Path to the input unobfuscated ART profile.') + parser.add_argument('--output-art-profile', + help='Path to the output obfuscated ART profile.') + parser.add_argument( + '--apply-startup-profile', + action='store_true', + help='Whether to pass --input-art-profile as a startup profile to R8.') parser.add_argument( '--keep-rules-targets-regex', metavar='KEEP_RULES_REGEX', @@ -187,6 +195,11 @@ def _ParseOptions(): parser.error('You must path both --keep-rules-targets-regex and ' '--keep-rules-output-path') + if options.output_art_profile and not options.input_art_profile: + parser.error('--output-art-profile requires --input-art-profile') + if options.apply_startup_profile and not options.input_art_profile: + parser.error('--apply-startup-profile requires --input-art-profile') + if options.force_enable_assertions and options.assertion_handler: parser.error('Cannot use both --force-enable-assertions and ' '--assertion-handler') @@ -319,6 +332,14 @@ def _OptimizeWithR8(options, config_paths, libraries, dynamic_config_data): if options.disable_checks: cmd += ['--map-diagnostics:CheckDiscardDiagnostic', 'error', 'none'] + # chromium has junit lib in third_party/junit and third_party/android_sdk + # which causes r8 to print "info" level diagnostic for duplicates. + # So turn it off explicitly. + # TODO(crbug.com/1476663): Fix the duplicates and remove this setting. + cmd += [ + '--map-diagnostics:DuplicateTypeInProgramAndLibraryDiagnostic', 'info', + 'none' + ] cmd += ['--map-diagnostics', 'info', 'warning'] # An "error" level diagnostic causes r8 to return an error exit code. Doing # this allows our filter to decide what should/shouldn't break our build. @@ -342,6 +363,18 @@ def _OptimizeWithR8(options, config_paths, libraries, dynamic_config_data): for main_dex_rule in options.main_dex_rules_path: cmd += ['--main-dex-rules', main_dex_rule] + if options.output_art_profile: + cmd += [ + '--art-profile', + options.input_art_profile, + options.output_art_profile, + ] + if options.apply_startup_profile: + cmd += [ + '--startup-profile', + options.input_art_profile, + ] + # Add any extra inputs to the base context (e.g. desugar runtime). extra_jars = set(options.input_paths) for split_context in split_contexts_by_name.values(): diff --git a/chromium/build/android/gyp/util/build_utils.py b/chromium/build/android/gyp/util/build_utils.py index ad0515b36a0..752aa21ec55 100644 --- a/chromium/build/android/gyp/util/build_utils.py +++ b/chromium/build/android/gyp/util/build_utils.py @@ -34,17 +34,24 @@ DIR_SOURCE_ROOT = os.path.relpath( 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') +JAVA_PATH_FOR_INPUTS = f'{JAVA_PATH}.chromium' JAVAC_PATH = os.path.join(JAVA_HOME, 'bin', 'javac') JAVAP_PATH = os.path.join(JAVA_HOME, 'bin', 'javap') KOTLIN_HOME = os.path.join(DIR_SOURCE_ROOT, 'third_party', 'kotlinc', 'current') KOTLINC_PATH = os.path.join(KOTLIN_HOME, 'bin', 'kotlinc') + def JavaCmd(xmx='1G'): - ret = [os.path.join(JAVA_HOME, 'bin', 'java')] + ret = [JAVA_PATH] # Limit heap to avoid Java not GC'ing when it should, and causing # bots to OOM when many java commands are runnig at the same time # https://crbug.com/1098333 ret += ['-Xmx' + xmx] + # JDK17 bug. + # See: https://chromium-review.googlesource.com/c/chromium/src/+/4705883/3 + # https://github.com/iBotPeaches/Apktool/issues/3174 + ret += ['-Djdk.util.zip.disableZip64ExtraFieldValidation=true'] return ret diff --git a/chromium/build/android/gyp/util/dep_utils.py b/chromium/build/android/gyp/util/dep_utils.py index 1220991abb1..370e3587598 100644 --- a/chromium/build/android/gyp/util/dep_utils.py +++ b/chromium/build/android/gyp/util/dep_utils.py @@ -76,8 +76,8 @@ class ClassLookupIndex: """A map from full Java class to its build targets. A class might be in multiple targets if it's bytecode rewritten.""" - def __init__(self, abs_build_output_dir: pathlib.Path, should_build: bool): - self._abs_build_output_dir = abs_build_output_dir + def __init__(self, build_output_dir: pathlib.Path, should_build: bool): + self._abs_build_output_dir = build_output_dir.resolve().absolute() self._should_build = should_build self._class_index = self._index_root() @@ -223,7 +223,7 @@ class ClassLookupIndex: full_class_names.update( jar_utils.extract_full_class_names_from_jar( - self._abs_build_output_dir, abs_unprocessed_jar_path)) + abs_unprocessed_jar_path)) return full_class_names diff --git a/chromium/build/android/gyp/util/jar_utils.py b/chromium/build/android/gyp/util/jar_utils.py index eabae59ad30..05ecdbfb8c4 100644 --- a/chromium/build/android/gyp/util/jar_utils.py +++ b/chromium/build/android/gyp/util/jar_utils.py @@ -3,12 +3,10 @@ # found in the LICENSE file. """Methods to run tools over jars and cache their output.""" -import dataclasses -import functools import logging import pathlib import zipfile -from typing import List, Optional +from typing import List, Optional, Union from util import build_utils @@ -36,59 +34,6 @@ def _is_relative_to(path: pathlib.Path, other_path: pathlib.Path): return False -@dataclasses.dataclass -class CacheFile: - jar_path: pathlib.Path - cache_suffix: str - build_output_dir: pathlib.Path - src_dir: pathlib.Path = _SRC_PATH - - def __post_init__(self): - # Ensure that all paths are absolute so that relative_to works correctly. - self.jar_path = self.jar_path.resolve() - self.build_output_dir = self.build_output_dir.resolve() - self.src_dir = self.src_dir.resolve() - - @functools.cached_property - def cache_path(self): - """Return a cache path for the jar that is always in the output dir. - - Example: - - Given: - src_path = /cr/src - build_output_dir = /cr/src/out/Debug - cache_suffix = .jdeps - - filepath = /cr/src/out/Debug/a/d/file.jar - Returns: /cr/src/out/Debug/a/d/file.jar.jdeps - - filepath = /cr/src/out/b/c/file.jar - Returns: /cr/src/out/Debug/gen/b/c/file.jar.jdeps - - filepath = /random/path/file.jar - Returns: /cr/src/out/Debug/gen/abs/random/path/file.jar.jdeps - """ - path = self.jar_path.with_suffix(self.jar_path.suffix + self.cache_suffix) - if _is_relative_to(path, self.build_output_dir): - # already in the outdir, no need to adjust cache path - return path - if _is_relative_to(self.jar_path, _SRC_PATH): - return self.build_output_dir / 'gen' / path.relative_to(_SRC_PATH) - return self.build_output_dir / 'gen/abs' / path.relative_to(path.anchor) - - def is_valid(self): - return (self.cache_path.exists() and self.jar_path.exists() - and self.cache_path.stat().st_mtime > self.jar_path.stat().st_mtime) - - def read(self): - with open(self.cache_path) as f: - return f.read() - - def write(self, content: str): - # If the jar file is in //src but not in the output dir or outside //src - # then the reparented dirs within the output dir need to be created first. - self.cache_path.parent.mkdir(parents=True, exist_ok=True) - with open(self.cache_path, 'w') as f: - f.write(content) - - def _should_ignore(jar_path: pathlib.Path) -> bool: for ignored_jar_path in _IGNORED_JAR_PATHS: if ignored_jar_path in str(jar_path): @@ -98,33 +43,14 @@ def _should_ignore(jar_path: pathlib.Path) -> bool: def run_jdeps(filepath: pathlib.Path, *, - build_output_dir: pathlib.Path, - jdeps_path: pathlib.Path = _JDEPS_PATH, - src_path: pathlib.Path = _SRC_PATH) -> Optional[str]: - """Runs jdeps on the given filepath and returns the output. - - Uses a simple file cache for the output of jdeps. If the jar file's mtime is - older than the jdeps cache then just use the cached content instead. - Otherwise jdeps is run again and the output used to update the file cache. - - Tested Nov 2nd, 2022: - - With all cache hits, script takes 13 seconds. - - Without the cache, script takes 1 minute 14 seconds. - """ - # Some __compile_java targets do not generate a .jar file, skipping these - # does not affect correctness. + jdeps_path: pathlib.Path = _JDEPS_PATH) -> Optional[str]: + """Runs jdeps on the given filepath and returns the output.""" if not filepath.exists() or _should_ignore(filepath): + # Some __compile_java targets do not generate a .jar file, skipping these + # does not affect correctness. return None - cache_file = CacheFile(jar_path=filepath, - cache_suffix='.jdeps_cache', - build_output_dir=build_output_dir, - src_dir=src_path) - if cache_file.is_valid(): - return cache_file.read() - - # Cache either doesn't exist or is older than the jar file. - output = build_utils.CheckOutput([ + return build_utils.CheckOutput([ str(jdeps_path), '-verbose:class', '--multi-release', # Some jars support multiple JDK releases. @@ -132,20 +58,10 @@ def run_jdeps(filepath: pathlib.Path, str(filepath), ]) - cache_file.write(output) - return output - -def extract_full_class_names_from_jar(build_output_dir: pathlib.Path, - jar_path: pathlib.Path) -> List[str]: +def extract_full_class_names_from_jar( + jar_path: Union[str, pathlib.Path]) -> List[str]: """Returns set of fully qualified class names in passed-in jar.""" - - cache_file = CacheFile(jar_path=jar_path, - cache_suffix='.class_name_cache', - build_output_dir=build_output_dir) - if cache_file.is_valid(): - return cache_file.read().splitlines() - out = set() with zipfile.ZipFile(jar_path) as z: for zip_entry_name in z.namelist(): @@ -161,10 +77,7 @@ def extract_full_class_names_from_jar(build_output_dir: pathlib.Path, full_java_class = full_java_class[0:dollar_index] out.add(full_java_class) - out = sorted(out) - - cache_file.write('\n'.join(out)) - return out + return sorted(out) def parse_full_java_class(source_path: pathlib.Path) -> str: diff --git a/chromium/build/android/gyp/write_build_config.py b/chromium/build/android/gyp/write_build_config.py index 7976dd89cc7..3565329d355 100755 --- a/chromium/build/android/gyp/write_build_config.py +++ b/chromium/build/android/gyp/write_build_config.py @@ -437,12 +437,6 @@ into the final APK as-is. NOTE: This has nothing to do with *Android* resources. -* `deps_info['jni_all_source']` -The list of all `deps_info['target_sources_file']` entries for all library -dependencies for this APK. Note: this is a list of files, where each file -contains a list of Java and Kotlin source files. This is used for JNI -registration. - * `deps_info['proguard_all_configs']`: The collection of all 'deps_info['proguard_configs']` values from this target and all its dependencies. @@ -1473,19 +1467,6 @@ def main(argv): if options.r_text_path: deps_info['r_text_path'] = options.r_text_path - # TODO(tiborg): Remove creation of JNI info for type group and java_library - # once we can generate the JNI registration based on APK / module targets as - # opposed to groups and libraries. - if is_apk_or_module_target or options.type in ('group', 'java_library', - 'robolectric_binary', - 'dist_aar'): - all_target_sources = [ - c['target_sources_file'] for c in all_library_deps - if 'target_sources_file' in c - ] - if options.target_sources_file: - all_target_sources.append(options.target_sources_file) - if is_apk_or_module_target or options.type in ('group', 'java_library', 'robolectric_binary'): if options.apk_proto_resources: @@ -1822,7 +1803,6 @@ def main(argv): 'device_classpath', 'trace_event_rewritten_device_classpath', 'all_dex_files' ] - jni_all_source = set() lint_aars = set() lint_srcjars = set() lint_sources = set() @@ -1843,7 +1823,6 @@ def main(argv): deps_info['lint_android_manifest'] = c['android_manifest'] else: lint_extra_android_manifests.add(c['android_manifest']) - jni_all_source.update(c['jni_all_source']) lint_aars.update(c['lint_aars']) lint_srcjars.update(c['lint_srcjars']) lint_sources.update(c['lint_sources']) @@ -1853,7 +1832,6 @@ def main(argv): for f in per_module_fields: if f in c: module[f] = c[f] - deps_info['jni_all_source'] = sorted(jni_all_source) deps_info['lint_aars'] = sorted(lint_aars) deps_info['lint_srcjars'] = sorted(lint_srcjars) deps_info['lint_sources'] = sorted(lint_sources) @@ -1865,11 +1843,6 @@ def main(argv): _DedupFeatureModuleSharedCode(options.uses_split, modules, per_module_fields) - if is_apk_or_module_target or options.type in ('group', 'java_library', - 'robolectric_binary', - 'dist_aar'): - deps_info['jni_all_source'] = sorted(set(all_target_sources)) - system_jars = [c['unprocessed_jar_path'] for c in system_library_deps] system_interface_jars = [c['interface_jar_path'] for c in system_library_deps] if system_library_deps: @@ -2173,7 +2146,6 @@ def main(argv): RemoveObjDups(config, ancestor, 'deps_info', 'dependency_zips') RemoveObjDups(config, ancestor, 'deps_info', 'dependency_zip_overlays') RemoveObjDups(config, ancestor, 'deps_info', 'extra_package_names') - RemoveObjDups(config, ancestor, 'deps_info', 'jni_all_source') RemoveObjDups(config, ancestor, 'extra_android_manifests') if is_java_target: diff --git a/chromium/build/android/gyp/write_native_libraries_java.py b/chromium/build/android/gyp/write_native_libraries_java.py index e96dabc29f8..167f8dd25ea 100755 --- a/chromium/build/android/gyp/write_native_libraries_java.py +++ b/chromium/build/android/gyp/write_native_libraries_java.py @@ -38,6 +38,10 @@ public class NativeLibraries {{ public static {MAYBE_FINAL}String[] LIBRARIES = {{{LIBRARIES}}}; public static {MAYBE_FINAL}int sCpuFamily = {CPU_FAMILY}; + + public static {MAYBE_FINAL}boolean sSupport32Bit{SUPPORT_32_BIT}; + + public static {MAYBE_FINAL}boolean sSupport64Bit{SUPPORT_64_BIT}; }} """ @@ -76,6 +80,12 @@ def main(): parser.add_argument( '--output', required=True, help='Path to the generated srcjar file.') + parser.add_argument('--native-lib-32-bit', + action='store_true', + help='32-bit binaries.') + parser.add_argument('--native-lib-64-bit', + action='store_true', + help='64-bit binaries.') options = parser.parse_args(build_utils.ExpandFileArgs(sys.argv[1:])) @@ -105,6 +115,8 @@ def main(): 'USE_LINKER': bool_str(options.enable_chromium_linker), 'LIBRARIES': ','.join(_FormatLibraryName(n) for n in native_libraries), 'CPU_FAMILY': options.cpu_family, + 'SUPPORT_32_BIT': bool_str(options.native_lib_32_bit), + 'SUPPORT_64_BIT': bool_str(options.native_lib_64_bit), } with action_helpers.atomic_output(options.output) as f: with zipfile.ZipFile(f.name, 'w') as srcjar_file: |