Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android SDK declares toolchains that should be registered. #11737

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static com.google.devtools.build.lib.packages.Type.INTEGER;
import static com.google.devtools.build.lib.packages.Type.STRING;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
Expand All @@ -27,6 +27,7 @@
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
import com.google.devtools.build.lib.rules.repository.WorkspaceBaseRule;
import com.google.devtools.build.lib.rules.repository.WorkspaceConfiguredTargetFactory;
import java.util.List;
import java.util.Map;

/**
Expand All @@ -35,27 +36,28 @@
public class AndroidSdkRepositoryRule implements RuleDefinition {
public static final String NAME = "android_sdk_repository";

private static final Function<? super Rule, Map<String, Label>> BINDINGS_FUNCTION =
rule -> {
String prefix = "@" + rule.getName() + "//:";
ImmutableMap.Builder<String, Label> builder = ImmutableMap.builder();
builder.put("android/sdk", Label.parseAbsoluteUnchecked(prefix + "sdk"));
builder.put(
"android/d8_jar_import", Label.parseAbsoluteUnchecked(prefix + "d8_jar_import"));
builder.put(
"android/dx_jar_import", Label.parseAbsoluteUnchecked(prefix + "dx_jar_import"));
builder.put("android_sdk_for_testing", Label.parseAbsoluteUnchecked(prefix + "files"));
builder.put(
"has_androidsdk",
Label.parseAbsoluteUnchecked("@bazel_tools//tools/android:always_true"));
return builder.build();
};
private static final Map<String, Label> calculateBindings(Rule rule) {
String prefix = "@" + rule.getName() + "//:";
ImmutableMap.Builder<String, Label> builder = ImmutableMap.builder();
builder.put("android/sdk", Label.parseAbsoluteUnchecked(prefix + "sdk"));
builder.put("android/d8_jar_import", Label.parseAbsoluteUnchecked(prefix + "d8_jar_import"));
builder.put("android/dx_jar_import", Label.parseAbsoluteUnchecked(prefix + "dx_jar_import"));
builder.put("android_sdk_for_testing", Label.parseAbsoluteUnchecked(prefix + "files"));
builder.put(
"has_androidsdk", Label.parseAbsoluteUnchecked("@bazel_tools//tools/android:always_true"));
return builder.build();
}

private static final List<String> calculateToolchainsToRegister(Rule rule) {
return ImmutableList.of(String.format("@%s//:all", rule.getName()));
}

@Override
public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) {
return builder
.setWorkspaceOnly()
.setExternalBindingsFunction(BINDINGS_FUNCTION)
.setExternalBindingsFunction(AndroidSdkRepositoryRule::calculateBindings)
.setToolchainsToRegisterFunction(AndroidSdkRepositoryRule::calculateToolchainsToRegister)
/* <!-- #BLAZE_RULE(android_sdk_repository).ATTRIBUTE(path) -->
An absolute or relative path to an Android SDK. Either this attribute or the
<code>$ANDROID_HOME</code> environment variable must be set.
Expand Down