Skip to content

Commit

Permalink
Remove repackaging of protobuf code.
Browse files Browse the repository at this point in the history
I don't know why it's there, but I'm pretty sure it's no longer necessary. Removing it has several advantages:
1. code only depends on the protos they really need
2. we get the benefit of proto-specific lint checks which were lost in the build/import steps previously
3. Simpler build rules
4. Targets depending on the protos don't also pull in other things unknowningly, but instead have to declare all deps explicitly.

Note, the code changes here are the result of 2 above: proto mesisages cannot be null. Some BUILD file changes to explicitly add deps (e.g. jsr305) were required as a result of 4.

The IJ plugin classloader (com.intellij.ide.plugins.cl.PluginClassLoader) prefers classes from itself over the parent classloader. This differs from the standard Java classloader order. As a result, proto classes will always be loaded from the plugin instead of the underlying IDE (where they are also present).

(cherry picked from commit b0688f9)
  • Loading branch information
Googler authored and mai93 committed Sep 17, 2022
1 parent 2024a79 commit fe1c1e8
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 41 deletions.
2 changes: 1 addition & 1 deletion aspect/tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ java_library(
srcs = glob(["src/**/*.java"]),
deps = [
":guava",
"//intellij_platform_sdk:jsr305",
"//proto:proto_deps",
"@jsr305_annotations//jar",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.google.idea.blaze.aspect;

import com.google.common.annotations.VisibleForTesting;
import com.google.repackaged.bazel.protobuf.MessageLite;
import com.google.protobuf.MessageLite;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.OutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.google.common.collect.Maps;
import com.google.devtools.intellij.aspect.Common.ArtifactLocation;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.repackaged.bazel.protobuf.MessageLite;
import com.google.protobuf.MessageLite;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand Down
1 change: 1 addition & 0 deletions aswb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ intellij_integration_test_suite(
"//common/experiments",
"//common/experiments:unit_test_utils",
"//cpp",
"//intellij_platform_sdk:jsr305",
"//intellij_platform_sdk:plugin_api_for_tests",
"//intellij_platform_sdk:test_libs",
"//java",
Expand Down
1 change: 1 addition & 0 deletions base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ intellij_unit_test_suite(
":unit_test_utils",
"//common/experiments",
"//common/experiments:unit_test_utils",
"//intellij_platform_sdk:jsr305",
"//intellij_platform_sdk:plugin_api_for_tests",
"//intellij_platform_sdk:test_libs",
"//proto:proto_deps",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private static BlazeArtifact parseTestFile(
private static SourceArtifact parseLocalFile(
BuildEventStreamProtos.File file, Predicate<String> fileFilter) {
String uri = file.getUri();
if (uri == null || !uri.startsWith(URLUtil.FILE_PROTOCOL)) {
if (!uri.startsWith(URLUtil.FILE_PROTOCOL)) {
return null;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public OutputArtifact parse(
String configurationMnemonic,
long syncStartTimeMillis) {
String uri = file.getUri();
if (uri == null || !uri.startsWith(URLUtil.FILE_PROTOCOL)) {
if (!uri.startsWith(URLUtil.FILE_PROTOCOL)) {
return null;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Streams;
import com.google.repackaged.bazel.protobuf.Message;
import com.google.protobuf.Message;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings;
import com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder;
import com.google.idea.blaze.base.sync.workspace.WorkingSet;
import com.google.repackaged.bazel.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.InvalidProtocolBufferException;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
Expand Down
2 changes: 1 addition & 1 deletion base/src/com/google/idea/blaze/base/model/SyncData.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.devtools.intellij.model.ProjectData;
import com.google.idea.blaze.base.ideinfo.ProtoWrapper;
import com.google.repackaged.bazel.protobuf.Message;
import com.google.protobuf.Message;
import com.intellij.openapi.extensions.ExtensionPointName;
import java.util.Arrays;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.google.idea.blaze.base.model.BlazeVersionData;
import com.google.idea.blaze.base.model.primitives.LanguageClass;
import com.google.idea.common.experiments.BoolExperiment;
import com.google.repackaged.bazel.protobuf.TextFormat;
import com.google.protobuf.TextFormat;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.google.idea.blaze.base.command.BlazeCommand;
import com.google.idea.blaze.base.settings.BuildSystemName;
import com.google.idea.blaze.base.util.BuildSystemExtensionPoint;
import com.google.repackaged.bazel.protobuf.TextFormat;
import com.google.protobuf.TextFormat;
import com.intellij.openapi.extensions.ExtensionPointName;
import java.io.BufferedInputStream;
import java.io.File;
Expand Down
1 change: 1 addition & 0 deletions kotlin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ intellij_integration_test_suite(
"//base:unit_test_utils",
"//common/experiments",
"//common/experiments:unit_test_utils",
"//intellij_platform_sdk:jsr305",
"//intellij_platform_sdk:kotlin_for_tests",
"//intellij_platform_sdk:plugin_api_for_tests",
"//intellij_platform_sdk:test_libs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.google.idea.blaze.base.io.FileOperationProvider;
import com.google.idea.blaze.base.model.primitives.Label;
import com.google.idea.common.experiments.BoolExperiment;
import com.google.repackaged.bazel.protobuf.TextFormat;
import com.google.protobuf.TextFormat;
import com.intellij.concurrency.AsyncUtil;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.util.Key;
Expand Down
36 changes: 9 additions & 27 deletions proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ licenses(["notice"])

create_proto_visibility_group()

java_import(
name = "proto_deps",
jars = [":repackaged_proto_deps"],
visibility = PLUGIN_PACKAGES_VISIBILITY,
)

proto_library(
name = "common_proto",
srcs = ["common.proto"],
Expand Down Expand Up @@ -97,27 +91,13 @@ java_proto_library(
deps = [":intellij_plugin_target_deploy_info_proto"],
)

genrule(
name = "repackaged_proto_deps",
srcs = [
":proto_deps_binary_deploy.jar",
":jarjar_protobuf_rule.txt",
],
outs = [":repackaged_proto_deps.jar"],
cmd = """
$(location @jarjar//:jarjar_bin) \
process \
$(location :jarjar_protobuf_rule.txt) \
$(location :proto_deps_binary_deploy.jar) \
$@
""",
tools = ["@jarjar//:jarjar_bin"],
)

java_binary(
name = "proto_deps_binary",
main_class = "None",
runtime_deps = [
# TODO delete this build rule. Dependants should use the proto targets they use
# directly instead.
java_library(
name = "proto_deps",
visibility = PLUGIN_PACKAGES_VISIBILITY,
exports = [
":common_java_proto",
":fast_build_info_java_proto",
":intellij_ide_info_java_proto",
":intellij_plugin_target_deploy_info_java_proto",
Expand All @@ -126,6 +106,8 @@ java_binary(
"//third_party/bazel/src/main/java/com/google/devtools/build/lib/starlarkdebug/proto:starlark_debugging_java_proto",
"//third_party/bazel/src/main/protobuf:android_deploy_info_java_proto",
"//third_party/bazel/src/main/protobuf:build_java_proto",
"//third_party/bazel/src/main/protobuf:command_line_java_proto",
"//third_party/bazel/src/main/protobuf:deps_java_proto",
"@com_google_protobuf//:protobuf_java",
],
)
1 change: 0 additions & 1 deletion proto/jarjar_protobuf_rule.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import static com.google.common.base.Preconditions.checkState;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.starlarkdebugging.StarlarkDebuggingProtos;
Expand Down Expand Up @@ -576,7 +575,7 @@ private boolean individualThreadPausedByUser(StarlarkDebuggingProtos.PauseReason
private void handleConditionalBreakpointError(
XLineBreakpoint<XBreakpointProperties> breakpoint, PausedThread thread) {
// TODO(brendandouglas): also navigate to the problematic breakpoint
String error = Preconditions.checkNotNull(thread.getConditionalBreakpointError().getMessage());
String error = thread.getConditionalBreakpointError().getMessage();
String title = "Breakpoint Condition Error";
String message =
String.format(
Expand Down

0 comments on commit fe1c1e8

Please sign in to comment.