Skip to content

Commit

Permalink
Automated rollback of commit 4b9534a.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 671846225
Change-Id: I41b08154e5022b72509211361836928df4bcde33
  • Loading branch information
timpeut authored and copybara-github committed Sep 6, 2024
1 parent cf1b1e0 commit 2bcdf53
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 68 deletions.
1 change: 0 additions & 1 deletion rules/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ bzl_library(
visibility = [
"//mobile_install:__pkg__",
"//stardoc:__pkg__",
"//test/rules/android_sdk_repository:__pkg__",
],
deps = [
":common_bzl",
Expand Down
40 changes: 22 additions & 18 deletions rules/android_sdk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,35 @@

load("//rules:providers.bzl", "AndroidSdkInfo")
load("//rules:visibility.bzl", "PROJECT_VISIBILITY")
load("@rules_java//java/common:java_common.bzl", "java_common")
load(":attrs.bzl", "ANDROID_SDK_ATTRS")

visibility(PROJECT_VISIBILITY)

def _impl(ctx):
proguard = ctx.attr._proguard if ctx.attr._proguard else ctx.attr.proguard
android_sdk_info = AndroidSdkInfo(
build_tools_version = ctx.attr.build_tools_version,
framework_aidl = ctx.file.framework_aidl,
aidl_lib = None,
android_jar = ctx.file.android_jar,
source_properties = ctx.file.source_properties,
shrinked_android_jar = ctx.file.shrinked_android_jar,
main_dex_classes = ctx.file.main_dex_classes,
adb = ctx.attr.adb.files_to_run,
dx = ctx.attr.dx.files_to_run,
main_dex_list_creator = ctx.attr.main_dex_list_creator.files_to_run,
aidl = ctx.attr.aidl.files_to_run,
aapt = ctx.attr.aapt.files_to_run,
aapt2 = ctx.attr.aapt2.files_to_run,
apk_builder = ctx.attr.apkbuilder.files_to_run if ctx.attr.apkbuilder else None,
apk_signer = ctx.attr.apksigner.files_to_run,
proguard = proguard.files_to_run,
zip_align = ctx.attr.zipalign.files_to_run,
legacy_main_dex_list_generator = ctx.attr.legacy_main_dex_list_generator.files_to_run if ctx.attr.legacy_main_dex_list_generator else None,
ctx.attr.build_tools_version,
ctx.file.framework_aidl,
None,
ctx.file.android_jar,
ctx.file.source_properties,
ctx.file.shrinked_android_jar,
ctx.file.main_dex_classes,
ctx.attr.adb.files_to_run,
ctx.attr.dx.files_to_run,
ctx.attr.main_dex_list_creator.files_to_run,
ctx.attr.aidl.files_to_run,
ctx.attr.aapt.files_to_run,
ctx.attr.aapt2.files_to_run,
ctx.attr.apkbuilder.files_to_run if ctx.attr.apkbuilder else None,
ctx.attr.apksigner.files_to_run,
proguard.files_to_run,
ctx.attr.zipalign.files_to_run,
# Passing the 'system' here is only necessary to support native android_binary.
# TODO(b/149114743): remove this after the migration to android_application.
ctx.attr._system[java_common.BootClassPathInfo] if ctx.attr._system and java_common.BootClassPathInfo in ctx.attr._system else None,
ctx.attr.legacy_main_dex_list_generator.files_to_run if ctx.attr.legacy_main_dex_list_generator else None,
)
return [
android_sdk_info,
Expand Down
4 changes: 1 addition & 3 deletions rules/android_sdk_repository/helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"""Helpers for the build file used in android_sdk_repository."""

load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")
load("@rules_android//rules:rules.bzl", "android_sdk")
load("@rules_java//java:defs.bzl", "java_binary", "java_import")

def _bool_flag_impl(_unused_ctx):
Expand Down Expand Up @@ -221,7 +220,6 @@ def create_android_sdk_rules(
framework_aidl = "platforms/android-%d/framework.aidl" % api_level,
legacy_main_dex_list_generator = ":generate_main_dex_list",
main_dex_classes = "build-tools/%s/mainDexClasses.rules" % build_tools_directory,
main_dex_list_creator = ":main_dex_list_creator",
proguard = select({
":disallow_proguard": ":fail",
"//conditions:default": "@bazel_tools//tools/jdk:proguard",
Expand Down Expand Up @@ -566,7 +564,7 @@ def create_dummy_sdk_toolchain():

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

android_sdk(
native.android_sdk(
name = "sdk-dummy",
aapt = ":empty-binary",
adb = ":empty-binary",
Expand Down
3 changes: 3 additions & 0 deletions rules/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ ANDROID_SDK_ATTRS = dict(
name = "proguard_top",
),
),
_system = attr.label(
default = Label("//tools/android:bootclasspath_android_only"),
),
)

# Attributes for resolving platform-based toolchains. Only needed by the native
Expand Down
25 changes: 1 addition & 24 deletions rules/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -343,33 +343,10 @@ AndroidSandboxedSdkApkInfo = provider(
),
)

AndroidSdkInfo = provider(
doc = "AndroidSdkInfo",
fields = dict(
build_tools_version = "",
framework_aidl = "",
aidl_lib = "",
android_jar = "",
source_properties = "",
shrinked_android_jar = "",
main_dex_classes = "",
adb = "",
dx = "",
main_dex_list_creator = "",
aidl = "",
aapt = "",
aapt2 = "",
apk_builder = "",
apk_signer = "",
proguard = "",
legacy_main_dex_list_generator = "",
zip_align = "",
),
)

# Native defined providers which will be gradually migrated to Starlark.
# We re-export these here so that all our providers can be loaded from this file.
AndroidResourcesInfo = providers.AndroidResourcesInfo
AndroidSdkInfo = providers.AndroidSdkInfo
AndroidManifestInfo = providers.AndroidManifestInfo
AndroidAssetsInfo = providers.AndroidAssetsInfo
AndroidIdeInfo = providers.AndroidIdeInfo
1 change: 1 addition & 0 deletions rules/reexport_providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ visibility(PROJECT_VISIBILITY)

providers = struct(
AndroidResourcesInfo = AndroidResourcesInfo,
AndroidSdkInfo = AndroidSdkInfo,
AndroidManifestInfo = AndroidManifestInfo,
AndroidAssetsInfo = AndroidAssetsInfo,
AndroidIdeInfo = AndroidIdeInfo,
Expand Down
2 changes: 1 addition & 1 deletion test/rules/android_sdk_repository/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sh_library(
testonly = True,
srcs = ["android_helper.sh"],
data = [
"//rules:bzl",
"//rules/android_sdk_repository:bzl",
],
visibility = ["//visibility:private"],
deps = [
Expand Down
31 changes: 10 additions & 21 deletions test/rules/android_sdk_repository/android_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,52 +36,41 @@ function set_up() {
cat > .bazelrc <<EOF
# Re-enable workspace after https://github.com/bazelbuild/bazel/commit/5881c38c54416add9faec35b7731954f4baf12d8
common --enable_workspace=true
common --experimental_google_legacy_api
EOF

# Clean out the test android SDK if any
rm -rf "${TEST_TMPDIR}/android_sdk"

# Make sure the rules exist and seed the WORKSPACE.
rm -rf "${TEST_TMPDIR}/rules_android"
rm -rf "${TEST_TMPDIR}/android_sdk_repository_src"
set_up_rules
}

function set_up_rules() {
local rules_android="$(dirname $(rlocation rules_android/rules/android_sdk.bzl))"
if [[ -z "${rules_android}" ]]; then
fail "Failed to locate rules_android"
fi
local dest_dir="${TEST_TMPDIR}/rules_android"
mkdir -p "${dest_dir}/rules"

cp -r -L "${rules_android}"/* "${dest_dir}/rules"
chmod +r "${dest_dir}/rules/rules.bzl"

cat > "${dest_dir}/rules/rules.bzl" <<EOF
load("//rules:android_sdk.bzl", _android_sdk = "android_sdk")
android_sdk = _android_sdk
EOF
local android_revision_rule="$(rlocation rules_android/rules/android_revision.bzl)"

local repo_rule="$(rlocation rules_android/rules/android_sdk_repository/rule.bzl)"
local repo_rule_dir="$(dirname "${repo_rule}")"
local dest_dir="${TEST_TMPDIR}/android_sdk_repository_src"
mkdir -p "${dest_dir}/rules/android_sdk_repository"
cp -r "${repo_rule_dir}"/* "${dest_dir}/rules/android_sdk_repository"
cat > "${dest_dir}/WORKSPACE" <<EOF
workspace(name = "android_sdk_repository_src")
EOF

cat > "${dest_dir}/rules/BUILD" <<EOF
exports_files(["*.bzl"])
EOF

cp "${android_revision_rule}" "${dest_dir}/rules/"
cat > "${dest_dir}/rules/android_sdk_repository/BUILD" <<EOF
exports_files(["*.bzl"])
EOF

cat >> WORKSPACE <<EOF
local_repository(
name = "rules_android",
name = "android_sdk_repository_src",
path = "${dest_dir}",
)
load("@rules_android//rules/android_sdk_repository:rule.bzl", "android_sdk_repository")
load("@android_sdk_repository_src//rules/android_sdk_repository:rule.bzl", "android_sdk_repository")
EOF
}

Expand Down
2 changes: 2 additions & 0 deletions toolchains/android_sdk/rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
"""Starlark rules to include sdk toolchain into dep graph without actually utilize it."""

load("//rules:providers.bzl", "AndroidSdkInfo")
load("//rules:visibility.bzl", "PROJECT_VISIBILITY")

visibility(PROJECT_VISIBILITY)
Expand All @@ -31,6 +32,7 @@ dummy_toolchain_dep = rule(
attrs = {
"sdk_toolchain": attr.label(
mandatory = True,
providers = [AndroidSdkInfo],
),
},
)

0 comments on commit 2bcdf53

Please sign in to comment.