Skip to content

Commit

Permalink
Changes to Bazel's java_tools to enable Error Prone auto-patching
Browse files Browse the repository at this point in the history
Summary:
This diff contains the changes in bazelbuild#21640, ported to the uber/java/7.0.2.001 branch.  We also commit a modified version of the Error Prone check_api jar.  The modifications in that jar are those changes in google/error-prone#4318 applied to Error Prone 2.22.0 (the version used in our branch).  Probably, rather than committing the modified jar, we could upload the modified jar to artifactory and change the version we depend on here.

I have tested that these changes work locally on a devpod.  `IN_PLACE` patching will most likely not work under stronger sandboxes, as it relies on modifying the source files in the sandbox (which, by default on a devpod, are just symlinks to the original source files).

Also, there seem to be some weird interactions with the Bazel cache, such that when I tried to run the same autopatch twice (after undoing the initial changes), I had to blow away my local `~/.bazelcache` directory to make it work.

Test Plan:
Tested locally by copying over the built java_tools jars and running:

```
EP_PATCH_CHECK=MissingOverride EP_PATCH_CHECK_PATH_ONLY=a/b/c tools/bazel build //a/b/c:src
```

It would be good to write an integration test for this at some point, since it hasn't been upstreamed.

Reviewers: cjk

Subscribers: ravirajj, ravi

Revert Plan: n/a

JIRA Issues: JAVADEVX-8326

Differential Revision: https://code.uberinternal.com/D13309409

Update Error Prone jar in Bazel java_tools with further fix

Summary: Jar now includes the fix in https://code.uberinternal.com/D13331711?vs=37208341&id=37966971

JIRA Issues: JAVADEVX-8326

Differential Revision: https://code.uberinternal.com/D13628673
  • Loading branch information
msridh2 authored and raviagarwal7 committed Aug 20, 2024
1 parent 42a40ae commit 52eb0e6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ java_library(
name = "errorprone",
srcs = glob(["errorprone/*.java"]),
javacopts = [
"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
import com.google.errorprone.ErrorProneOptions;
import com.google.errorprone.ErrorProneTimings;
import com.google.errorprone.InvalidCommandLineOptionException;
import com.google.errorprone.RefactoringCollection;
import com.google.errorprone.scanner.BuiltInCheckerSuppliers;
import com.google.errorprone.scanner.ScannerSupplier;
import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskEvent.Kind;
import com.sun.tools.javac.api.MultiTaskListener;
import com.sun.tools.javac.code.DeferredCompletionFailureHandler;
import com.sun.tools.javac.comp.AttrContext;
import com.sun.tools.javac.comp.Env;
Expand Down Expand Up @@ -106,8 +108,14 @@ public void init(
if (epOptions == null) {
epOptions = ErrorProneOptions.empty();
}
RefactoringCollection[] refactoringCollection = {null};
errorProneAnalyzer =
ErrorProneAnalyzer.createByScanningForPlugins(scannerSupplier, epOptions, context);
ErrorProneAnalyzer.createAnalyzer(scannerSupplier, epOptions, context, refactoringCollection);
if (refactoringCollection[0] != null) {
ErrorProneAnalyzer.RefactoringTask refactoringTask =
new ErrorProneAnalyzer.RefactoringTask(context, refactoringCollection[0]);
MultiTaskListener.instance(context).add(refactoringTask);
}
timings = ErrorProneTimings.instance(context);
deferredCompletionFailureHandler = DeferredCompletionFailureHandler.instance(context);
}
Expand Down
7 changes: 6 additions & 1 deletion third_party/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,16 @@ distrib_jar_filegroup(
enable_distributions = ["debian"],
)

java_import(
name = "error_prone_check_api_patched",
jars = ["error_prone_check_api_patched/error_prone_check_api-2.22.0.jar"],
)

java_library(
name = "error_prone",
exports = [
":error_prone_annotations",
"@maven//:com_google_errorprone_error_prone_check_api",
":error_prone_check_api_patched",
"@maven//:com_google_errorprone_error_prone_core",
],
)
Expand Down
Binary file not shown.

0 comments on commit 52eb0e6

Please sign in to comment.