-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. As suggested in #6354 (comment), add a JDK version attribute to the java_runtime rule. This will allow changing behavior based on the Java runtime's version. 2. As an application of the above, pass -Djava.security.manager=allow to Java tests on JDK 17+. This makes the Bazel Java test runner to work on JDK 19. Fixes #14502. 3. To make the above generally useful, the remote_java_repository and local_java_repository must set the new version attribute in the java_runtime rules that they create. This means the old static jdk.BUILD file no longer suffices. Move the contents of jdk.BUILD into a Starlark file, so the version can be interpolated in by JDK repository rules and macros. (This isn't the nicest, but local_java_repository is not a repository rule, so the template cannot be in a non-Starlark file.) Closes #17775. PiperOrigin-RevId: 518860040 Change-Id: I8223b6407dd09528a4e5a6bf12354e5fc68278c6 (cherry picked from commit 7556e11)
- Loading branch information
Showing
17 changed files
with
159 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/test/java/com/google/devtools/build/lib/bazel/rules/java/JavaConfiguredTargetsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2022 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.bazel.rules.java; | ||
|
||
import static com.google.common.collect.ImmutableList.toImmutableList; | ||
import static com.google.common.collect.MoreCollectors.onlyElement; | ||
import static com.google.common.truth.Truth.assertThat; | ||
import static com.google.devtools.build.lib.testutil.TestConstants.TOOLS_REPOSITORY; | ||
|
||
import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction; | ||
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; | ||
import com.google.devtools.build.lib.util.OS; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
/** Tests of bazel java rules. */ | ||
@RunWith(JUnit4.class) | ||
public final class JavaConfiguredTargetsTest extends BuildViewTestCase { | ||
|
||
@Test | ||
public void javaTestSetsSecurityManagerPropertyOnVersion17() throws Exception { | ||
scratch.file( | ||
"a/BUILD", | ||
"java_runtime(", | ||
" name = 'jvm',", | ||
" java = 'java_home/bin/java',", | ||
" version = 17,", | ||
")", | ||
"toolchain(", | ||
" name = 'java_runtime_toolchain',", | ||
" toolchain = ':jvm',", | ||
" toolchain_type = '" + TOOLS_REPOSITORY + "//tools/jdk:runtime_toolchain_type',", | ||
")", | ||
"java_test(", | ||
" name = 'test',", | ||
" srcs = ['FooTest.java'],", | ||
" test_class = 'FooTest',", | ||
")"); | ||
useConfiguration("--extra_toolchains=//a:java_runtime_toolchain"); | ||
var ct = getConfiguredTarget("//a:test"); | ||
var executable = getExecutable(ct); | ||
if (OS.getCurrent() == OS.WINDOWS) { | ||
var jvmFlags = | ||
getGeneratingSpawnActionArgs(executable).stream() | ||
.filter(a -> a.startsWith("jvm_flags=")) | ||
.flatMap(a -> Arrays.stream(a.substring("jvm_flags=".length()).split("\t"))) | ||
.collect(toImmutableList()); | ||
assertThat(jvmFlags).contains("-Djava.security.manager=allow"); | ||
} else { | ||
var jvmFlags = | ||
((TemplateExpansionAction) getGeneratingAction(executable)) | ||
.getSubstitutions().stream() | ||
.filter(s -> Objects.equals(s.getKey(), "%jvm_flags%")) | ||
.collect(onlyElement()) | ||
.getValue(); | ||
assertThat(jvmFlags).contains("-Djava.security.manager=allow"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,7 +210,6 @@ alias( | |
|
||
exports_files([ | ||
"BUILD.java_tools", | ||
"jdk.BUILD", | ||
]) | ||
|
||
alias( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters