diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 4e826dba..9c186288 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -8,8 +8,6 @@ build_targets: &build_targets - "@remote_java_tools//:one_version_cc_bin" - "@remote_java_tools//:proguard" - "@remote_java_tools//:singlejar_cc_bin" - # can't build @remote_java_tools_X repos for other platforms - - "-//toolchains/..." build_targets_integration: &build_targets_integration - "//..." @@ -28,8 +26,8 @@ flags_workspace_integration: &flags_workspace_integration buildifier: latest matrix: - all_platforms: ["rockylinux8_arm64", "ubuntu2004", "macos", "macos_arm64", "windows"] - bazel: ["7.x", "8.x", "9.x", "last_green"] + all_platforms: ["rockylinux8_arm64", "ubuntu2404", "macos", "macos_arm64", "windows"] + bazel: ["8.x", "9.x", "last_green"] modern_bazel: ["9.x", "last_green", "rolling"] # Fully supported Bazel versions tasks: @@ -49,15 +47,6 @@ tasks: test_targets: *test_targets test_flags: - "--test_tag_filters=-min_bazel_9" -# Bazel 7.x - build_and_test_bazel7: - name: "Bazel 7.x" - bazel: "7.x" - platform: ${{ all_platforms }} - build_targets: *build_targets - test_targets: *test_targets - test_flags: - - "--test_tag_filters=-min_bazel_8,-min_bazel_9" # Integration tests integration_build_and_test: @@ -87,7 +76,7 @@ tasks: # internal tests for configs and release process internal_tests: name: "Internal tests" - platform: "ubuntu2004" + platform: "ubuntu2404" shell_commands: - "git init" - "git config user.name 'fake-user-for-testing'" diff --git a/.bazelrc b/.bazelrc index 12d684fc..f25f6d28 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,6 +1,6 @@ common --incompatible_disallow_empty_glob -# Use hermetic JDKs for testing and ensure compatibliity with Java 8. +# Use hermetic JDKs for testing and ensure compatibility with Java 8. common --java_language_version=8 common --java_runtime_version=remotejdk_8 common --tool_java_language_version=8 diff --git a/.bcr/metadata.template.json b/.bcr/metadata.template.json index 9d091448..8ef2f6a7 100644 --- a/.bcr/metadata.template.json +++ b/.bcr/metadata.template.json @@ -4,7 +4,8 @@ { "email": "hvd@google.com", "github": "hvadehra", - "name": "Hemanshu Vadehra" + "name": "Hemanshu Vadehra", + "github_user_id": 2486163 } ], "versions": [], diff --git a/.bcr/presubmit.yml b/.bcr/presubmit.yml index 26dad0fe..c26fb618 100644 --- a/.bcr/presubmit.yml +++ b/.bcr/presubmit.yml @@ -6,8 +6,8 @@ matrix: - ubuntu2004 - windows bazel: - - 7.x - 8.x + - 9.x tasks: verify_build_targets: name: "Verify build targets w/ Bazel {bazel}" diff --git a/MODULE.bazel b/MODULE.bazel index a088efe7..13d44ed5 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,12 +1,11 @@ module( name = "rules_java", version = "0.0.0", - bazel_compatibility = [">=7.0.0"], - compatibility_level = 1, + bazel_compatibility = [">=8.0.0"], ) bazel_dep(name = "platforms", version = "0.0.11") -bazel_dep(name = "rules_cc", version = "0.2.17") +bazel_dep(name = "rules_cc", version = "0.2.25") bazel_dep(name = "bazel_features", version = "1.30.0") bazel_dep(name = "bazel_skylib", version = "1.6.1") bazel_dep(name = "protobuf", version = "32.1", repo_name = "com_google_protobuf") @@ -124,9 +123,9 @@ bazel_dep(name = "rules_shell", version = "0.2.0", dev_dependency = True) bazel_dep(name = "rules_testing", dev_dependency = True) archive_override( module_name = "rules_testing", - integrity = "sha256-ZmrwZSmn3NkEj0MOnix9oSMzPXJWbuJbCCbOM1C03QQ=", - strip_prefix = "rules_testing-ff65fc8b7f1b7c37de71d781601ff40288de80f2", - urls = ["https://github.com/bazelbuild/rules_testing/archive/ff65fc8b7f1b7c37de71d781601ff40288de80f2.tar.gz"], + integrity = "sha256-UlGXv0mAHt6sQtadxJ97TeqrJVIaKP7X+M8SrNpqM7s=", + strip_prefix = "rules_testing-2529012de853e1147460363c04dbe911c1025a6b", + urls = ["https://github.com/bazelbuild/rules_testing/archive/2529012de853e1147460363c04dbe911c1025a6b.tar.gz"], ) test_repositories = use_extension("//test:repositories.bzl", "test_repositories_ext", dev_dependency = True) diff --git a/java/bazel/BUILD.bazel b/java/bazel/BUILD.bazel index 225628e8..dcf657ab 100644 --- a/java/bazel/BUILD.bazel +++ b/java/bazel/BUILD.bazel @@ -27,7 +27,7 @@ genrule( echo > $@ while read -r config; do TMP_FILE=$$(mktemp -q /tmp/remotejdk.XXXXXX) - IFS=\\| read -r name version urls strip_prefix target_compatible_with primary_url <<< "$$config" + IFS=\\| read -r name version urls strip_prefix target_compatible_with primary_url patch_cmds <<< "$$config" echo "fetching: $$primary_url to $$TMP_FILE" > /dev/stderr curl --retry 5 --write-out '%{{onerror}}%{{url}}\n' --show-error --silent --fail -o $$TMP_FILE -L "$$primary_url" > /dev/stderr sha256=`sha256sum $$TMP_FILE | cut -d' ' -f1` @@ -38,7 +38,11 @@ while read -r config; do echo " strip_prefix = \\"$$strip_prefix\\"," echo " urls = $$urls," echo " version = \\"$$version\\"," + if [[ "$$patch_cmds" != "[]" ]]; then + echo " patch_cmds = $$patch_cmds," + fi echo ")," + rm -f "$$TMP_FILE" done <<< '{configs}' >> $@ """.format(configs = "\n".join([ "|".join([ @@ -48,6 +52,7 @@ done <<< '{configs}' >> $@ config.strip_prefix, json.encode(config.target_compatible_with), config.urls[0], + json.encode(config.patch_cmds), ]) for config in FLAT_CONFIGS ])), diff --git a/java/bazel/repositories_util.bzl b/java/bazel/repositories_util.bzl index 40101d37..813f5f13 100644 --- a/java/bazel/repositories_util.bzl +++ b/java/bazel/repositories_util.bzl @@ -18,7 +18,7 @@ visibility(["//test"]) _RELEASE_CONFIGS = { "8": { "zulu": { - "release": "8.90.0.19-ca-jdk8.0.472", + "release": "8.96.0.19-ca-jdk8.0.502", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], @@ -34,7 +34,7 @@ _RELEASE_CONFIGS = { }, "11": { "zulu": { - "release": "11.84.17-ca-jdk11.0.29", + "release": "11.90.19-ca-jdk11.0.32", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], @@ -56,7 +56,7 @@ _RELEASE_CONFIGS = { }, "17": { "zulu": { - "release": "17.62.17-ca-jdk17.0.17", + "release": "17.68.17-ca-jdk17.0.20", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], @@ -72,7 +72,7 @@ _RELEASE_CONFIGS = { }, "21": { "zulu": { - "release": "21.46.19-ca-jdk21.0.9", + "release": "21.52.15-ca-jdk21.0.12", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], @@ -88,7 +88,7 @@ _RELEASE_CONFIGS = { }, "25": { "zulu": { - "release": "25.32.17-ca-jdk25.0.2", + "release": "25.36.15-ca-jdk25.0.4", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], @@ -135,7 +135,16 @@ def _zulu_remote_jdk_repo(os, cpu, release): "https://" + primary_url, "https://mirror.bazel.build/" + primary_url, ] - return urls, archive_name + patch_cmds = [] + if os == "macos": + # Recent Zulu macOS archives are application bundles: the JDK lives + # under Contents/Home and the top-level bin/lib/... symlinks that + # earlier releases shipped are gone. strip_prefix stays at the + # archive root (uniform with the other platforms); recreate the + # top-level symlinks so the shared JDK BUILD template still finds + # bin/, lib/, etc. + patch_cmds = ["ln -s Contents/Home/* ."] + return urls, archive_name, patch_cmds def _adoptium_linux_remote_jdk_repo(version, cpu, release): os = "linux" @@ -173,8 +182,9 @@ def _flatten_configs(): for os, cpus in distrib_cfg["platforms"].items(): for cpu in cpus: name = _name_for_remote_jdk(version, os, cpu) + patch_cmds = [] if distrib == "zulu": - urls, strip_prefix = _zulu_remote_jdk_repo(os, cpu, release) + urls, strip_prefix, patch_cmds = _zulu_remote_jdk_repo(os, cpu, release) elif distrib == "adoptium": if os != "linux": fail("adoptium jdk configured but not linux") @@ -193,6 +203,7 @@ def _flatten_configs(): urls = urls, strip_prefix = _STRIP_PREFIX_OVERRIDES.get(name, strip_prefix), target_compatible_with = ["@platforms//os:" + os, "@platforms//cpu:" + cpu], + patch_cmds = patch_cmds, )) return result diff --git a/java/bazel/rules/bazel_java_binary.bzl b/java/bazel/rules/bazel_java_binary.bzl index 4ee9c881..998ac898 100644 --- a/java/bazel/rules/bazel_java_binary.bzl +++ b/java/bazel/rules/bazel_java_binary.bzl @@ -79,15 +79,16 @@ def bazel_base_binary_impl(ctx, is_test_rule_class): _java_runtime_version = semantics.find_java_runtime_toolchain(ctx).version if _java_runtime_version >= 17 and _java_runtime_version < 24: jvm_flags.append("-Djava.security.manager=allow") - test_class = ctx.attr.test_class if hasattr(ctx.attr, "test_class") else "" - if test_class == "": - test_class = helper.primary_class(ctx) - if test_class == None: - fail("cannot determine test class. You might want to rename the " + - "rule or add a 'test_class' attribute.") + test_classes = helper.test_classes(ctx) + if not test_classes: + fail("cannot determine test class. You might want to add a " + + "'test_class' or 'test_classes' attribute.") jvm_flags.extend([ "-ea", - "-Dbazel.test_suite=" + helper.shell_escape(test_class), + "-D{prop_name}={prop_value}".format( + prop_name = semantics.TEST_SUITE_PROPERTY_NAME, + prop_value = helper.shell_escape(",".join(test_classes)), + ), ]) java_attrs = providers["InternalDeployJarInfo"].java_attrs @@ -119,6 +120,7 @@ def bazel_base_binary_impl(ctx, is_test_rule_class): main_class, coverage_main_class, info.strip_as_default, + exclude_build_data = ctx.attr.exclude_build_data, add_exports = info.add_exports, add_opens = info.add_opens, ) @@ -278,6 +280,7 @@ def _format_classpath_entry(runfiles_enabled, workspace_prefix, file): return "$(rlocation " + paths.normalize(workspace_prefix + file.short_path) + ")" def _create_windows_exe_launcher(ctx, java_executable, classpath, main_class, jvm_flags_for_launcher, runfiles_enabled, coverage_enabled, executable, coverage_main_class): + java_runtime_toolchain = semantics.find_java_runtime_toolchain(ctx) launch_info = ctx.actions.args().use_param_file("%s", use_always = True).set_param_file_format("multiline") launch_info.add("binary_type=Java") launch_info.add(ctx.workspace_name, format = "workspace_name=%s") @@ -288,7 +291,8 @@ def _create_windows_exe_launcher(ctx, java_executable, classpath, main_class, jv launch_info.add(coverage_main_class, format = "jacoco_main_class=%s") launch_info.add_joined(classpath, map_each = _short_path, join_with = ";", format_joined = "classpath=%s", omit_if_empty = False) launch_info.add_joined(jvm_flags_for_launcher, join_with = "\t", format_joined = "jvm_flags=%s", omit_if_empty = False) - launch_info.add(semantics.find_java_runtime_toolchain(ctx).java_home_runfiles_path, format = "jar_bin_path=%s/bin/jar.exe") + launch_info.add(java_runtime_toolchain.java_home_runfiles_path, format = "jar_bin_path=%s/bin/jar.exe") + launch_info.add(java_runtime_toolchain.version, format = "java_version=%s") # TODO(b/295221112): Change to use the "launcher" attribute (only windows use a fixed _launcher attribute) launcher_artifact = ctx.executable._launcher @@ -341,6 +345,13 @@ def make_binary_rule(implementation, *, doc, attrs, executable = False, test = F BASE_BINARY_ATTRS = merge_attrs( BASIC_JAVA_BINARY_ATTRIBUTES, { + "exclude_build_data": attr.bool( + default = False, + doc = """ +Whether to omit the build-data.properties file from the +*_deploy.jar output. + """, + ), "resource_strip_prefix": attr.string( doc = """ The path prefix to strip from Java resources. diff --git a/java/common/BUILD b/java/common/BUILD index 7887b1f0..096f77b8 100644 --- a/java/common/BUILD +++ b/java/common/BUILD @@ -38,6 +38,7 @@ bzl_library( visibility = ["//visibility:public"], deps = [ "@bazel_features//:features", + "@rules_cc//cc:action_names_bzl", "@rules_cc//cc/common:cc_helper_bzl", ], ) diff --git a/java/common/java_semantics.bzl b/java/common/java_semantics.bzl index 919553e9..c85ec048 100644 --- a/java/common/java_semantics.bzl +++ b/java/common/java_semantics.bzl @@ -128,4 +128,5 @@ semantics = struct( update_args_for_import_deps = _update_args_for_import_deps, expand_javacopts_make_variables = True, java_toolchain_supports_one_version = _bazel_version_ge("8.0.0"), # can be dropped once we no longer support Bazel 7 + TEST_SUITE_PROPERTY_NAME = "bazel.test_suite", ) diff --git a/java/common/rules/BUILD b/java/common/rules/BUILD index 4c24d073..fa181d26 100644 --- a/java/common/rules/BUILD +++ b/java/common/rules/BUILD @@ -92,6 +92,7 @@ filegroup( srcs = [ "BUILD", ":core_rules", + ":java_helper_bzl", ":java_single_jar_bzl", ":toolchain_rules", "//java/common/rules/impl:for_bazel_tests", diff --git a/java/common/rules/android_lint.bzl b/java/common/rules/android_lint.bzl index 7152990c..d07bb5e3 100644 --- a/java/common/rules/android_lint.bzl +++ b/java/common/rules/android_lint.bzl @@ -82,7 +82,7 @@ def _android_lint_action(ctx, source_files, source_jars, compilation_info, is_li executable = linter.tool.executable transitive_inputs = [] if executable.extension != "jar": - tools = [linter.tool] + tools = [linter.tool, linter.tools] transitive_inputs.append(linter.data) args_list = [args] else: @@ -91,7 +91,7 @@ def _android_lint_action(ctx, source_files, source_jars, compilation_info, is_li jvm_args.add_all(linter.jvm_opts) jvm_args.add("-jar", executable) executable = java_runtime.java_executable_exec_path - tools = [java_runtime.files, linter.tool.executable] + tools = [java_runtime.files, linter.tool.executable, linter.tools] transitive_inputs.append(linter.data) args_list = [jvm_args, args] diff --git a/java/common/rules/impl/BUILD b/java/common/rules/impl/BUILD index 70adeccd..ed1eb2f7 100644 --- a/java/common/rules/impl/BUILD +++ b/java/common/rules/impl/BUILD @@ -21,7 +21,7 @@ bzl_library( deps = [ ":java_helper_bzl", "//java/common:proguard_spec_info_bzl", - "@com_google_protobuf//bazel/common:proto_info_bzl", + "@rules_cc//cc:action_names_bzl", # TODO: remove after https://github.com/bazelbuild/rules_cc/issues/913 is fixed "@rules_cc//cc/common:cc_helper_bzl", ], ) diff --git a/java/common/rules/impl/bazel_java_import_impl.bzl b/java/common/rules/impl/bazel_java_import_impl.bzl index c402fc44..aa829d1f 100644 --- a/java/common/rules/impl/bazel_java_import_impl.bzl +++ b/java/common/rules/impl/bazel_java_import_impl.bzl @@ -115,16 +115,23 @@ def bazel_java_import_rule( collected_jars = _collect_jars(ctx, jars) all_deps = _filter_provider(JavaInfo, deps, exports) - jdeps_artifact = None merged_java_info = java_common.merge(all_deps) - if not skip_incomplete_deps_check and "incomplete-deps" not in ctx.attr.tags: - jdeps_artifact = import_deps_check( - ctx, - collected_jars, - merged_java_info.compile_jars, - merged_java_info.transitive_compile_time_jars, - "java_import", - ) + + # import_deps_check is always run to generate the jdeps proto for downstream compile actions, + # but may be silenced. + has_incomplete_deps = "incomplete-deps" in ctx.attr.tags + if skip_incomplete_deps_check or has_incomplete_deps: + checking_mode = "silence" + else: + checking_mode = "error" + jdeps_artifact = import_deps_check( + ctx, + collected_jars, + merged_java_info.compile_jars, + merged_java_info.transitive_compile_time_jars, + "java_import", + checking_mode = checking_mode, + ) compilation_to_runtime_jar_map = _process_with_ijars_if_needed(collected_jars, ctx) runtime_deps_list = [runtime_dep[JavaInfo] for runtime_dep in runtime_deps if JavaInfo in runtime_dep] @@ -134,6 +141,7 @@ def bazel_java_import_rule( java_infos.append(JavaInfo( output_jar = jar, compile_jar = compilation_to_runtime_jar_map[jar], + compile_jdeps = jdeps_artifact, deps = all_deps, runtime_deps = runtime_deps_list, neverlink = neverlink, @@ -169,7 +177,7 @@ def bazel_java_import_rule( output_group_src_jars = depset() if srcjar == None else depset([srcjar]) validation_group = [] - if jdeps_artifact != None: + if jdeps_artifact != None and checking_mode != "silence": validation_group.append(jdeps_artifact) if srcjar != None: validation_group.append(srcjar) diff --git a/java/common/rules/impl/import_deps_check.bzl b/java/common/rules/impl/import_deps_check.bzl index 69dec8b6..f5a950f7 100644 --- a/java/common/rules/impl/import_deps_check.bzl +++ b/java/common/rules/impl/import_deps_check.bzl @@ -23,7 +23,8 @@ def import_deps_check( jars_to_check, declared_deps, transitive_deps, - rule_class): + rule_class, + checking_mode = "error"): """ Creates actions that checks import deps for java rules. @@ -33,6 +34,7 @@ def import_deps_check( declared_deps: (list[File]) A list of direct dependencies. transitive_deps: (list[File]) A list of transitive dependencies. rule_class: (String) Rule class. + checking_mode: (String) One of "error", "warning" or "silence". Returns: (File) Output file of the created action. @@ -53,9 +55,11 @@ def import_deps_check( before_each = "--classpath_entry", ) args.add_all(java_toolchain.bootclasspath, before_each = "--bootclasspath_entry") - args.add("--checking_mode=error") + args.add(checking_mode, format = "--checking_mode=%s") args.add("--jdeps_output", jdeps_output) - args.add("--rule_label", ctx.label) + + # ctx.label can start with an @ and must not be understood as a flagfile. + args.add(ctx.label, format = "--rule_label=%s") semantics.update_args_for_import_deps(ctx, args) inputs = depset( diff --git a/java/common/rules/impl/java_binary_deploy_jar.bzl b/java/common/rules/impl/java_binary_deploy_jar.bzl index d6add141..41cc9bf6 100644 --- a/java/common/rules/impl/java_binary_deploy_jar.bzl +++ b/java/common/rules/impl/java_binary_deploy_jar.bzl @@ -19,6 +19,9 @@ load(":java_helper.bzl", "helper") # copybara: default visibility +def _map_hermetic_resource(f): + return "%s:%s" % (f.path, f.short_path) + def create_deploy_archives( ctx, java_attrs, @@ -32,7 +35,8 @@ def create_deploy_archives( one_version_level = "OFF", one_version_allowlist = None, extra_args = [], - extra_manifest_lines = []): + extra_manifest_lines = [], + exclude_build_data = False): """ Registers actions for _deploy.jar and _deploy.jar.unstripped Args: @@ -49,6 +53,7 @@ def create_deploy_archives( one_version_allowlist: (File) Optional allowlist for one version check extra_args: (list[Args]) Optional arguments for the deploy jar action extra_manifest_lines: (list[String]) Optional lines added to the jar manifest + exclude_build_data: (bool) Whether to omit build-data.properties """ classpath_resources = java_attrs.classpath_resources @@ -61,7 +66,10 @@ def create_deploy_archives( order = "preorder", ) multi_release = ctx.fragments.java.multi_release_deploy_jars - build_info_files = helper.get_build_info(ctx, ctx.attr.stamp) + if exclude_build_data and ctx.attr.stamp == 1: + fail("Enabling stamping has no effect with exclude_build_data enabled") + + build_info_files = [] if exclude_build_data else helper.get_build_info(ctx, ctx.attr.stamp) build_target = str(ctx.label) manifest_lines = ctx.attr.deploy_manifest_lines + extra_manifest_lines create_deploy_archive( @@ -69,13 +77,13 @@ def create_deploy_archives( launcher_info.launcher, main_class, coverage_main_class, - java_attrs.resources, classpath_resources, runtime_classpath, manifest_lines, build_info_files, build_target, output = ctx.outputs.deployjar, + exclude_build_data = exclude_build_data, one_version_level = one_version_level, one_version_allowlist = one_version_allowlist, multi_release = multi_release, @@ -91,13 +99,13 @@ def create_deploy_archives( launcher_info.unstripped_launcher, main_class, coverage_main_class, - java_attrs.resources, classpath_resources, runtime_classpath, manifest_lines, build_info_files, build_target, output = ctx.outputs.unstrippeddeployjar, + exclude_build_data = exclude_build_data, multi_release = multi_release, hermetic = hermetic, add_exports = add_exports, @@ -112,7 +120,6 @@ def create_deploy_archive( launcher, main_class, coverage_main_class, - resources, classpath_resources, runtime_classpath, manifest_lines, @@ -125,7 +132,8 @@ def create_deploy_archive( hermetic = False, add_exports = [], add_opens = [], - extra_args = []): + extra_args = [], + exclude_build_data = False): """ Creates a deploy jar Requires a Java runtime toolchain if and only if hermetic is True. @@ -135,7 +143,6 @@ def create_deploy_archive( launcher: (File) the launcher artifact main_class: (String) FQN of the entry point for execution coverage_main_class: (String) FQN of the entry point for coverage collection - resources: (Depset) resource inputs classpath_resources: (Depset) classpath resource inputs runtime_classpath: (Depset) source files to add to the jar build_target: (String) Name of the build target for stamping @@ -150,12 +157,12 @@ def create_deploy_archive( add_exports: (depset) add_opens: (depset) extra_args: (list[Args]) Optional arguments for the deploy jar action + exclude_build_data: (bool) Whether to omit build-data.properties """ input_files = [] input_files.extend(build_info_files) transitive_input_files = [ - resources, classpath_resources, runtime_classpath, ] @@ -177,7 +184,10 @@ def create_deploy_archive( if main_class: args.add("--main_class", main_class) args.add_all("--deploy_manifest_lines", manifest_lines) - args.add_all(build_info_files, before_each = "--build_info_file") + if exclude_build_data: + args.add("--exclude_build_data") + else: + args.add_all(build_info_files, before_each = "--build_info_file") if launcher: input_files.append(launcher) args.add("--java_launcher", launcher) @@ -201,13 +211,17 @@ def create_deploy_archive( if hermetic: runtime = ctx.toolchains["@//tools/jdk/hermetic:hermetic_runtime_toolchain_type"].java_runtime if runtime.lib_modules != None: - java_home = runtime.java_home + java_home = runtime.java_home_runfiles_path lib_modules = runtime.lib_modules hermetic_files = runtime.hermetic_files default_cds = runtime.default_cds args.add("--hermetic_java_home", java_home) args.add("--jdk_lib_modules", lib_modules) - args.add_all("--resources", hermetic_files) + args.add_all( + "--resources", + hermetic_files, + map_each = _map_hermetic_resource, + ) input_files.append(lib_modules) transitive_input_files.append(hermetic_files) if default_cds: @@ -227,6 +241,9 @@ def create_deploy_archive( tools = [single_jar], outputs = [output], arguments = [args] + extra_args, + execution_requirements = { + "supports-path-mapping": "1", + }, use_default_shell_env = True, toolchain = semantics.JAVA_TOOLCHAIN_TYPE, ) diff --git a/java/common/rules/impl/java_binary_impl.bzl b/java/common/rules/impl/java_binary_impl.bzl index 8b9b68de..6308ec32 100644 --- a/java/common/rules/impl/java_binary_impl.bzl +++ b/java/common/rules/impl/java_binary_impl.bzl @@ -14,7 +14,6 @@ """ Implementation of java_binary for bazel """ -load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo") load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_cc//cc/common:cc_helper.bzl", "cc_helper") load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") @@ -23,7 +22,6 @@ load("//java/common/rules/impl:basic_java_library_impl.bzl", "basic_java_library load("//java/private:java_common.bzl", "java_common") load( "//java/private:java_common_internal.bzl", - "collect_native_deps_dirs", "get_runtime_classpath_for_archive", ) load("//java/private:java_info.bzl", "JavaCompilationInfo", "JavaInfo", "to_java_binary_info") @@ -88,7 +86,14 @@ def basic_java_binary( if not ctx.attr.use_launcher and (ctx.attr.launcher and ctx.attr.launcher.label != semantics.LAUNCHER_FLAG_LABEL): fail("launcher specified but use_launcher is false") - if not ctx.attr.srcs and ctx.attr.deps: + if not is_test_rule_class: + if hasattr(ctx.attr, "test_classes") and ctx.attr.test_classes: + fail("in %s: 'test_classes' is not allowed on java_binary" % ctx.label) + if hasattr(ctx.attr, "non_test_srcs") and ctx.attr.non_test_srcs: + fail("in %s: 'non_test_srcs' is not allowed on java_binary" % ctx.label) + + srcs = ctx.files.srcs + [src for src in getattr(ctx.files, "non_test_srcs", []) if src not in ctx.files.srcs] + if not srcs and ctx.attr.deps: fail("deps not allowed without srcs; move to runtime_deps?") module_flags = [dep[JavaInfo].module_flags_info for dep in runtime_deps if JavaInfo in dep] @@ -104,7 +109,7 @@ def basic_java_binary( timezone_data = [toolchain._timezone_data] if toolchain._timezone_data else [] target, common_info = basic_java_library( ctx, - srcs = ctx.files.srcs, + srcs = srcs, deps = deps, runtime_deps = runtime_deps, plugins = ctx.attr.plugins, @@ -160,11 +165,12 @@ def basic_java_binary( native_libs_depsets.append(dep[CcInfo]._legacy_transitive_native_libraries) else: native_libs_depsets.append(dep[CcInfo].transitive_native_libraries()) - native_libs_dirs = collect_native_deps_dirs(depset(transitive = native_libs_depsets)) + native_libs_dirs = _collect_native_deps_dirs(depset(transitive = native_libs_depsets)) if native_libs_dirs: prefix = "${JAVA_RUNFILES}/" + ctx.workspace_name + "/" + separator = ";" if helper.is_target_platform_windows(ctx) else ":" jvm_flags.append("-Djava.library.path=%s" % ( - ":".join([prefix + d for d in native_libs_dirs]) + separator.join([prefix + d for d in native_libs_dirs]) )) jvm_flags.extend(ctx.fragments.java.default_jvm_opts) @@ -300,13 +306,6 @@ def _collect_attrs(ctx, runtime_classpath, classpath_resources): runtime_classpath_for_archive = get_runtime_classpath_for_archive(runtime_classpath, deploy_env_jars) runtime_jars = [ctx.outputs.classjar] - resources = [p for p in ctx.files.srcs if p.extension == "properties"] - transitive_resources = [] - for r in ctx.attr.resources: - transitive_resources.append( - r[ProtoInfo].transitive_sources if ProtoInfo in r else r.files, - ) - resource_names = dict() for r in classpath_resources: if r.basename in resource_names: @@ -318,7 +317,6 @@ def _collect_attrs(ctx, runtime_classpath, classpath_resources): runtime_classpath_for_archive = runtime_classpath_for_archive, classpath_resources = depset(classpath_resources), runtime_classpath = depset(order = "preorder", direct = runtime_jars, transitive = [runtime_classpath]), - resources = depset(resources, transitive = transitive_resources), ) def _generate_coverage_manifest(ctx, output, runtime_classpath): @@ -455,7 +453,6 @@ def _auto_create_deploy_jar(ctx, info, launcher_info, main_class, coverage_main_ launcher = launcher_info.launcher, main_class = main_class, coverage_main_class = coverage_main_class, - resources = java_attrs.resources, classpath_resources = java_attrs.classpath_resources, runtime_classpath = runtime_classpath, manifest_lines = [], @@ -471,6 +468,22 @@ def _auto_create_deploy_jar(ctx, info, launcher_info, main_class, coverage_main_ ) return output +def _collect_native_deps_dirs(libraries): + result = {} + for library_to_link in libraries.to_list(): + candidate = None + if library_to_link.interface_library: + candidate = library_to_link.interface_library + elif library_to_link.dynamic_library: + candidate = library_to_link.dynamic_library + if candidate: + ext = "." + candidate.extension + if ext in cc_helper.extensions.INTERFACE_SHARED_LIBRARY: + continue + parent_dir = candidate.short_path[:-(1 + len(candidate.basename))] + result[parent_dir] = None + return result.keys() + def _test_providers(ctx): test_providers = [] if helper.has_target_constraints(ctx, ctx.attr._apple_constraints): diff --git a/java/common/rules/impl/java_helper.bzl b/java/common/rules/impl/java_helper.bzl index 638878ba..c7fb8693 100644 --- a/java/common/rules/impl/java_helper.bzl +++ b/java/common/rules/impl/java_helper.bzl @@ -88,23 +88,50 @@ def _check_and_get_main_class(ctx): main_class = _primary_class(ctx) return main_class +def _canonical_class_from_target_name(ctx): + return _loading_phase_helper.full_classname(helper.get_relative(ctx.label.package, ctx.label.name)) + def _primary_class(ctx): if ctx.attr.srcs: main = ctx.label.name + ".java" - for src in ctx.files.srcs: + for src in _test_srcs(ctx): if src.basename == main: - return _full_classname(_strip_extension(src)) - return _full_classname(helper.get_relative(ctx.label.package, ctx.label.name)) + return _loading_phase_helper.full_classname(_strip_extension(src)) + return _canonical_class_from_target_name(ctx) + +def _test_srcs(ctx): + """Returns ctx.files.srcs excluding any files listed in non_test_srcs.""" + if not hasattr(ctx.files, "non_test_srcs") or not ctx.files.non_test_srcs: + return ctx.files.srcs + non_test_srcs = {src: None for src in ctx.files.non_test_srcs} + return [src for src in ctx.files.srcs if src not in non_test_srcs] def _strip_extension(file): return file.dirname + "/" + ( file.basename[:-(1 + len(file.extension))] if file.extension else file.basename ) -# TODO(b/465048589): once out of builtins, create a canonical implementation and remove duplicates in depot -def _full_classname(path): - java_segments = _loading_phase_helper.java_segments(path) - return ".".join(java_segments) if java_segments != None else None +def _test_classes(ctx): + has_test_class = hasattr(ctx.attr, "test_class") and bool(ctx.attr.test_class) + has_test_classes = hasattr(ctx.attr, "test_classes") and bool(ctx.attr.test_classes) + if has_test_class and has_test_classes: + fail("in %s: cannot specify both 'test_class' and 'test_classes'" % ctx.label) + if has_test_class: + return [ctx.attr.test_class] + if has_test_classes: + return ctx.attr.test_classes + if ctx.attr.srcs: + classes = [] + for src in _test_srcs(ctx): + if src.extension == "java": + cls = _loading_phase_helper.full_classname(_strip_extension(src)) + if cls == None: + return [] + classes.append(cls) + if classes: + return classes + canonical = _canonical_class_from_target_name(ctx) + return [canonical] if canonical != None else [] def _concat(*lists): result = [] @@ -256,6 +283,7 @@ helper = struct( launcher_artifact_for_target = _launcher_artifact_for_target, check_and_get_main_class = _check_and_get_main_class, primary_class = _primary_class, + test_classes = _test_classes, strip_extension = _strip_extension, concat = _concat, get_shared_native_deps_path = _get_shared_native_deps_path, @@ -277,4 +305,8 @@ helper = struct( get_build_info = _get_build_info, get_relative = _loading_phase_helper.get_relative, has_target_constraints = _loading_phase_helper.has_target_constraints, + java_segments = _loading_phase_helper.java_segments, + java_path = _loading_phase_helper.java_path, + java_root = _loading_phase_helper.java_root, + full_classname = _loading_phase_helper.full_classname, ) diff --git a/java/common/rules/java_binary.bzl b/java/common/rules/java_binary.bzl index 609ca974..8c0e00ed 100644 --- a/java/common/rules/java_binary.bzl +++ b/java/common/rules/java_binary.bzl @@ -337,10 +337,12 @@ The Java class to be loaded by the test runner.

