diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 8e4692ac8..a6cda5af0 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -1,17 +1,44 @@ --- +# Common task configurations. +.unittests: &unittests + build_flags: ${{ test_flags }} + test_flags: ${{ test_flags }} + test_targets: + - "//src/..." + build_targets: + - "//src/..." + +.integration_tests: &integration_tests + name: "Integration Tests" + platform: ${{ platform.name }} + environment: + ANDROID_NDK_HOME: ${{ platform.android_ndk_home }} + test_flags: ${{ integration_shard_flags }} + test_targets: + - //examples:all + +# Common platform configurations. +.ubuntu2404: &ubuntu2404 + platform: ubuntu2404 + environment: + ANDROID_NDK_HOME: /opt/android-ndk-r25b + +.ubuntu2204: &ubuntu2204 + platform: ubuntu2204 + environment: + ANDROID_NDK_HOME: /opt/android-ndk-r25b + +.macos: &macos + platform: macos + environment: + ANDROID_NDK_HOME: /Users/buildkite/android-ndk-r25b + +# bazelci pipeline matrix: - unittest_platform: - - ubuntu2404 - - ubuntu2204 - integration_platform: - - ubuntu2404 - - ubuntu2204 integration_shard_flags: - ["--test_tag_filters=shard_0", "--config=rbe"] - ["--test_tag_filters=shard_1", "--config=rbe"] - ["--test_tag_filters=shard_2", "--config=rbe"] - # - macos - # - windows re-enable when rules_bazel_integration_test can support custom test runner on windows. test_flags: - ["--enable_bzlmod=true"] validate_config: 1 @@ -22,21 +49,16 @@ buildifier: # keep this argument in sync with .pre-commit-config.yaml warnings: "-confusing-name,-constant-glob,-duplicated-name,-function-docstring,-function-docstring-args,-function-docstring-header,-module-docstring,-name-conventions,-no-effect,-constant-glob,-provider-params,-print,-rule-impl-return,-bzl-visibility,-unnamed-macro,-uninitialized,-unreachable" tasks: - unittests: - name: "Unit Tests" - platform: ${{ unittest_platform }} - build_flags: ${{ test_flags }} - test_flags: ${{ test_flags }} - test_targets: - - "//src/..." - build_targets: - - "//src/..." - integration_tests: - name: "Integration Tests" - platform: ${{ integration_platform }} - test_flags: ${{ integration_shard_flags }} - test_targets: - - //examples:all + macos_unittests: + <<: [ *macos, *unittests ] + ubuntu2404_unittests: + <<: [*ubuntu2404, *unittests] + ubuntu2404_integration_tests: + <<: [*ubuntu2404, *integration_tests] + ubuntu2204_unittests: + <<: [*ubuntu2204, *unittests] + ubuntu2204_integration_tests: + <<: [*ubuntu2204, *integration_tests] rbe_ubuntu1604: test_targets: - "--" @@ -52,7 +74,7 @@ tasks: - "--strategy=KotlinCompile=remote" stardoc: name: Stardoc api documentation - platform: ubuntu2404 + <<: *ubuntu2404 build_flags: - "--enable_bzlmod=true" build_targets: @@ -61,7 +83,7 @@ tasks: - //docs:are_docs_up_to_date_test ktlint: name: KtLint - platform: ubuntu2404 + <<: *ubuntu2404 test_targets: - //... test_flags: diff --git a/.bazelrc b/.bazelrc index 3d8bc157a..c73b8137d 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,7 +1,7 @@ common --enable_bzlmod=true common --incompatible_use_plus_in_repo_names common --incompatible_disallow_empty_glob=false - +common --incompatible_disable_native_repo_rules=true common:rbe --java_runtime_version=11 common:rbe --tool_java_runtime_version=11 diff --git a/BUILD b/BUILD index 108d7a3c8..d5490366c 100644 --- a/BUILD +++ b/BUILD @@ -58,9 +58,6 @@ test_suite( # Release target. release_archive( name = "rules_kotlin_release", - srcs = [ - "WORKSPACE.bzlmod", - ], src_map = { "BUILD.release.bazel": "BUILD.bazel", "MODULE.release.bazel": "MODULE.bazel", diff --git a/MODULE.bazel b/MODULE.bazel index 40af3bee4..112342a19 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -13,7 +13,19 @@ bazel_dep(name = "platforms", version = "0.0.11") bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep(name = "rules_java", version = "8.9.0") bazel_dep(name = "rules_python", version = "0.23.1") -bazel_dep(name = "rules_android", version = "0.6.4") +bazel_dep(name = "rules_android", version = "0.6.6") + +remote_android_extensions = use_extension( + "@rules_android//bzlmod_extensions:android_extensions.bzl", + "remote_android_tools_extensions", +) +use_repo(remote_android_extensions, "android_tools") + +android_sdk_repository_extension = use_extension("@rules_android//rules/android_sdk_repository:rule.bzl", "android_sdk_repository_extension") +use_repo(android_sdk_repository_extension, "androidsdk") + +register_toolchains("@androidsdk//:all") + bazel_dep(name = "bazel_features", version = "1.25.0") bazel_dep(name = "rules_shell", version = "0.4.1") diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod deleted file mode 100644 index 9cc43bba4..000000000 --- a/WORKSPACE.bzlmod +++ /dev/null @@ -1 +0,0 @@ -android_sdk_repository(name = "androidsdk") diff --git a/examples/android/.bazelrc b/examples/android/.bazelrc index 900fb9c83..a013f2836 100644 --- a/examples/android/.bazelrc +++ b/examples/android/.bazelrc @@ -2,6 +2,9 @@ common --lockfile_mode=off test --test_output=all build --config=android_worker +common --incompatible_disable_native_repo_rules=true +common --incompatible_autoload_externally= + # Worker configuration build:android_worker \ --worker_max_instances=auto \ diff --git a/examples/android/MODULE.bazel b/examples/android/MODULE.bazel index 91f7dc85a..84c9a4c0f 100644 --- a/examples/android/MODULE.bazel +++ b/examples/android/MODULE.bazel @@ -12,6 +12,13 @@ use_repo(android_sdk_repository_extension, "androidsdk") register_toolchains("@androidsdk//:sdk-toolchain", "@androidsdk//:all") +bazel_dep(name = "rules_android_ndk", version = "0.1.2") + +android_ndk_repository_extension = use_extension("@rules_android_ndk//:extension.bzl", "android_ndk_repository_extension") +use_repo(android_ndk_repository_extension, "androidndk") + +register_toolchains("@androidndk//:all") + maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") maven.install( name = "maven_rules_kotlin_example", diff --git a/examples/android/WORKSPACE.bzlmod b/examples/android/WORKSPACE.bzlmod index 1754a3eee..e69de29bb 100644 --- a/examples/android/WORKSPACE.bzlmod +++ b/examples/android/WORKSPACE.bzlmod @@ -1,3 +0,0 @@ -android_sdk_repository(name = "androidsdk") - -android_ndk_repository(name = "androidndk") diff --git a/src/test/starlark/core/plugin/kapt/kapt_test.bzl b/src/test/starlark/core/plugin/kapt/kapt_test.bzl index 99b2005a5..a77c8a5c3 100644 --- a/src/test/starlark/core/plugin/kapt/kapt_test.bzl +++ b/src/test/starlark/core/plugin/kapt/kapt_test.bzl @@ -5,26 +5,51 @@ load("//kotlin/compiler:kapt.bzl", "kapt_compiler_plugin") load("//src/test/starlark:case.bzl", "Want", "suite") load("//src/test/starlark:truth.bzl", "flags_and_values_of") +def _normalize_path_with_cfg(file): + """Attempts to normalize the file to standard configs. + + This turns out to be necessary due to multiple transitions with testing.analysis_test. + """ + prefix = file.path.removesuffix(file.short_path) + segments = prefix.split("/") + if segments[0] == "bazel-out": + # not exactly reliable, but the current test rules perform several transitions making it + # difficult to validate if a file is actually where it should be. + if "exec" in segments[1]: + return "(exec) " + file.short_path + return "(target) " + file.short_path + if file.is_source: + return "(source) " + file.short_path + + return file.path + def _action(env, got): got_target = env.expect.that_target(got) - inputs = [] + want_inputs = {} for i in env.ctx.attr.exec_inputs: if JavaInfo in i: for jo in i[JavaInfo].java_outputs: - inputs.append(jo.compile_jar) + want_inputs[_normalize_path_with_cfg(jo.compile_jar)] = True else: - inputs.extend(i[DefaultInfo].files.to_list()) + for f in i[DefaultInfo].files.to_list(): + want_inputs[_normalize_path_with_cfg(f)] = True for i in env.ctx.attr.target_inputs: if JavaInfo in i: for jo in i[JavaInfo].java_outputs: - inputs.append(jo.compile_jar) + want_inputs[_normalize_path_with_cfg(jo.compile_jar)] = True else: - inputs.extend(i[DefaultInfo].files.to_list()) + for f in i[DefaultInfo].files.to_list(): + want_inputs[_normalize_path_with_cfg(f)] = True compile = got_target.action_named(env.ctx.attr.mnemonic) - compile.contains_at_least_inputs(inputs) + got_inputs = { + _normalize_path_with_cfg(f): True + for f in compile.actual.inputs.to_list() + } + + env.expect.that_collection(got_inputs.keys()).contains_at_least(want_inputs.keys()) got_target.runfiles().contains_at_least([ "/".join((env.ctx.workspace_name, f.short_path))