Skip to content

Commit

Permalink
Android: Properly track GN .py inputs for actions in internal_rules.gni
Browse files Browse the repository at this point in the history
* Most templates use a hard-coded list of build_utils.py deps.
* A few use exec_script() when compute_inputs_for_analyze = true.

Bug: 843562
Change-Id: I0bb1ca7927f7366d23c23b8beb56d39a22208a06
Reviewed-on: https://chromium-review.googlesource.com/1114122
Commit-Queue: agrieve <agrieve@chromium.org>
Reviewed-by: Eric Stevenson <estevenson@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570811}
  • Loading branch information
agrieve authored and Commit Bot committed Jun 27, 2018
1 parent 46c6339 commit ce84d1c
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 164 deletions.
3 changes: 2 additions & 1 deletion build/android/gyp/apkbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ def copy_resource(zipinfo):
input_paths=input_paths + depfile_deps,
input_strings=input_strings,
output_paths=output_paths,
depfile_deps=depfile_deps)
depfile_deps=depfile_deps,
add_pydeps=False)


if __name__ == '__main__':
Expand Down
7 changes: 0 additions & 7 deletions build/android/gyp/bytecode_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def _AddSwitch(parser, val):
def main(argv):
argv = build_utils.ExpandFileArgs(argv[1:])
parser = argparse.ArgumentParser()
build_utils.AddDepfileOption(parser)
parser.add_argument('--script', required=True,
help='Path to the java binary wrapper script.')
parser.add_argument('--input-jar', required=True)
Expand All @@ -39,12 +38,6 @@ def main(argv):
args.enable_custom_resources] + extra_classpath_jars
build_utils.CheckOutput(cmd)

if args.depfile:
# Do not write classpath jars to depfile under the assumption that if
# the input jar has not changed, then bytecode rewriting will not have to
# be re-run.
build_utils.WriteDepfile(args.depfile, args.output_jar)


if __name__ == '__main__':
sys.exit(main(sys.argv))
4 changes: 2 additions & 2 deletions build/android/gyp/copy_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def main(args):
DoRenaming(options, deps)

if options.depfile:
assert options.stamp
build_utils.WriteDepfile(options.depfile, options.stamp, deps)
build_utils.WriteDepfile(
options.depfile, options.stamp, deps, add_pydeps=False)

if options.stamp:
build_utils.Touch(options.stamp)
Expand Down
4 changes: 0 additions & 4 deletions build/android/gyp/create_java_binary_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
def main(argv):
argv = build_utils.ExpandFileArgs(argv)
parser = optparse.OptionParser()
build_utils.AddDepfileOption(parser)
parser.add_option('--output', help='Output path for executable script.')
parser.add_option('--main-class',
help='Name of the java class with the "main" entry point.')
Expand Down Expand Up @@ -108,9 +107,6 @@ def main(argv):

os.chmod(options.output, 0750)

if options.depfile:
build_utils.WriteDepfile(options.depfile, options.output)


if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
4 changes: 0 additions & 4 deletions build/android/gyp/create_stack_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def main(argv):
def main(args):

parser = argparse.ArgumentParser()
build_utils.AddDepfileOption(parser)
parser.add_argument(
'--script-path',
help='Path to the wrapped script.')
Expand Down Expand Up @@ -74,9 +73,6 @@ def relativize(p):

os.chmod(args.script_output_path, 0750)

if args.depfile:
build_utils.WriteDepfile(args.depfile, args.script_output_path)

return 0


Expand Down
5 changes: 0 additions & 5 deletions build/android/gyp/create_test_runner_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ def main(args):
parser = argparse.ArgumentParser()
parser.add_argument('--script-output-path',
help='Output path for executable script.')
parser.add_argument('--depfile',
help='Path to the depfile. This must be specified as '
"the action's first output.")
parser.add_argument('--test-runner-path',
help='Path to test_runner.py (optional).')

Expand Down Expand Up @@ -164,8 +161,6 @@ def RelativizePathToScript(path):

os.chmod(args.script_output_path, 0750)

if args.depfile:
build_utils.WriteDepfile(args.depfile, args.script_output_path)

if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
56 changes: 19 additions & 37 deletions build/android/gyp/desugar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,11 @@
from util import build_utils


_DESUGAR_JAR_PATH = os.path.normpath(
os.path.join(build_utils.DIR_SOURCE_ROOT, 'third_party', 'bazel', 'desugar',
'Desugar.jar'))


def _OnStaleMd5(input_jar, output_jar, classpath, bootclasspath):
cmd = [
'java',
'-jar',
_DESUGAR_JAR_PATH,
'--input',
input_jar,
'--output',
output_jar,
# Don't include try-with-resources files in every .jar. Instead, they
# are included via //third_party/bazel/desugar:desugar_runtime_java.
'--desugar_try_with_resources_omit_runtime_classes',
]
for path in bootclasspath:
cmd += ['--bootclasspath_entry', path]
for path in classpath:
cmd += ['--classpath_entry', path]
build_utils.CheckOutput(cmd, print_stdout=False)


def main():
args = build_utils.ExpandFileArgs(sys.argv[1:])
parser = argparse.ArgumentParser()
build_utils.AddDepfileOption(parser)
parser.add_argument('--desugar-jar', required=True,
help='Path to Desugar.jar.')
parser.add_argument('--input-jar', required=True,
help='Jar input path to include .class files from.')
parser.add_argument('--output-jar', required=True,
Expand All @@ -52,18 +28,24 @@ def main():

options.bootclasspath = build_utils.ParseGnList(options.bootclasspath)
options.classpath = build_utils.ParseGnList(options.classpath)
input_paths = options.classpath + options.bootclasspath + [options.input_jar]
output_paths = [options.output_jar]
depfile_deps = options.classpath + [_DESUGAR_JAR_PATH]

build_utils.CallAndWriteDepfileIfStale(
lambda: _OnStaleMd5(options.input_jar, options.output_jar,
options.classpath, options.bootclasspath),
options,
input_paths=input_paths,
input_strings=[],
output_paths=output_paths,
depfile_deps=depfile_deps)
cmd = [
'java',
'-jar',
options.desugar_jar,
'--input',
options.input_jar,
'--output',
options.output_jar,
# Don't include try-with-resources files in every .jar. Instead, they
# are included via //third_party/bazel/desugar:desugar_runtime_java.
'--desugar_try_with_resources_omit_runtime_classes',
]
for path in options.bootclasspath:
cmd += ['--bootclasspath_entry', path]
for path in options.classpath:
cmd += ['--classpath_entry', path]
build_utils.CheckOutput(cmd, print_stdout=False)


if __name__ == '__main__':
Expand Down
3 changes: 2 additions & 1 deletion build/android/gyp/dex.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ def on_stale_md5_callback():
input_strings=dex_cmd,
output_paths=output_paths,
force=force,
depfile_deps=input_paths)
depfile_deps=input_paths,
add_pydeps=False)


if __name__ == '__main__':
Expand Down
10 changes: 0 additions & 10 deletions build/android/gyp/emma_instr.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

def _AddCommonOptions(option_parser):
"""Adds common options to |option_parser|."""
build_utils.AddDepfileOption(option_parser)
option_parser.add_option('--input-path',
help=('Path to input file(s). Either the classes '
'directory, or the path to a jar.'))
Expand Down Expand Up @@ -93,9 +92,6 @@ def _RunCopyCommand(_command, options, _, option_parser):

shutil.copy(options.input_path, options.output_path)

if options.depfile:
build_utils.WriteDepfile(options.depfile, options.output_path)


