Skip to content

Fix Unicode matching for regex options #26100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ build:windows --per_file_copt=external/.*@/w
build:windows --host_per_file_copt=external/.*@/w

# Enable Java 21 language features
build --java_runtime_version=21
build --java_language_version=21
build --tool_java_language_version=21
build --tool_java_runtime_version=21
common --java_runtime_version=21
common --java_language_version=21
common --tool_java_language_version=21
common --tool_java_runtime_version=21
# Ensure that Java language level and bootclasspath version are the same.
# This avoids accidental usage of more recent Java APIs.
common --@rules_java//toolchains:incompatible_language_version_bootclasspath

# User-specific .bazelrc
try-import %workspace%/user.bazelrc
Expand Down
7 changes: 6 additions & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ DIST_ARCHIVE_REPOS = [get_canonical_repo_name(repo) for repo in [
"rules_proto",
"rules_python",
"rules_shell",
"with_cfg.bzl",
"zlib",
"zstd-jni",
]] + [(get_canonical_repo_name("com_github_grpc_grpc") + "+grpc_repo_deps_ext+" + suffix) for suffix in [
Expand Down
54 changes: 25 additions & 29 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_java//java:java_binary.bzl", "java_binary")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load("//src:build_defs.bzl", "transition_java_language_8_archive")
load("//src:release_archive.bzl", "release_archive")
load("//src:release_archive.bzl", "minimum_java_compilation_runtime_filegroup", "minimum_java_runtime_filegroup", "release_archive")
load(":embedded_tools.bzl", "srcsfile")
load(":rule_size_test.bzl", "rule_size_test")

Expand Down Expand Up @@ -512,19 +511,33 @@ genrule(
)

# Following targets build java_tools.zip - platform independent part of java_tools
JAVA_TOOLS_DEPLOY_JARS = [
"//src/java_tools/buildjar:JavaBuilder_deploy.jar",
"//src/java_tools/buildjar:VanillaJavaBuilder_deploy.jar",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass:GenClass_deploy.jar",
"//src/java_tools/buildjar/java/com/google/devtools/build/java/turbine:turbine_direct_binary_deploy.jar",
"//src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps:ImportDepsChecker_deploy.jar",
"//src/java_tools/junitrunner/java/com/google/testing/coverage:JacocoCoverage_jarjar_deploy.jar",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner:Runner_deploy.jar",
]
minimum_java_runtime_filegroup(
name = "minimum_java_runtime_tools",
srcs = [
"//src/java_tools/junitrunner/java/com/google/testing/coverage:JacocoCoverage_jarjar_deploy.jar",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner:Runner_deploy.jar",
],
visibility = ["//visibility:private"],
)

minimum_java_compilation_runtime_filegroup(
name = "minimum_java_compilation_runtime_tools",
srcs = [
"//src/java_tools/buildjar:JavaBuilder_deploy.jar",
"//src/java_tools/buildjar:VanillaJavaBuilder_deploy.jar",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass:GenClass_deploy.jar",
"//src/java_tools/buildjar/java/com/google/devtools/build/java/turbine:turbine_direct_binary_deploy.jar",
"//src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps:ImportDepsChecker_deploy.jar",
],
visibility = ["//visibility:private"],
)

release_archive(
name = "jars_java_tools_zip",
srcs = JAVA_TOOLS_DEPLOY_JARS,
srcs = [
":minimum_java_compilation_runtime_tools",
":minimum_java_runtime_tools",
],
package_dir = "java_tools",
visibility = ["//visibility:private"],
)
Expand All @@ -545,12 +558,6 @@ release_archive(
],
)

transition_java_language_8_archive(
name = "java_tools_java8.zip",
archive_zip = ":java_tools.zip",
visibility = ["//src/test/shell/bazel:__pkg__"],
)

release_archive(
name = "turbine_direct_graal_zip",
srcs = ["//src/java_tools/buildjar/java/com/google/devtools/build/java/turbine:turbine_direct_graal"],
Expand All @@ -573,12 +580,6 @@ release_archive(
],
)

transition_java_language_8_archive(
name = "java_tools_prebuilt_java8.zip",
archive_zip = ":java_tools_prebuilt.zip",
visibility = ["//src/test/shell/bazel:__pkg__"],
)

# Following targets used by the java_tools_binaries Buildkite pipeline to upload
# the java_tools_*.zip to either tmp/sources or tmp/build directories in GCS.
sh_binary(
Expand Down Expand Up @@ -664,11 +665,6 @@ filegroup(
],
)

bzl_library(
name = "build_defs_bzl",
srcs = ["build_defs.bzl"],
)

java_binary(
name = "CheckSunJnuEncoding",
srcs = ["CheckSunJnuEncoding.java"],
Expand Down
58 changes: 0 additions & 58 deletions src/build_defs.bzl

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ private static void setLocations(JavacFileManager fileManager, BlazeJavacArgumen
try {
fileManager.setLocationFromPaths(StandardLocation.CLASS_PATH, arguments.classPath());
// modular dependencies must be on the module path, not the classpath
fileManager.setLocationFromPaths(
StandardLocation.locationFor("MODULE_PATH"), arguments.classPath());
fileManager.setLocationFromPaths(StandardLocation.MODULE_PATH, arguments.classPath());

fileManager.setLocationFromPaths(
StandardLocation.CLASS_OUTPUT, ImmutableList.of(arguments.classOutput()));
Expand Down Expand Up @@ -326,7 +325,7 @@ private static void setLocations(JavacFileManager fileManager, BlazeJavacArgumen
Path system = arguments.system();
if (system != null) {
fileManager.setLocationFromPaths(
StandardLocation.locationFor("SYSTEM_MODULES"), ImmutableList.of(system));
StandardLocation.SYSTEM_MODULES, ImmutableList.of(system));
}
// The bootclasspath may legitimately be empty if --release is being used.
Collection<Path> bootClassPath = arguments.bootClassPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@

package com.google.testing.junit.runner.internal;

import static java.util.Arrays.stream;
import static java.util.stream.Collectors.toList;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -28,40 +26,41 @@
*/
public class SystemExitDetectingShutdownHook {
public static Thread newShutdownHook(PrintStream testRunnerOut) {
Runnable hook = () -> {
boolean foundRuntimeExit = false;
for (StackTraceElement[] stack : Thread.getAllStackTraces().values()) {
@SuppressWarnings("JdkCollectors") // can't use ImmutableList here
List<String> framesStartingWithRuntimeExit =
stream(stack)
.dropWhile(
frame ->
!frame.getClassName().equals("java.lang.Runtime")
|| !frame.getMethodName().equals("exit"))
.map(SystemExitDetectingShutdownHook::frameString)
.collect(toList());
if (!framesStartingWithRuntimeExit.isEmpty()) {
foundRuntimeExit = true;
testRunnerOut.println("\nSystem.exit or Runtime.exit was called!");
testRunnerOut.println(String.join("\n", framesStartingWithRuntimeExit));
}
}
if (foundRuntimeExit) {
// We must call halt rather than exit, because exit would lead to a deadlock. We use a
// hopefully unique exit code to make it easier to identify this case.
Runtime.getRuntime().halt(121);
}
};
Runnable hook =
() -> {
boolean foundRuntimeExit = false;
for (StackTraceElement[] stack : Thread.getAllStackTraces().values()) {
List<String> framesStartingWithRuntimeExit = new ArrayList<>();
boolean foundRuntimeExitInThisThread = false;
for (StackTraceElement frame : stack) {
if (!foundRuntimeExitInThisThread
&& frame.getClassName().equals("java.lang.Runtime")
&& frame.getMethodName().equals("exit")) {
foundRuntimeExitInThisThread = true;
}
if (foundRuntimeExitInThisThread) {
framesStartingWithRuntimeExit.add(frameString(frame));
}
}
if (foundRuntimeExitInThisThread) {
foundRuntimeExit = true;
testRunnerOut.println("\nSystem.exit or Runtime.exit was called!");
testRunnerOut.println(String.join("\n", framesStartingWithRuntimeExit));
}
}
if (foundRuntimeExit) {
// We must call halt rather than exit, because exit would lead to a deadlock. We use a
// hopefully unique exit code to make it easier to identify this case.
Runtime.getRuntime().halt(121);
}
};
return new Thread(hook, "SystemExitDetectingShutdownHook");
}

private static String frameString(StackTraceElement frame) {
return String.format(
" at %s.%s(%s:%d)",
frame.getClassName(),
frame.getMethodName(),
frame.getFileName(),
frame.getLineNumber());
frame.getClassName(), frame.getMethodName(), frame.getFileName(), frame.getLineNumber());
}

private SystemExitDetectingShutdownHook() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ java_library(
name = "execution_info_modifier",
srcs = ["ExecutionInfoModifier.java"],
deps = [
"//src/main/java/com/google/devtools/build/lib/util:string_encoding",
"//src/main/java/com/google/devtools/common/options",
"//third_party:auto_value",
"//third_party:guava",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.google.devtools.build.lib.analysis.config;

import static com.google.devtools.build.lib.util.StringEncoding.internalToUnicode;

import com.google.auto.value.AutoValue;
import com.google.auto.value.extension.memoized.Memoized;
import com.google.common.base.Splitter;
Expand Down Expand Up @@ -102,7 +104,8 @@ private static ExecutionInfoModifier create(String input, ImmutableList<Expressi
* Determines whether the given {@code mnemonic} (e.g. "CppCompile") matches any of the patterns.
*/
boolean matches(String mnemonic) {
return expressions().stream().anyMatch(expr -> expr.pattern().matcher(mnemonic).matches());
return expressions().stream()
.anyMatch(expr -> expr.pattern().matcher(internalToUnicode(mnemonic)).matches());
}

/** Checks whether the {@code executionInfoList} matches the {@code mnemonic}. */
Expand Down Expand Up @@ -139,7 +142,7 @@ public static void apply(
/** Modifies the given map of {@code executionInfo} to add or remove the keys for this option. */
void apply(String mnemonic, Map<String, String> executionInfo) {
for (Expression expr : expressions()) {
if (expr.pattern().matcher(mnemonic).matches()) {
if (expr.pattern().matcher(internalToUnicode(mnemonic)).matches()) {
if (expr.remove()) {
executionInfo.remove(expr.key());
} else {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/events/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ java_library(
name = "events",
srcs = glob(["*.java"]),
deps = [
"//src/main/java/com/google/devtools/build/lib/util:string_encoding",
"//src/main/java/com/google/devtools/build/lib/util/io:out-err",
"//src/main/java/net/starlark/java/eval",
"//src/main/java/net/starlark/java/syntax",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,19 @@

package com.google.devtools.build.lib.events;

import com.google.devtools.build.lib.util.StringEncoding;
import java.util.regex.Pattern;

/**
* An output filter for warnings.
*/
/** An output filter for warnings. */
public interface OutputFilter {

/** An output filter that matches everything. */
public static final OutputFilter OUTPUT_EVERYTHING = new OutputFilter() {
@Override
public boolean showOutput(String tag) {
return true;
}
};
OutputFilter OUTPUT_EVERYTHING = tag -> true;

/** An output filter that matches nothing. */
public static final OutputFilter OUTPUT_NOTHING = new OutputFilter() {
@Override
public boolean showOutput(String tag) {
return false;
}
};
OutputFilter OUTPUT_NOTHING = tag -> false;

/**
* Returns true iff the given tag matches the output filter.
*/
/** Returns true iff the given tag matches the output filter. */
boolean showOutput(String tag);

/** An output filter using regular expression matching. */
Expand All @@ -62,7 +49,7 @@ private RegexOutputFilter(Pattern pattern) {

@Override
public boolean showOutput(String tag) {
return pattern.matcher(tag).find();
return pattern.matcher(StringEncoding.internalToUnicode(tag)).find();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/shell",
"//src/main/java/com/google/devtools/build/lib/util",
"//src/main/java/com/google/devtools/build/lib/util:os",
"//src/main/java/com/google/devtools/build/lib/util:string_encoding",
"//src/main/java/com/google/devtools/build/lib/util/io",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/protobuf:failure_details_java_proto",
Expand Down
Loading