Skip to content

Commit

Permalink
use the one_version_allowlist_for_tests instead of the `one_version…
Browse files Browse the repository at this point in the history
…_allowlist` for test targets

PiperOrigin-RevId: 555263433
Change-Id: I67322f53da7c6bc71df3c82036d0c38ff8857fac
  • Loading branch information
Googler authored and copybara-github committed Aug 9, 2023
1 parent c279c7b commit 37268de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ public Artifact build(RuleContext ruleContext) throws InterruptedException {
Preconditions.checkNotNull(jarsToCheck);

FilesToRunProvider oneVersionTool = javaToolchain.getOneVersionBinary();
Artifact oneVersionAllowlist = javaToolchain.getOneVersionAllowlist();
Artifact oneVersionAllowlist;
if (ruleContext.isTestTarget()) {
oneVersionAllowlist = javaToolchain.oneVersionAllowlistForTests();
} else {
oneVersionAllowlist = javaToolchain.getOneVersionAllowlist();
}
if (oneVersionTool == null || oneVersionAllowlist == null) {
return null;
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/starlark/builtins_bzl/common/java/java_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def basic_java_binary(
transitive = [output_groups["_source_jars"]],
)

one_version_output = _create_one_version_check(ctx, java_attrs.runtime_classpath) if (
one_version_output = _create_one_version_check(ctx, java_attrs.runtime_classpath, is_test_rule_class) if (
ctx.fragments.java.one_version_enforcement_on_java_tests or not is_test_rule_class
) else None
validation_outputs = [one_version_output] if one_version_output else []
Expand Down Expand Up @@ -383,12 +383,18 @@ def _create_shared_archive(ctx, java_attrs):
)
return jsa

def _create_one_version_check(ctx, inputs):
def _create_one_version_check(ctx, inputs, is_test_rule_class):
one_version_level = ctx.fragments.java.one_version_enforcement_level
if one_version_level == "OFF":
return None
tool = helper.check_and_get_one_version_attribute(ctx, "one_version_tool")
allowlist = helper.check_and_get_one_version_attribute(ctx, "one_version_allowlist")

if is_test_rule_class:
toolchain = semantics.find_java_toolchain(ctx)
allowlist = toolchain.one_version_allowlist_for_tests()
else:
allowlist = helper.check_and_get_one_version_attribute(ctx, "one_version_allowlist")

if not tool or not allowlist: # On Mac oneversion tool is not available
return None

Expand Down

0 comments on commit 37268de

Please sign in to comment.