Skip to content

Commit

Permalink
Android SDK delcares toolchains that should be registered.
Browse files Browse the repository at this point in the history
  • Loading branch information
katre committed Jul 20, 2020
1 parent 1e00502 commit 95042e6
Showing 1 changed file with 19 additions and 17 deletions.
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

0 comments on commit 95042e6

Please sign in to comment.