Add one version enforcement to android_robolectric_test
RELNOTES: add one-version enforcement to android_local_test
@@ -15,6 +15,7 @@ package com.google.devtools.build.lib.rules.android;
import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
import static com.google.devtools.build.lib.rules.java.DeployArchiveBuilder.Compression.COMPRESSED;
+import static com.google.devtools.build.lib.vfs.FileSystemUtils.replaceExtension;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
@@ -41,6 +42,8 @@ import com.google.devtools.build.lib.rules.java.JavaCommon;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider;
import com.google.devtools.build.lib.rules.java.JavaCompilationArtifacts;
import com.google.devtools.build.lib.rules.java.JavaCompilationHelper;
+import com.google.devtools.build.lib.rules.java.JavaConfiguration;
+import com.google.devtools.build.lib.rules.java.JavaConfiguration.OneVersionEnforcementLevel;
import com.google.devtools.build.lib.rules.java.JavaHelper;
import com.google.devtools.build.lib.rules.java.JavaPrimaryClassProvider;
import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider;
@@ -51,6 +54,7 @@ import com.google.devtools.build.lib.rules.java.JavaSkylarkApiProvider;
import com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider;
import com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider;
import com.google.devtools.build.lib.rules.java.JavaTargetAttributes;
+import com.google.devtools.build.lib.rules.java.OneVersionCheckActionBuilder;
import com.google.devtools.build.lib.rules.java.SingleJarActionBuilder;
import com.google.devtools.build.lib.rules.java.proto.GeneratedExtensionRegistryProvider;
import com.google.devtools.build.lib.syntax.Type;
@@ -173,6 +177,28 @@ public abstract class AndroidLocalTestBase implements RuleConfiguredTargetFactor
Artifact deployJar =
ruleContext.getImplicitOutputArtifact(JavaSemantics.JAVA_BINARY_DEPLOY_JAR);
+ OneVersionEnforcementLevel oneVersionEnforcementLevel =
+ ruleContext.getFragment(JavaConfiguration.class).oneVersionEnforcementLevel();
+ if (oneVersionEnforcementLevel != OneVersionEnforcementLevel.OFF) {
+ Artifact oneVersionOutput =
+ ruleContext
+ .getAnalysisEnvironment()
+ .getDerivedArtifact(
+ replaceExtension(classJar.getRootRelativePath(), "-one-version.txt"),
+ classJar.getRoot());
+ filesToBuildBuilder.add(oneVersionOutput);
+
+ NestedSet<Artifact> transitiveDependencies =
+ NestedSetBuilder.fromNestedSet(helper.getAttributes().getRuntimeClassPath())
+ .add(classJar)
+ .build();
+ OneVersionCheckActionBuilder.build(
+ ruleContext,
+ transitiveDependencies,
+ oneVersionOutput,
+ oneVersionEnforcementLevel);
+ }
+
NestedSet<Artifact> filesToBuild = filesToBuildBuilder.build();
Iterable<AndroidLibraryAarProvider> androidAarProviders =
