aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/android
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2018-04-27 21:25:43 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-27 21:26:46 -0700
commit1b672c2d15cea87e525faace615e1eb1fd6851fa (patch)
treeb16e37b215f5bbda4fdb37b820044a2dc1b35ce1 /src/main/java/com/google/devtools/build/lib/rules/android
parent15933a7a2dce343043d9f123a50f788120c9e849 (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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/android')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AarImport.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java21
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBase.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidMigrationSemantics.java30
6 files changed, 65 insertions, 3 deletions
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;
+}