This attribute specifies the name of a Java class to be run by this test. It is rare to need to set this. If this argument is omitted, - it will be inferred using the target's name and its - source-root-relative path. If the test is located outside a known - source root, Bazel will report an error if test_class - is unset. + the test classes will be inferred from srcs if present, or + otherwise inferred using the target's name and its + source-root-relative path (which is discouraged; when srcs is + empty, prefer setting test_class explicitly). If the test is + located outside a known source root, Bazel will report an error if + test_class is unset.

For JUnit3, the test class needs to either be a subclass of @@ -357,6 +359,26 @@ The Java class to be loaded by the test runner.
behavior differs in each case, such as running a different subset of the tests. This attribute also enables the use of Java tests outside the javatests tree. +

+ """, + ), + "test_classes": attr.string_list( + doc = """ +The Java classes to be loaded by the test runner. +

+ By default, test classes are automatically inferred from source file names in + srcs. Setting test_classes is generally discouraged: + prefer listing test sources directly in srcs and omitting + test_classes. In particular, specifying test_classes + when srcs is non-empty is discouraged, and placing test sources in + a separate java_library with test_classes risks + silently skipping newly added test files unless they are also manually listed + in test_classes. +

+

+ Specify test_classes only when srcs is empty and the + test target runs multiple pre-compiled test classes from deps or + runtime_deps.

""", ), diff --git a/java/common/rules/java_helper.bzl b/java/common/rules/java_helper.bzl index ee274ade..0c36be11 100644 --- a/java/common/rules/java_helper.bzl +++ b/java/common/rules/java_helper.bzl @@ -19,17 +19,27 @@ load("//java/common:java_semantics.bzl", "semantics") # copybara: rules_java visibility -def _java_segments(path): +def _java_segment_index(path): if path.startswith("/"): fail("path must not be absolute: '%s'" % path) segments = path.split("/") + if path.startswith("third_party/java/"): + # For third_party/java, try skipping past the first two segments and looking for a nested + # source root, to relativize e.g. third_party/java/foo/java/resource into 'resource', + # not 'foo/java/resource'. + idx = _java_segment_index_impl(segments[2:]) + if idx >= 0: + return idx + 2 + return _java_segment_index_impl(segments) + +def _java_segment_index_impl(segments): root_idx = -1 for idx, segment in enumerate(segments): if segment in ["java", "javatests", "src", "testsrc"]: root_idx = idx break if root_idx < 0: - return None + return -1 is_src = "src" == segments[root_idx] check_mvn_idx = root_idx if is_src else -1 if (root_idx == 0 or is_src): @@ -49,7 +59,23 @@ def _java_segments(path): next = segments[check_mvn_idx + 2] if next in ["java", "resources"]: root_idx = check_mvn_idx + 2 - return segments[(root_idx + 1):] + return root_idx + +def _java_segments(path): + idx = _java_segment_index(path) + return path.split("/")[(idx + 1):] if idx >= 0 else None + +def _java_path(path): + java_segments = _java_segments(path) + return "/".join(java_segments) if java_segments != None else None + +def _java_root(path): + idx = _java_segment_index(path) + return "/".join(path.split("/")[:(idx + 1)]) if idx >= 0 else None + +def _full_classname(path): + java_segments = _java_segments(path) + return ".".join(java_segments) if java_segments != None else None def _has_target_constraints(ctx, constraints): # Constraints is a label_list. @@ -209,4 +235,7 @@ helper = struct( get_relative = _get_relative, has_target_constraints = _has_target_constraints, java_segments = _java_segments, + java_path = _java_path, + java_root = _java_root, + full_classname = _full_classname, ) diff --git a/java/common/rules/java_single_jar.bzl b/java/common/rules/java_single_jar.bzl index ca768873..e36c1b70 100644 --- a/java/common/rules/java_single_jar.bzl +++ b/java/common/rules/java_single_jar.bzl @@ -37,7 +37,8 @@ def _single_jar_inputs(deps, deploy_env): fail("unexpected file type in java_single_jar.deps: %s" % f.path) files.append(f) transitive_inputs.append(depset(files)) - inputs = depset(transitive = transitive_inputs) + all_inputs = depset(transitive = transitive_inputs) + inputs = all_inputs if hasattr(java_common, "JavaRuntimeClasspathInfo"): deploy_env_jars = depset(transitive = [ @@ -47,15 +48,15 @@ def _single_jar_inputs(deps, deploy_env): excluded_jars = {jar: None for jar in deploy_env_jars.to_list()} if excluded_jars: inputs = depset([jar for jar in inputs.to_list() if jar not in excluded_jars]) - return inputs + return inputs, all_inputs def _bazel_java_single_jar_impl(ctx): - inputs = _single_jar_inputs(ctx.attr.deps, ctx.attr.deploy_env) + inputs, all_inputs = _single_jar_inputs(ctx.attr.deps, ctx.attr.deploy_env) args = ctx.actions.args() args.add_all("--sources", inputs) args.use_param_file("@%s") - args.set_param_file_format("multiline") + args.set_param_file_format("shell") args.add_all("--deploy_manifest_lines", ctx.attr.deploy_manifest_lines) args.add("--output", ctx.outputs.output) args.add("--normalize") @@ -93,6 +94,9 @@ def _bazel_java_single_jar_impl(ctx): progress_message = "Merging into %s" % ctx.outputs.output.short_path, mnemonic = "JavaSingleJar", executable = ctx.executable._singlejar, + execution_requirements = { + "supports-path-mapping": "1", + }, use_default_shell_env = True, ) @@ -102,7 +106,7 @@ def _bazel_java_single_jar_impl(ctx): runfiles = ctx.runfiles(transitive_files = files), )] if hasattr(java_common, "JavaRuntimeClasspathInfo"): - providers.append(java_common.JavaRuntimeClasspathInfo(runtime_classpath = inputs)) + providers.append(java_common.JavaRuntimeClasspathInfo(runtime_classpath = all_inputs)) return providers bazel_java_single_jar = rule( diff --git a/java/common/rules/java_toolchain.bzl b/java/common/rules/java_toolchain.bzl index a24ae4f1..12050839 100644 --- a/java/common/rules/java_toolchain.bzl +++ b/java/common/rules/java_toolchain.bzl @@ -176,8 +176,9 @@ def _get_android_lint_tool(ctx): fail(ctx.attr.android_lint_runner.label, "does not refer to a valid executable target") return struct( tool = files_to_run, + tools = depset(ctx.files.android_lint_tools), data = depset(ctx.files.android_lint_data), - jvm_opts = depset([ctx.expand_location(opt, ctx.attr.android_lint_data) for opt in ctx.attr.android_lint_jvm_opts]), + jvm_opts = depset([ctx.expand_location(opt, ctx.attr.android_lint_tools) for opt in ctx.attr.android_lint_jvm_opts]), lint_opts = [ctx.expand_location(opt, ctx.attr.android_lint_data) for opt in ctx.attr.android_lint_opts], package_config = [dep[JavaPackageConfigurationInfo] for dep in ctx.attr.android_lint_package_configuration], ) @@ -297,6 +298,13 @@ java_toolchain( cfg = "exec", allow_files = True, doc = """ +Labels of files available for label-expansion in android_lint_opts. + """, + ), + "android_lint_tools": attr.label_list( + cfg = "exec", + allow_files = True, + doc = """ Labels of tools available for label-expansion in android_lint_jvm_opts. """, ), diff --git a/java/defs.bzl b/java/defs.bzl index 8899a705..2034bf45 100644 --- a/java/defs.bzl +++ b/java/defs.bzl @@ -13,8 +13,6 @@ # limitations under the License. """Starlark rules for building Java projects.""" -load("@com_google_protobuf//bazel:java_lite_proto_library.bzl", _java_lite_proto_library = "java_lite_proto_library") -load("@com_google_protobuf//bazel:java_proto_library.bzl", _java_proto_library = "java_proto_library") load("//java:java_binary.bzl", _java_binary = "java_binary") load("//java:java_import.bzl", _java_import = "java_import") load("//java:java_library.bzl", _java_library = "java_library") @@ -41,26 +39,6 @@ java_runtime = _java_runtime java_toolchain = _java_toolchain java_package_configuration = _java_package_configuration -# Proto rules -# Deprecated: don't use java proto libraries from here -def java_proto_library(**kwargs): - if "deprecation" not in kwargs: - _java_proto_library( - deprecation = "Use java_proto_library from @com_google_protobuf//bazel:java_proto_library.bzl", - **kwargs - ) - else: - _java_proto_library(**kwargs) - -def java_lite_proto_library(**kwargs): - if "deprecation" not in kwargs: - _java_lite_proto_library( - deprecation = "Use java_lite_proto_library from @com_google_protobuf//bazel:java_lite_proto_library.bzl", - **kwargs - ) - else: - _java_lite_proto_library(**kwargs) - # Modules and providers JavaInfo = _JavaInfo diff --git a/java/private/BUILD b/java/private/BUILD index 510c3010..244de292 100644 --- a/java/private/BUILD +++ b/java/private/BUILD @@ -76,7 +76,7 @@ bzl_library( name = "android_support", srcs = ["android_support.bzl"], visibility = ["//visibility:public"], - deps = ["@compatibility_proxy//:proxy_bzl"], + deps = [":internals"], ) filegroup( diff --git a/java/private/android_support.bzl b/java/private/android_support.bzl index fa80a17b..8301234d 100644 --- a/java/private/android_support.bzl +++ b/java/private/android_support.bzl @@ -13,8 +13,10 @@ # limitations under the License. """Legacy support for the android rules.""" -load("@compatibility_proxy//:proxy.bzl", "java_info_to_implicit_exportable") +load(":java_info.bzl", _java_info_to_implicit_exportable = "to_implicit_exportable") + +# copybara: android_support visibility android_support = struct( - enable_implicit_sourceless_deps_exports_compatibility = java_info_to_implicit_exportable, + enable_implicit_sourceless_deps_exports_compatibility = _java_info_to_implicit_exportable, ) diff --git a/java/private/java_common_internal.bzl b/java/private/java_common_internal.bzl index 30d9533c..4c5b6035 100644 --- a/java/private/java_common_internal.bzl +++ b/java/private/java_common_internal.bzl @@ -507,17 +507,6 @@ def target_kind(target): """ return get_internal_java_common().target_kind(target) -def collect_native_deps_dirs(libraries): - """Collect the set of root-relative paths containing native libraries - - Args: - libraries: (depset[LibraryToLink]) set of native libraries - - Returns: - ([String]) A set of root-relative paths as a list - """ - return get_internal_java_common().collect_native_deps_dirs(libraries) - def get_runtime_classpath_for_archive(jars, excluded_jars): """Filters a classpath to remove certain entries diff --git a/java/repositories.bzl b/java/repositories.bzl index df95f86d..bfa229a7 100644 --- a/java/repositories.bzl +++ b/java/repositories.bzl @@ -22,39 +22,39 @@ load("//toolchains:remote_java_repository.bzl", "remote_java_repository") # visible for tests JAVA_TOOLS_CONFIG = { - "version": "v19.0", - "source_revision": "61972bfd7fb6f587fc4576b5114e20758b501806", + "version": "v22.0", + "source_revision": "c9b10ec53b5fa49a1bb9c593f08f73ff52f60d95", "release": "true", "artifacts": { "java_tools_linux": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_linux-v19.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_linux-v19.0.zip", - "sha": "7d5b0c01f99ea5596b7901a7e5f9173f3ae3c4f0b480378e87567eaf97d75d25", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v22.0/java_tools_linux-v22.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v22.0/java_tools_linux-v22.0.zip", + "sha": "b0b3c2873f30c1123cdd77a74f89fcc4d4debc09a70c8619a4fe8e322f7fda96", }, "java_tools_linux_aarch64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_linux_aarch64-v19.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_linux_aarch64-v19.0.zip", - "sha": "34b14fdfe8d6e32ed7f80e7c4d34ce79f4006e0d4b621552f507e51b9d6a3d7d", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v22.0/java_tools_linux_aarch64-v22.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v22.0/java_tools_linux_aarch64-v22.0.zip", + "sha": "f0899527a8784ea0510801a3ee27b3276e2bb78e599473999fe88585a505ddd3", }, "java_tools_windows": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_windows-v19.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_windows-v19.0.zip", - "sha": "86c5a58ccefdb9e704fddd325f5fbc7867b2cdd128fb8b9abfdf607a75d2ae71", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v22.0/java_tools_windows-v22.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v22.0/java_tools_windows-v22.0.zip", + "sha": "1b302daf293b9ec15eaa2705581976e8c5fd91153fabc6a939a043e6c3d9cf90", }, "java_tools_darwin_x86_64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_darwin_x86_64-v19.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_darwin_x86_64-v19.0.zip", - "sha": "78ff8ec7038ab5f9cd261cdf9ff75ea0eb2af7579f9aeef9d658459ee37fabac", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v22.0/java_tools_darwin_x86_64-v22.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v22.0/java_tools_darwin_x86_64-v22.0.zip", + "sha": "fd5d51572f9e2911ae1564849e011805b328f982587e3aaed034f363d646452f", }, "java_tools_darwin_arm64": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools_darwin_arm64-v19.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools_darwin_arm64-v19.0.zip", - "sha": "86f15280dd0ce121a22f061e2e301ecf746597caa4938cf56852b3d311b830d8", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v22.0/java_tools_darwin_arm64-v22.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v22.0/java_tools_darwin_arm64-v22.0.zip", + "sha": "0c78a0d00f09867d56a5064857c936370dab257e5d29dc8d875825509460a456", }, "java_tools": { - "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v19.0/java_tools-v19.0.zip", - "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v19.0/java_tools-v19.0.zip", - "sha": "d21d4aad1a18062512bcf4e8f7a09a4f5a042c760daa779e0ddda6e41b170507", + "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v22.0/java_tools-v22.0.zip", + "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_v22.0/java_tools-v22.0.zip", + "sha": "b13ee1eaa8681d3ec4faffab4251902a0c1b5135b1f5c718831fc5798db82f9b", }, }, } @@ -86,41 +86,43 @@ _REMOTE_JDK_CONFIGS_LIST = [ struct( name = "remote_jdk8_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], - sha256 = "c372fb26480c052537125013cb0ba7336c404e5190ea8f6e2de247b676432a67", - strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-linux_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-linux_aarch64.tar.gz"], + sha256 = "b23296caf10d0c3db054d4a58b9dd168976991472f2203335d7c4820f98c4a4e", + strip_prefix = "zulu8.96.0.19-ca-jdk8.0.502-linux_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-linux_aarch64.tar.gz"], version = "8", ), struct( name = "remote_jdk8_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], - sha256 = "6f9e3fa773829ac2553411fb0cdeb394980627c47c9ab8f8892d4b917b70e2dd", - strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-linux_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-linux_x64.tar.gz"], + sha256 = "5923daaf12fd0b87e60e437aaae7b2e5b257846cdb8ac15065258fb59a1da70a", + strip_prefix = "zulu8.96.0.19-ca-jdk8.0.502-linux_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-linux_x64.tar.gz"], version = "8", ), struct( name = "remote_jdk8_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], - sha256 = "823d547ab9508e3a2b8abd3c5de66a39a50a254dc5835747cf3c2617fbe55600", - strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-macosx_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-macosx_aarch64.tar.gz"], + sha256 = "9f9e5038c638e415e507e8b5118a774822f553a56e76bdf4b042c3fbe7b69083", + strip_prefix = "zulu8.96.0.19-ca-jdk8.0.502-macosx_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-macosx_aarch64.tar.gz"], version = "8", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remote_jdk8_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], - sha256 = "96fb7bc3a2babd7f807484b1b8f1dfb8cf2c61ea27b2d0630e2237088b0a5100", - strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-macosx_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-macosx_x64.tar.gz"], + sha256 = "b29088ddb00f81db1e01d6d5bfddd44a58e46ef44b50c372cff3eb1bf5b23173", + strip_prefix = "zulu8.96.0.19-ca-jdk8.0.502-macosx_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-macosx_x64.tar.gz"], version = "8", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remote_jdk8_windows", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], - sha256 = "ff90484103d3fdb9808f737af027586c8dbfa1aa8a310ce99b0b5e0517567aee", - strip_prefix = "zulu8.90.0.19-ca-jdk8.0.472-win_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.90.0.19-ca-jdk8.0.472-win_x64.zip"], + sha256 = "0d64e817ba56962d447339040f9e7bd1119f98b813d0a968e3485aab0c530a47", + strip_prefix = "zulu8.96.0.19-ca-jdk8.0.502-win_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.96.0.19-ca-jdk8.0.502-win_x64.zip"], version = "8", ), struct( @@ -134,41 +136,43 @@ _REMOTE_JDK_CONFIGS_LIST = [ struct( name = "remotejdk11_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], - sha256 = "5a225a0fe0a92bc6c04c8c5aeb03c697c6fd114465829f23e494a2ad44fa1cc0", - strip_prefix = "zulu11.84.17-ca-jdk11.0.29-linux_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-linux_aarch64.tar.gz"], + sha256 = "31fb32a1c9d842f96e8e79c683996e217d087b3aeac0cc6bfc39f028eb860146", + strip_prefix = "zulu11.90.19-ca-jdk11.0.32-linux_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-linux_aarch64.tar.gz"], version = "11", ), struct( name = "remotejdk11_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], - sha256 = "681b2e4bf7fedf4d20666fc2a954b83ff5675ccfb916c867267d29c85c2ee310", - strip_prefix = "zulu11.84.17-ca-jdk11.0.29-linux_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-linux_x64.tar.gz"], + sha256 = "d4832d97886444346ed75fd1059c68c5e38795098e3273e4a0929fe2eb2abf76", + strip_prefix = "zulu11.90.19-ca-jdk11.0.32-linux_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-linux_x64.tar.gz"], version = "11", ), struct( name = "remotejdk11_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], - sha256 = "09ed1734c2d88fadcb75fdbec1ba5467d32e7fa2b10894541aa8e3d3ce78dc2d", - strip_prefix = "zulu11.84.17-ca-jdk11.0.29-macosx_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-macosx_aarch64.tar.gz"], + sha256 = "a552338385fa27026ced01a3c56a3b3a2de048ed4b79907d876e99be80547551", + strip_prefix = "zulu11.90.19-ca-jdk11.0.32-macosx_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-macosx_aarch64.tar.gz"], version = "11", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk11_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], - sha256 = "b7f5a37c47ed94af1c8ecf631b1dc6dec990958f3afd4222a7dd27d6ca1084bd", - strip_prefix = "zulu11.84.17-ca-jdk11.0.29-macosx_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-macosx_x64.tar.gz"], + sha256 = "5ba1b39cc08999645944bcfd54da48dd6c9a0891785d56cff95e92324fa841f6", + strip_prefix = "zulu11.90.19-ca-jdk11.0.32-macosx_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-macosx_x64.tar.gz"], version = "11", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk11_win", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], - sha256 = "f4002a8090662ff66bf9f3248604be0f9d226e964085bd59bbea4b8535df3de1", - strip_prefix = "zulu11.84.17-ca-jdk11.0.29-win_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.84.17-ca-jdk11.0.29-win_x64.zip"], + sha256 = "700a42d5764b5f41ab43adbfe3e03deac329cc10886f2312a5908fd5a3c78d46", + strip_prefix = "zulu11.90.19-ca-jdk11.0.32-win_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.90.19-ca-jdk11.0.32-win_x64.zip"], version = "11", ), struct( @@ -198,49 +202,51 @@ _REMOTE_JDK_CONFIGS_LIST = [ struct( name = "remotejdk17_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], - sha256 = "527b76fbd60e8f9644f6b70800d15160cdbd3344bc6fbf30d42e905f540a770c", - strip_prefix = "zulu17.62.17-ca-jdk17.0.17-linux_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-linux_aarch64.tar.gz"], + sha256 = "46f1dc7678760d37d38699c5a5a34dea8ed451dcdf6d27890a7b61f025e7ff60", + strip_prefix = "zulu17.68.17-ca-jdk17.0.20-linux_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-linux_aarch64.tar.gz"], version = "17", ), struct( name = "remotejdk17_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], - sha256 = "1dcbbed73e95dc35f5c60402a84936f6830ff43c2a0dc0037a5657dbc25472c1", - strip_prefix = "zulu17.62.17-ca-jdk17.0.17-linux_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-linux_x64.tar.gz"], + sha256 = "32c5efedf69f4a95635ea2923f6a6ee90ce6ca83df0bd43ba55dd662d5af429a", + strip_prefix = "zulu17.68.17-ca-jdk17.0.20-linux_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-linux_x64.tar.gz"], version = "17", ), struct( name = "remotejdk17_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], - sha256 = "5558f7efe6297ecb20f422f31471555cd43e9499beb304b8f3ddc68796d2874b", - strip_prefix = "zulu17.62.17-ca-jdk17.0.17-macosx_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-macosx_aarch64.tar.gz"], + sha256 = "0da52534760b74ba8a42660384b2f4e44311a47ae52faa45fcbd829b2797b244", + strip_prefix = "zulu17.68.17-ca-jdk17.0.20-macosx_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-macosx_aarch64.tar.gz"], version = "17", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk17_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], - sha256 = "e6b2fb0cd3f929225a179c2fb2813abd1834f839a3b4c8cdcb36067aa16b6f83", - strip_prefix = "zulu17.62.17-ca-jdk17.0.17-macosx_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-macosx_x64.tar.gz"], + sha256 = "b5bace4a346a7af0fe4f50904c46770e66d4b465800b038693c35e5d5b9bd52a", + strip_prefix = "zulu17.68.17-ca-jdk17.0.20-macosx_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-macosx_x64.tar.gz"], version = "17", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk17_win_arm64", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"], - sha256 = "c1bba9148907348da93b0de2c9abd56bd180efcb6b1f35068ab9785015fcd74b", - strip_prefix = "zulu17.62.17-ca-jdk17.0.17-win_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-win_aarch64.zip"], + sha256 = "e125b3b64c9b5a0a2f2737e4a94ba275b541d8cc85d61c95ff875a3463ce0d8e", + strip_prefix = "zulu17.68.17-ca-jdk17.0.20-win_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-win_aarch64.zip"], version = "17", ), struct( name = "remotejdk17_win", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], - sha256 = "bd8a942bb543f109a28d3eadf3ec2f29a3ee28ab53506e31d2858292f63c6949", - strip_prefix = "zulu17.62.17-ca-jdk17.0.17-win_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.62.17-ca-jdk17.0.17-win_x64.zip"], + sha256 = "d207d8cec299f4d216bef1c7c081ba9504e79ba1cbc740de312d4a91b2d46436", + strip_prefix = "zulu17.68.17-ca-jdk17.0.20-win_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.68.17-ca-jdk17.0.20-win_x64.zip"], version = "17", ), struct( @@ -262,49 +268,51 @@ _REMOTE_JDK_CONFIGS_LIST = [ struct( name = "remotejdk21_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], - sha256 = "a826a93c18d4388ec8d5d4057f5bb1b5c60f00ffc875ed299dea17aa947555ee", - strip_prefix = "zulu21.46.19-ca-jdk21.0.9-linux_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-linux_aarch64.tar.gz"], + sha256 = "dc7ed9ab7dfd33f2ddb1cd8311d3b00738497961a420533d81088051eac3f195", + strip_prefix = "zulu21.52.15-ca-jdk21.0.12-linux_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-linux_aarch64.tar.gz"], version = "21", ), struct( name = "remotejdk21_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], - sha256 = "67e810b31427ac0ff1c249473595066a00bdf0f9265df186c32905d5f75c93b8", - strip_prefix = "zulu21.46.19-ca-jdk21.0.9-linux_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-linux_x64.tar.gz"], + sha256 = "b1a9df12e798770d1b2db43b402a80f1e6080cff6d5d1d1fbe5c768fb4225f6a", + strip_prefix = "zulu21.52.15-ca-jdk21.0.12-linux_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-linux_x64.tar.gz"], version = "21", ), struct( name = "remotejdk21_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], - sha256 = "b56112ad12d3dfe62802840655ecf198fe4ca48729824c939d65a69e803536c7", - strip_prefix = "zulu21.46.19-ca-jdk21.0.9-macosx_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-macosx_aarch64.tar.gz"], + sha256 = "84d38c4bf04f73d585bd319b949758d00abde50149a9522c2d9deef46b9a3ec6", + strip_prefix = "zulu21.52.15-ca-jdk21.0.12-macosx_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-macosx_aarch64.tar.gz"], version = "21", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk21_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], - sha256 = "3d870d823e3e101189b00ad975188c0321e31056ac8ca8b487bcf4454f3b5cfe", - strip_prefix = "zulu21.46.19-ca-jdk21.0.9-macosx_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-macosx_x64.tar.gz"], + sha256 = "14e05cb1299c27cd26d3c5c6815723f63018df548dc7278c810767607902b4f4", + strip_prefix = "zulu21.52.15-ca-jdk21.0.12-macosx_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-macosx_x64.tar.gz"], version = "21", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk21_win_arm64", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"], - sha256 = "1210b169db7b40d7305a94d41ab3eb87aaee51108b43f8f7f36f0c2865107790", - strip_prefix = "zulu21.46.19-ca-jdk21.0.9-win_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-win_aarch64.zip"], + sha256 = "d75658d371e025bb6378231551b4d53d1f5312cb0fccf7aa3b039d91ce1f0b7e", + strip_prefix = "zulu21.52.15-ca-jdk21.0.12-win_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-win_aarch64.zip"], version = "21", ), struct( name = "remotejdk21_win", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], - sha256 = "0c9812c0fe527b59f48c70cb527035c8a7abe620b31f776b4ddc21bddc1cd067", - strip_prefix = "zulu21.46.19-ca-jdk21.0.9-win_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.46.19-ca-jdk21.0.9-win_x64.zip"], + sha256 = "3c06e6693fd6fa725b985e66798a6a8293c75f52b793490754ad3c54d3d8b5a6", + strip_prefix = "zulu21.52.15-ca-jdk21.0.12-win_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.52.15-ca-jdk21.0.12-win_x64.zip"], version = "21", ), struct( @@ -334,49 +342,51 @@ _REMOTE_JDK_CONFIGS_LIST = [ struct( name = "remotejdk25_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], - sha256 = "f7295abb1decb2f6e0ea9f760a70917f2d47356db4366d615c7ab9b01c3c6866", - strip_prefix = "zulu25.32.17-ca-jdk25.0.2-linux_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-linux_aarch64.tar.gz"], + sha256 = "ae04e25b16116ddd0f72cb387742d5122bb29c4b94f0fed08ff2bccc395f9daa", + strip_prefix = "zulu25.36.15-ca-jdk25.0.4-linux_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-linux_aarch64.tar.gz"], version = "25", ), struct( name = "remotejdk25_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], - sha256 = "f1752d0051b6ca233625ddb2c18c9170edbe55c5ee6515bfefd8ea0197ee1c20", - strip_prefix = "zulu25.32.17-ca-jdk25.0.2-linux_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-linux_x64.tar.gz"], + sha256 = "e476f5c98952cb365ca77a814dbe3c74341e71ae76d1a87d1c0a69c7d2b1b2d0", + strip_prefix = "zulu25.36.15-ca-jdk25.0.4-linux_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-linux_x64.tar.gz"], version = "25", ), struct( name = "remotejdk25_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], - sha256 = "537ac74fa1ca2c4dd8f6063ddede0138ae4a896f128bfe10b428a7dcc4aa929f", - strip_prefix = "zulu25.32.17-ca-jdk25.0.2-macosx_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-macosx_aarch64.tar.gz"], + sha256 = "c422f22713510992c764a7d577ae4f5add223529ab356993f38f8df2d4b247bd", + strip_prefix = "zulu25.36.15-ca-jdk25.0.4-macosx_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-macosx_aarch64.tar.gz"], version = "25", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk25_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], - sha256 = "fe22346c192920c5b84b23f4aa24e3debb0bb94fc428016f7c2b2c7790c82780", - strip_prefix = "zulu25.32.17-ca-jdk25.0.2-macosx_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-macosx_x64.tar.gz"], + sha256 = "63273c6b9e2d9b250a0009ffdaa6d9f27af6ba98772516c391276106fb9f2820", + strip_prefix = "zulu25.36.15-ca-jdk25.0.4-macosx_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-macosx_x64.tar.gz"], version = "25", + patch_cmds = ["ln -s Contents/Home/* ."], ), struct( name = "remotejdk25_win_arm64", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"], - sha256 = "5f44792a12af2100b4db9b5120c27c42af8080ad63bc9eaadc9ca25e5c7dd590", - strip_prefix = "zulu25.32.17-ca-jdk25.0.2-win_aarch64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_aarch64.zip"], + sha256 = "2e8468229aea447152343fff87dbebe5c339e1fbab143a8f227f6b2f388c0a8c", + strip_prefix = "zulu25.36.15-ca-jdk25.0.4-win_aarch64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-win_aarch64.zip"], version = "25", ), struct( name = "remotejdk25_win", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], - sha256 = "90bcbbcbe2fb7aec43ce8fd2efa024fcc48f00bbdcd7a76b58f912d6b97e6d56", - strip_prefix = "zulu25.32.17-ca-jdk25.0.2-win_x64", - urls = ["https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_x64.zip"], + sha256 = "a91265f0f0fb40155befe8f1cae7d1a0ae2ab4b7760f52733160d206637b50d1", + strip_prefix = "zulu25.36.15-ca-jdk25.0.4-win_x64", + urls = ["https://cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu25.36.15-ca-jdk25.0.4-win_x64.zip"], version = "25", ), struct( @@ -425,6 +435,7 @@ def _remote_jdk_repos_for_version(version): strip_prefix = item.strip_prefix, urls = item.urls, version = item.version, + patch_cmds = getattr(item, "patch_cmds", []), ) def remote_jdk8_repos(name = ""): diff --git a/java/rules_java_deps.bzl b/java/rules_java_deps.bzl index b2086dc1..c9742f94 100644 --- a/java/rules_java_deps.bzl +++ b/java/rules_java_deps.bzl @@ -103,6 +103,10 @@ http_jar = _http_jar """, ) + if hasattr(rctx, "repo_metadata"): + return rctx.repo_metadata(reproducible = True) + return None + _compatibility_proxy_repo_rule = repository_rule( _compatibility_proxy_repo_impl, # force reruns on server restarts to use correct native.bazel_version diff --git a/java/testutil.bzl b/java/testutil.bzl index 4063ea6f..cc7c2ec5 100644 --- a/java/testutil.bzl +++ b/java/testutil.bzl @@ -12,7 +12,11 @@ def _cc_info_transitive_native_libraries(cc_info): def _cc_library_to_link_static_library(library_to_link): return library_to_link.static_library or library_to_link.pic_static_library +def _cc_library_to_link_dynamic_library(library_to_link): + return library_to_link.interface_library or library_to_link.dynamic_library + testutil = struct( cc_info_transitive_native_libraries = _cc_info_transitive_native_libraries, cc_library_to_link_static_library = _cc_library_to_link_static_library, + cc_library_to_link_dynamic_library = _cc_library_to_link_dynamic_library, ) diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 9d133ce7..9469fb99 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -54,7 +54,7 @@ sh_test( name = "check_release_notes_test", srcs = ["check_release_notes_test.sh"], args = [ - "$(location //distro:relnotes.txt)", + "$(rootpath //distro:relnotes.txt)", module_version(), ], data = ["//distro:relnotes.txt"], diff --git a/test/bazel/BUILD.bazel b/test/bazel/BUILD.bazel new file mode 100644 index 00000000..50fff509 --- /dev/null +++ b/test/bazel/BUILD.bazel @@ -0,0 +1,11 @@ +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_binary.bzl", "java_binary") + +# Used in test/java/bazel/rules/java_binary_tests.bzl%_test_java_binary_empty_srcs +util.helper_target( + java_binary, + name = "bin_without_srcs", + visibility = [ + "//test/java/bazel/rules:__pkg__", + ], +) diff --git a/test/check_remote_jdk_configs.sh b/test/check_remote_jdk_configs.sh index b1c509fe..e7f27201 100755 --- a/test/check_remote_jdk_configs.sh +++ b/test/check_remote_jdk_configs.sh @@ -13,33 +13,40 @@ # See the License for the specific language governing permissions and # limitations under the License. +function fail() { + echo "$@" + exit 1 +} + +function debug_log() { + # bazel test --test_env=DEBUG=1 ... + [[ -z "${DEBUG}" ]] || echo "$@" +} + echo "Checking hashes and strip_prefix for $# configs" _MISSING_MIRRORS=() for config in "$@"; do TMP_FILE=$(mktemp -q /tmp/remotejdk.XXXXXX) IFS=, read -r name url mirror_url hash strip_prefix <<< "${config}" - echo "fetching $name from $url to ${TMP_FILE}" + debug_log "fetching $name from $url to ${TMP_FILE}" curl --silent -o ${TMP_FILE} -L "$url" actual_hash=$(sha256sum ${TMP_FILE} | cut -d' ' -f1) if [ "${hash}" != "${actual_hash}" ]; then - echo "ERROR: wrong hash for ${name}! wanted: ${hash}, got: ${actual_hash}" - exit 1 + fail "ERROR: wrong hash for ${name}! wanted: ${hash}, got: ${actual_hash}" fi if [[ -z "${url##*.tar.gz}" ]]; then root_dir=$(tar ztf ${TMP_FILE} --exclude='*/*') elif [[ -z "${url##*.zip}" ]]; then root_dir=$(unzip -Z1 ${TMP_FILE} | head -n1) else - echo "ERROR: unexpected archive type for ${name}" - exit 1 + fail "ERROR: unexpected archive type for ${name}" fi if [ "${root_dir}" != "${strip_prefix}/" ]; then - echo "ERROR: bad strip_prefix for ${name}, wanted: ${strip_prefix}/, got: ${root_dir}" - exit 1 + fail "ERROR: bad strip_prefix for ${name}, wanted: ${strip_prefix}/, got: ${root_dir}" fi if [[ -n "${mirror_url}" ]]; then - echo "checking mirror: ${mirror_url}" + debug_log "checking mirror: ${mirror_url}" curl --silent --fail -I -L ${mirror_url} > /dev/null || { _MISSING_MIRRORS+=("${url}"); } fi done diff --git a/test/java/bazel/common/java_common_tests.bzl b/test/java/bazel/common/java_common_tests.bzl index 80fdf442..9702f735 100644 --- a/test/java/bazel/common/java_common_tests.bzl +++ b/test/java/bazel/common/java_common_tests.bzl @@ -20,8 +20,6 @@ def _test_java_common_pack_sources_with_external_resource(name): name = name, impl = _test_java_common_pack_sources_with_external_resource_impl, target = name + "/custom", - # Bazel 7 names external repos differently - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_java_common_pack_sources_with_external_resource_impl(env, target): diff --git a/test/java/bazel/rules/BUILD.bazel b/test/java/bazel/rules/BUILD.bazel index 6f97d15a..09c1f1a0 100644 --- a/test/java/bazel/rules/BUILD.bazel +++ b/test/java/bazel/rules/BUILD.bazel @@ -1,10 +1,13 @@ load(":java_binary_tests.bzl", "java_binary_tests") +load(":java_import_tests.bzl", "java_import_tests") load(":java_library_tests.bzl", "java_library_tests") load(":java_plugin_tests.bzl", "java_plugin_tests") load(":java_test_tests.bzl", "java_test_tests") java_binary_tests(name = "java_binary_tests") +java_import_tests(name = "java_import_tests") + java_library_tests(name = "java_library_tests") java_plugin_tests(name = "java_plugin_tests") diff --git a/test/java/bazel/rules/java_binary_tests.bzl b/test/java/bazel/rules/java_binary_tests.bzl index 8c385046..39bd787d 100644 --- a/test/java/bazel/rules/java_binary_tests.bzl +++ b/test/java/bazel/rules/java_binary_tests.bzl @@ -1,8 +1,11 @@ """Tests for the Bazel java_binary rule""" +load("@bazel_features//private:util.bzl", _bazel_version_ge = "ge") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") +load("//test/java/testutil:helper.bzl", "always_passes") load("//test/java/testutil:java_info_subject.bzl", "java_info_subject") load("//test/java/testutil:rules/template_var_info_rule.bzl", "template_var_info_rule") @@ -13,7 +16,7 @@ def _test_java_binary_cross_compilation_to_unix(name): # - is not supported by the default C++ toolchain util.helper_target( native.platform, - name = name + "/platform", + name = name + "_platform", constraint_values = [ "@platforms//os:linux", "@platforms//cpu:s390x", @@ -32,7 +35,7 @@ def _test_java_binary_cross_compilation_to_unix(name): impl = _test_java_binary_cross_compilation_to_unix_impl, target = name + "/bin", config_settings = { - "//command_line_option:platforms": [Label(name + "/platform")], + "//command_line_option:platforms": [Label(name + "_platform")], }, # Requires the launcher_maker toolchain. attr_values = {"tags": ["min_bazel_9"]}, @@ -48,6 +51,64 @@ def _test_java_binary_cross_compilation_to_unix_impl(env, target): assert_action.substitutions().keys().contains("%jvm_flags%") assert_action.inputs().contains_exactly(["java/bazel/rules/java_stub_template.txt"]) +def _test_java_binary_excludes_build_data(name): + if not _bazel_version_ge("8.0.0"): + always_passes(name) + return + + util.helper_target( + java_binary, + name = name + "/bin", + srcs = ["Main.java"], + exclude_build_data = True, + ) + + analysis_test( + name = name, + impl = _test_java_binary_excludes_build_data_impl, + target = name + "/bin", + ) + +def _test_java_binary_excludes_build_data_impl(env, target): + assert_deploy_jar_action = env.expect.that_target(target).action_generating( + "{package}/{name}_deploy.jar", + ) + + assert_deploy_jar_action.argv().contains("--normalize") + assert_deploy_jar_action.argv().contains("--exclude_build_data") + assert_deploy_jar_action.argv().not_contains("--build_info_file") + assert_deploy_jar_action.inputs().not_contains_predicate( + matching.file_basename_equals("non_volatile_file.properties"), + ) + assert_deploy_jar_action.inputs().not_contains_predicate( + matching.file_basename_equals("redacted_file.properties"), + ) + +def _test_java_binary_stamping_enabled_build_data_excluded_fails(name): + if not _bazel_version_ge("8.0.0"): + always_passes(name) + return + + util.helper_target( + java_binary, + name = name + "/bin", + srcs = ["Main.java"], + exclude_build_data = True, + stamp = 1, + ) + + analysis_test( + name = name, + impl = _test_java_binary_stamping_enabled_build_data_excluded_fails_impl, + target = name + "/bin", + expect_failure = True, + ) + +def _test_java_binary_stamping_enabled_build_data_excluded_fails_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("Enabling stamping has no effect with exclude_build_data enabled"), + ) + def _test_java_binary_javacopts_make_variable_expansion(name): util.helper_target( template_var_info_rule, @@ -68,8 +129,6 @@ def _test_java_binary_javacopts_make_variable_expansion(name): name = name, impl = _test_java_binary_javacopts_make_variable_expansion_impl, target = name + "/bin", - # Broken by Starlarkification in the embedded rules in Bazel 7 - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_java_binary_javacopts_make_variable_expansion_impl(env, target): @@ -118,13 +177,29 @@ def _test_java_binary_resource_strip_prefix_impl(env, target): ("--resources", "{package}/path/to/strip/bar.props:bar.props"), ]) +def _test_java_binary_empty_srcs(name): + analysis_test( + name = name, + impl = _test_java_binary_empty_srcs_impl, + target = "//test/bazel:bin_without_srcs", # need a target not under a `/java/` segment + expect_failure = True, + ) + +def _test_java_binary_empty_srcs_impl(env, target): + env.expect.that_target(target).failures().contains_predicate(matching.str_matches( + "need at least one of 'main_class' or Java source files", + )) + def java_binary_tests(name): test_suite( name = name, tests = [ _test_java_binary_cross_compilation_to_unix, + _test_java_binary_excludes_build_data, + _test_java_binary_stamping_enabled_build_data_excluded_fails, _test_java_binary_javacopts_make_variable_expansion, _test_java_binary_javacopts_location_expansion, _test_java_binary_resource_strip_prefix, + _test_java_binary_empty_srcs, ], ) diff --git a/test/java/bazel/rules/java_import_tests.bzl b/test/java/bazel/rules/java_import_tests.bzl new file mode 100644 index 00000000..e368b14a --- /dev/null +++ b/test/java/bazel/rules/java_import_tests.bzl @@ -0,0 +1,40 @@ +"""Tests for the Bazel java_import rule""" + +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_import.bzl", "java_import") + +def _test_import_deps_checker_checking_mode(name): + util.helper_target( + java_import, + name = name + "/import-jar", + jars = ["import.jar"], + deps = [name + "/depjar"], + ) + util.helper_target( + java_import, + name = name + "/depjar", + jars = ["depjar.jar"], + ) + + analysis_test( + name = name, + impl = _test_import_deps_checker_checking_mode_impl, + target = name + "/import-jar", + ) + +def _test_import_deps_checker_checking_mode_impl(env, target): + # java_import only generates the jdeps proto, it never fails the build on incomplete deps. + assert_action = env.expect.that_target(target).action_named("ImportDepsChecker") + assert_action.contains_flag_values([ + ("--checking_mode", "silence"), + ("--rule_label", "//{package}:{name}"), + ]) + +def java_import_tests(name): + test_suite( + name = name, + tests = [ + _test_import_deps_checker_checking_mode, + ], + ) diff --git a/test/java/bazel/rules/java_library_tests.bzl b/test/java/bazel/rules/java_library_tests.bzl index 770fbe60..fd20980d 100644 --- a/test/java/bazel/rules/java_library_tests.bzl +++ b/test/java/bazel/rules/java_library_tests.bzl @@ -26,8 +26,6 @@ def _test_java_library_javacopts_make_variable_expansion(name): name = name, impl = _test_java_library_javacopts_make_variable_expansion_impl, target = name + "/lib", - # Broken by Starlarkification in the embedded rules in Bazel 7 - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_java_library_javacopts_make_variable_expansion_impl(env, target): diff --git a/test/java/bazel/rules/java_plugin_tests.bzl b/test/java/bazel/rules/java_plugin_tests.bzl index 4df4bcca..9015ebf1 100644 --- a/test/java/bazel/rules/java_plugin_tests.bzl +++ b/test/java/bazel/rules/java_plugin_tests.bzl @@ -25,8 +25,6 @@ def _test_java_plugin_javacopts_make_variable_expansion(name): name = name, impl = _test_java_plugin_javacopts_make_variable_expansion_impl, target = name + "/plug", - # Broken by Starlarkification in the embedded rules in Bazel 7 - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_java_plugin_javacopts_make_variable_expansion_impl(env, target): diff --git a/test/java/bazel/rules/java_test_tests.bzl b/test/java/bazel/rules/java_test_tests.bzl index 5c76b0ee..5955a92e 100644 --- a/test/java/bazel/rules/java_test_tests.bzl +++ b/test/java/bazel/rules/java_test_tests.bzl @@ -1,11 +1,17 @@ """Tests for the Bazel java_test rule""" +load("@bazel_features//private:util.bzl", _bazel_version_ge = "ge") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:truth.bzl", "matching", "subjects") load("@rules_testing//lib:util.bzl", "util") load("//java:java_test.bzl", "java_test") +load("//test/java/testutil:helper.bzl", "always_passes") def _test_deduced_test_class(name): + if not _bazel_version_ge("8.0.0"): + always_passes(name) + return + util.helper_target( java_test, name = name + "/foo", @@ -32,7 +38,7 @@ def _test_deduced_test_class_impl(env, target): # Windows assert_jvm_flags = assert_action.argv() assert_jvm_flags.contains_predicate( - matching.str_matches("-Dbazel.test_suite=bazel.rules.test_deduced_test_class.foo"), + matching.str_matches("-Dbazel.test_suite=bazel.rules.test_deduced_test_class.Foo"), ) # regression test for https://github.com/bazelbuild/bazel/issues/20378 @@ -49,11 +55,71 @@ def _test_invalid_test_class_at_repo_root_impl(env, target): matching.str_matches("cannot determine test class."), ) +def _test_test_classes(name): + if not _bazel_version_ge("8.0.0"): + always_passes(name) + return + + util.helper_target( + java_test, + name = name + "/foo", + test_classes = ["com.example.FooTest", "com.example.BarTest"], + ) + + analysis_test( + name = name, + impl = _test_test_classes_impl, + target = name + "/foo", + ) + +def _test_test_classes_impl(env, target): + executable = target[DefaultInfo].files_to_run.executable.short_path + assert_action = env.expect.that_target(target).action_generating(executable) + + if assert_action.actual.substitutions: + # TemplateExpansion action on linux/mac + assert_jvm_flags = assert_action.substitutions().get( + "%jvm_flags%", + factory = lambda v, meta: subjects.collection([v], meta), + ) + else: + # Windows + assert_jvm_flags = assert_action.argv() + assert_jvm_flags.contains_predicate( + matching.str_matches("-Dbazel.test_suite=com.example.FooTest,com.example.BarTest"), + ) + +def _test_both_test_class_and_test_classes_fails(name): + if not _bazel_version_ge("8.0.0"): + always_passes(name) + return + + util.helper_target( + java_test, + name = name + "/foo", + test_class = "FooTest", + test_classes = ["FooTest"], + ) + + analysis_test( + name = name, + impl = _test_both_test_class_and_test_classes_fails_impl, + target = name + "/foo", + expect_failure = True, + ) + +def _test_both_test_class_and_test_classes_fails_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("cannot specify both 'test_class' and 'test_classes'"), + ) + def java_test_tests(name): test_suite( name = name, tests = [ _test_deduced_test_class, _test_invalid_test_class_at_repo_root, + _test_test_classes, + _test_both_test_class_and_test_classes_fails, ], ) diff --git a/test/java/common/java_common_tests.bzl b/test/java/common/java_common_tests.bzl index 0a3b257c..e9942abd 100644 --- a/test/java/common/java_common_tests.bzl +++ b/test/java/common/java_common_tests.bzl @@ -782,8 +782,6 @@ def _test_compile_strict_deps_enum(name): impl = _test_compile_strict_deps_enum_impl, target = name + "/custom", expect_failure = True, - # This is a crash in earlier Bazel versions (i.e. native rules) - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_compile_strict_deps_enum_impl(env, target): diff --git a/test/java/common/java_info_tests.bzl b/test/java/common/java_info_tests.bzl index daea0485..8f4c2c13 100644 --- a/test/java/common/java_info_tests.bzl +++ b/test/java/common/java_info_tests.bzl @@ -1130,8 +1130,6 @@ def _transitive_native_libraries_test(name): name = name, impl = _transitive_native_libraries_test_impl, target = target_name, - # LibraryToLink.library_indentifier only available from Bazel 8 - attr_values = {"tags": ["min_bazel_8"]}, ) def _transitive_native_libraries_test_impl(env, target): @@ -1191,8 +1189,6 @@ def _native_libraries_propagation_test(name): name = name, impl = _native_libraries_propagation_test_impl, target = target_name, - # LibraryToLink.library_identifier only available from Bazel 8 - attr_values = {"tags": ["min_bazel_8"]}, ) def _native_libraries_propagation_test_impl(env, target): diff --git a/test/java/common/rules/BUILD b/test/java/common/rules/BUILD index 97589249..b115dbb3 100644 --- a/test/java/common/rules/BUILD +++ b/test/java/common/rules/BUILD @@ -5,6 +5,7 @@ load(":common_launcher_java_binary_tests.bzl", "java_binary_launcher_tests") load(":common_launcher_java_library_tests.bzl", "java_library_launcher_tests") load(":deploy_archive_builder_tests.bzl", "deploy_archive_builder_test_suite") load(":java_binary_tests.bzl", "java_binary_tests") +load(":java_helper_tests.bzl", "java_helper_test_suite") load(":java_import_tests.bzl", "java_import_tests") load(":java_launcher_tests.bzl", "java_launcher_tests") load(":java_library_tests.bzl", "java_library_tests") @@ -17,6 +18,8 @@ package(default_applicable_licenses = ["@rules_java//:license"]) deploy_archive_builder_test_suite(name = "deploy_archive_builder_tests") +java_helper_test_suite(name = "java_helper_tests") + merge_attrs_test_suite(name = "merge_attrs_tests") java_binary_tests(name = "java_binary_tests") @@ -55,5 +58,5 @@ util.helper_target( "open/one", "open/two", ], - visibility = ["//test/java:__subpackages__"], + visibility = ["//visibility:private"], ) diff --git a/test/java/common/rules/a.foo b/test/java/common/rules/a.foo new file mode 100644 index 00000000..e69de29b diff --git a/test/java/common/rules/common_launcher_java_binary_tests.bzl b/test/java/common/rules/common_launcher_java_binary_tests.bzl index 572f27a0..0a83d9c6 100644 --- a/test/java/common/rules/common_launcher_java_binary_tests.bzl +++ b/test/java/common/rules/common_launcher_java_binary_tests.bzl @@ -1,8 +1,20 @@ """Parameterized tests for java_binary with --java_launcher""" +load("@bazel_features//:features.bzl", "bazel_features") +load("@rules_cc//cc:cc_binary.bzl", "cc_binary") +load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@rules_testing//lib:truth.bzl", "subjects") load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") +load("//java:java_library.bzl", "java_library") +load("//java:java_test.bzl", "java_test") +load("//java/common/rules:java_helper.bzl", "helper") +load("//test/java/testutil:artifact_closure.bzl", "artifact_closure") +load("//test/java/testutil:binary_executable_subject.bzl", "expect_that_executable") +load("//test/java/testutil:helper.bzl", "always_passes") +load("//test/java/testutil:javac_action_subject.bzl", "javac_action_subject") +load("//test/java/testutil:mock_java_toolchain.bzl", "mock_java_toolchain") def _test_java_binary_non_executable_rule_outputs(name): util.helper_target( @@ -23,10 +35,610 @@ def _test_java_binary_non_executable_rule_outputs_impl(env, target): "{package}/{name}.jar", ]) +def _test_java_binary_resources_only(name): + util.helper_target( + java_binary, + name = name + "/bin", + main_class = "doesnotmatter", + resources = [ + "someFile.xml", + "someOtherFile.xml", + ], + runtime_deps = [name + "/lib"], + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["Xml.java"], + ) + util.helper_target( + mock_java_toolchain, + name = name + "/toolchain", + ) + + analysis_test( + name = name, + config_settings = { + "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], + }, + extra_target_under_test_aspects = [artifact_closure.aspect], + impl = _test_java_binary_resources_only_impl, + target = name + "/bin", + ) + +def _test_java_binary_resources_only_impl(env, target): + deploy_jar = env.expect.that_target(target).action_named("JavaDeployJar").actual.outputs.to_list()[0] + env.expect.that_file(deploy_jar).basename().equals("bin_deploy.jar") + + # check that we do have a jar file build for bin, although + # it does not contain any source files + artifact_closure.of_target(env, target, extensions = ["jar"], initial = deploy_jar).contains_exactly([ + "{package}/JavaBuilder_deploy.jar", + "{package}/lib{test_name}/lib.jar", + "{package}/{test_name}/bin-class.jar", + "{package}/{test_name}/bin.jar", + "{package}/{test_name}/bin_deploy.jar", + ]) + artifact_closure.of_target(env, target, extensions = ["xml"], initial = deploy_jar).contains_exactly([ + "{package}/someFile.xml", + "{package}/someOtherFile.xml", + ]) + +def _test_java_binary_deploy_jar_coverage_setup(name): + util.helper_target( + java_binary, + name = name + "/app", + main_class = "com.google.app", + ) + + analysis_test( + name = name, + config_settings = { + "//command_line_option:collect_code_coverage": True, + }, + impl = _test_java_binary_deploy_jar_coverage_setup_impl, + target = name + "/app", + ) + +def _test_java_binary_deploy_jar_coverage_setup_impl(env, target): + assert_that_action = env.expect.that_target(target).action_generating("{package}/{name}_deploy.jar") + assert_that_action.argv().contains("Coverage-Main-Class: com.google.app") + +def _test_java_binary_transitive_dependency_from_java_library(name): + util.helper_target( + java_binary, + name = name + "/Binary", + srcs = ["Binary.java"], + deps = [name + "/somedep"], + ) + util.helper_target( + java_library, + name = name + "/somedep", + srcs = ["Dependency.java"], + deps = [name + "/otherdep"], + ) + util.helper_target( + java_library, + name = name + "/otherdep", + srcs = ["OtherDependency.java"], + ) + + analysis_test( + name = name, + extra_target_under_test_aspects = [artifact_closure.aspect], + impl = _test_java_binary_transitive_dependency_from_java_library_impl, + target = name + "/Binary", + ) + +def _test_java_binary_transitive_dependency_from_java_library_impl(env, target): + artifact_closure.of_target(env, target, extensions = ["java"]).contains_exactly([ + "{package}/Binary.java", + "{package}/Dependency.java", + "{package}/OtherDependency.java", + ]) + +def _test_java_binary_explicit_main_class(name): + util.helper_target( + java_binary, + name = name + "/bin", + main_class = "foo.bar.baz", + ) + + analysis_test( + name = name, + impl = _test_java_binary_explicit_main_class_impl, + target = name + "/bin", + ) + +def _test_java_binary_explicit_main_class_impl(env, target): + expect_that_executable.of_target(env, target).java_start_class().equals( + "foo.bar.baz", + ) + +def _test_java_binary_implicit_main_class(name): + util.helper_target( + java_binary, + name = name + "/Binary", + srcs = ["Binary.java"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_implicit_main_class_impl, + target = name + "/Binary", + ) + +def _test_java_binary_implicit_main_class_impl(env, target): + expect_that_executable.of_target(env, target).java_start_class().equals( + "common.rules.{test_name}.Binary".format(test_name = env.ctx.label.name), + ) + +def _test_java_test_main_class(name): + util.helper_target( + java_test, + name = name + "/Test", + ) + + analysis_test( + name = name, + impl = _test_java_test_main_class_impl, + target = name + "/Test", + ) + +def _test_java_test_main_class_impl(env, target): + expect_that_executable.of_target(env, target).test_suite().equals( + "common.rules.{test_name}.Test".format(test_name = env.ctx.label.name), + ) + +def _test_java_test_main_class_with_dot(name): + util.helper_target( + java_test, + name = name + "/withdot.Test", + ) + + analysis_test( + name = name, + impl = _test_java_test_main_class_with_dot_impl, + target = name + "/withdot.Test", + ) + +def _test_java_test_main_class_with_dot_impl(env, target): + expect_that_executable.of_target(env, target).test_suite().equals( + "common.rules.{test_name}.withdot.Test".format(test_name = env.ctx.label.name), + ) + +def _test_java_test_has_assertions_enabled(name): + util.helper_target( + java_test, + name = name + "/testea", + ) + + analysis_test( + name = name, + impl = _test_java_test_has_assertions_enabled_impl, + target = name + "/testea", + ) + +def _test_java_test_has_assertions_enabled_impl(env, target): + expect_that_executable.of_target(env, target).jvm_flags().contains("-ea") + +# Tests that the native library path computed from a ".so" cc_binary dependency +# includes the transitive closure of that dependency. +def _test_java_binary_native_library_path_includes_transitive_deps(name): + util.helper_target( + java_binary, + name = name + "/app", + srcs = ["DoesNotMatter.java"], + deps = [name + "/jni.so"], + ) + util.helper_target( + java_binary, + name = name + "/runtime_app", + srcs = ["AlsoDoesNotMatter.java"], + runtime_deps = [name + "/jni.so"], + ) + util.helper_target( + cc_binary, + name = name + "/jni.so", + srcs = ["lib1.so"], + deps = [name + "/helper_lib"], + ) + util.helper_target( + cc_library, + name = name + "/helper_lib", + srcs = ["lib2.so"], + ) + + analysis_test( + name = name, + attrs = { + "_windows_constraints": attr.label_list(default = ["@platforms//os:windows"]), + "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), + }, + impl = _test_java_binary_native_library_path_includes_transitive_deps_impl, + target = [ + name + "/app", + name + "/runtime_app", + ], + ) + +def _test_java_binary_native_library_path_includes_transitive_deps_impl(env, targets): + for target in targets: + if helper.is_target_platform_windows(env.ctx): + expect_that_executable.of_target(env, target).native_library_paths().contains_exactly([ + "${{JAVA_RUNFILES}}/{workspace}/{package}", + ]) + else: + expect_that_executable.of_target(env, target).native_library_paths().contains_exactly([ + "${{JAVA_RUNFILES}}/{workspace}/_solib_{cpu}/_//{package}:{test_name}/helper_lib___{package}", + "${{JAVA_RUNFILES}}/{workspace}/_solib_{cpu}/_//{package}:{test_name}/jni.so___{package}", + ]) + +# Regression test: the native library path separator on Windows is ";" instead of ":". +def _test_java_binary_native_library_path_separator(name): + util.helper_target( + java_binary, + name = name + "/app", + srcs = ["DoesNotMatter.java"], + deps = [ + name + "/lib1", + name + "/lib2", + ], + ) + + # Define two native libs (in different directories so java.library.path has multiple entries). + util.helper_target( + cc_binary, + name = name + "/lib1", + srcs = ["lib1.so"], + ) + util.helper_target( + cc_binary, + name = name + "/lib2", + srcs = ["subdir/lib2.so"], + ) + + analysis_test( + name = name, + attrs = { + "_windows_constraints": attr.label_list(default = ["@platforms//os:windows"]), + "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), + }, + impl = _test_java_binary_native_library_path_separator_impl, + target = name + "/app", + ) + +def _test_java_binary_native_library_path_separator_impl(env, target): + # We should find two libraries on java.library.path (if the correct path separator was used). + native_library_paths = expect_that_executable.of_target(env, target).native_library_paths() + native_library_paths.has_size(2) + +# Regression test for bug 2774317: Problems with inner classes as main class. +def _test_java_binary_inner_class(name): + util.helper_target( + java_binary, + name = name + "/inner", + srcs = ["Main.java"], + main_class = "Main$Inner", + ) + + analysis_test( + name = name, + attrs = {"_windows_constraints": attr.label_list(default = ["@platforms//os:windows"])}, + impl = _test_java_binary_inner_class_impl, + target = name + "/inner", + ) + +def _test_java_binary_inner_class_impl(env, target): + if helper.is_target_platform_windows(env.ctx): + expected = "Main$Inner" # unquoted on windows + else: + expected = "'Main$Inner'" # shell-quoted + expect_that_executable.of_target(env, target).java_start_class().equals(expected) + +def _test_java_test_inner_class(name): + util.helper_target( + java_test, + name = name + "/inner", + test_class = "Outer$Inner", + ) + + analysis_test( + name = name, + attrs = {"_windows_constraints": attr.label_list(default = ["@platforms//os:windows"])}, + impl = _test_java_test_inner_class_impl, + target = name + "/inner", + ) + +def _test_java_test_inner_class_impl(env, target): + if helper.is_target_platform_windows(env.ctx): + expected = "Outer$Inner" # unquoted on windows + else: + expected = "'Outer$Inner'" # shell-quoted + expect_that_executable.of_target(env, target).test_suite().equals(expected) + +def _test_java_binary_strict_java_deps_flag(name): + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + always_passes(name) + return + + util.helper_target( + java_binary, + name = name + "/app", + srcs = ["App.java"], + deps = [ + name + "/alpha", + name + "/bravo", + ], + ) + util.helper_target( + java_library, + name = name + "/alpha", + srcs = ["Alpha.java"], + ) + util.helper_target( + java_library, + name = name + "/bravo", + srcs = ["Bravo.java"], + exports = [name + "/delta"], + deps = [name + "/charlie"], + ) + util.helper_target( + java_library, + name = name + "/charlie", + srcs = ["Charlie.java"], + ) + util.helper_target( + java_library, + name = name + "/delta", + srcs = ["Delta.java"], + ) + + analysis_test( + name = name, + attrs = { + "off": {"@config_settings": {"//command_line_option:experimental_strict_java_deps": "OFF"}}, + "warn": {"@config_settings": {"//command_line_option:experimental_strict_java_deps": "WARN"}}, + "error": {"@config_settings": {"//command_line_option:experimental_strict_java_deps": "ERROR"}}, + "strict": {"@config_settings": {"//command_line_option:experimental_strict_java_deps": "STRICT"}}, + }, + impl = _test_java_binary_strict_java_deps_flag_impl, + targets = { + "off": name + "/app", + "warn": name + "/app", + "error": name + "/app", + "strict": name + "/app", + }, + ) + +def _test_java_binary_strict_java_deps_flag_impl(env, targets): + # off + assert_that_javac = javac_action_subject.of(env, targets.off, desc = "off") + assert_that_javac.direct_dependencies().contains_exactly([]) + assert_that_javac.strict_java_deps().equals("OFF") + + for mode, target, expected_flag_value in [ + ("WARN", targets.warn, "WARN"), + ("ERROR", targets.error, "ERROR"), + ("STRICT", targets.strict, "ERROR"), + ]: + assert_that_javac = javac_action_subject.of(env, target, desc = "mode=" + mode) + assert_that_javac.strict_java_deps().equals(expected_flag_value) + assert_that_javac.direct_dependencies().contains_exactly([ + "{bindir}/{package}/lib{test_name}/alpha-hjar.jar", + "{bindir}/{package}/lib{test_name}/bravo-hjar.jar", + "{bindir}/{package}/lib{test_name}/delta-hjar.jar", + ]).in_order() + +def _test_java_binary_runtime_deps_transitivity(name): + util.helper_target( + java_library, + name = name + "/l0", + srcs = ["l0.java"], + ) + util.helper_target( + java_library, + name = name + "/l1", + srcs = ["l1.java"], + ) + util.helper_target( + java_library, + name = name + "/l2", + srcs = ["l2.java"], + runtime_deps = [name + "/l1"], + deps = [name + "/l0"], + ) + util.helper_target( + java_library, + name = name + "/l3", + srcs = ["l3.java"], + deps = [name + "/l2"], + ) + util.helper_target( + java_library, + name = name + "/l4", + srcs = ["l4.java"], + deps = [name + "/l1"], + ) + util.helper_target( + java_binary, + name = name + "/b1", + srcs = ["b1.java"], + deps = [name + "/l2"], + ) + util.helper_target( + java_binary, + name = name + "/b2", + srcs = ["b2.java"], + runtime_deps = [name + "/l3"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_runtime_deps_transitivity_impl, + targets = { + "b1": name + "/b1", + "b2": name + "/b2", + }, + ) + +def _expect_that_deploy_jar_action_inputs(env, target, extension): + action = env.expect.that_target(target).action_generating("{package}/{name}_deploy.jar") + return subjects.collection( + action.actual.inputs.to_list(), + meta = action.meta, + ).transform( + desc = extension + " inputs", + filter = lambda f: f.extension == extension, + format = True, + map_each = lambda f: f.short_path, + ) + +def _test_java_binary_runtime_deps_transitivity_impl(env, targets): + _expect_that_deploy_jar_action_inputs(env, targets.b1, "jar").contains_exactly([ + "{package}/lib{test_name}/l0.jar", + "{package}/lib{test_name}/l1.jar", + "{package}/lib{test_name}/l2.jar", + "{package}/{test_name}/b1.jar", + ]) + _expect_that_deploy_jar_action_inputs(env, targets.b2, "jar").contains_exactly([ + "{package}/lib{test_name}/l0.jar", + "{package}/lib{test_name}/l1.jar", + "{package}/lib{test_name}/l2.jar", + "{package}/lib{test_name}/l3.jar", + "{package}/{test_name}/b2.jar", + ]) + +def _test_java_binary_runtime_deps_with_transitive_data(name): + util.helper_target( + java_binary, + name = name + "/bin", + srcs = ["Bin.java"], + runtime_deps = [name + "/lib"], + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["Lib.java"], + deps = [name + "/bundle"], + ) + util.helper_target( + java_library, + name = name + "/bundle", + data = [name + "/fava"], + exports = [name + "/bundle2"], + ) + util.helper_target( + java_library, + name = name + "/bundle2", + data = [name + "/extra"], + ) + util.helper_target( + native.filegroup, + name = name + "/fava", + srcs = ["some.js"], + ) + util.helper_target( + native.filegroup, + name = name + "/extra", + srcs = ["some.gss"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_runtime_deps_with_transitive_data_impl, + target = name + "/bin", + ) + +def _test_java_binary_runtime_deps_with_transitive_data_impl(env, target): + env.expect.that_target(target).runfiles().contains_at_least([ + "{workspace}/{package}/some.js", + "{workspace}/{package}/some.gss", + ]) + +def _test_java_binary_runtime_deps_with_genrule(name): + util.helper_target( + java_binary, + name = name + "/bin", + srcs = ["Bin.java"], + runtime_deps = [name + "/langtools"], + ) + util.helper_target( + native.genrule, + name = name + "/langtools", + outs = [name + "/langtools.jar"], + cmd = "", + ) + + analysis_test( + name = name, + impl = _test_java_binary_runtime_deps_with_genrule_impl, + target = name + "/bin", + ) + +def _test_java_binary_runtime_deps_with_genrule_impl(env, target): + env.expect.that_target(target).runfiles().contains( + "{workspace}/{package}/{test_name}/langtools.jar", + ) + +def _test_java_binary_runtime_deps_with_native_libraries(name): + util.helper_target( + java_binary, + name = name + "/bin", + srcs = ["Bin.java"], + runtime_deps = [name + "/lib"], + ) + util.helper_target( + java_library, + name = name + "/lib", + srcs = ["Foo.java"], + deps = [name + "/jni.so"], + ) + util.helper_target( + cc_binary, + name = name + "/jni.so", + srcs = ["lib1.so"], + deps = [name + "/helper_library"], + ) + util.helper_target( + cc_library, + name = name + "/helper_library", + srcs = ["lib2.so"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_runtime_deps_with_native_libraries_impl, + target = name + "/bin", + ) + +def _test_java_binary_runtime_deps_with_native_libraries_impl(env, target): + env.expect.that_target(target).runfiles().paths().transform( + desc = "basenames", + map_each = lambda f: reversed(f.rsplit("/"))[0], + ).contains_at_least(["lib1.so", "lib2.so"]) + def java_binary_launcher_tests(name): test_suite( name = name, tests = [ _test_java_binary_non_executable_rule_outputs, + _test_java_binary_resources_only, + _test_java_binary_deploy_jar_coverage_setup, + _test_java_binary_transitive_dependency_from_java_library, + _test_java_binary_explicit_main_class, + _test_java_binary_implicit_main_class, + _test_java_test_main_class, + _test_java_test_main_class_with_dot, + _test_java_test_has_assertions_enabled, + _test_java_binary_native_library_path_includes_transitive_deps, + _test_java_binary_native_library_path_separator, + _test_java_binary_inner_class, + _test_java_test_inner_class, + _test_java_binary_strict_java_deps_flag, + _test_java_binary_runtime_deps_transitivity, + _test_java_binary_runtime_deps_with_transitive_data, + _test_java_binary_runtime_deps_with_genrule, + _test_java_binary_runtime_deps_with_native_libraries, ], ) diff --git a/test/java/common/rules/deploy_archive_builder_tests.bzl b/test/java/common/rules/deploy_archive_builder_tests.bzl index 727790f8..57d3035a 100644 --- a/test/java/common/rules/deploy_archive_builder_tests.bzl +++ b/test/java/common/rules/deploy_archive_builder_tests.bzl @@ -25,8 +25,6 @@ def _test_custom_singlejar(name): config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], }, - # Starlark rules are only used with Bazel 8 onwards. - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_custom_singlejar_impl(env, target): diff --git a/test/java/common/rules/java_binary_tests.bzl b/test/java/common/rules/java_binary_tests.bzl index d4699fa0..6ee32ba3 100644 --- a/test/java/common/rules/java_binary_tests.bzl +++ b/test/java/common/rules/java_binary_tests.bzl @@ -47,8 +47,6 @@ def _test_stamp_conversion_does_not_override_int(name): config_settings = { "//command_line_option:stamp": False, }, - # deploy jars are in a separate rule in Bazel 7, Bazel 6 generated build-info differently - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_stamp_conversion_does_not_override_int_impl(env, target): @@ -56,6 +54,9 @@ def _test_stamp_conversion_does_not_override_int_impl(env, target): "{package}/{name}_deploy.jar", ) + assert_deploy_jar_action.argv().contains("--normalize") + assert_deploy_jar_action.argv().not_contains("--exclude_build_data") + assert_deploy_jar_action.argv().contains("--build_info_file") assert_deploy_jar_action.inputs().not_contains_predicate( matching.file_basename_equals("non_volatile_file.properties"), ) @@ -428,6 +429,179 @@ def _test_java_binary_no_launcher_dep_if_not_executable(name): }, ) +# regression test for #887069 +def _test_java_binary_java_package(name): + analysis_test( + name = name, + impl = _test_java_binary_java_package_impl, + target = "//test/testdata:non_java", + expect_failure = True, + ) + +def _test_java_binary_java_package_impl(env, target): + env.expect.that_target(target).failures().contains_predicate(matching.str_matches( + "main_class was not provided and cannot be inferred", + )) + +# Regression test for CL 7314966. +def _test_java_binary_rule_in_sub_directory(name): + util.helper_target( + java_binary, + name = "subdir/MyBinary", + srcs = ["subdir/MyBinary.java"], + ) + + analysis_test( + name = name, + impl = lambda *args, **kwargs: None, # should not be an error + target = "subdir/MyBinary", + ) + +def _test_java_binary_duplicate_classpath_resources(name): + util.helper_target( + native.filegroup, + name = name + "/a", + srcs = ["a/same.txt"], + ) + util.helper_target( + native.filegroup, + name = name + "/b", + srcs = ["b/same.txt"], + ) + util.helper_target( + java_binary, + name = name + "/app", + srcs = ["App.java"], + classpath_resources = [ + name + "/a", + name + "/b", + ], + ) + + analysis_test( + name = name, + impl = _test_java_binary_duplicate_classpath_resources_impl, + target = name + "/app", + expect_failure = True, + ) + +def _test_java_binary_duplicate_classpath_resources_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("entries must have different file names (duplicate: same.txt)"), + ) + +def _test_java_binary_jdeps(name): + util.helper_target( + java_binary, + name = name + "/app", + srcs = ["App.java"], + resources = ["app.properties"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_jdeps_impl, + target = name + "/app", + ) + +def _test_java_binary_jdeps_impl(env, target): + # should produce an app.jdeps file, not an app-class.jdeps file. + env.expect.that_target(target).action_generating("{package}/{name}-class.jar").contains_flag_values([ + ("--output_deps_proto", "{bindir}/{package}/{name}.jdeps"), + ]) + +def _test_java_binary_deps_without_srcs(name): + util.helper_target( + java_binary, + name = name + "/a", + srcs = [], + deps = [name + "/b"], + main_class = "B", + ) + util.helper_target( + java_library, + name = name + "/b", + srcs = ["B.java"], + ) + + analysis_test( + name = name, + impl = _test_java_binary_deps_without_srcs_impl, + target = name + "/a", + expect_failure = True, + ) + +def _test_java_binary_deps_without_srcs_impl(env, target): + env.expect.that_target(target).failures().contains_predicate( + matching.str_matches("deps not allowed without srcs"), + ) + +def _test_java_binary_srcs_filetypes(name): + util.helper_target( + java_binary, + name = name + "/valid", + srcs = [ + "a.java", + name + "/gmix", + name + "/gvalid", + ], + ) + util.helper_target( + java_binary, + name = name + "/invalid", + srcs = [ + "a.foo", + name + "/ginvalid", + ], + ) + util.helper_target( + java_binary, + name = name + "/mix", + srcs = [ + "a.foo", + "a.java", + ], + ) + util.helper_target( + native.genrule, + name = name + "/gvalid", + outs = [name + "/b.java"], + cmd = "", + ) + util.helper_target( + native.genrule, + name = name + "/ginvalid", + outs = [name + "/b.foo"], + cmd = "", + ) + util.helper_target( + native.genrule, + name = name + "/gmix", + outs = [name + "/c.java", name + "/c.foo"], + cmd = "", + ) + + analysis_test( + name = name, + impl = _test_java_binary_srcs_filetypes_impl, + targets = { + "valid": name + "/valid", + "invalid": name + "/invalid", + "mix": name + "/mix", + }, + expect_failure = True, + ) + +def _test_java_binary_srcs_filetypes_impl(env, targets): + env.expect.that_target(targets.valid).failures().contains_exactly([]) + env.expect.that_target(targets.invalid).failures().contains_at_least_predicates([ + matching.str_matches("'*/ginvalid' does not produce any java_binary srcs files"), + matching.str_matches("source file '*:a.foo' is misplaced here"), + ]) + env.expect.that_target(targets.mix).failures().contains_at_least_predicates([ + matching.str_matches("'*:a.foo' does not produce any java_binary srcs files"), + ]) + def java_binary_tests(name): test_suite( name = name, @@ -442,5 +616,11 @@ def java_binary_tests(name): _test_one_version_check_violations_allowed, _test_one_version_check_disabled, _test_java_binary_no_launcher_dep_if_not_executable, + _test_java_binary_java_package, + _test_java_binary_rule_in_sub_directory, + _test_java_binary_duplicate_classpath_resources, + _test_java_binary_jdeps, + _test_java_binary_deps_without_srcs, + _test_java_binary_srcs_filetypes, ], ) diff --git a/test/java/common/rules/java_helper_tests.bzl b/test/java/common/rules/java_helper_tests.bzl new file mode 100644 index 00000000..89a44d24 --- /dev/null +++ b/test/java/common/rules/java_helper_tests.bzl @@ -0,0 +1,134 @@ +"""Tests for java_helper functions""" + +load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") +load( + "//java/common/rules:java_helper.bzl", + "helper", +) + +def _java_segments_test_impl(ctx): + env = unittest.begin(ctx) + + asserts.equals( + env, + ["com", "google", "foo", "Foo"], + helper.java_segments("java/com/google/foo/Foo"), + ) + asserts.equals( + env, + ["com", "google", "foo", "FooTest"], + helper.java_segments("javatests/com/google/foo/FooTest"), + ) + asserts.equals( + env, + ["com", "google", "foo", "Foo"], + helper.java_segments("src/main/java/com/google/foo/Foo"), + ) + asserts.equals( + env, + ["com", "google", "foo", "FooTest"], + helper.java_segments("src/test/java/com/google/foo/FooTest"), + ) + asserts.equals( + env, + ["com", "google", "foo", "Foo"], + helper.java_segments("third_party/java/foo/java/com/google/foo/Foo"), + ) + asserts.equals( + env, + ["com", "google", "foo", "FooTest"], + helper.java_segments("third_party/java/foo/javatests/com/google/foo/FooTest"), + ) + asserts.equals( + env, + ["com", "google", "foo", "Foo"], + helper.java_segments("third_party/java/foo/src/main/java/com/google/foo/Foo"), + ) + asserts.equals( + env, + ["com", "google", "foo", "FooTest"], + helper.java_segments("third_party/java/foo/src/test/java/com/google/foo/FooTest"), + ) + asserts.equals( + env, + ["foo", "org", "foo", "Foo"], + helper.java_segments("third_party/java/foo/org/foo/Foo"), + ) + asserts.equals( + env, + None, + helper.java_segments("foo/bar/Baz"), + ) + + asserts.equals( + env, + "com/google/foo/Foo", + helper.java_path("java/com/google/foo/Foo"), + ) + asserts.equals( + env, + "com/google/foo/Foo", + helper.java_path("third_party/java/foo/java/com/google/foo/Foo"), + ) + asserts.equals( + env, + None, + helper.java_path("foo/bar/Baz"), + ) + + asserts.equals( + env, + "java", + helper.java_root("java/com/google/foo/Foo"), + ) + asserts.equals( + env, + "javatests", + helper.java_root("javatests/com/google/foo/FooTest"), + ) + asserts.equals( + env, + "foo/java", + helper.java_root("foo/java/com/google/foo/Foo"), + ) + asserts.equals( + env, + "third_party/java/foo/java", + helper.java_root("third_party/java/foo/java/com/google/foo/Foo"), + ) + asserts.equals( + env, + None, + helper.java_root("foo/bar/Baz"), + ) + + asserts.equals( + env, + "com.google.foo.Foo", + helper.full_classname("java/com/google/foo/Foo"), + ) + asserts.equals( + env, + "com.google.foo.Foo", + helper.full_classname("third_party/java/foo/java/com/google/foo/Foo"), + ) + asserts.equals( + env, + None, + helper.full_classname("foo/bar/Baz"), + ) + + return unittest.end(env) + +java_segments_test = unittest.make(_java_segments_test_impl) + +def java_helper_test_suite(name): + """Sets up java_helper test suite + + Args: + name: the name of the test suite target + """ + unittest.suite( + name, + java_segments_test, + ) diff --git a/test/java/common/rules/java_import_tests.bzl b/test/java/common/rules/java_import_tests.bzl index 35b713df..ead39e4c 100644 --- a/test/java/common/rules/java_import_tests.bzl +++ b/test/java/common/rules/java_import_tests.bzl @@ -178,6 +178,49 @@ def _test_deps_impl(env, targets): "{package}/depjar.jar", ]) +# Regression test for https://github.com/bazelbuild/rules_java/issues/362: every java_import +# records a jdeps proto as its compile_jdeps so that reduced classpaths of downstream compilations +# are not missing its transitive dependencies. +def _test_compile_jdeps_propagated_for_deps(name): + util.helper_target( + java_import, + name = name + "/import-jar", + jars = ["import.jar"], + deps = [name + "/depjar"], + ) + util.helper_target( + java_import, + name = name + "/incomplete-jar", + jars = ["incomplete.jar"], + deps = [name + "/depjar"], + tags = ["incomplete-deps"], + ) + util.helper_target( + java_import, + name = name + "/depjar", + jars = ["depjar.jar"], + ) + + analysis_test( + name = name, + impl = _test_compile_jdeps_propagated_for_deps_impl, + targets = { + "incomplete_deps": name + "/incomplete-jar", + "with_deps": name + "/import-jar", + "without_deps": name + "/depjar", + }, + ) + +def _test_compile_jdeps_propagated_for_deps_impl(env, targets): + for name in ["with_deps", "without_deps", "incomplete_deps"]: + java_info_subject.from_target( + env, + getattr(targets, name), + expr = name, + ).compilation_args().compile_time_java_dependencies().contains_exactly([ + "{package}/_java_import/{name}/jdeps.proto", + ]) + # Regression test for b/262751943. def _test_commandline_contains_target_label(name): util.helper_target( @@ -305,8 +348,6 @@ def _test_srcjar_added_to_validation_output_group(name): name = name, impl = _test_srcjar_added_to_validation_output_group_impl, target = name + "/libraryjar_with_srcjar", - # Starlark rules are only used with Bazel 8 onwards. - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_srcjar_added_to_validation_output_group_impl(env, target): @@ -875,8 +916,6 @@ def _test_transitive_proguard_specs_are_exported(name): name = name, impl = _test_transitive_proguard_specs_are_exported_impl, target = target_name, - # Before Bazel 8, native rules use the native ProguardSpecProvider - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_transitive_proguard_specs_are_exported_impl(env, target): @@ -959,6 +998,7 @@ def java_import_tests(name): _test_simple, _test_with_java_library, _test_deps, + _test_compile_jdeps_propagated_for_deps, _test_commandline_contains_target_label, _test_java_library_allows_import_in_deps, _test_module_flags, diff --git a/test/java/common/rules/java_library_tests.bzl b/test/java/common/rules/java_library_tests.bzl index 4115b121..ec5500ce 100644 --- a/test/java/common/rules/java_library_tests.bzl +++ b/test/java/common/rules/java_library_tests.bzl @@ -337,7 +337,7 @@ def _test_strict_java_deps_impl(env, target): # javac action's argv at all; the "OFF" value (which is equivalent to an unset flag) in that # case is injected by javac_action_subject for convenience and canonicalization. expect_that_javac_action = javac_action_subject.of(env, target, "{package}/lib{name}.jar") - expect_that_javac_action.strict_java_deps().contains_exactly([env.ctx.attr.expected_strict_java_deps]) + expect_that_javac_action.strict_java_deps().equals(env.ctx.attr.expected_strict_java_deps) def _test_strict_java_deps_off(name): _test_strict_java_deps(name, "OFF") diff --git a/test/java/common/rules/java_plugin_tests.bzl b/test/java/common/rules/java_plugin_tests.bzl index 71c2d156..b6e48610 100644 --- a/test/java/common/rules/java_plugin_tests.bzl +++ b/test/java/common/rules/java_plugin_tests.bzl @@ -194,8 +194,6 @@ def _test_java_plugin_exports_transitive_proguard_specs(name): name = name, impl = _test_java_plugin_exports_transitive_proguard_specs_impl, target = name + "/top", - # Before Bazel 8, native rules use the native ProguardSpecProvider - attr_values = {"tags": ["min_bazel_8"]}, provider_subject_factories = [struct( type = ProguardSpecInfo, name = "ProguardInfo", diff --git a/test/java/common/rules/java_single_jar_tests.bzl b/test/java/common/rules/java_single_jar_tests.bzl index 488aab3f..87c92463 100644 --- a/test/java/common/rules/java_single_jar_tests.bzl +++ b/test/java/common/rules/java_single_jar_tests.bzl @@ -1,11 +1,60 @@ """Tests for the java_single_jar rule""" -load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") +load("@bazel_features//:features.bzl", "bazel_features") +load("@rules_testing//lib:analysis_test.bzl", _analysis_test = "analysis_test") load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "util") +load("@rules_testing//lib/private:util.bzl", "get_test_name_from_function") # buildifier: disable=bzl-visibility +load("//java:java_binary.bzl", "java_binary") +load("//java:java_library.bzl", "java_library") load("//java:java_single_jar.bzl", "java_single_jar") load("//java/common:java_semantics.bzl", "semantics") +def _path_stripping_analysis_test(name, impl, config_settings = {}, **kwargs): + if name.endswith("_off"): + output_path_mode = "off" + elif name.endswith("_strip"): + output_path_mode = "strip" + else: + fail("expected test name to end with one of [_strip, _off]") + + # TODO: remove once Bazel 7 is no longer supported + if bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + config_settings = config_settings | { + "//command_line_option:experimental_output_paths": output_path_mode, + } + + _analysis_test( + name = name, + impl = lambda env, target: impl(env, target, output_path_mode), + config_settings = config_settings, + **kwargs + ) + +def _path_stripping_test_suite(name, *, tests = [], test_kwargs = {}): + """Expands each test into 'off' and 'strip' output path mode variants""" + test_targets = [] + for suffix in ["_off", "_strip"]: + for setup_func in tests: + test_name = get_test_name_from_function(setup_func) + suffix + setup_func(name = test_name, **test_kwargs) + test_targets.append(test_name) + native.test_suite( + name = name, + tests = test_targets, + ) + +def _get_bindir_for_output_path_mode(output_path_mode): + # TODO: remove once Bazel 7 is no longer supported + if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: + return "{bindir}" + + if output_path_mode == "off": + return "{bindir}" + elif output_path_mode == "strip": + return "{cfg_stripped_bindir}" + fail("unexpected output path mode: " + output_path_mode) + def _test_java_single_jar_basic(name): util.helper_target( java_single_jar, @@ -13,20 +62,20 @@ def _test_java_single_jar_basic(name): deps = ["1.jar", "2.jar"], ) - analysis_test( + _path_stripping_analysis_test( name = name, impl = _test_java_single_jar_basic_impl, target = name + "/jar", ) -def _test_java_single_jar_basic_impl(env, target): +def _test_java_single_jar_basic_impl(env, target, output_path_mode): assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") assert_that_action.argv().contains_at_least([ "--sources", "{package}/1.jar", "{package}/2.jar", "--output", - "{bindir}/{package}/{name}.jar", + _get_bindir_for_output_path_mode(output_path_mode) + "/{package}/{name}.jar", "--normalize", "--dont_change_compression", "--exclude_build_data", @@ -41,7 +90,7 @@ def _test_java_single_jar_force_enable_stamping(name): exclude_build_data = False, ) - analysis_test( + _path_stripping_analysis_test( name = name, impl = _test_java_single_jar_force_enable_stamping_impl, targets = { @@ -50,13 +99,22 @@ def _test_java_single_jar_force_enable_stamping(name): }, ) -def _test_java_single_jar_force_enable_stamping_impl(env, targets): - assert_that_action = env.expect.that_target(targets.jar).action_named("JavaSingleJar") +def _assert_build_info_files(env, jar_target, build_info_files, output_path_mode): + bin_dir = _get_bindir_for_output_path_mode(output_path_mode) + assert_that_action = env.expect.that_target(jar_target).action_named("JavaSingleJar") assert_that_action.contains_flag_values([ - ("--build_info_file", f.path) - for f in targets.build_info[OutputGroupInfo].non_redacted_build_info_files.to_list() + ("--build_info_file", bin_dir + f.path[len(f.root.path):]) + for f in build_info_files.to_list() ]) +def _test_java_single_jar_force_enable_stamping_impl(env, targets, output_path_mode): + _assert_build_info_files( + env, + targets.jar, + targets.build_info[OutputGroupInfo].non_redacted_build_info_files, + output_path_mode, + ) + def _test_java_single_jar_force_disable_stamping(name): util.helper_target( java_single_jar, @@ -65,7 +123,7 @@ def _test_java_single_jar_force_disable_stamping(name): exclude_build_data = False, ) - analysis_test( + _path_stripping_analysis_test( name = name, impl = _test_java_single_jar_force_disable_stamping_impl, targets = { @@ -74,12 +132,13 @@ def _test_java_single_jar_force_disable_stamping(name): }, ) -def _test_java_single_jar_force_disable_stamping_impl(env, targets): - assert_that_action = env.expect.that_target(targets.jar).action_named("JavaSingleJar") - assert_that_action.contains_flag_values([ - ("--build_info_file", f.path) - for f in targets.build_info[OutputGroupInfo].redacted_build_info_files.to_list() - ]) +def _test_java_single_jar_force_disable_stamping_impl(env, targets, output_path_mode): + _assert_build_info_files( + env, + targets.jar, + targets.build_info[OutputGroupInfo].redacted_build_info_files, + output_path_mode, + ) def _test_java_single_jar_stamping_enabled_build_data_excluded_fails(name): util.helper_target( @@ -89,7 +148,7 @@ def _test_java_single_jar_stamping_enabled_build_data_excluded_fails(name): exclude_build_data = True, ) - analysis_test( + _analysis_test( name = name, impl = _test_java_single_jar_stamping_enabled_build_data_excluded_fails_impl, target = name + "/jar", @@ -109,7 +168,7 @@ def _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled(name): exclude_build_data = False, ) - analysis_test( + _path_stripping_analysis_test( name = name, impl = _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled_impl, targets = { @@ -121,12 +180,13 @@ def _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled(name): }, ) -def _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled_impl(env, targets): - assert_that_action = env.expect.that_target(targets.jar).action_named("JavaSingleJar") - assert_that_action.contains_flag_values([ - ("--build_info_file", f.path) - for f in targets.build_info[OutputGroupInfo].non_redacted_build_info_files.to_list() - ]) +def _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled_impl(env, targets, output_path_mode): + _assert_build_info_files( + env, + targets.jar, + targets.build_info[OutputGroupInfo].non_redacted_build_info_files, + output_path_mode, + ) def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled(name): util.helper_target( @@ -136,7 +196,7 @@ def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled(name): exclude_build_data = False, ) - analysis_test( + _path_stripping_analysis_test( name = name, impl = _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled_impl, targets = { @@ -148,22 +208,139 @@ def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled(name): }, ) -def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled_impl(env, targets): - assert_that_action = env.expect.that_target(targets.jar).action_named("JavaSingleJar") - assert_that_action.contains_flag_values([ - ("--build_info_file", f.path) - for f in targets.build_info[OutputGroupInfo].redacted_build_info_files.to_list() +def _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled_impl(env, targets, output_path_mode): + _assert_build_info_files( + env, + targets.jar, + targets.build_info[OutputGroupInfo].redacted_build_info_files, + output_path_mode, + ) + +def _test_java_single_jar_deploy_manifest_lines(name): + util.helper_target( + java_single_jar, + name = name + "/jar", + deps = ["1.jar"], + deploy_manifest_lines = [ + "Manifest-Entry-A: valueA", + "Manifest-Entry-B: line1,\n line2", + ], + ) + + _analysis_test( + name = name, + impl = _test_java_single_jar_deploy_manifest_lines_impl, + target = name + "/jar", + ) + +def _test_java_single_jar_deploy_manifest_lines_impl(env, target): + assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") + assert_that_action.argv().contains_at_least([ + "--deploy_manifest_lines", + "Manifest-Entry-A: valueA", + "Manifest-Entry-B: line1,\n line2", + ]) + +def _test_java_single_jar_transitive_deploy_env(name): + util.helper_target( + java_library, + name = name + "_lib_a", + srcs = ["A.java"], + ) + util.helper_target( + java_library, + name = name + "_lib_b", + srcs = ["B.java"], + ) + util.helper_target( + java_library, + name = name + "_lib_c", + srcs = ["C.java"], + ) + util.helper_target( + java_single_jar, + name = name + "_env1", + deps = [name + "_lib_a"], + ) + util.helper_target( + java_single_jar, + name = name + "_inner", + deps = [name + "_lib_a", name + "_lib_b"], + deploy_env = [name + "_env1"], + ) + util.helper_target( + java_single_jar, + name = name + "_outer", + deps = [name + "_lib_a", name + "_lib_b", name + "_lib_c"], + deploy_env = [name + "_inner"], + ) + + _path_stripping_analysis_test( + name = name, + impl = _test_java_single_jar_transitive_deploy_env_impl, + target = name + "_outer", + ) + +def _test_java_single_jar_transitive_deploy_env_impl(env, target, output_path_mode): + bin_dir = _get_bindir_for_output_path_mode(output_path_mode) + assert_that_action = env.expect.that_target(target).action_named("JavaSingleJar") + assert_that_action.argv().contains_at_least([ + "--sources", + bin_dir + "/{package}/lib{test_name}_lib_c.jar", + "--output", + ]) + assert_that_action.argv().not_contains(bin_dir + "/{package}/lib{test_name}_lib_a.jar") + assert_that_action.argv().not_contains(bin_dir + "/{package}/lib{test_name}_lib_b.jar") + +def _test_java_binary_deploy_env_with_java_single_jar(name): + util.helper_target( + java_library, + name = name + "_lib_a", + srcs = ["A.java"], + ) + util.helper_target( + java_library, + name = name + "_lib_b", + srcs = ["B.java"], + ) + util.helper_target( + java_single_jar, + name = name + "_single_jar", + deps = [name + "_lib_a"], + ) + util.helper_target( + java_binary, + name = name + "_bin", + main_class = "Main", + runtime_deps = [name + "_lib_a", name + "_lib_b"], + deploy_env = [name + "_single_jar"], + ) + + _analysis_test( + name = name, + impl = _test_java_binary_deploy_env_with_java_single_jar_impl, + target = name + "_bin", + ) + +def _test_java_binary_deploy_env_with_java_single_jar_impl(env, target): + assert_that_action = env.expect.that_target(target).action_named("JavaDeployJar") + assert_that_action.inputs().contains_at_least([ + "{package}/lib{test_name}_lib_b.jar", ]) + assert_that_action.inputs().not_contains("{package}/lib{test_name}_lib_a.jar") def java_single_jar_tests(name): - test_suite( + _path_stripping_test_suite( name = name, tests = [ _test_java_single_jar_basic, + _test_java_single_jar_deploy_manifest_lines, _test_java_single_jar_force_enable_stamping, _test_java_single_jar_force_disable_stamping, _test_java_single_jar_stamping_enabled_build_data_excluded_fails, _test_java_single_jar_stamp_attr_auto_stamp_flag_enabled, _test_java_single_jar_stamp_attr_auto_stamp_flag_disabled, + _test_java_single_jar_transitive_deploy_env, + _test_java_binary_deploy_env_with_java_single_jar, ], ) diff --git a/test/java/common/rules/java_test_tests.bzl b/test/java/common/rules/java_test_tests.bzl index 995872f1..04674ee7 100644 --- a/test/java/common/rules/java_test_tests.bzl +++ b/test/java/common/rules/java_test_tests.bzl @@ -10,7 +10,6 @@ load("@rules_testing//lib:util.bzl", "util") load("//java:java_binary.bzl", "java_binary") load("//java:java_library.bzl", "java_library") load("//java:java_test.bzl", "java_test") -load("//java/common:java_info.bzl", "JavaInfo") load("//java/common:java_semantics.bzl", "semantics") load("//java/common/rules:java_helper.bzl", "helper") load("//test/java/testutil:helper.bzl", "always_passes") @@ -210,47 +209,10 @@ def _test_stamp_values_impl(env, targets): env.expect.that_target(targets.defaultstamp).attr("stamp", factory = subjects.int).equals(0) env.expect.that_target(targets.autostamp).attr("stamp", factory = subjects.int).equals(-1) -def _test_add_test_support_to_compile_time_deps_flag(name): - if not bazel_features.rules.analysis_tests_can_transition_on_experimental_incompatible_flags: - always_passes(name) - return - util.helper_target( - rule = java_test, - name = name + "/test", - srcs = [name + "/Test.java"], - ) - - analysis_test( - name = name, - targets = { - "add_support": name + "/test", - "no_add_support": name + "/test", - }, - attrs = { - "test_runner": attr.label(default = semantics.JAVA_TEST_RUNNER_LABEL), - "add_support": { - "@config_settings": { - "//command_line_option:experimental_add_test_support_to_compile_time_deps": True, - }, - }, - "no_add_support": { - "@config_settings": { - "//command_line_option:experimental_add_test_support_to_compile_time_deps": False, - }, - }, - }, - impl = _test_add_test_support_to_compile_time_deps_flag_impl, - ) - -def _test_add_test_support_to_compile_time_deps_flag_impl(env, targets): - compile_jars = env.ctx.attr.test_runner[JavaInfo].compile_jars - env.expect.that_target(targets.add_support).action_named("Javac").inputs().contains_at_least(compile_jars.to_list()) - env.expect.that_target(targets.no_add_support).action_named("Javac").inputs().contains_none_of(compile_jars.to_list()) - def _test_mac_requires_darwin_for_execution(name): util.helper_target( rule = native.platform, - name = name + "/darwin_x86_64", + name = name + "_darwin_x86_64", constraint_values = [ "@platforms//os:macos", "@platforms//cpu:x86_64", @@ -282,7 +244,7 @@ def _test_mac_requires_darwin_for_execution(name): name = name, target = name + "/test", config_settings = { - "//command_line_option:platforms": [Label(name + "/darwin_x86_64")], + "//command_line_option:platforms": [Label(name + "_darwin_x86_64")], "//command_line_option:extra_toolchains": toolchains, }, impl = _test_mac_requires_darwin_for_execution_impl, @@ -434,6 +396,72 @@ def _test_one_version_check_disabled_for_java_test_impl(env, targets): env.expect.that_collection(binary_action_mnemonics).contains("JavaOneVersion") env.expect.that_collection(test_action_mnemonics).not_contains("JavaOneVersion") +def _test_java_test_srcs_filetypes(name): + util.helper_target( + java_test, + name = name + "/valid", + srcs = [ + "a.java", + name + "/gmix", + name + "/gvalid", + ], + ) + util.helper_target( + java_test, + name = name + "/invalid", + srcs = [ + "a.foo", + name + "/ginvalid", + ], + ) + util.helper_target( + java_test, + name = name + "/mix", + srcs = [ + "a.foo", + "a.java", + ], + ) + util.helper_target( + native.genrule, + name = name + "/gvalid", + outs = [name + "/b.java"], + cmd = "", + ) + util.helper_target( + native.genrule, + name = name + "/ginvalid", + outs = [name + "/b.foo"], + cmd = "", + ) + util.helper_target( + native.genrule, + name = name + "/gmix", + outs = [name + "/c.java", name + "/c.foo"], + cmd = "", + ) + + analysis_test( + name = name, + impl = _test_java_test_srcs_filetypes_impl, + targets = { + "valid": name + "/valid", + "invalid": name + "/invalid", + "mix": name + "/mix", + }, + expect_failure = True, + ) + +def _test_java_test_srcs_filetypes_impl(env, targets): + env.expect.that_target(targets.valid).failures().contains_exactly([]) + env.expect.that_target(targets.invalid).failures().contains_at_least_predicates([ + matching.str_matches("'*/ginvalid' does not produce any java_test srcs files"), + matching.str_matches("source file '*:a.foo' is misplaced here"), + ]) + env.expect.that_target(targets.mix).failures().contains_at_least_predicates([ + matching.str_matches("'*:a.foo' does not produce any java_test srcs files"), + ]) + def java_test_tests(name): test_suite( name = name, @@ -443,10 +471,10 @@ def java_test_tests(name): _test_java_test_propagates_direct_native_libraries, _test_coverage_uses_coverage_runner_for_main, _test_stamp_values, - _test_add_test_support_to_compile_time_deps_flag, _test_mac_requires_darwin_for_execution, _test_java_test_sets_securiry_manager_property_jdk17, _test_one_version_check_java_test, _test_one_version_check_disabled_for_java_test, + _test_java_test_srcs_filetypes, ], ) diff --git a/test/java/testutil/artifact_closure.bzl b/test/java/testutil/artifact_closure.bzl index b7141f0f..48353582 100644 --- a/test/java/testutil/artifact_closure.bzl +++ b/test/java/testutil/artifact_closure.bzl @@ -4,8 +4,11 @@ load("@rules_testing//lib:truth.bzl", "subjects") # TODO: consider upstreaming this to @rules_testing -def _compute(target): - to_process = target[DefaultInfo].files.to_list() +def _compute(target, initial = None): + if not initial: + to_process = target[DefaultInfo].files.to_list() + else: + to_process = [initial] if _ArtifactActionMapInfo not in target: fail("Did you forget to add the aspect to analysis_test(extra_target_under_test_aspects = )?") map = target[_ArtifactActionMapInfo].map @@ -51,13 +54,19 @@ def _aspect_impl(target, ctx): _aspect = aspect(_aspect_impl, attr_aspects = ["*"]) -def _of_target(env, target, as_paths = True, extensions = None): +def _of_target( + env, + target, + initial = None, + as_paths = True, + extensions = None, + package_local_only = True): meta = env.expect.meta.derive(format_str_kwargs = { "name": target.label.name, "package": target.label.package, }) result = subjects.collection( - _compute(target), + _compute(target, initial = initial), meta = meta, container_name = "artifact clousre of {}".format(target.label), format = True, @@ -67,6 +76,11 @@ def _of_target(env, target, as_paths = True, extensions = None): filter = lambda f: f.extension in extensions, desc = "with extensions: {exts}".format(exts = extensions), ) + if package_local_only: + result = result.transform( + filter = lambda f: f.short_path.startswith(target.label.package), + desc = "in package: {package}".format(package = target.label.package), + ) if as_paths: result = result.transform( desc = "short_path", diff --git a/test/java/testutil/binary_executable_subject.bzl b/test/java/testutil/binary_executable_subject.bzl new file mode 100644 index 00000000..29df32d0 --- /dev/null +++ b/test/java/testutil/binary_executable_subject.bzl @@ -0,0 +1,67 @@ +"""Custom rules_testing subject for java_binary/java_test executable output""" + +load("@rules_cc//cc/common:cc_common.bzl", "cc_common") +load("@rules_testing//lib:truth.bzl", "subjects") +load("//java/common:java_semantics.bzl", "semantics") +load("//java/common/rules:java_helper.bzl", "helper") + +def _of_target(env, target): + executable = target[DefaultInfo].files_to_run.executable.short_path + action_subject = env.expect.that_target(target).action_generating(executable) + public = struct( + java_start_class = lambda: _java_start_class_subject(action_subject), + test_suite = lambda: _test_suite_subject(action_subject), + jvm_flags = lambda: _jvm_flags_subject(action_subject), + native_library_paths = lambda: _native_library_paths_subject(env, action_subject), + ) + return public + +def _java_start_class_subject(action): + if action.actual.substitutions: + return action.substitutions().get("%java_start_class%", factory = subjects.str) + else: + # Windows + return action.argv().transform( + filter = lambda e: e.startswith("java_start_class="), + map_each = lambda e: e.split("=", 1)[1], + desc = "java_start_class", + ).offset(0, factory = subjects.str) + +def _test_suite_subject(action): + return _jvm_flags_subject(action).transform( + filter = lambda e: e.startswith("-D" + semantics.TEST_SUITE_PROPERTY_NAME + "="), + map_each = lambda e: e.split("=", 1)[1], + desc = semantics.TEST_SUITE_PROPERTY_NAME, + ).offset(0, factory = subjects.str) + +def _jvm_flags_subject(action): + if action.actual.substitutions: + return action.substitutions().get("%jvm_flags%", factory = subjects.str).split(" ") + else: + # Windows + return action.argv().transform( + filter = lambda e: e.startswith("jvm_flags="), + map_each = lambda e: e.split("=", 1)[1], + desc = "jvm_flags", + ).offset(0, factory = subjects.str).split("\t") + +def _native_library_paths_subject(env, action): + separator = ";" if helper.is_target_platform_windows(env.ctx) else ":" + return _jvm_flags_subject(action).transform( + filter = lambda e: e.startswith("-Djava.library.path="), + map_each = lambda e: e.split("=", 1)[1], + desc = "native library paths", + ).offset( + 0, + factory = lambda actual, meta: subjects.str(actual, meta.derive( + format_str_kwargs = {"cpu": meta.ctx.attr._cc_toolchain[cc_common.CcToolchainInfo].cpu}, + )), + ).split(separator).transform( + map_each = lambda e: e.replace("_U", "_").replace("_S", "/").replace("_C", ":"), + desc = "pretty", + format = True, + ) + +expect_that_executable = struct( + of_target = _of_target, +) diff --git a/test/java/testutil/cc_info_subject.bzl b/test/java/testutil/cc_info_subject.bzl index b50ff2e6..3fd8f860 100644 --- a/test/java/testutil/cc_info_subject.bzl +++ b/test/java/testutil/cc_info_subject.bzl @@ -72,6 +72,7 @@ def _new_cc_info_libraries_to_link_subject(libraries_to_link, meta): ) public = struct( static_libraries = lambda: _new_library_to_link_static_libraries_subject(self.actual, self.meta), + dynamic_libraries = lambda: _new_library_to_link_dynamic_libraries_subject(self.actual, self.meta), singleton = lambda: _new_library_to_link_subject(_get_singleton(self.actual), self.meta.derive("[0]")), ) return public @@ -93,6 +94,12 @@ def _new_library_to_link_static_libraries_subject(libraries_to_link, meta): ) return public +def _new_library_to_link_dynamic_libraries_subject(libraries_to_link, meta): + return subjects.depset_file( + [testutil.cc_library_to_link_dynamic_library(lib) for lib in libraries_to_link], + meta = meta.derive("dynamic_library()"), + ) + def _get_singleton(seq): if len(seq) != 1: fail("expected singleton, got:", seq) diff --git a/test/java/testutil/java_info_subject.bzl b/test/java/testutil/java_info_subject.bzl index 9a0fb533..8df4f786 100644 --- a/test/java/testutil/java_info_subject.bzl +++ b/test/java/testutil/java_info_subject.bzl @@ -31,8 +31,9 @@ def _new_java_info_subject(java_info, meta): ) return public -def _java_info_subject_from_target(env, target): +def _java_info_subject_from_target(env, target, expr = None): return _new_java_info_subject(target[JavaInfo], meta = truth.expect(env).meta.derive( + expr = expr, format_str_kwargs = { "name": target.label.name, "package": target.label.package, diff --git a/test/java/testutil/javac_action_subject.bzl b/test/java/testutil/javac_action_subject.bzl index a887d689..41bf2e35 100644 --- a/test/java/testutil/javac_action_subject.bzl +++ b/test/java/testutil/javac_action_subject.bzl @@ -1,15 +1,19 @@ """Bespoke rules_testing subject for the Java compilation action""" -load("@rules_testing//lib:truth.bzl", "subjects", "truth") +load("@rules_testing//lib:truth.bzl", "subjects") load("@rules_testing//lib:util.bzl", "TestingAspectInfo") -def _new_javac_action_subject(env, target, output): - action_subject = env.expect.that_target(target).action_generating(output) +def _new_javac_action_subject(env, target, output = None, desc = ""): + target_subject = env.expect.that_target(target) + if output: + action_subject = target_subject.action_generating(output) + else: + action_subject = target_subject.action_named("Javac") self = struct( actual = action_subject.actual, parsed_flags = _parse_flags(action_subject.actual.argv), - meta = truth.expect(env).meta.derive( - "Javac", + meta = target_subject.meta.derive( + desc + ".Javac", format_str_kwargs = { "name": target.label.name, "package": target.label.package, @@ -19,12 +23,12 @@ def _new_javac_action_subject(env, target, output): ) public = struct( - direct_dependencies = lambda: _create_subject_for_flag("--direct_dependencies", self.parsed_flags, self.meta), + direct_dependencies = lambda: _create_subject_for_flag("--direct_dependencies", self.parsed_flags, self.meta, default = []), deps_artifacts = lambda: _create_subject_for_flag("--deps_artifacts", self.parsed_flags, self.meta), javacopts = lambda: _create_subject_for_flag("--javacopts", self.parsed_flags, self.meta), jar = lambda: _create_subject_for_flag("-jar", self.parsed_flags, self.meta), # An unset --strict_java_deps is equivalent to "OFF". - strict_java_deps = lambda: _create_subject_for_flag("--strict_java_deps", self.parsed_flags, self.meta, default = ["OFF"]), + strict_java_deps = lambda: _create_subject_for_flag("--strict_java_deps", self.parsed_flags, self.meta, default = ["OFF"]).offset(0, factory = subjects.str), sources = lambda: _create_subject_for_flag("--sources", self.parsed_flags, self.meta), resources = lambda: _create_subject_for_flag("--resources", self.parsed_flags, self.meta), classpath = lambda: _create_subject_for_flag("--classpath", self.parsed_flags, self.meta), @@ -40,6 +44,7 @@ def _new_javac_action_subject(env, target, output): argv = action_subject.argv, mnemonic = action_subject.mnemonic, native_header_output = lambda: _create_subject_for_flag("--native_header_output", self.parsed_flags, self.meta), + fix_deps_tool = lambda: _create_subject_for_flag("--experimental_fix_deps_tool", self.parsed_flags, self.meta).offset(0, factory = subjects.str), ) return public diff --git a/test/java/toolchains/java_toolchain_tests.bzl b/test/java/toolchains/java_toolchain_tests.bzl index 793de8ea..af4e69c3 100644 --- a/test/java/toolchains/java_toolchain_tests.bzl +++ b/test/java/toolchains/java_toolchain_tests.bzl @@ -111,8 +111,6 @@ def _test_singlejar_get_command_line(name): config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], }, - # This crashes in earlier Bazel versions where native rules handled deploy jars differently. - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_singlejar_get_command_line_impl(env, target): @@ -296,7 +294,7 @@ def _test_no_header_compiler_header_compilation_disabled_analyzes_successfully(n analysis_test( name = name, - impl = _test_no_header_compiler_header_compilation_disabled_analyzes_successfully_impl, + impl = lambda unused_env, unused_target: None, # Implicitly succeeds. target = name + "/a", config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], @@ -304,12 +302,6 @@ def _test_no_header_compiler_header_compilation_disabled_analyzes_successfully(n }, ) -def _test_no_header_compiler_header_compilation_disabled_analyzes_successfully_impl( - env, # @unused - target): # @unused - # Implicitly succeeds. - pass - def _test_header_compiler_builtin_processors(name): util.helper_target( mock_java_toolchain, @@ -703,7 +695,6 @@ def _test_default_javac_opts_depset(name): name = name, impl = _test_default_javac_opts_depset_impl, target = name + "/alias", - attr_values = {"tags": ["min_bazel_8"]}, config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], }, @@ -733,7 +724,6 @@ def _test_default_javac_opts(name): config_settings = { "//command_line_option:extra_toolchains": [Label(name + "/toolchain")], }, - attr_values = {"tags": ["min_bazel_8"]}, ) def _test_default_javac_opts_impl(env, target): diff --git a/test/repo/MODULE.bazel b/test/repo/MODULE.bazel index 5f300800..5fdac278 100644 --- a/test/repo/MODULE.bazel +++ b/test/repo/MODULE.bazel @@ -54,15 +54,15 @@ custom_jdk = use_extension("@rules_java//java:extensions.bzl", "java_repository" custom_jdk.remote( name = "my_funky_jdk", prefix = "funky", - strip_prefix = "zulu24.32.13-ca-jdk24.0.2-linux_x64", + strip_prefix = "zulu25.36.205-ca-jdk25.0.4.1-linux_x64", target_compatible_with = [ "@platforms//os:linux", "@platforms//cpu:x86_64", ], urls = [ - "https://cdn.azul.com/zulu/bin/zulu24.32.13-ca-jdk24.0.2-linux_x64.tar.gz", + "https://cdn.azul.com/zulu/bin/zulu25.36.205-ca-jdk25.0.4.1-linux_x64.tar.gz", ], - version = "24", + version = "25", ) use_repo(custom_jdk, "my_funky_jdk", "my_funky_jdk_toolchain_config_repo") diff --git a/test/repo/WORKSPACE b/test/repo/WORKSPACE index 32cadb59..a100961e 100644 --- a/test/repo/WORKSPACE +++ b/test/repo/WORKSPACE @@ -60,15 +60,15 @@ load("@rules_java//toolchains:remote_java_repository.bzl", "remote_java_reposito remote_java_repository( name = "my_funky_jdk", prefix = "funky", - strip_prefix = "zulu24.32.13-ca-jdk24.0.2-linux_x64", + strip_prefix = "zulu25.36.205-ca-jdk25.0.4.1-linux_x64", target_compatible_with = [ "@platforms//os:linux", "@platforms//cpu:x86_64", ], urls = [ - "https://cdn.azul.com/zulu/bin/zulu24.32.13-ca-jdk24.0.2-linux_x64.tar.gz", + "https://cdn.azul.com/zulu/bin/zulu25.36.205-ca-jdk25.0.4.1-linux_x64.tar.gz", ], - version = "24", + version = "25", ) register_toolchains("@my_funky_jdk_toolchain_config_repo//:all") diff --git a/test/testdata/BUILD b/test/testdata/BUILD new file mode 100644 index 00000000..2de4a356 --- /dev/null +++ b/test/testdata/BUILD @@ -0,0 +1,21 @@ +load("@rules_testing//lib:util.bzl", "util") +load("//java:java_binary.bzl", "java_binary") +load("//java:java_library.bzl", "java_library") + +package(default_applicable_licenses = ["@rules_java//:license"]) + +# Make a sample jar for the http_jar test. +java_library( + name = "my_jar", + srcs = ["MyLib.java"], +) + +# Used by //test/java/common/rules/java_binary_tests.bzl%_test_java_binary_java_package +util.helper_target( + java_binary, + name = "non_java", + srcs = ["Foo.java"], + visibility = [ + "//test/java/common/rules:__pkg__", + ], +) diff --git a/test/testdata/BUILD.bazel b/test/testdata/BUILD.bazel deleted file mode 100644 index 7a0c7589..00000000 --- a/test/testdata/BUILD.bazel +++ /dev/null @@ -1,9 +0,0 @@ -load("//java:java_library.bzl", "java_library") - -package(default_applicable_licenses = ["@rules_java//:license"]) - -# Make a sample jar for the http_jar test. -java_library( - name = "my_jar", - srcs = ["MyLib.java"], -) diff --git a/toolchains/BUILD b/toolchains/BUILD index 30b78e59..e6056073 100644 --- a/toolchains/BUILD +++ b/toolchains/BUILD @@ -129,6 +129,19 @@ java_runtime_files( srcs = ["include/openbsd/jni_md.h"], ) +java_runtime_files( + name = "jni_md_header-netbsd", + srcs = ["include/netbsd/jni_md.h"], +) + +# Defined here rather than taken from @bazel_tools//src/conditions so that it +# resolves with every Bazel version: @platforms//os:netbsd has been in the +# platforms module since 0.0.11. +config_setting( + name = "netbsd", + constraint_values = ["@platforms//os:netbsd"], +) + # The Java native interface. Depend on this package if you #include . # # See test_jni in third_party/bazel/src/test/shell/bazel/bazel_java_test.sh for @@ -140,6 +153,7 @@ cc_library( "@bazel_tools//src/conditions:freebsd": [":jni_md_header-freebsd"], "@bazel_tools//src/conditions:linux": [":jni_md_header-linux"], "@bazel_tools//src/conditions:openbsd": [":jni_md_header-openbsd"], + ":netbsd": [":jni_md_header-netbsd"], "@bazel_tools//src/conditions:windows": [":jni_md_header-windows"], "//conditions:default": [], }), @@ -148,6 +162,7 @@ cc_library( "@bazel_tools//src/conditions:freebsd": ["include/freebsd"], "@bazel_tools//src/conditions:linux": ["include/linux"], "@bazel_tools//src/conditions:openbsd": ["include/openbsd"], + ":netbsd": ["include/netbsd"], "@bazel_tools//src/conditions:windows": ["include/win32"], "//conditions:default": [], }), @@ -171,10 +186,6 @@ cc_library( actual = "@remote_java_tools_%s//:prebuilt_one_version" % OS, visibility = ["//visibility:private"], ), - alias( - name = "turbine_direct_graal_%s" % OS, - actual = "@remote_java_tools_%s//:turbine_direct_graal" % OS, - ), ) for OS in [ "linux", @@ -185,6 +196,19 @@ cc_library( ] ] +[ + alias( + name = "turbine_direct_graal_%s" % OS, + actual = "@remote_java_tools_%s//:turbine_direct_graal" % OS, + ) + for OS in [ + "linux", + "linux_aarch64", + "darwin_arm64", + "windows", + ] +] + alias( name = "ijar", actual = ":ijar_prebuilt_binary_or_cc_binary", @@ -278,7 +302,6 @@ alias( name = "turbine_direct_graal_or_java", actual = select({ "@bazel_tools//src/conditions:darwin_arm64": ":turbine_direct_graal_darwin_arm64", - "@bazel_tools//src/conditions:darwin_x86_64": ":turbine_direct_graal_darwin_x86_64", "@bazel_tools//src/conditions:linux_x86_64": ":turbine_direct_graal_linux", "@bazel_tools//src/conditions:linux_aarch64": ":turbine_direct_graal_linux_aarch64", "@bazel_tools//src/conditions:windows": ":turbine_direct_graal_windows", @@ -290,11 +313,11 @@ alias( name = "turbine_direct_graal", actual = select({ "@bazel_tools//src/conditions:darwin_arm64": ":turbine_direct_graal_darwin_arm64", - "@bazel_tools//src/conditions:darwin_x86_64": ":turbine_direct_graal_darwin_x86_64", "@bazel_tools//src/conditions:linux_x86_64": ":turbine_direct_graal_linux", "@bazel_tools//src/conditions:linux_aarch64": ":turbine_direct_graal_linux_aarch64", "@bazel_tools//src/conditions:windows": ":turbine_direct_graal_windows", }), + tags = ["manual"], # So we can build //... on CI platforms that don't match ) string_setting( @@ -366,7 +389,7 @@ RELEASES = (8, 9, 10, 11, 17, 21, 25) [ default_java_toolchain( name = ("toolchain_java%d" if release <= 11 else "toolchain_jdk_%d") % release, - configuration = DEFAULT_TOOLCHAIN_CONFIGURATION | {"java_runtime": ":remotejdk_25"}, + configuration = DEFAULT_TOOLCHAIN_CONFIGURATION, source_version = "%s" % release, target_version = "%s" % release, ) diff --git a/toolchains/default_java_toolchain.bzl b/toolchains/default_java_toolchain.bzl index f4f83f66..f131a620 100644 --- a/toolchains/default_java_toolchain.bzl +++ b/toolchains/default_java_toolchain.bzl @@ -76,6 +76,7 @@ _DEFAULT_JAVA_LANGUAGE_VERSION = "11" # Default java_toolchain parameters _BASE_TOOLCHAIN_CONFIGURATION = dict( + deps_checker = Label("@remote_java_tools//:ImportDepsChecker"), forcibly_disable_header_compilation = False, genclass = Label("@remote_java_tools//:GenClass"), header_compiler = Label("@remote_java_tools//:TurbineDirect"), @@ -99,9 +100,7 @@ _BASE_TOOLCHAIN_CONFIGURATION = dict( reduced_classpath_incompatible_processors = [ "dagger.hilt.processor.internal.root.RootProcessor", # see b/21307381 ], - # TODO: Update to JDK 25 after some time has passed - it no longer supports - # targeting JDK 7. - java_runtime = Label("//toolchains:remotejdk_21"), + java_runtime = Label("//toolchains:remotejdk_25"), oneversion = Label("//toolchains:one_version"), ) diff --git a/toolchains/local_java_repository.bzl b/toolchains/local_java_repository.bzl index 769c2d19..88115bb7 100644 --- a/toolchains/local_java_repository.bzl +++ b/toolchains/local_java_repository.bzl @@ -176,6 +176,10 @@ def _local_java_repository_impl(repository_ctx): repository_ctx: repository context """ + repository_metadata = None + if hasattr(repository_ctx, "repo_metadata"): + repository_metadata = repository_ctx.repo_metadata(reproducible = True) + java_home = _determine_java_home(repository_ctx) local_java_runtime_name = repository_ctx.attr.runtime_name @@ -198,7 +202,7 @@ def _local_java_repository_impl(repository_ctx): "either correct your JAVA_HOME, PATH or specify Java from " + "remote repository (e.g. --java_runtime_version=remotejdk_11)", ) - return + return repository_metadata # Detect version version = repository_ctx.attr.version if repository_ctx.attr.version != "" else _detect_java_version(repository_ctx, java_bin) @@ -211,7 +215,7 @@ def _local_java_repository_impl(repository_ctx): message = "Cannot detect Java version of {java_binary} in {java_home}; " + "make sure it points to a valid Java executable", ) - return + return repository_metadata # Prepare BUILD file using "local_java_runtime" macro if repository_ctx.attr.build_file_content and repository_ctx.attr.build_file: @@ -247,6 +251,8 @@ local_java_runtime( for file in repository_ctx.path(java_home).readdir(): repository_ctx.symlink(file, file.basename) + return repository_metadata + # Build file template, when JDK could not be detected _AUTO_CONFIG_ERROR_BUILD_TPL = '''load("@rules_java//toolchains:fail_rule.bzl", "fail_rule") fail_rule( diff --git a/toolchains/remote_java_repository.bzl b/toolchains/remote_java_repository.bzl index 65bbe482..500beb7b 100644 --- a/toolchains/remote_java_repository.bzl +++ b/toolchains/remote_java_repository.bzl @@ -23,6 +23,9 @@ load("//toolchains:jdk_build_file.bzl", "JDK_BUILD_TEMPLATE") def _toolchain_config_impl(ctx): ctx.file("WORKSPACE", "workspace(name = \"{name}\")\n".format(name = ctx.name)) ctx.file("BUILD.bazel", ctx.attr.build_file) + if hasattr(ctx, "repo_metadata"): + return ctx.repo_metadata(reproducible = True) + return None _toolchain_config = repository_rule( local = True,