Skip to content

Commit

Permalink
Add toolchain type attribute for DexArchiveAspect.
Browse files Browse the repository at this point in the history
Also fix AndroidSdkProvider to figure out the correct attribute type. When a native aspect is used with a Starlark rule, the previous logic was incorrect.

PiperOrigin-RevId: 620208668
Change-Id: I8cf600294fbc1acdd584f90a8bdd89ddc1135e13
  • Loading branch information
katre authored and copybara-github committed Mar 29, 2024
1 parent 0662df0 commit f83c20f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,21 @@ private static boolean usingDummyToolchain(

@Nullable
private static Label getToolchainTypeFromAttribute(RuleContext ruleContext) {
Type<Label> depType =
ruleContext.getRule().getRuleClassObject().isStarlark()
? BuildType.LABEL
: BuildType.NODEP_LABEL;
Type<Label> depType;
if (ruleContext.attributes().has(ANDROID_SDK_TOOLCHAIN_TYPE_ATTRIBUTE_NAME, BuildType.LABEL)) {
depType = BuildType.LABEL;
} else if (ruleContext
.attributes()
.has(ANDROID_SDK_TOOLCHAIN_TYPE_ATTRIBUTE_NAME, BuildType.NODEP_LABEL)) {
depType = BuildType.NODEP_LABEL;
} else {
String message =
String.format(
"%s does not have the attribute %s of type LABEL or NODEP_LABEL, cannot find the"
+ " Android SDK",
ruleContext.toString(), ANDROID_SDK_TOOLCHAIN_TYPE_ATTRIBUTE_NAME);
throw new IllegalStateException(message);
}
return ruleContext.attributes().get(ANDROID_SDK_TOOLCHAIN_TYPE_ATTRIBUTE_NAME, depType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
import static com.google.devtools.build.lib.actions.ParameterFile.ParameterFileType.UNQUOTED;
import static com.google.devtools.build.lib.packages.Attribute.attr;
import static com.google.devtools.build.lib.packages.BuildType.LABEL;
import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL;
import static com.google.devtools.build.lib.packages.BuildType.TRISTATE;
import static com.google.devtools.build.lib.packages.StarlarkProviderIdentifier.forKey;
import static com.google.devtools.build.lib.packages.Type.INTEGER;
import static com.google.devtools.build.lib.rules.android.AndroidCommon.getAndroidConfig;
import static com.google.devtools.build.lib.rules.android.AndroidSdkProvider.ANDROID_SDK_TOOLCHAIN_TYPE_ATTRIBUTE_NAME;

import com.google.common.base.Function;
import com.google.common.base.Functions;
Expand Down Expand Up @@ -160,6 +162,7 @@ public AspectDefinition getDefinition(AspectParameters params) {
// For proto_lang_toolchain rules, where we just want to get at their runtime
// deps.
ImmutableSet.of(ProtoLangToolchainProvider.PROVIDER_ID)))
.add(attr(ANDROID_SDK_TOOLCHAIN_TYPE_ATTRIBUTE_NAME, NODEP_LABEL).value(toolchainType))
.addToolchainTypes(
ToolchainTypeRequirement.builder(toolchainType).mandatory(true).build())
// Parse labels since we don't have RuleDefinitionEnvironment.getLabel like in a rule
Expand Down

0 comments on commit f83c20f

Please sign in to comment.