Skip to content

Commit

Permalink
Adds a bzlmod extension for remote android_tools
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 488720288
Change-Id: I6e7baa1d87d2d7b5434d8870e726faf362842dac
  • Loading branch information
ted-xie authored and Copybara-Service committed Nov 15, 2022
1 parent 0666fb6 commit e7d50fc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions WORKSPACE
Expand Up @@ -387,6 +387,7 @@ dist_http_archive(
)

# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/android/android_remote_tools.WORKSPACE
# and tools/android/android_extensions.bzl
http_archive(
name = "android_tools_for_testing",
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
Expand All @@ -396,6 +397,7 @@ http_archive(
)

# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/android/android_remote_tools.WORKSPACE
# and tools/android/android_extensions.bzl
http_jar(
name = "android_gmaven_r8_for_testing",
sha256 = "8626ca32fb47aba7fddd2c897615e2e8ffcdb4d4b213572a2aefb3f838f01972",
Expand Down
3 changes: 3 additions & 0 deletions src/MODULE.tools
Expand Up @@ -33,3 +33,6 @@ register_toolchains("@local_config_sh//:local_sh_toolchain")

remote_coverage_tools_extension = use_extension("//tools/test:extensions.bzl", "remote_coverage_tools_extension")
use_repo(remote_coverage_tools_extension, "remote_coverage_tools")

remote_android_extensions = use_extension("//tools/android:android_extensions.bzl", "remote_android_tools_extensions")
use_repo(remote_android_extensions, "android_gmaven_r8", "android_tools")
2 changes: 2 additions & 0 deletions src/test/shell/bazel/android/BUILD
Expand Up @@ -44,6 +44,8 @@ android_sh_test(
tags = [
"no-remote",
"no_windows",
# bzlmod test requires network
"requires-network",
],
)

Expand Down
22 changes: 22 additions & 0 deletions src/test/shell/bazel/android/android_integration_test.sh
Expand Up @@ -219,6 +219,28 @@ EOF
//java/com/example/hello:hello || fail "build failed"
}

function test_hello_android_bzlmod() {
write_hello_android_files
setup_android_sdk_support
cat > java/com/example/hello/BUILD <<'EOF'
android_binary(
name = 'hello',
manifest = "AndroidManifest.xml",
srcs = ['MainActivity.java'],
resource_files = glob(["res/**"]),
)
EOF
cat > MODULE.bazel << 'EOF'
# Required for android_integration_test_with_platforms
bazel_dep(name = "platforms", version = "0.0.5")
EOF

bazel clean
# Check that android builds with bzlmod enable work.
bazel build --experimental_enable_bzlmod \
//java/com/example/hello:hello || fail "build failed"
}

function test_android_tools_version() {
create_new_workspace
setup_android_sdk_support
Expand Down
33 changes: 33 additions & 0 deletions tools/android/android_extensions.bzl
@@ -0,0 +1,33 @@
# Copyright 2022 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Module extension to declare Android runtime dependencies for Bazel."""

load("//tools/build_defs/repo:http.bzl", "http_archive", "http_jar")

def _remote_android_tools_extensions_impl(_ctx):
http_archive(
name = "android_tools",
sha256 = "1afa4b7e13c82523c8b69e87f8d598c891ec7e2baa41d9e24e08becd723edb4d", # do_not_remove_this_android_tools_update_marker
url = "https://mirror.bazel.build/bazel_android_tools/android_tools_pkg-0.27.0.tar.gz",
)
http_jar(
name = "android_gmaven_r8",
sha256 = "8626ca32fb47aba7fddd2c897615e2e8ffcdb4d4b213572a2aefb3f838f01972",
url = "https://maven.google.com/com/android/tools/r8/3.3.28/r8-3.3.28.jar",
)

remote_android_tools_extensions = module_extension(
implementation = _remote_android_tools_extensions_impl,
)

0 comments on commit e7d50fc

Please sign in to comment.