Skip to content

Commit

Permalink
Add a dependency on rules_bazel_integration_test.
Browse files Browse the repository at this point in the history
Also add a smoke test to confirm that it works properly.

Part of #76.

PiperOrigin-RevId: 563174586
Change-Id: Ic186af201f7c40aa3e42e9149b81fa13d662994b
  • Loading branch information
katre authored and copybara-github committed Sep 6, 2023
1 parent a54904b commit bb96e31
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 23 deletions.
32 changes: 28 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module(
bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "rules_license", version = "0.0.4")
bazel_dep(name = "rules_java", version = "6.0.0")

rules_java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains")
use_repo(rules_java_toolchains, "remote_java_tools")

Expand All @@ -15,20 +16,24 @@ bazel_dep(name = "bazel_skylib", version = "1.0.3")
bazel_dep(name = "rules_robolectric", version = "4.10")

register_toolchains("//toolchains/android:all")

register_toolchains("//toolchains/android_sdk:all")

register_toolchains("//toolchains/emulator:all")

# go-related dependency setup
bazel_dep(name = "rules_go", version = "0.39.1", repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.28.0", repo_name = "bazel_gazelle")
bazel_dep(name = "abseil-py", version = "1.4.0", repo_name = "py_absl")

go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")

go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
use_repo(
go_deps,
"org_golang_google_protobuf",
"com_github_google_go_cmp",
"org_golang_google_protobuf",
"org_golang_x_sync",
)

Expand All @@ -49,11 +54,30 @@ maven.install(
"https://repo1.maven.org/maven2",
],
)

use_repo(
maven,
"rules_android_maven"
"rules_android_maven",
)

remote_android_extensions = use_extension("@bazel_tools//tools/android:android_extensions.bzl", "remote_android_tools_extensions")
use_repo(remote_android_extensions, "android_tools", "android_gmaven_r8")
use_repo(remote_android_extensions, "android_gmaven_r8", "android_tools")

# integration test setup
bazel_dep(
name = "rules_bazel_integration_test",
version = "0.16.0",
dev_dependency = True,
)
bazel_dep(
name = "cgrindel_bazel_starlib",
version = "0.17.0",
dev_dependency = True,
)

bazel_binaries = use_extension(
"@rules_bazel_integration_test//:extensions.bzl",
"bazel_binaries",
dev_dependency = True,
)
bazel_binaries.download(version = "last_green")
use_repo(bazel_binaries, "bazel_binaries")
13 changes: 12 additions & 1 deletion defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

"""Workspace setup macro for rules_android."""

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")
load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "bazel_binaries")
load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")
load("@rules_jvm_external//:defs.bzl", "maven_install")
load("@rules_jvm_external//:specs.bzl", "maven")
Expand Down Expand Up @@ -102,3 +104,12 @@ def rules_android_workspace():
rules_proto_toolchains()

py_repositories()

# Integration test setup
bazel_starlib_dependencies()

bazel_binaries(
versions = [
"last_green",
],
)
52 changes: 34 additions & 18 deletions prereqs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")


def rules_android_prereqs():
"""Downloads prerequisite repositories for rules_android."""
maybe(
Expand Down Expand Up @@ -50,8 +49,8 @@ def rules_android_prereqs():
name = "remote_java_tools_for_rules_android",
sha256 = "8fb4d3138bd92a9d3324dae29c9f70d91ca2db18cd0bf1997446eed4657d19b3",
urls = [
"https://mirror.bazel.build/bazel_java_tools/releases/java/v11.8/java_tools-v11.8.zip",
"https://github.com/bazelbuild/java_tools/releases/download/java_v11.8/java_tools-v11.8.zip",
"https://mirror.bazel.build/bazel_java_tools/releases/java/v11.8/java_tools-v11.8.zip",
"https://github.com/bazelbuild/java_tools/releases/download/java_v11.8/java_tools-v11.8.zip",
],
)

