Skip to content

Commit

Permalink
New Sync View (#6813)
Browse files Browse the repository at this point in the history
Adds a new sync view that uses the build view provided by platform. Error messages received by BEP rather than parsing the command line output to increase the quality and relevance of reported errors. Currently the view is disabled by default but can be enabled in the settings.
  • Loading branch information
LeFrosch authored Oct 18, 2024
1 parent 94b38b5 commit c1a3c5a
Show file tree
Hide file tree
Showing 95 changed files with 1,314 additions and 1,252 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build --java_language_version=17 --java_runtime_version=17
build --tool_java_language_version=17 --tool_java_runtime_version=17

# Delete test data packages, needed for bazel integration tests. Update by running the following command:
# bazel run @rules_bazel_integration_test//tools:update_deleted_packages
Expand Down
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module(
repo_name = "intellij_with_bazel",
)

register_toolchains("//third_party/kotlin:toolchain")

bazel_dep(
name = "platforms",
version = "0.0.10",
Expand Down
4 changes: 4 additions & 0 deletions aswb/aswb.bazelproject
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ test_sources:
*/testcompat/unittests*
*/testcompat/integrationtests*
*/testcompat/utils/integration*

additional_languages:
kotlin

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

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo;
import com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.Artifact;
import com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest;
Expand All @@ -29,6 +30,7 @@
import com.google.idea.blaze.common.artifact.OutputArtifact;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.util.containers.ContainerUtil;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -45,7 +47,7 @@ public class BlazeApkDeployInfoProtoHelper {
public AndroidDeployInfo readDeployInfoProtoForTarget(
Label target, BuildResultHelper buildResultHelper, Predicate<String> pathFilter)
throws GetDeployInfoException {
ImmutableList<OutputArtifact> outputArtifacts;
ImmutableSet<OutputArtifact> outputArtifacts;
try {
outputArtifacts = buildResultHelper.getBuildArtifactsForTarget(target, pathFilter);
} catch (GetArtifactsException e) {
Expand All @@ -62,7 +64,7 @@ public AndroidDeployInfo readDeployInfoProtoForTarget(
log.warn(outputArtifact.getRelativePath() + " -> " + outputArtifact.getRelativePath());
}
log.warn("All local artifacts for " + target + ":");
List<OutputArtifact> allBuildArtifacts =
ImmutableSet<OutputArtifact> allBuildArtifacts =
buildResultHelper.getBuildArtifactsForTarget(target, path -> true);
List<File> allLocalFiles = LocalFileArtifact.getLocalFiles(allBuildArtifacts);
for (File file : allLocalFiles) {
Expand All @@ -87,7 +89,7 @@ public AndroidDeployInfo readDeployInfoProtoForTarget(
.collect(Collectors.joining(", ", "[", "]")));
}

try (InputStream inputStream = outputArtifacts.get(0).getInputStream()) {
try (InputStream inputStream = ContainerUtil.getFirstItem(outputArtifacts).getInputStream()) {
return AndroidDeployInfo.parseFrom(inputStream);
} catch (IOException e) {
throw new GetDeployInfoException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import com.google.idea.blaze.base.command.BlazeCommandName;
import com.google.idea.blaze.base.command.BlazeFlags;
import com.google.idea.blaze.base.command.buildresult.BuildResultHelper;
import com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException;
import com.google.idea.blaze.base.command.buildresult.BuildResultHelperBep;
import com.google.idea.blaze.base.filecache.FileCaches;
import com.google.idea.blaze.base.ideinfo.AndroidInstrumentationInfo;
import com.google.idea.blaze.base.ideinfo.TargetIdeInfo;
Expand Down Expand Up @@ -195,7 +193,7 @@ public void run(@NotNull BlazeLaunchContext launchContext)
String.format("Starting %s test...\n", Blaze.buildSystemName(project)));

int retVal;
try (BuildResultHelper buildResultHelper = new BuildResultHelperBep()) {
try (final var buildResultHelper = new BuildResultHelper()) {
commandBuilder.addBlazeFlags(buildResultHelper.getBuildFlags());
BlazeCommand command = commandBuilder.build();
ExecutionUtils.println(console, command + "\n");
Expand All @@ -212,16 +210,13 @@ public void run(@NotNull BlazeLaunchContext launchContext)
if (retVal != 0) {
context.setHasError();
} else {
testResultsHolder.setTestResults(
buildResultHelper.getTestResults(Optional.empty()));
testResultsHolder.setTestResults(buildResultHelper.getTestResults());
}
ListenableFuture<Void> unusedFuture =
FileCaches.refresh(
project,
context,
BlazeBuildOutputs.noOutputs(BuildResult.fromExitCode(retVal)));
} catch (GetArtifactsException e) {
LOG.error(e.getMessage());
}
return !context.hasErrors();
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static void notifyMissingPlugin(BlazeContext context, PluginNameAndId pl
+ "Click here to install/enable it, then restart the IDE",
plugin.name);
IssueOutput.error(msg)
.navigatable(PluginUtils.installOrEnablePluginNavigable(plugin.id))
.withNavigatable(PluginUtils.installOrEnablePluginNavigable(plugin.id))
.submit(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
import com.google.idea.blaze.base.model.primitives.Label;
import com.google.idea.blaze.base.scope.BlazeContext;
import com.google.idea.blaze.base.scope.output.IssueOutput;
import com.google.idea.blaze.base.scope.output.IssueOutput.Category;
import com.google.idea.blaze.base.scope.output.PerformanceWarning;
import com.google.idea.blaze.common.Output;
import com.google.idea.common.experiments.BoolExperiment;
import com.intellij.build.events.MessageEvent.Kind;
import com.intellij.openapi.project.Project;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -327,7 +327,7 @@ private ImmutableList<AndroidResourceModule> buildAndroidResourceModules(
if (mergeResourcesEnabled.getValue()) {
messageBuilder.append(" ").append("Merging Resources...").append("\n");
String message = messageBuilder.toString();
context.accept(IssueOutput.issue(Category.INFORMATION, message).build());
context.accept(IssueOutput.issue(Kind.INFO, message).build());

result.add(mergeAndroidResourceModules(androidResourceModulesWithJavaPackage));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter;
import com.google.idea.blaze.common.Output;
import com.google.idea.blaze.java.sync.model.BlazeJarLibrary;
import com.intellij.build.events.MessageEvent.Kind;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import java.util.Collection;
Expand Down Expand Up @@ -110,8 +111,7 @@ static Consumer<Output> asConsumer(BlazeContext context) {
context.output(issue);
if (issue instanceof IssueOutput) {
IssueOutput issueOutput = (IssueOutput) issue;
if (issueOutput.getCategory()
== com.google.idea.blaze.base.scope.output.IssueOutput.Category.ERROR) {
if (issueOutput.getKind() == Kind.ERROR) {
context.setHasError();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,15 @@ public static void submit(
+ "Double-click to add to project view if needed to resolve"
+ " references.",
interestingDirectories.size()))
.inFile(projectViewFile)
.onLine(1)
.inColumn(1)
.withFile(projectViewFile)
.build());
for (Map.Entry<ArtifactLocation, Integer> entry : interestingDirectories.entrySet()) {
context.accept(
IssueOutput.warn(
String.format(
"Dropping generated resource directory '%s' w/ %d subdirs",
entry.getKey(), entry.getValue()))
.inFile(projectViewFile)
.navigatable(
new AddGeneratedResourceDirectoryNavigatable(
project, projectViewFile, entry.getKey()))
.withFile(projectViewFile)
.build());
}
}
Expand All @@ -98,7 +93,7 @@ public static void submit(
unusedAllowlistEntries.size(),
GeneratedAndroidResourcesSection.KEY.getName(),
String.join("\n ", unusedAllowlistEntries)))
.inFile(projectViewFile)
.withFile(projectViewFile)
.build());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static AndroidSdkPlatform getAndroidSdkPlatform(
if (sdks.isEmpty()) {
String msg = "No Android SDK configured. Please use the SDK manager to configure.";
IssueOutput.error(msg)
.navigatable(
.withNavigatable(
new Navigatable() {
@Override
public void navigate(boolean b) {
Expand Down Expand Up @@ -87,7 +87,7 @@ public boolean canNavigateToSource() {
+ getAvailableTargetHashesAsList(sdks)
+ ". To install more android SDKs, use the SDK manager.";
IssueOutput.error(msg)
.inFile(projectViewFile != null ? projectViewFile.projectViewFile : null)
.withFile(projectViewFile != null ? projectViewFile.projectViewFile : null)
.submit(context);
BlazeSyncManager.printAndLogError(msg, context);
return null;
Expand All @@ -98,7 +98,7 @@ public boolean canNavigateToSource() {
ProjectViewFile projectViewFile = projectViewSet.getTopLevelProjectViewFile();
String msg = String.format(NO_SDK_ERROR_TEMPLATE, androidSdk, getAllAvailableTargetHashes());
IssueOutput.error(msg)
.inFile(projectViewFile != null ? projectViewFile.projectViewFile : null)
.withFile(projectViewFile != null ? projectViewFile.projectViewFile : null)
.submit(context);
BlazeSyncManager.printAndLogError(msg, context);
return null;
Expand Down
7 changes: 4 additions & 3 deletions base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ load(
"intellij_integration_test_suite",
"intellij_unit_test_suite",
)
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")

java_library(
kt_jvm_library(
name = "base",
srcs = glob(["src/**/*.java"]),
javacopts = ["-Xep:FutureReturnValueIgnored:OFF"],
srcs = glob(["src/**/*.java", "src/**/*.kt"]),
resources = glob(["src/resources/**/*"]),
resource_strip_prefix = "base/src",
visibility = PLUGIN_PACKAGES_VISIBILITY,
deps = [
"//common/actions",
Expand Down
6 changes: 4 additions & 2 deletions base/src/META-INF/blaze-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@
<extensionPoint qualifiedName="com.google.idea.blaze.OutputGroupsProvider" interface="com.google.idea.blaze.base.sync.aspects.strategy.OutputGroupsProvider"/>
<extensionPoint qualifiedName="com.google.idea.blaze.ExperimentLoader" interface="com.google.idea.common.experiments.ExperimentLoader"/>
<extensionPoint qualifiedName="com.google.idea.blaze.EmptyLibraryFilterSettings" interface="com.google.idea.blaze.java.sync.importer.emptylibrary.EmptyLibraryFilterSettings" />
<extensionPoint qualifiedName="com.google.idea.blaze.BuildEventParser" interface="com.google.idea.blaze.base.buildview.events.BuildEventParser" />
</extensionPoints>

<extensions defaultExtensionNs="com.google.idea.blaze">
Expand All @@ -615,7 +616,6 @@
<VcsHandler implementation="com.google.idea.blaze.base.vcs.FallbackBlazeVcsHandlerProvider" order="last" id="fallback"/>
<BuildSystemProvider implementation="com.google.idea.blaze.base.bazel.BazelBuildSystemProvider" id="BazelBuildSystemProvider" order="last"/>
<BuildifierBinaryProvider implementation="com.google.idea.blaze.base.buildmodifier.DefaultBuildifierBinaryProvider"/>
<BuildResultHelperProvider order="last" implementation="com.google.idea.blaze.base.command.buildresult.BuildResultHelperBep$Provider"/>
<BlazeCommandRunConfigurationHandlerProvider implementation="com.google.idea.blaze.base.run.confighandler.PendingTargetRunConfigurationHandlerProvider"/>
<BlazeCommandRunConfigurationHandlerProvider implementation="com.google.idea.blaze.base.run.confighandler.BlazeCommandGenericRunConfigurationHandlerProvider" order="last"/>
<AttributeSpecificStringLiteralReferenceProvider implementation="com.google.idea.blaze.base.lang.buildfile.references.VisibilityReferenceProvider"/>
Expand Down Expand Up @@ -684,7 +684,9 @@
<ExperimentLoader implementation="com.google.idea.common.experiments.SystemPropertyExperimentLoader" order="first" id="SystemPropertyExperimentLoader"/>
<ExperimentLoader implementation="com.google.idea.common.experiments.UserOverridesExperimentLoader" order="after SystemPropertyExperimentLoader" id="UserOverridesExperimentLoader"/>
<ExperimentLoader implementation="com.google.idea.common.experiments.DefaultValuesExperimentLoader" order="last" id="DefaultValuesExperimentLoader"/>
<BlazeGuard implementation="com.google.idea.blaze.base.execution.TrustedProjectGuard"/>
<BlazeGuard implementation="com.google.idea.blaze.base.execution.TrustedProjectGuard"/>
<BuildEventParser implementation="com.google.idea.blaze.base.buildview.events.AbortedParser"/>
<BuildEventParser implementation="com.google.idea.blaze.base.buildview.events.ActionCompletedParser"/>
</extensions>

<extensions defaultExtensionNs="com.google.idea.blaze.qsync">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import com.google.common.util.concurrent.MoreExecutors;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.progress.PerformInBackgroundOption;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Progressive;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator;
import com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase;
import com.intellij.openapi.progress.util.ProgressWindow;
Expand All @@ -40,7 +42,8 @@ public class ProgressiveTaskWithProgressIndicator {
public enum Modality {
MODAL, // This task must start in the foreground and stay there.
BACKGROUNDABLE, // This task will start in the foreground, but can be sent to the background.
ALWAYS_BACKGROUND // This task will start in the background and stay there.
ALWAYS_BACKGROUND, // This task will start in the background and stay there.
BUILD_VIEW // Progress of this task is tracked in the build view
}

@Nullable private final Project project;
Expand Down Expand Up @@ -104,6 +107,10 @@ public void submitTaskLater(Progressive progressive) {
* progress dialog.
*/
public <T> ListenableFuture<T> submitTaskWithResult(ProgressiveWithResult<T> progressive) {
if (modality == Modality.BUILD_VIEW) {
return executor.submit(() -> progressive.compute(new EmptyProgressIndicator(ModalityState.NON_MODAL)));
}

// The progress indicator must be created on the UI thread.
final ProgressWindow indicator =
UIUtil.invokeAndWaitIfNeeded(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.google.idea.blaze.base.command.BlazeFlags;
import com.google.idea.blaze.base.command.BlazeInvocationContext;
import com.google.idea.blaze.base.command.buildresult.BuildResultHelper;
import com.google.idea.blaze.base.command.buildresult.BuildResultHelperBep;
import com.google.idea.blaze.base.command.info.BlazeInfo;
import com.google.idea.blaze.base.command.info.BlazeInfoProvider;
import com.google.idea.blaze.base.command.info.BlazeInfoRunner;
Expand Down Expand Up @@ -95,7 +94,7 @@ public boolean supportsParallelism() {
@Override
@MustBeClosed
public BuildResultHelper createBuildResultHelper() {
return new BuildResultHelperBep();
return new BuildResultHelper();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
*/
package com.google.idea.blaze.base.bazel;

import com.google.errorprone.annotations.MustBeClosed;
import com.google.idea.blaze.base.command.BlazeCommandName;
import com.google.idea.blaze.base.command.CommandLineBlazeCommandRunner;
import com.google.idea.blaze.base.command.buildresult.BuildResultHelper;
import com.google.idea.blaze.base.command.buildresult.BuildResultHelperBep;
import com.google.idea.blaze.base.command.info.BlazeInfo;
import com.google.idea.blaze.base.model.BlazeVersionData;
import com.google.idea.blaze.base.model.primitives.Kind;
Expand Down Expand Up @@ -52,12 +49,6 @@ public BazelInvoker(Project project, BlazeContext blazeContext, String path) {
BazelBuildSystem.this,
new CommandLineBlazeCommandRunner());
}

@Override
@MustBeClosed
public BuildResultHelper createBuildResultHelper() {
return new BuildResultHelperBep();
}
}

@Override
Expand Down
Loading

0 comments on commit c1a3c5a

Please sign in to comment.