Skip to content

Commit

Permalink
Make Android tests work with --enable_workspace=false
Browse files Browse the repository at this point in the history
A part of #23087

Working towards: #23023

Android tests are leaving the Bazel codebases, so it's fine to not migrate the legacy tests to Bzlmod.

PiperOrigin-RevId: 660569455
Change-Id: Ibde570e27f6f76443fe7e74a92c7fa18d967e7af
  • Loading branch information
meteorcloudy authored and copybara-github committed Aug 7, 2024
1 parent a52fca7 commit 0831f1a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function test_DexFileSplitter_synthetic_classes_crossing_dexfiles() {
# dex_shards default is 1
create_test_app 21400 6000 1

bazel build java/com/testapp || fail "Test app should have built succesfully"
bazel build --enable_bzlmod java/com/testapp --verbose_failures || fail "Test app should have built succesfully"

dex_file_count=$(unzip -l bazel-bin/java/com/testapp/testapp.apk | grep "classes[0-9]*.dex" | wc -l)
if [[ ! "$dex_file_count" -ge "2" ]]; then
Expand All @@ -175,7 +175,7 @@ function test_DexMapper_synthetic_classes_crossing_dexfiles() {
echo $TEST_TMPDIR/bazelrc
cat $TEST_TMPDIR/bazelrc

bazel build java/com/testapp || fail "Test app should have built succesfully"
bazel build --enable_bzlmod java/com/testapp --verbose_failures || fail "Test app should have built succesfully"

dex_file_count=$(unzip -l bazel-bin/java/com/testapp/testapp.apk | grep "classes[0-9]*.dex" | wc -l)
if [[ ! "$dex_file_count" -eq "4" ]]; then
Expand Down
3 changes: 3 additions & 0 deletions src/test/shell/bazel/android/android_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ function setup_head_android_tools_if_exists() {

# Resolves Android toolchains with platforms.
function resolve_android_toolchains() {
# Disable Bzlmod and enable WORKSPACE for android tests, piggybacking in this function
# since it's called by all Android tests.
disable_bzlmod
add_to_bazelrc "build --android_platforms=//test_android_platforms:simple"
}

Expand Down
15 changes: 12 additions & 3 deletions src/test/shell/bazel/android/android_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ android_binary(
srcs = ['MainActivity.java'],
resource_files = glob(["res/**"]),
)
EOF
cat > MODULE.bazel << 'EOF'
bazel_dep(name = "platforms", version = "0.0.7")
EOF

# The next line ensures that the test passes in IPv6-only networks.
Expand All @@ -213,6 +210,18 @@ function test_android_tools_version() {
create_new_workspace
setup_android_sdk_support

cat >> WORKSPACE <<EOF
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_pkg",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
],
sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
)
EOF

label="1.2.3 4.5.6 1000000000000000000000000000000000000002"
bazel build --embed_label="$label" //tools/android/runtime_deps:version.txt
actual="$(cat bazel-bin/tools/android/runtime_deps/version.txt)"
Expand Down
6 changes: 3 additions & 3 deletions src/test/shell/bazel/android/android_sdk_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function test_android_sdk_repository_path_from_environment() {
# Overwrite WORKSPACE that was created by setup_android_sdk_support with one
# that does not set the path attribute of android_sdk_repository.
rm WORKSPACE
cat >> $(create_workspace_with_default_repos WORKSPACE) <<EOF
cat >> WORKSPACE <<EOF
android_sdk_repository(
name = "androidsdk",
)
Expand All @@ -54,7 +54,7 @@ EOF
function test_android_sdk_repository_no_path_or_android_home() {
create_new_workspace
setup_android_platforms
cat >> $(create_workspace_with_default_repos WORKSPACE) <<EOF
cat >> WORKSPACE <<EOF
android_sdk_repository(
name = "androidsdk",
api_level = 25,
Expand All @@ -68,7 +68,7 @@ function test_android_sdk_repository_wrong_path() {
create_new_workspace
setup_android_platforms
mkdir "$TEST_SRCDIR/some_dir"
cat >> $(create_workspace_with_default_repos WORKSPACE) <<EOF
cat >> WORKSPACE <<EOF
android_sdk_repository(
name = "androidsdk",
api_level = 25,
Expand Down

0 comments on commit 0831f1a

Please sign in to comment.