Commit 4eb18a55 authored by agrieve's avatar agrieve Committed by Commit bot

Fix android depfiles to always list GN's outputs[0]

Ninja complains with:
expected depfile 'foo.d' to mention 'bar', got 'baz'

Running ninja twice now reports "no work to do" again.

This change required updating all calls to build_utils.WriteDepFile() so
that the output is passed in. While doing this, I also made the helper
add in GetPythonDependencies() by default.

build/android/gyp/ant.py I just deleted rather than updating since it's
GYP-only.

BUG=646165

Review-Url: https://codereview.chromium.org/2336173003
Cr-Commit-Position: refs/heads/master@{#418455}
parent e226eff5
......@@ -1379,9 +1379,7 @@ See SampleForTests.java for more details.
GenerateJNIHeader(input_file, output_file, options)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
build_utils.GetPythonDependencies())
build_utils.WriteDepfile(options.depfile, output_file)
if __name__ == '__main__':
......
......@@ -21,7 +21,6 @@ if (enable_java_templates) {
script = "//build/android/gyp/find_sun_tools_jar.py"
depfile = "$target_gen_dir/$target_name.d"
outputs = [
depfile,
sun_tools_jar_path,
]
args = [
......
......@@ -105,10 +105,8 @@ def main():
print
else:
if args.depfile:
build_utils.WriteDepfile(
args.depfile,
build_utils.GetPythonDependencies() + args.auxclasspath
+ args.jar_paths)
deps = args.auxclasspath + args.jar_paths
build_utils.WriteDepfile(args.depfile, args.output_file, deps)
if args.stamp:
build_utils.Touch(args.stamp)
......
......@@ -34,9 +34,7 @@ def main():
build_utils.DoZip(inputs, output, base_dir)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
build_utils.GetPythonDependencies())
build_utils.WriteDepfile(options.depfile, output)
if __name__ == '__main__':
......
......@@ -53,9 +53,7 @@ def main(argv):
srcjar.writestr(arcname, data)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
build_utils.GetPythonDependencies())
build_utils.WriteDepfile(options.depfile, options.srcjar)
if __name__ == '__main__':
......
#!/usr/bin/env python
#
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""An Ant wrapper that suppresses useless Ant output.
Ant build scripts output "BUILD SUCCESSFUL" and build timing at the end of
every build. In the Android build, this just adds a lot of useless noise to the
build output. This script forwards its arguments to ant, and prints Ant's
output up until the BUILD SUCCESSFUL line.
Also, when a command fails, this script will re-run that ant command with the
'-verbose' argument so that the failure is easier to debug.
"""
import optparse
import sys
import traceback
from util import build_utils
def main(argv):
option_parser = optparse.OptionParser()
build_utils.AddDepfileOption(option_parser)
options, args = option_parser.parse_args(argv[1:])
try:
stdout = build_utils.CheckOutput(['ant'] + args)
except build_utils.CalledProcessError:
# It is very difficult to diagnose ant failures without the '-verbose'
# argument. So, when an ant command fails, re-run it with '-verbose' so that
# the cause of the failure is easier to identify.
verbose_args = ['-verbose'] + [a for a in args if a != '-quiet']
try:
stdout = build_utils.CheckOutput(['ant'] + verbose_args)
except build_utils.CalledProcessError:
traceback.print_exc()
sys.exit(1)
# If this did sys.exit(1), building again would succeed (which would be
# awkward). Instead, just print a big warning.
build_utils.PrintBigWarning(
'This is unexpected. `ant ' + ' '.join(args) + '` failed.' +
'But, running `ant ' + ' '.join(verbose_args) + '` passed.')
stdout = stdout.strip().split('\n')
for line in stdout:
if line.strip() == 'BUILD SUCCESSFUL':
break
print line
if options.depfile:
assert '-buildfile' in args
ant_buildfile = args[args.index('-buildfile') + 1]
build_utils.WriteDepfile(
options.depfile,
[ant_buildfile] + build_utils.GetPythonDependencies())
if __name__ == '__main__':
sys.exit(main(sys.argv))
......@@ -104,9 +104,8 @@ def main(args):
DoRenaming(options, deps)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
deps + build_utils.GetPythonDependencies())
assert options.stamp
build_utils.WriteDepfile(options.depfile, options.stamp, deps)
if options.stamp:
build_utils.Touch(options.stamp)
......
......@@ -27,9 +27,7 @@ def main(args):
build_utils.MergeZips(options.output, input_jars)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
input_jars + build_utils.GetPythonDependencies())
build_utils.WriteDepfile(options.depfile, options.output, input_jars)
if __name__ == '__main__':
......
......@@ -110,9 +110,7 @@ def main(argv):
os.chmod(options.output, 0750)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
build_utils.GetPythonDependencies())
build_utils.WriteDepfile(options.depfile, options.output)
if __name__ == '__main__':
......
......@@ -123,9 +123,7 @@ def main(args):
os.chmod(args.script_output_path, 0750)
if args.depfile:
build_utils.WriteDepfile(
args.depfile,
build_utils.GetPythonDependencies())
build_utils.WriteDepfile(args.depfile, args.script_output_path)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
......@@ -100,8 +100,7 @@ def _RunCopyCommand(_command, options, _, option_parser):
build_utils.Touch(options.stamp)
if options.depfile:
build_utils.WriteDepfile(options.depfile,
build_utils.GetPythonDependencies())
build_utils.WriteDepfile(options.depfile, options.output_path)
def _GetSourceDirsFromSourceFiles(source_files):
......
......@@ -35,9 +35,7 @@ def main():
shutil.copyfile(sun_tools_jar_path, args.output)
if args.depfile:
build_utils.WriteDepfile(
args.depfile,
[sun_tools_jar_path] + build_utils.GetPythonDependencies())
build_utils.WriteDepfile(args.depfile, args.output, [sun_tools_jar_path])
def FindSunToolsJarPath():
......
......@@ -46,9 +46,7 @@ def main(args):
DoGcc(options)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
build_utils.GetPythonDependencies())
build_utils.WriteDepfile(options.depfile, options.output)
if options.stamp:
build_utils.Touch(options.stamp)
......
......@@ -88,9 +88,8 @@ def main():
f.write(split_manifest)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
[options.main_manifest] + build_utils.GetPythonDependencies())
deps = [options.main_manifest]
build_utils.WriteDepfile(options.depfile, options.out_manifest, deps)
if __name__ == '__main__':
......
......@@ -107,17 +107,10 @@ def main():
options, _ = parser.parse_args()
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
build_utils.GetPythonDependencies())
DoJarToc(options)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
build_utils.GetPythonDependencies())
build_utils.WriteDepfile(options.depfile, options.toc_path)
if options.stamp:
build_utils.Touch(options.stamp)
......
......@@ -340,78 +340,27 @@ ${ENUM_ENTRIES}
return template.substitute(values)
def AssertFilesList(output_paths, assert_files_list):
actual = set(output_paths)
expected = set(assert_files_list)
if not actual == expected:
need_to_add = list(actual - expected)
need_to_remove = list(expected - actual)
raise Exception('Output files list does not match expectations. Please '
'add %s and remove %s.' % (need_to_add, need_to_remove))
def DoMain(argv):
usage = 'usage: %prog [options] [output_dir] input_file(s)...'
parser = optparse.OptionParser(usage=usage)
build_utils.AddDepfileOption(parser)
parser.add_option('--assert_file', action="append", default=[],
dest="assert_files_list", help='Assert that the given '
'file is an output. There can be multiple occurrences of '
'this flag.')
parser.add_option('--srcjar',
help='When specified, a .srcjar at the given path is '
'created instead of individual .java files.')
parser.add_option('--print_output_only', help='Only print output paths.',
action='store_true')
parser.add_option('--verbose', help='Print more information.',
action='store_true')
options, args = parser.parse_args(argv)
if options.srcjar:
if not args:
parser.error('Need to specify at least one input file')
input_paths = args
else:
if len(args) < 2:
parser.error(
'Need to specify output directory and at least one input file')
output_dir = args[0]
input_paths = args[1:]
if not args:
parser.error('Need to specify at least one input file')
input_paths = args
if options.depfile:
python_deps = build_utils.GetPythonDependencies()
build_utils.WriteDepfile(options.depfile, input_paths + python_deps)
if options.srcjar:
if options.print_output_only:
parser.error('--print_output_only does not work with --srcjar')
if options.assert_files_list:
parser.error('--assert_file does not work with --srcjar')
with zipfile.ZipFile(options.srcjar, 'w', zipfile.ZIP_STORED) as srcjar:
for output_path, data in DoGenerate(input_paths):
build_utils.AddToZipHermetic(srcjar, output_path, data=data)
else:
# TODO(agrieve): Delete this non-srcjar branch once GYP is gone.
output_paths = []
with zipfile.ZipFile(options.srcjar, 'w', zipfile.ZIP_STORED) as srcjar:
for output_path, data in DoGenerate(input_paths):
full_path = os.path.join(output_dir, output_path)
output_paths.append(full_path)
if not options.print_output_only:
build_utils.MakeDirectory(os.path.dirname(full_path))
with open(full_path, 'w') as out_file:
out_file.write(data)
if options.assert_files_list:
AssertFilesList(output_paths, options.assert_files_list)
if options.verbose:
print 'Output paths:'
print '\n'.join(output_paths)
# Used by GYP.
return ' '.join(output_paths)
build_utils.AddToZipHermetic(srcjar, output_path, data=data)
if options.depfile:
build_utils.WriteDepfile(options.depfile, options.srcjar)
if __name__ == '__main__':
......
......@@ -128,8 +128,9 @@ def main():
options.outputs_zip)
if options.depfile:
deps = processor.GetLoadedTemplates() + build_utils.GetPythonDependencies()
build_utils.WriteDepfile(options.depfile, deps)
output = options.output or options.outputs_zip
deps = processor.GetLoadedTemplates()
build_utils.WriteDepfile(options.depfile, output, deps)
if __name__ == '__main__':
......
......@@ -96,8 +96,8 @@ def main():
sources = build_utils.ParseGnList(options.locale_paks)
if options.depfile:
deps = sources + build_utils.GetPythonDependencies()
build_utils.WriteDepfile(options.depfile, deps)
assert options.resources_zip
build_utils.WriteDepfile(options.depfile, options.resources_zip, sources)
mappings, lang_to_locale_map = ComputeMappings(sources)
if options.print_languages:
......
......@@ -90,11 +90,10 @@ def main(args):
if options.filelistjson:
build_utils.WriteJson({ 'files': output_paths }, options.filelistjson)
output_paths.append(options.filelistjson)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
libraries + build_utils.GetPythonDependencies())
build_utils.WriteDepfile(options.depfile, output_paths[-1], libraries)
if options.stamp:
build_utils.Touch(options.stamp)
......
......@@ -423,12 +423,17 @@ def AddDepfileOption(parser):
help='Path to depfile. Must be specified as the action\'s first output.')
def WriteDepfile(path, dependencies):
MakeDirectory(os.path.dirname(path))
with open(path, 'w') as depfile:
depfile.write(path)
def WriteDepfile(depfile_path, first_gn_output, inputs=None, add_pydeps=True):
assert depfile_path != first_gn_output # http://crbug.com/646165
inputs = inputs or []
if add_pydeps:
inputs = GetPythonDependencies() + inputs
MakeDirectory(os.path.dirname(depfile_path))
# Ninja does not support multiple outputs in depfiles.
with open(depfile_path, 'w') as depfile:
depfile.write(first_gn_output.replace(' ', '\\ '))
depfile.write(': ')
depfile.write(' '.join(dependencies))
depfile.write(' '.join(i.replace(' ', '\\ ') for i in inputs))
depfile.write('\n')
......@@ -524,7 +529,8 @@ def CallAndWriteDepfileIfStale(function, options, record_path=None,
all_depfile_deps = list(python_deps)
if depfile_deps:
all_depfile_deps.extend(depfile_deps)
WriteDepfile(options.depfile, all_depfile_deps)
WriteDepfile(options.depfile, output_paths[0], all_depfile_deps,
add_pydeps=False)
if stamp_file:
Touch(stamp_file)
......
......@@ -337,7 +337,7 @@ def main(argv):
options.type)
deps = Deps(direct_deps_config_paths)
all_inputs = deps.AllConfigPaths() + build_utils.GetPythonDependencies()
all_inputs = deps.AllConfigPaths()
# Remove other locale resources if there is alternative_locale_resource in
# direct deps.
......@@ -662,7 +662,7 @@ def main(argv):
build_utils.WriteJson(config, options.build_config, only_if_changed=True)
if options.depfile:
build_utils.WriteDepfile(options.depfile, all_inputs)
build_utils.WriteDepfile(options.depfile, options.build_config, all_inputs)
if __name__ == '__main__':
......
......@@ -133,9 +133,7 @@ def main():
build_utils.Touch(options.stamp)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
libraries + build_utils.GetPythonDependencies())
build_utils.WriteDepfile(options.depfile, options.output, libraries)
if __name__ == '__main__':
......
......@@ -151,9 +151,7 @@ def main(args):
os.chmod(options.script_output_path, 0750)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
build_utils.GetPythonDependencies())
build_utils.WriteDepfile(options.depfile, options.script_output_path)
if __name__ == '__main__':
......
......@@ -101,9 +101,8 @@ def main():
f.write(new_manifest_data)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
[options.src_manifest] + build_utils.GetPythonDependencies())
deps = [options.src_manifest]
build_utils.WriteDepfile(options.depfile, options.out_manifest, deps)
if __name__ == '__main__':
......
......@@ -692,8 +692,8 @@ if (enable_java_templates) {
]
outputs = [
_config_path,
_result_path,
_config_path,
]
args = [
......
......@@ -21,7 +21,6 @@ template("zip") {
depfile = "$target_gen_dir/$target_name.d"
inputs = invoker.inputs
outputs = [
depfile,
invoker.output,
]
......
......@@ -57,9 +57,9 @@ def main(argv):
build_utils.ZipDir(options.srcjar, temp_dir)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
args + [options.protoc] + build_utils.GetPythonDependencies())
assert options.srcjar
deps = args + [options.protoc]
build_utils.WriteDepfile(options.depfile, options.srcjar, deps)
if options.stamp:
build_utils.Touch(options.stamp)
......
......@@ -763,8 +763,10 @@ action("extract_cronet_jars") {
"$root_out_dir/lib.java/net/android/net_java.jar",
"$root_out_dir/lib.java/url/url_java.jar",
]
_stamp_file = "$target_gen_dir/$target_name.stamp"
outputs = [
depfile,
_stamp_file,
]
_rebased_sources = rebase_path(sources, root_build_dir)
......@@ -775,6 +777,8 @@ action("extract_cronet_jars") {
"--jars=${_rebased_sources}",
"--depfile",
rebase_path(depfile, root_build_dir),
"--stamp",
rebase_path(_stamp_file, root_build_dir),
]
deps = [
......@@ -872,8 +876,9 @@ action("generate_licenses") {
action("generate_javadoc") {
script = "//components/cronet/tools/generate_javadoc.py"
depfile = "$target_gen_dir/$target_name.d"
_stamp_file = "$target_gen_dir/$target_name.stamp"
outputs = [
depfile,
_stamp_file,
]
args = [
"--output-dir",
......@@ -886,6 +891,8 @@ action("generate_javadoc") {
rebase_path("//components/cronet/README.md", root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
"--stamp",
rebase_path(_stamp_file, root_build_dir),
"--lib-java-dir",
rebase_path("$root_build_dir/lib.java/components/cronet/android",
root_build_dir),
......
......@@ -40,8 +40,8 @@ def main():
ExtractJars(options)
if options.depfile:
build_utils.WriteDepfile(options.depfile,
build_utils.GetPythonDependencies())
assert options.stamp
build_utils.WriteDepfile(options.depfile, options.stamp)
if options.stamp:
build_utils.Touch(options.stamp)
......
......@@ -57,6 +57,7 @@ def main():
parser.add_option('--overview-file', help='Path of the overview page')
parser.add_option('--readme-file', help='Path of the README.md')
parser.add_option('--lib-java-dir', help='Directory containing java libs')
parser.add_option('--stamp', help='Path to touch on success.')
options, _ = parser.parse_args()
# A temporary directory to put the output of cronet api source jar files.
......@@ -72,12 +73,14 @@ def main():
GenerateJavadoc(options, os.path.abspath(unzipped_jar_path))
if options.stamp:
build_utils.Touch(options.stamp)
if options.depfile:
input_paths = []
assert options.stamp
deps = []
for root, _, filenames in os.walk(options.input_dir):
input_paths.extend(os.path.join(root, f) for f in filenames)
build_utils.WriteDepfile(options.depfile,
input_paths + build_utils.GetPythonDependencies())
deps.extend(os.path.join(root, f) for f in filenames)
build_utils.WriteDepfile(options.depfile, options.stamp, deps)
# Clean up temporary output directory.
build_utils.DeleteDirectory(unzipped_jar_path)
......
......@@ -71,12 +71,12 @@ def main():
JarSources(src_dir, options.jar_path)
if options.depfile:
input_paths = []
deps = []
for src_dir in src_dirs:
for root, _, filenames in os.walk(src_dir):
input_paths.extend(os.path.join(root, f) for f in filenames)
build_utils.WriteDepfile(options.depfile,
input_paths + build_utils.GetPythonDependencies())
deps.extend(os.path.join(root, f) for f in filenames)
build_utils.WriteDepfile(options.depfile, options.jar_path, deps)
# Clean up temporary output directory.
if unzipped_jar_path:
build_utils.DeleteDirectory(unzipped_jar_path)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment