Skip to content

Commit

Permalink
[integration testing] Add all exmaples as multi-version bazel integra…
Browse files Browse the repository at this point in the history
…tion tests
  • Loading branch information
restingbull committed Jun 22, 2024
1 parent 7dcb7f9 commit 26fdfa6
Show file tree
Hide file tree
Showing 15 changed files with 637 additions and 211 deletions.
165 changes: 14 additions & 151 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,157 +48,20 @@ tasks:
# cannot be used with remote builds)
- "--strategy=KotlinCompile=remote"
- "--config=rbe"
# TODO: Enable these tests once this example is building against the release rules_kotlin binary
# example-android-5.x:
# name: "Example - Android using Bazel 5.x"
# platform: ubuntu1804
# working_directory: examples/android
# bazel: 5.4.1
# test_targets:
# - //app:all
example-android-6.x:
name: "Example - Android using Bazel 6.x"
platform: ubuntu1804
working_directory: examples/android
bazel: 6.4.0
test_flags:
- "--enable_bzlmod=false"
test_targets:
- //app:all
example-android:
name: "Example - Android"
platform: ubuntu1804
working_directory: examples/android
bazel: 8.0.0-pre.20240206.3
test_flags:
- "--incompatible_enable_android_toolchain_resolution"
- "--android_platforms=//:arm64-v8a"
- "--enable_bzlmod=false"
test_targets:
- //app:all
example-bzlmod-android:
name: "Example Bzlmod - Android"
platform: ubuntu1804
working_directory: examples/android
bazel: 8.0.0-pre.20240206.3
test_flags:
- "--incompatible_enable_android_toolchain_resolution"
- "--android_platforms=//:arm64-v8a"
- "--enable_bzlmod=true"
test_targets:
- //app:all
example-ksp:
name: "Example - Android KSP"
platform: ubuntu1804
working_directory: examples/ksp
test_targets:
- //...
example-associates:
name: "Example - Associates"
platform: ubuntu1804
working_directory: examples/associates
test_targets:
- //...
example-anvil:
name: "Example - Anvil"
platform: ubuntu1804
working_directory: examples/anvil
bazel: 8.0.0-pre.20240206.3
test_flags:
- "--incompatible_enable_android_toolchain_resolution"
- "--android_platforms=//:arm64-v8a"
test_targets:
- //app:all
example-plugins:
name: "Example - Plugins"
platform: ubuntu1804
working_directory: examples/plugin
test_targets:
- //...
example-multiplex:
name: "Example - Multiplex"
platform: ubuntu1804
working_directory: examples/multiplex
build_flags:
- "--enable_bzlmod=false"
build_targets:
- //...
example-bzlmod-multiplex:
name: "Example Bzlmod - Multiplex"
platform: ubuntu1804
working_directory: examples/multiplex
build_flags:
- "--enable_bzlmod=true"
build_targets:
- //...
examples-trivial-ubuntu1804:
name: "Example - Trivial (Ubuntu 18.04)"
platform: ubuntu1804
working_directory: examples/trivial
include_json_profile:
- build
- test
build_targets:
- //...
test_targets:
- //...
examples-trivial-bzlmod-ubuntu1804:
name: "Example - Trivial Bzlmod (Ubuntu 18.04)"
platform: ubuntu1804
working_directory: examples/trivial
build_flags:
- "--enable_bzlmod=true"
test_flags:
- "--enable_bzlmod=true"
include_json_profile:
- build
- test
build_targets:
- //...
test_targets:
- //...
examples-trivial-windows:
name: "Example - Trivial (Windows)"
platform: windows
working_directory: examples/trivial
include_json_profile:
- build
- test
build_targets:
- //...
test_flags:
- "--enable_runfiles"
test_targets:
- //...
examples-dagger:
name: "Example - Dagger"
platform: ubuntu1804
working_directory: examples/dagger
include_json_profile:
- build
- test
build_targets:
- //...
# examples-nodejs:
# name: Example - Node
# platform: ubuntu1804
# working_directory: examples/node
# include_json_profile:
# - build
# - test
# build_targets:
# - //coroutines-helloworld/...
# - //express/...
example-jetpack-compose:
name: "Example - Jetpack Compose"
platform: ubuntu1804
working_directory: examples/jetpack_compose
bazel: 8.0.0-pre.20240206.3
test_flags:
- "--incompatible_enable_android_toolchain_resolution"
- "--android_platforms=//:arm64-v8a"
test_targets:
- //app:all
bazel_integration_tests_ubuntu1804:
name: "Bazel Integration Tests (Ubuntu 18.04)"
platform: ubuntu1804
test_flags:
- "--enable_bzlmod=true"
test_targets:
- //examples:all
bazel_integration_tests_ubuntu2004:
name: "Bazel Integration Tests (Ubuntu 20.04)"
platform: ubuntu2004
test_flags:
- "--enable_bzlmod=true"
test_targets:
- //examples:all
stardoc:
name: Stardoc api documentation
platform: ubuntu1804
Expand Down
2 changes: 1 addition & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Exclude examples from //...:all
examples
examples/*
12 changes: 2 additions & 10 deletions .bazelproject
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@ directories:
.

targets:
//:all_local_tests
# These targets are built for the ide only. Primary purpose is to ensure the builder can build the targets, but it's
# also a good way of testing the intellij plugin.
//src/main/kotlin/io/bazel/kotlin/builder/tasks:tasks_for_ide
//src/main/kotlin/io/bazel/kotlin/builder/utils:utils_for_ide
//src/main/kotlin/io/bazel/kotlin/builder/toolchain:toolchain_for_ide
//src/main/kotlin/io/bazel/kotlin/compiler:compiler_for_ide
//kotlin:stardoc
//src/main/starlark/core/repositories:all
//src/...

test_sources:
src/test/*
Expand All @@ -37,4 +29,4 @@ additional_languages:
import_run_configurations:
src/test/Bazel_all_local_tests.xml

android_sdk_platform: android-31
#android_sdk_platform: android-31
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ build --strategy=KotlinCompile=worker
build --test_output=all
build --verbose_failures

try-import %workspace%/bit-ignore.bazelrc

# User-specific .bazelrc
try-import %workspace%/user.bazelrc
10 changes: 10 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,13 @@ release_archive(
"//third_party:pkg",
],
)

# This target collects all of the parent workspace files needed by the child workspaces.
filegroup(
name = "release_repositories",
# Include every package that is required by the child workspaces.
srcs = [
":rules_kotlin_release",
],
visibility = ["//:__subpackages__"],
)
20 changes: 14 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ module(
repo_name = "rules_kotlin",
)

bazel_dep(name = "platforms", version = "0.0.6")
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "rules_java", version = "7.2.0")
bazel_dep(name = "rules_java", version = "7.4.0")
bazel_dep(name = "rules_python", version = "0.23.1")
bazel_dep(name = "rules_cc", version = "0.0.8")
bazel_dep(name = "rules_cc", version = "0.0.9")

rules_kotlin_extensions = use_extension("//src/main/starlark/core/repositories:bzlmod_setup.bzl", "rules_kotlin_extensions")
use_repo(
rules_kotlin_extensions,
"buildkite_config",
"com_github_google_ksp",
"com_github_jetbrains_kotlin",
"com_github_jetbrains_kotlin_git",
"com_github_pinterest_ktlint",
"released_rules_kotlin",
"rules_android",
Expand Down Expand Up @@ -59,23 +60,23 @@ maven.install(
"com.google.protobuf:protobuf-java-util:3.6.0",
"com.google.guava:guava:27.1-jre",
"com.google.truth:truth:0.45",
"com.google.auto.service:auto-service:1.0.1",
"com.google.auto.service:auto-service-annotations:1.0.1",
"com.google.auto.service:auto-service:1.1.1",
"com.google.auto.service:auto-service-annotations:1.1.1",
"com.google.auto.value:auto-value:1.10.1",
"com.google.auto.value:auto-value-annotations:1.10.1",
"com.google.dagger:dagger:2.51",
"com.google.dagger:dagger-compiler:2.51",
"com.google.dagger:dagger-producers:2.51",
"javax.annotation:javax.annotation-api:1.3.2",
"javax.inject:javax.inject:1",
"org.apache.commons:commons-compress:1.26.2",
"org.pantsbuild:jarjar:1.7.2",
"org.jetbrains.kotlinx:atomicfu-js:0.15.2",
"org.jetbrains.kotlinx:kotlinx-serialization-runtime:1.0-M1-1.4.0-rc",
"dev.zacsweers.autoservice:auto-service-ksp:jar:1.1.0",
"com.squareup.moshi:moshi:1.15.0",
"com.squareup.moshi:moshi-kotlin:1.15.0",
"com.squareup.moshi:moshi-kotlin-codegen:1.15.0",
"com.google.auto.service:auto-service-annotations:jar:1.1.1",
],
fail_if_repin_required = True,
fetch_sources = True,
Expand All @@ -93,3 +94,10 @@ bazel_dep(name = "stardoc", version = "0.5.6", repo_name = "io_bazel_stardoc")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")

bazel_dep(name = "rules_testing", version = "0.5.0", dev_dependency = True)
bazel_dep(name = "rules_bazel_integration_test", version = "0.23.0", dev_dependency = True)

bazel_binaries = use_extension("@rules_bazel_integration_test//:extensions.bzl","bazel_binaries",dev_dependency = True)
bazel_binaries.download(version_file = "//:.bazelversion")
bazel_binaries.download(version = "6.0.0")
bazel_binaries.download(version = "last_green")
use_repo(bazel_binaries, "bazel_binaries", "bazel_binaries_bazelisk", "build_bazel_bazel_.bazelversion", "build_bazel_bazel_6_0_0", "build_bazel_bazel_last_green")
73 changes: 59 additions & 14 deletions examples/BUILD
Original file line number Diff line number Diff line change
@@ -1,14 +1,59 @@
# Copyright 2018 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.
package(default_visibility = ["//visibility:private"])
load("//src/main/starlark/release:packager.bzl", "release_archive")
load("@bazel_binaries//:defs.bzl", "bazel_binaries")
load(
"@rules_bazel_integration_test//bazel_integration_test:defs.bzl",
"bazel_integration_test",
"bazel_integration_tests",
"default_test_runner",
"integration_test_utils",
)

genrule(
name = "update_bit_ignore",
srcs = [],
outs = [
"update_bit_ignore.sh",
],
cmd = "\n".join([
"cat <<'EOS' > $@",
"#!/usr/bin/env bash",
"cd $${BUILD_WORKSPACE_DIRECTORY}",
"echo 'common --deleted_packages='$$(find examples -type 'd' | grep -v '^examples$$' | tr '\n' ',' | sed 's/,$$//')" +
"> bit-ignore.bazelrc",
"EOS",
]),
executable = True,
)

[
bazel_integration_tests(
name = "%s_test" % example,
bazel_versions = bazel_binaries.versions.all,
test_runner = "//src/main/kotlin/io/bazel/kotlin/test:BazelIntegrationTestRunner",
workspace_files = glob(["%s/**/*" % example]),
workspace_path = example,
)
for example in {
file.partition("/")[0]: True
for file in glob(
["**/*"],
exclude = ["*"],
)
}
]

# By default, the integration test targets are tagged as `manual`. This
# prevents the targets from being found from most target expansion (e.g.
# `//...`, `:all`). To easily execute a group of integration tests, you may
# want to define a test suite which includes the desired test targets.
#test_suite(
# name = "all_integration_tests",
# # If you don't apply the test tags to the test suite, the test suite will
# # be found when `bazel test //...` is executed.
# tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS,
# tests = integration_test_utils.bazel_integration_test_names(
# "simple_test",
# bazel_binaries.versions.other,
# ),
# visibility = ["//:__subpackages__"],
#)
9 changes: 8 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
The examples directory is for test applications. These could be used in tests or for verifying the intellij plugin.
# Examples

These are series of code samples useful for configuring a variety of use cases. They also serve as integration tests.

## Adding a new integration test
1. Create a new workspace in the `examples` directory
2. Ensure that the `rules_kotlin` repository is named `rules_kotlin`
3. Update the bazel excluded packages via `bazel run //examples:update_bit_ignore`
6 changes: 1 addition & 5 deletions examples/android/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ bazel_dep(name = "bazel_skylib", version = "1.2.1")
bazel_dep(name = "rules_robolectric", version = "4.10.3", repo_name = "robolectric")
bazel_dep(name = "rules_java", version = "6.4.0")
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "rules_kotlin")
local_path_override(
module_name = "rules_kotlin",
path = "../..",
)
bazel_dep(name = "rules_kotlin", version = "1.9.5")

bazel_dep(name = "rules_jvm_external", version = "5.3")

Expand Down
Loading

0 comments on commit 26fdfa6

Please sign in to comment.