Skip to content

Commit

Permalink
Remove TransitionMode from RuleContext prerequisite calls.
Browse files Browse the repository at this point in the history
Part of removing TransitionMode entirely.

PiperOrigin-RevId: 329741153
  • Loading branch information
katre authored and copybara-github committed Sep 2, 2020
1 parent 8a227ad commit 80bfa26
Show file tree
Hide file tree
Showing 31 changed files with 146 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.RunfilesProvider;
import com.google.devtools.build.lib.analysis.TransitionMode;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
Expand Down Expand Up @@ -79,7 +78,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
AndroidSdkProvider.verifyPresence(ruleContext);

RuleConfiguredTargetBuilder ruleBuilder = new RuleConfiguredTargetBuilder(ruleContext);
Artifact aar = ruleContext.getPrerequisiteArtifact("aar", TransitionMode.TARGET);
Artifact aar = ruleContext.getPrerequisiteArtifact("aar");

Artifact allAarJars = createAarTreeArtifact(ruleContext, "jars");
Artifact jarMergingParams = createAarArtifact(ruleContext, "jar_merging_params");
Expand Down Expand Up @@ -140,8 +139,8 @@ public ConfiguredTarget create(RuleContext ruleContext)

ImmutableList<TransitiveInfoCollection> targets =
ImmutableList.<TransitiveInfoCollection>builder()
.addAll(ruleContext.getPrerequisites("exports", TransitionMode.TARGET))
.addAll(ruleContext.getPrerequisites("deps", TransitionMode.TARGET))
.addAll(ruleContext.getPrerequisites("exports"))
.addAll(ruleContext.getPrerequisites("deps"))
.build();
JavaCommon common =
new JavaCommon(
Expand Down Expand Up @@ -198,16 +197,15 @@ public ConfiguredTarget create(RuleContext ruleContext)

// Wire up the source jar for the current target and transitive source jars from dependencies.
ImmutableList<Artifact> srcJars = ImmutableList.of();
Artifact srcJar = ruleContext.getPrerequisiteArtifact("srcjar", TransitionMode.TARGET);
Artifact srcJar = ruleContext.getPrerequisiteArtifact("srcjar");
NestedSetBuilder<Artifact> transitiveJavaSourceJarBuilder = NestedSetBuilder.stableOrder();
if (srcJar != null) {
srcJars = ImmutableList.of(srcJar);
transitiveJavaSourceJarBuilder.add(srcJar);
}
for (JavaSourceJarsProvider other :
JavaInfo.getProvidersFromListOfTargets(
JavaSourceJarsProvider.class,
ruleContext.getPrerequisites("exports", TransitionMode.TARGET))) {
JavaSourceJarsProvider.class, ruleContext.getPrerequisites("exports"))) {
transitiveJavaSourceJarBuilder.addTransitive(other.getTransitiveSourceJars());
}
NestedSet<Artifact> transitiveJavaSourceJars = transitiveJavaSourceJarBuilder.build();
Expand Down Expand Up @@ -269,7 +267,7 @@ private NestedSet<Artifact> getBootclasspath(RuleContext ruleContext) {
return NestedSetBuilder.<Artifact>stableOrder()
.addTransitive(
ruleContext
.getPrerequisite("$desugar_java8_extra_bootclasspath", TransitionMode.HOST)
.getPrerequisite("$desugar_java8_extra_bootclasspath")
.getProvider(FileProvider.class)
.getFilesToBuild())
.add(AndroidSdkProvider.fromRuleContext(ruleContext).getAndroidJar())
Expand Down Expand Up @@ -297,9 +295,7 @@ private static Action[] createSingleFileExtractorActions(
SpawnAction.Builder builder =
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setExecutable(
ruleContext.getExecutablePrerequisite(
AarImportBaseRule.ZIPPER, TransitionMode.HOST))
.setExecutable(ruleContext.getExecutablePrerequisite(AarImportBaseRule.ZIPPER))
.setMnemonic("AarFileExtractor")
.setProgressMessage("Extracting %s from %s", filename, aar.getFilename())
.addInput(aar)
Expand Down Expand Up @@ -327,8 +323,7 @@ private static Action[] createAarResourcesExtractorActions(
return new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setExecutable(
ruleContext.getExecutablePrerequisite(
AarImportBaseRule.AAR_RESOURCES_EXTRACTOR, TransitionMode.HOST))
ruleContext.getExecutablePrerequisite(AarImportBaseRule.AAR_RESOURCES_EXTRACTOR))
.setMnemonic("AarResourcesExtractor")
.addInput(aar)
.addOutput(resourcesDir)
Expand All @@ -354,8 +349,7 @@ private static Action[] createAarEmbeddedJarsExtractorActions(
return new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setExecutable(
ruleContext.getExecutablePrerequisite(
AarImportBaseRule.AAR_EMBEDDED_JARS_EXTACTOR, TransitionMode.HOST))
ruleContext.getExecutablePrerequisite(AarImportBaseRule.AAR_EMBEDDED_JARS_EXTACTOR))
.setMnemonic("AarEmbeddedJarsExtractor")
.setProgressMessage("Extracting classes.jar and libs/*.jar from %s", aar.getFilename())
.addInput(aar)
Expand Down Expand Up @@ -395,7 +389,7 @@ private static Action[] createAarNativeLibsFilterActions(
.useDefaultShellEnvironment()
.setExecutable(
ruleContext.getExecutablePrerequisite(
AarImportBaseRule.AAR_NATIVE_LIBS_ZIP_CREATOR, TransitionMode.HOST))
AarImportBaseRule.AAR_NATIVE_LIBS_ZIP_CREATOR))
.setMnemonic("AarNativeLibsFilter")
.setProgressMessage("Filtering AAR native libs by architecture")
.addInput(aar)
Expand All @@ -415,11 +409,10 @@ private static DataBindingV2Provider createDatabindingProvider(
SpecialArtifact databindingSetterStoreFiles) {

Iterable<? extends DataBindingV2ProviderApi<Artifact>> databindingProvidersFromDeps =
ruleContext.getPrerequisites("deps", TransitionMode.TARGET, DataBindingV2Provider.PROVIDER);
ruleContext.getPrerequisites("deps", DataBindingV2Provider.PROVIDER);

Iterable<? extends DataBindingV2ProviderApi<Artifact>> databindingProvidersFromExports =
ruleContext.getPrerequisites(
"exports", TransitionMode.TARGET, DataBindingV2Provider.PROVIDER);
ruleContext.getPrerequisites("exports", DataBindingV2Provider.PROVIDER);

DataBindingV2Provider dataBindingV2Provider =
DataBindingV2Provider.createProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.devtools.build.lib.analysis.FileProvider;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.RuleErrorConsumer;
import com.google.devtools.build.lib.analysis.TransitionMode;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.packages.Type;
Expand Down Expand Up @@ -110,7 +109,7 @@ private static Iterable<? extends TransitiveInfoCollection> getAssetTargets(
return null;
}

return ruleContext.getPrerequisitesIf(ASSETS_ATTR, TransitionMode.TARGET, FileProvider.class);
return ruleContext.getPrerequisitesIf(ASSETS_ATTR, FileProvider.class);
}

@Nullable
Expand Down
Loading

0 comments on commit 80bfa26

Please sign in to comment.