diff options
author | 2018-04-27 21:25:43 -0700 | |
---|---|---|
committer | 2018-04-27 21:26:46 -0700 | |
commit | 1b672c2d15cea87e525faace615e1eb1fd6851fa (patch) | |
tree | b16e37b215f5bbda4fdb37b820044a2dc1b35ce1 | |
parent | 15933a7a2dce343043d9f123a50f788120c9e849 (diff) |
Adding a check to verify the usage of the migration tag for the Skylark
migration, when a flag is enabled.
RELNOTES:
PiperOrigin-RevId: 194630925
11 files changed, 116 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImport.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImport.java index 9761c3b2eb..debb555b30 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImport.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImport.java @@ -20,6 +20,6 @@ import com.google.devtools.build.lib.rules.android.AarImport; /** Implementation of {@code aar_import} with Bazel semantics. */ public class BazelAarImport extends AarImport { public BazelAarImport() { - super(BazelJavaSemantics.INSTANCE); + super(BazelJavaSemantics.INSTANCE, BazelAndroidMigrationSemantics.INSTANCE); } } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinary.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinary.java index 5d9183b8d0..632d390b06 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinary.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinary.java @@ -16,6 +16,7 @@ package com.google.devtools.build.lib.bazel.rules.android; import com.google.devtools.build.lib.bazel.rules.cpp.BazelCppSemantics; import com.google.devtools.build.lib.bazel.rules.java.BazelJavaSemantics; import com.google.devtools.build.lib.rules.android.AndroidBinary; +import com.google.devtools.build.lib.rules.android.AndroidMigrationSemantics; import com.google.devtools.build.lib.rules.android.AndroidSemantics; import com.google.devtools.build.lib.rules.cpp.CppSemantics; import com.google.devtools.build.lib.rules.java.JavaSemantics; @@ -35,6 +36,11 @@ public class BazelAndroidBinary extends AndroidBinary { } @Override + protected AndroidMigrationSemantics createAndroidMigrationSemantics() { + return BazelAndroidMigrationSemantics.INSTANCE; + } + + @Override protected CppSemantics createCppSemantics() { return BazelCppSemantics.INSTANCE; } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidLibrary.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidLibrary.java index a30889652a..a51e9c4ea2 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidLibrary.java @@ -16,6 +16,7 @@ package com.google.devtools.build.lib.bazel.rules.android; import com.google.devtools.build.lib.bazel.rules.java.BazelJavaSemantics; import com.google.devtools.build.lib.rules.android.AndroidLibrary; +import com.google.devtools.build.lib.rules.android.AndroidMigrationSemantics; import com.google.devtools.build.lib.rules.android.AndroidSemantics; import com.google.devtools.build.lib.rules.java.JavaSemantics; @@ -33,4 +34,9 @@ public class BazelAndroidLibrary extends AndroidLibrary { protected AndroidSemantics createAndroidSemantics() { return BazelAndroidSemantics.INSTANCE; } + + @Override + protected AndroidMigrationSemantics createAndroidMigrationSemantics() { + return BazelAndroidMigrationSemantics.INSTANCE; + } } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidLocalTest.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidLocalTest.java index 7906fcc10c..06b6d308a8 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidLocalTest.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidLocalTest.java @@ -23,6 +23,7 @@ import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.bazel.rules.java.BazelJavaSemantics; import com.google.devtools.build.lib.rules.android.AndroidLocalTestBase; +import com.google.devtools.build.lib.rules.android.AndroidMigrationSemantics; import com.google.devtools.build.lib.rules.android.AndroidSemantics; import com.google.devtools.build.lib.rules.java.JavaCommon; import com.google.devtools.build.lib.rules.java.JavaCompilationArtifacts.Builder; @@ -42,6 +43,11 @@ public class BazelAndroidLocalTest extends AndroidLocalTestBase { } @Override + protected AndroidMigrationSemantics createAndroidMigrationSemantics() { + return BazelAndroidMigrationSemantics.INSTANCE; + } + + @Override protected JavaSemantics createJavaSemantics() { return BazelJavaSemantics.INSTANCE; } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidMigrationSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidMigrationSemantics.java new file mode 100644 index 0000000000..42e74c78ff --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidMigrationSemantics.java @@ -0,0 +1,32 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.bazel.rules.android; + +import com.google.devtools.build.lib.analysis.RuleContext; +import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; +import com.google.devtools.build.lib.rules.android.AndroidMigrationSemantics; + +/** + * Implementation of Bazel-specific behavior in Android rules migration. + */ +public class BazelAndroidMigrationSemantics implements AndroidMigrationSemantics { + public static final BazelAndroidMigrationSemantics INSTANCE = + new BazelAndroidMigrationSemantics(); + + private BazelAndroidMigrationSemantics() {} + + @Override + public void validateRuleContext(RuleContext ruleContext) throws RuleErrorException { + } +} diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AarImport.java b/src/main/java/com/google/devtools/build/lib/rules/android/AarImport.java index a85c74191a..056bc8a537 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AarImport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AarImport.java @@ -61,14 +61,18 @@ public class AarImport implements RuleConfiguredTargetFactory { private static final String MERGED_JAR = "classes_and_libs_merged.jar"; private final JavaSemantics javaSemantics; + private final AndroidMigrationSemantics androidMigrationSemantics; - protected AarImport(JavaSemantics javaSemantics) { + protected AarImport( + JavaSemantics javaSemantics, AndroidMigrationSemantics androidMigrationSemantics) { this.javaSemantics = javaSemantics; + this.androidMigrationSemantics = androidMigrationSemantics; } @Override public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException, ActionConflictException { + androidMigrationSemantics.validateRuleContext(ruleContext); AndroidSdkProvider.verifyPresence(ruleContext); RuleConfiguredTargetBuilder ruleBuilder = new RuleConfiguredTargetBuilder(ruleContext); 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 3f246766a0..69f8452b6f 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 @@ -93,6 +93,8 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { protected abstract CppSemantics createCppSemantics(); + protected abstract AndroidMigrationSemantics createAndroidMigrationSemantics(); + @Override public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException, ActionConflictException { @@ -100,6 +102,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { JavaSemantics javaSemantics = createJavaSemantics(); AndroidSemantics androidSemantics = createAndroidSemantics(); androidSemantics.validateAndroidBinaryRuleContext(ruleContext); + createAndroidMigrationSemantics().validateRuleContext(ruleContext); AndroidSdkProvider.verifyPresence(ruleContext); NestedSetBuilder<Artifact> filesBuilder = NestedSetBuilder.stableOrder(); 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 0a2fd839ed..256d749b77 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 @@ -808,6 +808,17 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { ) public boolean enforceStrictDepsForBinariesUnderTest; + @Option( + name = "android_migration_tag_check", + defaultValue = "false", + documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, + effectTags = { + OptionEffectTag.EAGERNESS_TO_EXIT, + }, + help = "If enabled, strict usage of the Skylark migration tag is enabled for android rules." + ) + public boolean checkForMigrationTag; + @Override public FragmentOptions getHost() { Options host = (Options) super.getHost(); @@ -888,6 +899,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { private final AndroidRobolectricTestDeprecationLevel robolectricTestDeprecationLevel; private final boolean decoupleDataProcessing; private final boolean enforceStrictDepsForBinariesUnderTest; + private final boolean checkForMigrationTag; AndroidConfiguration(Options options) throws InvalidConfigurationException { this.sdk = options.sdk; @@ -927,6 +939,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { this.robolectricTestDeprecationLevel = options.robolectricTestDeprecationLevel; this.decoupleDataProcessing = options.decoupleDataProcessing; this.enforceStrictDepsForBinariesUnderTest = options.enforceStrictDepsForBinariesUnderTest; + this.checkForMigrationTag = options.checkForMigrationTag; if (incrementalDexingShardsAfterProguard < 0) { throw new InvalidConfigurationException( @@ -978,7 +991,8 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { boolean fixedResourceNeverlinking, AndroidRobolectricTestDeprecationLevel robolectricTestDeprecationLevel, boolean decoupleDataProcessing, - boolean enforceStrictDepsForBinariesUnderTest) { + boolean enforceStrictDepsForBinariesUnderTest, + boolean checkForMigrationTag) { this.sdk = sdk; this.cpu = cpu; this.useIncrementalNativeLibs = useIncrementalNativeLibs; @@ -1013,6 +1027,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { this.robolectricTestDeprecationLevel = robolectricTestDeprecationLevel; this.decoupleDataProcessing = decoupleDataProcessing; this.enforceStrictDepsForBinariesUnderTest = enforceStrictDepsForBinariesUnderTest; + this.checkForMigrationTag = checkForMigrationTag; } public String getCpu() { @@ -1168,6 +1183,10 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { return enforceStrictDepsForBinariesUnderTest; } + public boolean checkForMigrationTag() { + return checkForMigrationTag; + } + @Override public void addGlobalMakeVariables(ImmutableMap.Builder<String, String> globalMakeEnvBuilder) { globalMakeEnvBuilder.put("ANDROID_CPU", cpu); diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java index fffda808d9..df7601b51a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java @@ -43,6 +43,8 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory { protected abstract AndroidSemantics createAndroidSemantics(); + protected abstract AndroidMigrationSemantics createAndroidMigrationSemantics(); + /** Checks expected rule invariants, throws rule errors if anything is set wrong. */ private static void validateRuleContext(RuleContext ruleContext) throws InterruptedException, RuleErrorException { @@ -114,6 +116,7 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory { JavaSemantics javaSemantics = createJavaSemantics(); AndroidSemantics androidSemantics = createAndroidSemantics(); androidSemantics.validateAndroidLibraryRuleContext(ruleContext); + createAndroidMigrationSemantics().validateRuleContext(ruleContext); AndroidSdkProvider.verifyPresence(ruleContext); NestedSetBuilder<Aar> transitiveAars = NestedSetBuilder.naiveLinkOrder(); NestedSetBuilder<Artifact> transitiveAarArtifacts = NestedSetBuilder.stableOrder(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBase.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBase.java index f5527ba934..91e8f302e9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBase.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBase.java @@ -78,7 +78,7 @@ public abstract class AndroidLocalTestBase implements RuleConfiguredTargetFactor JavaSemantics javaSemantics = createJavaSemantics(); AndroidSemantics androidSemantics = createAndroidSemantics(); - + createAndroidMigrationSemantics().validateRuleContext(ruleContext); AndroidLocalTestConfiguration androidLocalTestConfiguration = ruleContext.getFragment(AndroidLocalTestConfiguration.class); @@ -555,6 +555,9 @@ public abstract class AndroidLocalTestBase implements RuleConfiguredTargetFactor /** Get AndroidSemantics */ protected abstract AndroidSemantics createAndroidSemantics(); + /** Get AndroidMigrationSemantics */ + protected abstract AndroidMigrationSemantics createAndroidMigrationSemantics(); + /** Set test and robolectric specific jvm flags */ protected abstract ImmutableList<String> getJvmFlags(RuleContext ruleContext, String testClass) throws RuleErrorException; diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidMigrationSemantics.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidMigrationSemantics.java new file mode 100644 index 0000000000..2097a4b3bd --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidMigrationSemantics.java @@ -0,0 +1,30 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.rules.android; + +import com.google.devtools.build.lib.analysis.RuleContext; +import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; + +/** + * Pluggable semantics for Android rules migration. + */ +public interface AndroidMigrationSemantics { + + /** + * Validates the {@link RuleContext} against common migration checks. + * + * @throws RuleErrorException + */ + public void validateRuleContext(RuleContext ruleContext) throws RuleErrorException; +} |