Skip to content

Commit

Permalink
fix(java_extractor): properly filter/normalize Bazel javacopts (#4977)
Browse files Browse the repository at this point in the history
  • Loading branch information
schroederc committed Jun 23, 2021
1 parent 0291fce commit 59a94bf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 6 additions & 0 deletions external.bzl
Expand Up @@ -307,6 +307,12 @@ def _java_dependencies():
commit = "ca8ad22bc1479b5675118308f88ef3fff7d26c1f",
remote = "https://github.com/google/flogger",
)
maybe(
git_repository,
name = "io_bazel",
commit = "20c4596365d6e198ce9e4559a372190ceedff3f5",
remote = "https://github.com/bazelbuild/bazel",
)
maven_install(
name = "maven",
artifacts = [
Expand Down
Expand Up @@ -19,6 +19,7 @@ java_binary(
"//third_party/guava",
"@com_google_protobuf//:protobuf_java",
"@com_google_protobuf//:protobuf_java_util",
"@io_bazel//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:javac_options",
],
)

Expand Down
Expand Up @@ -24,6 +24,7 @@
import com.google.common.flogger.FluentLogger;
import com.google.common.io.ByteSource;
import com.google.common.io.MoreFiles;
import com.google.devtools.build.buildjar.javac.JavacOptions;
import com.google.devtools.build.lib.actions.extra.ExtraActionInfo;
import com.google.devtools.build.lib.actions.extra.ExtraActionsBase;
import com.google.devtools.build.lib.actions.extra.JavaCompileInfo;
Expand Down Expand Up @@ -105,15 +106,11 @@ public static void main(String[] args) throws IOException, ExtractionException {
}

List<String> javacOpts =
jInfo.getJavacOptList().stream()
.filter(
// Filter out Bazel-specific flags. Bazel adds its own flags (such as error-prone
// flags) to the javac_opt list that cannot be handled by the standard javac
// compiler, or in turn, by this extractor.
opt ->
!(opt.startsWith("-Werror:")
|| opt.startsWith("-extra_checks")
|| opt.startsWith("-Xep")))
JavacOptions.removeBazelSpecificFlags(
JavacOptions.normalizeOptionsWithNormalizers(
jInfo.getJavacOptList(), new JavacOptions.ReleaseOptionNormalizer()))
.stream()
.filter(opt -> !opt.startsWith("-extra_checks"))
.collect(toCollection(ArrayList::new));

// Set up a fresh output directory
Expand Down

0 comments on commit 59a94bf

Please sign in to comment.