Expand Down Expand Up @@ -94,13 +93,13 @@ def rules_android_prereqs():
)

maybe(
http_archive,
name = "rules_license",
urls = [
"https://github.com/bazelbuild/rules_license/releases/download/0.0.4/rules_license-0.0.4.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/0.0.4/rules_license-0.0.4.tar.gz",
],
sha256 = "6157e1e68378532d0241ecd15d3c45f6e5cfd98fc10846045509fb2a7cc9e381",
http_archive,
name = "rules_license",
urls = [
"https://github.com/bazelbuild/rules_license/releases/download/0.0.4/rules_license-0.0.4.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/0.0.4/rules_license-0.0.4.tar.gz",
],
sha256 = "6157e1e68378532d0241ecd15d3c45f6e5cfd98fc10846045509fb2a7cc9e381",
)

maybe(
Expand All @@ -124,13 +123,30 @@ def rules_android_prereqs():
)

maybe(
http_archive,
name = "rules_python",
strip_prefix = "rules_python-0.23.1",
urls = [
"https://github.com/bazelbuild/rules_python/releases/download/0.23.1/rules_python-0.23.1.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_python/releases/download/0.23.1/rules_python-0.23.1.tar.gz",
],
sha256 = "84aec9e21cc56fbc7f1335035a71c850d1b9b5cc6ff497306f84cced9a769841",
http_archive,
name = "rules_python",
strip_prefix = "rules_python-0.23.1",
urls = [
"https://github.com/bazelbuild/rules_python/releases/download/0.23.1/rules_python-0.23.1.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_python/releases/download/0.23.1/rules_python-0.23.1.tar.gz",
],
sha256 = "84aec9e21cc56fbc7f1335035a71c850d1b9b5cc6ff497306f84cced9a769841",
)

maybe(
http_archive,
name = "rules_bazel_integration_test",
sha256 = "cae27bc907fa036e40e57c952867a2ea8ea0ef7e10ecd599ce09887bf60fb1af",
urls = [
"https://github.com/bazel-contrib/rules_bazel_integration_test/releases/download/v0.16.0/rules_bazel_integration_test.v0.16.0.tar.gz",
],
)

maybe(
http_archive,
name = "cgrindel_bazel_starlib",
sha256 = "a8d25340956b429b56302d3fd702bb3df8b3a67db248dd32b3084891ad497964",
urls = [
"https://github.com/cgrindel/bazel-starlib/releases/download/v0.17.0/bazel-starlib.v0.17.0.tar.gz",
],
)
30 changes: 30 additions & 0 deletions test/utils/integration_demo/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
load("@bazel_binaries//:defs.bzl", "bazel_binaries")
load(
"@rules_bazel_integration_test//bazel_integration_test:defs.bzl",
"script_test",
)

package(
default_applicable_licenses = ["//:license"],
default_visibility = [
"//test:__subpackages__",
],
)

script_test(
name = "demo_test",
srcs = ["demo_test.sh"],
bazel_binaries = bazel_binaries,
bazel_version = bazel_binaries.versions.current,
deps = [
"//test/bashunit",
"@bazel_tools//tools/bash/runfiles",
],
)

test_suite(
name = "integration_tests",
tests = [
":demo_test",
],
)
40 changes: 40 additions & 0 deletions test/utils/integration_demo/demo_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
# Copyright 2023 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.

# Short demo of the rules_bazel_integration_test to ensure it works.

# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---

source "$(rlocation build_bazel_rules_android/test/bashunit/unittest.bash)" || \
(echo >&2 "Failed to locate bashunit.sh" && exit 1)

function test_bazel_exists() {
touch WORKSPACE
touch BUILD.bazel

"${BIT_BAZEL_BINARY}" info >& $TEST_log
expect_log "output_base: "
}

run_suite "Demo of rules_bazel_integration_test"

0 comments on commit bb96e31

Please sign in to comment.