From 75b75c89fc3b0f5e0c68c0c4a7ca188e9d2ee205 Mon Sep 17 00:00:00 2001 From: cushon Date: Wed, 18 Apr 2018 15:42:36 -0700 Subject: Add a flag to enable strict deps for android_binary.binary_under_test PiperOrigin-RevId: 193429470 --- .../build/lib/rules/android/AndroidBinary.java | 6 +++++- .../lib/rules/android/AndroidConfiguration.java | 23 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java index 025bac06df..5c83c42df4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java @@ -109,7 +109,11 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { javaSemantics.checkForProtoLibraryAndJavaProtoLibraryOnSameProto(ruleContext, javaCommon); AndroidCommon androidCommon = - new AndroidCommon(javaCommon, /* asNeverLink= */ true, /* exportDeps= */ true); + new AndroidCommon( + javaCommon, + /* asNeverLink= */ true, + /* exportDeps= */ !AndroidCommon.getAndroidConfig(ruleContext) + .getEnforceStrictDepsForBinariesUnderTest()); ResourceDependencies resourceDeps = ResourceDependencies.fromRuleDeps(ruleContext, /* neverlink= */ false); RuleConfiguredTargetBuilder builder = diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java index e8249eb7fe..0a2fd839ed 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java @@ -147,7 +147,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { return signV1; } - /** Wheter to sign the APK with the apksigner tool with APK Signature Schema V2. */ + /** Whether to sign the APK with the apksigner tool with APK Signature Schema V2. */ public boolean signV2() { return signV2; } @@ -798,6 +798,16 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { + "when possible. Otherwise, they will all be processed together.") public boolean decoupleDataProcessing; + // TODO(cushon): make this the default, and delete it + @Option( + name = "experimental_android_enforce_strict_deps_for_binaries_under_test", + defaultValue = "false", + documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, + effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS}, + help = "If enabled, strict dependencies are enforced for android_test.binary_under_test" + ) + public boolean enforceStrictDepsForBinariesUnderTest; + @Override public FragmentOptions getHost() { Options host = (Options) super.getHost(); @@ -820,6 +830,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { host.manifestMerger = manifestMerger; host.androidAaptVersion = androidAaptVersion; host.allowAndroidLibraryDepsWithoutSrcs = allowAndroidLibraryDepsWithoutSrcs; + host.enforceStrictDepsForBinariesUnderTest = enforceStrictDepsForBinariesUnderTest; return host; } } @@ -876,6 +887,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { private final boolean fixedResourceNeverlinking; private final AndroidRobolectricTestDeprecationLevel robolectricTestDeprecationLevel; private final boolean decoupleDataProcessing; + private final boolean enforceStrictDepsForBinariesUnderTest; AndroidConfiguration(Options options) throws InvalidConfigurationException { this.sdk = options.sdk; @@ -914,6 +926,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { this.fixedResourceNeverlinking = options.fixedResourceNeverlinking; this.robolectricTestDeprecationLevel = options.robolectricTestDeprecationLevel; this.decoupleDataProcessing = options.decoupleDataProcessing; + this.enforceStrictDepsForBinariesUnderTest = options.enforceStrictDepsForBinariesUnderTest; if (incrementalDexingShardsAfterProguard < 0) { throw new InvalidConfigurationException( @@ -964,7 +977,8 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { boolean skipParsingAction, boolean fixedResourceNeverlinking, AndroidRobolectricTestDeprecationLevel robolectricTestDeprecationLevel, - boolean decoupleDataProcessing) { + boolean decoupleDataProcessing, + boolean enforceStrictDepsForBinariesUnderTest) { this.sdk = sdk; this.cpu = cpu; this.useIncrementalNativeLibs = useIncrementalNativeLibs; @@ -998,6 +1012,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { this.fixedResourceNeverlinking = fixedResourceNeverlinking; this.robolectricTestDeprecationLevel = robolectricTestDeprecationLevel; this.decoupleDataProcessing = decoupleDataProcessing; + this.enforceStrictDepsForBinariesUnderTest = enforceStrictDepsForBinariesUnderTest; } public String getCpu() { @@ -1149,6 +1164,10 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { return decoupleDataProcessing; } + public boolean getEnforceStrictDepsForBinariesUnderTest() { + return enforceStrictDepsForBinariesUnderTest; + } + @Override public void addGlobalMakeVariables(ImmutableMap.Builder globalMakeEnvBuilder) { globalMakeEnvBuilder.put("ANDROID_CPU", cpu); -- cgit v1.2.3