Skip to content

Commit

Permalink
Automated rollback of commit 6d44813.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

rollforward now that we have dummy toolchains.

TESTED=[]

*** Original change description ***

Automated rollback of commit 3e79b0d.

*** Reason for rollback ***

need a dummy toolchain

*** Original change description ***

Add BazelSdkToolchainRule and GoogleSdkToolchainRule as ancestors to rules that currently access the AndroidSdkProvider from the :android_sdk attr.

This requires a lot of test infrastructure updates.

PiperOrigin-RevId: 335469783
  • Loading branch information
juliexxia authored and copybara-github committed Oct 5, 2020
1 parent 2350239 commit 080547f
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ protected ToolchainInfo(Map<String, Object> values, Location location) {
this.values = copyValues(values);
}

public ToolchainInfo(Map<String, Object> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public Metadata getMetadata() {
.ancestors(
AndroidRuleClasses.AndroidBinaryBaseRule.class,
BazelJavaRuleClasses.JavaBaseRule.class,
BazelSdkToolchainRule.class,
CcToolchainRequiringRule.class)
.factoryClass(BazelAndroidBinary.class)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public Metadata getMetadata() {
.ancestors(
AndroidInstrumentationTestBaseRule.class,
AndroidRuleClasses.AndroidBaseRule.class,
BazelSdkToolchainRule.class,
BaseRuleClasses.TestBaseRule.class)
.factoryClass(BazelAndroidInstrumentationTest.class)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public Metadata getMetadata() {
.name("android_library")
.ancestors(
BazelJavaRuleClasses.JavaBaseRule.class,
AndroidLibraryBaseRule.class)
AndroidLibraryBaseRule.class,
BazelSdkToolchainRule.class)
.factoryClass(BazelAndroidLibrary.class)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.<Artifact>emptySet(Order.STABLE_ORDER))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public List<String> 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
Expand Down Expand Up @@ -338,6 +339,11 @@ private ImmutableList<String> 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',",
Expand Down
2 changes: 2 additions & 0 deletions src/test/shell/testenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,13 @@ function setup_android_sdk_support() {
local android=$(dirname $android_jar)
local platforms=$(dirname $android)
ANDROID_SDK=$(dirname $platforms)

cat >> WORKSPACE <<EOF
android_sdk_repository(
name = "androidsdk",
path = "$ANDROID_SDK",
)
register_toolchains("//tools/android:all")
EOF
}

Expand Down
39 changes: 39 additions & 0 deletions tools/android/android_sdk_repository_template.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ def create_android_sdk_rules(
toolchain = ":sdk-%d" % api_level,
)

create_dummy_sdk_toolchain()

native.alias(
name = "org_apache_http_legacy",
actual = ":org_apache_http_legacy-%d" % default_api_level,
Expand Down Expand Up @@ -315,6 +317,43 @@ ARCHDIR_TO_ARCH_MAP = {
"armeabi-v7a": "arm",
}

# This is a dummy sdk toolchain that matches any platform. It will
# fail if actually resolved to and used.
def create_dummy_sdk_toolchain():
native.toolchain(
name = "sdk-dummy-toolchain",
toolchain_type = "@bazel_tools//tools/android:sdk_toolchain_type",
toolchain = ":sdk-dummy",
)

native.filegroup(name = "jar-filegroup", srcs = ["dummy.jar"])

native.genrule(
name = "genrule",
srcs = [],
outs = ["empty.sh"],
cmd = "echo '' >> \"$@\"",
executable = 1,
)

native.sh_binary(name = "empty-binary", srcs = [":genrule"])

native.android_sdk(
name = "sdk-dummy",
aapt = ":empty-binary",
adb = ":empty-binary",
aidl = ":empty-binary",
android_jar = ":jar-filegroup",
apksigner = ":empty-binary",
dx = ":empty-binary",
framework_aidl = "dummy.jar",
main_dex_classes = "dummy.jar",
main_dex_list_creator = ":empty-binary",
proguard = ":empty-binary",
shrinked_android_jar = "dummy.jar",
zipalign = ":empty-binary",
)

def create_system_images_filegroups(system_image_dirs):
"""Generate filegroups for the system images in the Android SDK.
Expand Down

0 comments on commit 080547f

Please sign in to comment.