From 8adc3cd78c299dd7125b754b5fd4048420ccffb8 Mon Sep 17 00:00:00 2001 From: agrieve Date: Thu, 28 Jul 2016 21:26:20 -0700 Subject: [PATCH] Fail write_build_config.py if current_toolchain != default_toolchain There are a few spots in the Android templates that assume appending __build_config to a given target label will result in the label for a write_build_config action. When toolchains exist in a label, appending like this doesn't work. E.g.: :some_label(//toolchain)__build_config Previously, we added a GN assert to enforce default toolchain, but that was too strict, as it made it so no other targets that are defined in the same BUILD.gn file could use a non-default toolchain. This change make the error a build-time error rather than a gn gen error. BUG=629371 Review-Url: https://codereview.chromium.org/2161063003 Cr-Original-Commit-Position: refs/heads/master@{#408576} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 83bcd862038586061feea4b390ac524ab0a9a358 --- android/gyp/write_build_config.py | 4 ++++ config/android/internal_rules.gni | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/android/gyp/write_build_config.py b/android/gyp/write_build_config.py index 70bc6d081..18d76348f 100755 --- a/android/gyp/write_build_config.py +++ b/android/gyp/write_build_config.py @@ -279,11 +279,15 @@ def main(argv): help='Path to the proguard .info output for this apk.') parser.add_option('--has-alternative-locale-resource', action='store_true', help='Whether there is alternative-locale-resource in direct deps') + parser.add_option('--fail', + help='GYP-list of error message lines to fail with.') options, args = parser.parse_args(argv) if args: parser.error('No positional arguments should be given.') + if options.fail: + parser.error('\n'.join(build_utils.ParseGypList(options.fail))) required_options_map = { 'java_binary': ['build_config', 'jar_path'], diff --git a/config/android/internal_rules.gni b/config/android/internal_rules.gni index 194c494ff..23641507f 100644 --- a/config/android/internal_rules.gni +++ b/config/android/internal_rules.gni @@ -336,6 +336,25 @@ template("write_build_config") { rebase_path(invoker.bundled_srcjars, root_build_dir) args += [ "--bundled-srcjars=$_rebased_bundled_srcjars" ] } + if (current_toolchain != default_toolchain) { + # This has to be a built-time error rather than a GN assert because many + # packages have a mix of java and non-java targets. For example, the + # following would fail even though nothing depends on :bar(//baz): + # + # shared_library("foo") { + # } + # + # android_library("bar") { + # deps = [ ":foo(//baz)" ] + # assert(current_toolchain == default_toolchain) + # } + _msg = [ + "Tried to build an Android target in a non-default toolchain.", + "target: " + get_label_info(":$target_name", "label_with_toolchain"), + "default_toolchain: $default_toolchain", + ] + args += [ "--fail=$_msg" ] + } } }