diff --git a/src/main/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfo.java b/src/main/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfo.java index c4593eb85186ea..cdc29155536ca0 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfo.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfo.java @@ -69,6 +69,11 @@ protected ToolchainInfo(Map values, Location location) { this.values = copyValues(values); } + public ToolchainInfo(Map values) { + super(PROVIDER, Location.BUILTIN); + this.values = copyValues(values); + } + /** * Preprocesses a map of field values to convert the field names and field values to * Starlark-acceptable names and types. diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImportRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImportRule.java index db7e47ded61823..a08bbd38c4dd3a 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImportRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImportRule.java @@ -36,7 +36,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment envi public Metadata getMetadata() { return RuleDefinition.Metadata.builder() .name("aar_import") - .ancestors(AarImportBaseRule.class, JavaBaseRule.class) + .ancestors(AarImportBaseRule.class, JavaBaseRule.class, BazelSdkToolchainRule.class) .factoryClass(BazelAarImport.class) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java index 5897f71b8ab657..9fe858a6c082fe 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java @@ -88,6 +88,7 @@ public Metadata getMetadata() { .ancestors( AndroidRuleClasses.AndroidBinaryBaseRule.class, BazelJavaRuleClasses.JavaBaseRule.class, + BazelSdkToolchainRule.class, CcToolchainRequiringRule.class) .factoryClass(BazelAndroidBinary.class) .build(); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidInstrumentationTestRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidInstrumentationTestRule.java index e7ad444cf089f1..b5cb48354b5c8c 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidInstrumentationTestRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidInstrumentationTestRule.java @@ -42,6 +42,7 @@ public Metadata getMetadata() { .ancestors( AndroidInstrumentationTestBaseRule.class, AndroidRuleClasses.AndroidBaseRule.class, + BazelSdkToolchainRule.class, BaseRuleClasses.TestBaseRule.class) .factoryClass(BazelAndroidInstrumentationTest.class) .build(); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidLibraryRule.java index 5000c6742a863a..6eecbd9e29b5f1 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidLibraryRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidLibraryRule.java @@ -56,7 +56,8 @@ public Metadata getMetadata() { .name("android_library") .ancestors( BazelJavaRuleClasses.JavaBaseRule.class, - AndroidLibraryBaseRule.class) + AndroidLibraryBaseRule.class, + BazelSdkToolchainRule.class) .factoryClass(BazelAndroidLibrary.class) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdkBase.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdkBase.java index 8d0f2d915faf24..911e44029768eb 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdkBase.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdkBase.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.rules.android; +import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException; import com.google.devtools.build.lib.analysis.ConfiguredTarget; @@ -22,6 +23,7 @@ import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.RunfilesProvider; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; +import com.google.devtools.build.lib.analysis.platform.ToolchainInfo; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.packages.AggregatingAttributeMapper; @@ -74,27 +76,30 @@ public ConfiguredTarget create(RuleContext ruleContext) return null; } + AndroidSdkProvider sdk = + new AndroidSdkProvider( + buildToolsVersion, + frameworkAidl, + aidlLib, + androidJar, + sourceProperties, + shrinkedAndroidJar, + mainDexClasses, + adb, + dx, + mainDexListCreator, + aidl, + aapt, + aapt2, + apkBuilder, + apkSigner, + proguard, + zipalign, + /* system= */ null); + return new RuleConfiguredTargetBuilder(ruleContext) - .addNativeDeclaredProvider( - new AndroidSdkProvider( - buildToolsVersion, - frameworkAidl, - aidlLib, - androidJar, - sourceProperties, - shrinkedAndroidJar, - mainDexClasses, - adb, - dx, - mainDexListCreator, - aidl, - aapt, - aapt2, - apkBuilder, - apkSigner, - proguard, - zipalign, - /* system= */ null)) + .addNativeDeclaredProvider(sdk) + .addNativeDeclaredProvider(new ToolchainInfo(ImmutableMap.of("android_sdk_info", sdk))) .addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY) .setFilesToBuild(NestedSetBuilder.emptySet(Order.STABLE_ORDER)) .build(); diff --git a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java index f0c63043ffaa00..4ec359b8eb3ac8 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java @@ -87,6 +87,7 @@ public List getWorkspaceContents(MockToolsConfig config) { "bind(name = 'android/sdk', actual='@bazel_tools//tools/android:sdk')", "register_toolchains('@bazel_tools//tools/cpp:all')", "register_toolchains('@bazel_tools//tools/jdk:all')", + "register_toolchains('@bazel_tools//tools/android:all')", "register_toolchains('@bazel_tools//tools/python:autodetecting_toolchain')", "local_repository(name = 'local_config_platform', path = '" + localConfigPlatformWorkspace @@ -338,6 +339,11 @@ private ImmutableList createAndroidBuildContents() { androidBuildContents.add( "toolchain_type(name = 'sdk_toolchain_type')", + "toolchain(", + " name = 'sdk_toolchain',", + " toolchain = ':sdk',", + " toolchain_type = ':sdk_toolchain_type',", + ")", "android_sdk(", " name = 'sdk',", " aapt = ':static_aapt_tool',", diff --git a/src/test/shell/testenv.sh b/src/test/shell/testenv.sh index 8d84f01107f8bb..a0ad144bc729b9 100755 --- a/src/test/shell/testenv.sh +++ b/src/test/shell/testenv.sh @@ -339,11 +339,13 @@ function setup_android_sdk_support() { local android=$(dirname $android_jar) local platforms=$(dirname $android) ANDROID_SDK=$(dirname $platforms) + cat >> WORKSPACE <