def _GetSourceDirsFromSourceFiles(source_files):
"""Returns list of directories for the files in |source_files|.
Expand Down Expand Up @@ -204,12 +200,6 @@ def _RunInstrumentCommand(_command, options, _, option_parser):
_CreateSourcesListFile(source_dirs, options.sources_list_file,
options.src_root)

if options.stamp:
build_utils.Touch(options.stamp)

if options.depfile:
build_utils.WriteDepfile(options.depfile, options.output_path)

return 0


Expand Down
3 changes: 2 additions & 1 deletion build/android/gyp/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ def main():
input_paths=input_paths,
input_strings=input_strings,
output_paths=output_paths,
depfile_deps=classpath)
depfile_deps=classpath,
add_pydeps=False)


if __name__ == '__main__':
Expand Down
33 changes: 16 additions & 17 deletions build/android/gyp/main_dex_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@
from util import build_utils
from util import proguard_util

sys.path.append(os.path.abspath(os.path.join(
os.path.dirname(__file__), os.pardir)))
from pylib import constants


def main(args):
parser = argparse.ArgumentParser()
build_utils.AddDepfileOption(parser)
parser.add_argument('--android-sdk-tools', required=True,
help='Android sdk build tools directory.')
parser.add_argument('--shrinked-android-path', required=True,
help='Path to shrinkedAndroid.jar')
parser.add_argument('--dx-path', required=True,
help='Path to dx.jar')
parser.add_argument('--main-dex-rules-path', action='append', default=[],
dest='main_dex_rules_paths',
help='A file containing a list of proguard rules to use '
Expand All @@ -46,28 +44,27 @@ def main(args):

args = parser.parse_args(build_utils.ExpandFileArgs(args))

depfile_deps = []
if args.inputs:
args.paths.extend(build_utils.ParseGnList(args.inputs))
args.inputs = build_utils.ParseGnList(args.inputs)
depfile_deps = args.inputs
args.paths.extend(args.inputs)

if args.negative_main_dex_globs:
args.negative_main_dex_globs = build_utils.ParseGnList(
args.negative_main_dex_globs)

shrinked_android_jar = os.path.abspath(
os.path.join(args.android_sdk_tools, 'lib', 'shrinkedAndroid.jar'))
dx_jar = os.path.abspath(
os.path.join(args.android_sdk_tools, 'lib', 'dx.jar'))

proguard_cmd = [
'java', '-jar', args.proguard_path,
'-forceprocessing',
'-dontwarn', '-dontoptimize', '-dontobfuscate', '-dontpreverify',
'-libraryjars', shrinked_android_jar,
'-libraryjars', args.shrinked_android_path,
]
for m in args.main_dex_rules_paths:
proguard_cmd.extend(['-include', m])

main_dex_list_cmd = [
'java', '-cp', dx_jar,
'java', '-cp', args.dx_path,
'com.android.multidex.MainDexListBuilder',
# This workaround significantly increases main dex size and doesn't seem to
# be needed by Chrome. See comment in the source:
Expand All @@ -77,8 +74,8 @@ def main(args):

input_paths = list(args.paths)
input_paths += [
shrinked_android_jar,
dx_jar,
args.shrinked_android_path,
args.dx_path,
]
input_paths += args.main_dex_rules_paths

Expand All @@ -100,7 +97,9 @@ def main(args):
args,
input_paths=input_paths,
input_strings=input_strings,
output_paths=output_paths)
output_paths=output_paths,
depfile_deps=depfile_deps,
add_pydeps=False)

return 0

Expand Down
8 changes: 7 additions & 1 deletion build/android/gyp/merge_jar_info_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def _MergeInfoFiles(output, jar_paths):
# allows us to later map these classes back to their respective src
# directories.
jar_info_path = jar_path + '.info'
# TODO(agrieve): This should probably also check that the mtime of the .info
# is newer than that of the .jar, or change prebuilts to always output
# .info files so that they always exist (and change the depfile to
# depend directly on them).
if os.path.exists(jar_info_path):
info_data.update(jar_info_utils.ParseJarInfoFile(jar_path + '.info'))
else:
Expand Down Expand Up @@ -86,7 +90,9 @@ def _OnStaleMd5():
build_utils.CallAndWriteDepfileIfStale(
_OnStaleMd5, options,
input_paths=jar_files,
output_paths=[options.output])
output_paths=[options.output],
depfile_deps=jar_files,
add_pydeps=False)


if __name__ == '__main__':
Expand Down
3 changes: 2 additions & 1 deletion build/android/gyp/merge_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def main(argv):
build_utils.IsTimeStale(args.output, [root_manifest] + extras))
if args.depfile:
inputs = extras + classpath.split(':')
build_utils.WriteDepfile(args.depfile, args.output, inputs=inputs)
build_utils.WriteDepfile(args.depfile, args.output, inputs=inputs,
add_pydeps=False)


if __name__ == '__main__':
Expand Down
3 changes: 2 additions & 1 deletion build/android/gyp/proguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def main(args):
input_paths=input_paths,
input_strings=input_strings,
output_paths=proguard.GetOutputs(),
depfile_deps=proguard.GetDepfileDeps())
depfile_deps=proguard.GetDepfileDeps(),
add_pydeps=False)


if __name__ == '__main__':
Expand Down
9 changes: 6 additions & 3 deletions build/android/gyp/util/build_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import tempfile
import zipfile

# Any new non-system import must be added to:
# //build/config/android/internal_rules.gni

# Some clients do not add //build/android/gyp to PYTHONPATH.
import md5_check # pylint: disable=relative-import

Expand Down Expand Up @@ -539,8 +542,8 @@ def ReadSourcesList(sources_list_file_name):
def CallAndWriteDepfileIfStale(function, options, record_path=None,
input_paths=None, input_strings=None,
output_paths=None, force=False,
pass_changes=False,
depfile_deps=None):
pass_changes=False, depfile_deps=None,
add_pydeps=True):
"""Wraps md5_check.CallAndRecordIfStale() and also writes dep & stamp files.
Depfiles and stamp files are automatically added to output_paths when present
Expand Down Expand Up @@ -572,7 +575,7 @@ def on_stale_md5(changes):
args = (changes,) if pass_changes else ()
function(*args)
if python_deps is not None:
all_depfile_deps = list(python_deps)
all_depfile_deps = list(python_deps) if add_pydeps else []
if depfile_deps:
all_depfile_deps.extend(depfile_deps)
WriteDepfile(options.depfile, output_paths[0], all_depfile_deps,
Expand Down
3 changes: 2 additions & 1 deletion build/android/gyp/write_build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,8 @@ def main(argv):
build_utils.WriteJson(config, options.build_config, only_if_changed=True)

if options.depfile:
build_utils.WriteDepfile(options.depfile, options.build_config, all_inputs)
build_utils.WriteDepfile(options.depfile, options.build_config, all_inputs,
add_pydeps=False) # pydeps listed in GN.


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit ce84d1c

Please sign in to comment.