Skip to content

Commit

Permalink
Handle proto rules if light classes are enabled
Browse files Browse the repository at this point in the history
As determining rules that require building involves communication with other components (and potentially other plugins eventually), separates the list from BlazeQueryParser and moves responsibility for tracking these values to QuerySyncManager.

PiperOrigin-RevId: 555689150
  • Loading branch information
Googler authored and copybara-github committed Aug 11, 2023
1 parent ec20e61 commit 64d46f4
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import com.google.idea.blaze.base.sync.projectview.ImportRoots;
import com.google.idea.blaze.common.Label;
import com.google.idea.blaze.exception.BuildException;
import com.google.idea.blaze.qsync.BlazeQueryParser;
import com.google.protobuf.TextFormat;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.extensions.PluginDescriptor;
Expand Down Expand Up @@ -96,7 +95,8 @@ public OutputInfo build(BlazeContext context, Set<Label> buildTargets)
.map(BazelDependencyBuilder::directoryToLabel)
.collect(joining(","));
String aspectLocation = prepareAspect(context);
String alwaysBuildRuleTypes = Joiner.on(",").join(BlazeQueryParser.ALWAYS_BUILD_RULE_TYPES);
String alwaysBuildRuleTypes =
Joiner.on(",").join(QuerySyncManager.getInstance(project).alwaysBuildRuleTypes());

ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
// TODO This is not SYNC_CONTEXT, but also not OTHER_CONTEXT, we need to decide what kind
Expand Down
3 changes: 2 additions & 1 deletion base/src/com/google/idea/blaze/base/qsync/ProjectLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public QuerySyncProject loadProject(BlazeContext context) throws IOException {
createWorkspaceRelativePackageReader(),
vcsHandler.map(BlazeVcsHandler::getVcsStateDiffer).orElse(VcsStateDiffer.NONE),
workspaceRoot.path(),
graph::getCurrent);
graph::getCurrent,
QuerySyncManager.getInstance(project).alwaysBuildRuleTypes());
QueryRunner queryRunner = createQueryRunner(buildSystem);
ProjectQuerier projectQuerier = createProjectQuerier(projectRefresher, queryRunner, vcsHandler);
ProjectUpdater projectUpdater =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.idea.blaze.base.qsync;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
Expand Down Expand Up @@ -44,6 +45,7 @@
import com.google.idea.blaze.base.toolwindow.Task;
import com.google.idea.blaze.base.util.SaveUtil;
import com.google.idea.blaze.common.Label;
import com.google.idea.blaze.qsync.AlwaysBuildRuleTypes;
import com.google.idea.blaze.qsync.project.BlazeProjectSnapshot;
import com.google.idea.blaze.qsync.project.PostQuerySyncData;
import com.google.idea.blaze.qsync.project.ProjectDefinition;
Expand Down Expand Up @@ -304,4 +306,8 @@ private boolean projectDefinitionHasChanged() {
SaveUtil.saveAllFiles();
return !loadedProject.isDefinitionCurrent();
}

public ImmutableSet<String> alwaysBuildRuleTypes() {
return AlwaysBuildRuleTypes.DEFAULT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2023 The Bazel Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.idea.blaze.qsync;

import com.google.common.collect.ImmutableSet;

/** Stores a set of rules which must be built even if in-project */
public class AlwaysBuildRuleTypes {
private AlwaysBuildRuleTypes() {}

/**
* Within the context of an IntelliJ project, use {@link QuerySyncManager#alwaysBuildRuleTypes}
*/
public static final ImmutableSet<String> DEFAULT =
ImmutableSet.of(
"java_proto_library",
"java_lite_proto_library",
"java_mutable_proto_library",
// Underlying rule for kt_jvm_lite_proto_library and kt_jvm_proto_library
"kt_proto_library_helper",
"_java_grpc_library",
"_java_lite_grpc_library",
"java_stubby_library",
"aar_import");
}
19 changes: 4 additions & 15 deletions querysync/java/com/google/idea/blaze/qsync/BlazeQueryParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,6 @@
*/
public class BlazeQueryParser {

// Rules that will need to be built, whether or not the target is included in the
// project.
public static final ImmutableSet<String> ALWAYS_BUILD_RULE_TYPES =
ImmutableSet.of(
"java_proto_library",
"java_lite_proto_library",
"java_mutable_proto_library",
// Underlying rule for kt_jvm_lite_proto_library and kt_jvm_proto_library
"kt_proto_library_helper",
"_java_grpc_library",
"_java_lite_grpc_library",
"java_stubby_library",
"aar_import");
private static final ImmutableSet<String> JAVA_RULE_TYPES =
ImmutableSet.of("java_library", "java_binary", "kt_jvm_library_helper", "java_test");
private static final ImmutableSet<String> ANDROID_RULE_TYPES =
Expand All @@ -69,9 +56,11 @@ public class BlazeQueryParser {
"kt_android_library_helper");

private final Context<?> context;
private final ImmutableSet<String> alwaysBuildRuleTypes;

public BlazeQueryParser(Context context) {
public BlazeQueryParser(Context<?> context, ImmutableSet<String> alwaysBuildRuleTypes) {
this.context = context;
this.alwaysBuildRuleTypes = alwaysBuildRuleTypes;
}

private static boolean isJavaRule(String ruleClass) {
Expand Down Expand Up @@ -163,7 +152,7 @@ public BuildGraphData parse(QuerySummary query) {
targetSources.put(ruleEntry.getKey(), Label.of(ruleEntry.getValue().getManifest()));
}
}
} else if (ALWAYS_BUILD_RULE_TYPES.contains(ruleClass)) {
} else if (alwaysBuildRuleTypes.contains(ruleClass)) {
projectTargetsToBuild.add(ruleEntry.getKey());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.idea.blaze.qsync;

import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.idea.blaze.common.Context;
import com.google.idea.blaze.common.vcs.VcsState;
Expand Down Expand Up @@ -52,13 +53,14 @@ public FullProjectUpdate(
Path effectiveWorkspaceRoot,
ProjectDefinition definition,
PackageReader packageReader,
Optional<VcsState> vcsState) {
Optional<VcsState> vcsState,
ImmutableSet<String> alwaysBuildRuleTypes) {
this.context = context;
this.effectiveWorkspaceRoot = effectiveWorkspaceRoot;
this.result =
PostQuerySyncData.builder().setProjectDefinition(definition).setVcsState(vcsState);
this.projectDefinition = definition;
this.queryParser = new BlazeQueryParser(context);
this.queryParser = new BlazeQueryParser(context, alwaysBuildRuleTypes);
this.graphToProjectConverter =
new GraphToProjectConverter(
packageReader, effectiveWorkspaceRoot, context, projectDefinition, executor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class PartialProjectRefresh implements RefreshOperation {
PostQuerySyncData previousState,
Optional<VcsState> currentVcsState,
ImmutableSet<Path> modifiedPackages,
ImmutableSet<Path> deletedPackages) {
ImmutableSet<Path> deletedPackages,
ImmutableSet<String> alwaysBuildRuleTypes) {
this.effectiveWorkspaceRoot = effectiveWorkspaceRoot;
this.previousState = previousState;
this.newState =
Expand All @@ -71,7 +72,7 @@ class PartialProjectRefresh implements RefreshOperation {
.setProjectDefinition(previousState.projectDefinition());
this.modifiedPackages = modifiedPackages;
this.deletedPackages = deletedPackages;
this.queryParser = new BlazeQueryParser(context);
this.queryParser = new BlazeQueryParser(context, alwaysBuildRuleTypes);
this.graphToProjectConverter =
new GraphToProjectConverter(
packageReader,
Expand Down
12 changes: 9 additions & 3 deletions querysync/java/com/google/idea/blaze/qsync/ProjectRefresher.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.idea.blaze.qsync;

import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.idea.blaze.common.Context;
import com.google.idea.blaze.common.PrintOutput;
Expand All @@ -38,18 +39,21 @@ public class ProjectRefresher {
private final VcsStateDiffer vcsDiffer;
private final Path workspaceRoot;
private final Supplier<Optional<BlazeProjectSnapshot>> latestProjectSnapshotSupplier;
private final ImmutableSet<String> alwaysBuildRuleTypes;

public ProjectRefresher(
ListeningExecutorService executor,
PackageReader workspaceRelativePackageReader,
VcsStateDiffer vcsDiffer,
Path workspaceRoot,
Supplier<Optional<BlazeProjectSnapshot>> latestProjectSnapshotSupplier) {
Supplier<Optional<BlazeProjectSnapshot>> latestProjectSnapshotSupplier,
ImmutableSet<String> alwaysBuildRuleTypes) {
this.executor = executor;
this.workspaceRelativePackageReader = workspaceRelativePackageReader;
this.vcsDiffer = vcsDiffer;
this.workspaceRoot = workspaceRoot;
this.latestProjectSnapshotSupplier = latestProjectSnapshotSupplier;
this.alwaysBuildRuleTypes = alwaysBuildRuleTypes;
}

public FullProjectUpdate startFullUpdate(
Expand All @@ -62,7 +66,8 @@ public FullProjectUpdate startFullUpdate(
effectiveWorkspaceRoot,
spec,
new WorkspaceResolvingPackageReader(effectiveWorkspaceRoot, workspaceRelativePackageReader),
vcsState);
vcsState,
alwaysBuildRuleTypes);
}

public RefreshOperation startPartialRefresh(
Expand Down Expand Up @@ -105,7 +110,8 @@ public RefreshOperation startPartialRefresh(RefreshParameters params, Context<?>
params.currentProject,
params.latestVcsState,
affected.getModifiedPackages(),
affected.getDeletedPackages());
affected.getDeletedPackages(),
alwaysBuildRuleTypes);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.idea.blaze.exception.BuildException;
import com.google.idea.blaze.qsync.AlwaysBuildRuleTypes;
import com.google.idea.blaze.qsync.BlazeQueryParser;
import com.google.idea.blaze.qsync.GraphToProjectConverter;
import com.google.idea.blaze.qsync.PackageReader;
Expand Down Expand Up @@ -84,7 +85,8 @@ private int run() throws IOException, BuildException {
.readFrom(new GZIPInputStream(new FileInputStream(snapshotFile)), context)
.orElseThrow()
.getSyncData();
BuildGraphData buildGraph = new BlazeQueryParser(context).parse(snapshot.querySummary());
BuildGraphData buildGraph =
new BlazeQueryParser(context, AlwaysBuildRuleTypes.DEFAULT).parse(snapshot.querySummary());
GraphToProjectConverter converter =
new GraphToProjectConverter(
packageReader, workspaceRoot, context, snapshot.projectDefinition(), executor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ public void testConvertProject_buildGraphWithSingleImportRoot() throws Exception
newDirectExecutorService());

BuildGraphData buildGraphData =
new BlazeQueryParser(NOOP_CONTEXT)
new BlazeQueryParser(NOOP_CONTEXT, AlwaysBuildRuleTypes.DEFAULT)
.parse(getQuerySummary(TestData.JAVA_LIBRARY_NO_DEPS_QUERY));
ProjectProto.Project project = converter.createProject(buildGraphData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public void testApplyDelta_replacePackage() {
baseProject,
QuerySyncTestUtils.CLEAN_VCS_STATE,
/* modifiedPackages= */ ImmutableSet.of(Path.of("my/build/package1")),
ImmutableSet.of());
ImmutableSet.of(),
AlwaysBuildRuleTypes.DEFAULT);
queryStrategy.setQueryOutput(delta);
QuerySummary applied = queryStrategy.applyDelta();
assertThat(applied.getRulesMap().keySet())
Expand Down Expand Up @@ -175,7 +176,8 @@ public void testApplyDelta_deletePackage() {
baseProject,
QuerySyncTestUtils.CLEAN_VCS_STATE,
ImmutableSet.of(),
/* deletedPackages= */ ImmutableSet.of(Path.of("my/build/package1")));
/* deletedPackages= */ ImmutableSet.of(Path.of("my/build/package1")),
AlwaysBuildRuleTypes.DEFAULT);
assertThat(queryStrategy.getQuerySpec()).isEmpty();
queryStrategy.setQueryOutput(QuerySummary.EMPTY);
QuerySummary applied = queryStrategy.applyDelta();
Expand Down Expand Up @@ -240,7 +242,8 @@ public void testDelta_addPackage() {
baseProject,
QuerySyncTestUtils.CLEAN_VCS_STATE,
/* modifiedPackages= */ ImmutableSet.of(Path.of("my/build/package2")),
ImmutableSet.of());
ImmutableSet.of(),
AlwaysBuildRuleTypes.DEFAULT);
queryStrategy.setQueryOutput(delta);
QuerySummary applied = queryStrategy.applyDelta();
assertThat(applied.getRulesMap().keySet())
Expand Down Expand Up @@ -274,7 +277,8 @@ public void testDelta_packagesWithErrors() {
baseProject,
QuerySyncTestUtils.CLEAN_VCS_STATE,
/* modifiedPackages= */ ImmutableSet.of(Path.of("my/build/package")),
ImmutableSet.of());
ImmutableSet.of(),
AlwaysBuildRuleTypes.DEFAULT);
queryStrategy.setQueryOutput(delta);
QuerySummary applied = queryStrategy.applyDelta();
assertThat(applied.getPackagesWithErrors()).containsExactly(Path.of("my/build/package"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ private ProjectRefresher createRefresher(
QuerySyncTestUtils.EMPTY_PACKAGE_READER,
vcsDiffer,
Path.of("/"),
Suppliers.ofInstance(existingSnapshot));
Suppliers.ofInstance(existingSnapshot),
AlwaysBuildRuleTypes.DEFAULT);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public BlazeProjectSnapshot sync(TestData testProject) throws IOException, Build
.setQuerySummary(querySummary)
.setVcsState(Optional.empty())
.build();
BuildGraphData buildGraphData = new BlazeQueryParser(context).parse(querySummary);
BuildGraphData buildGraphData =
new BlazeQueryParser(context, AlwaysBuildRuleTypes.DEFAULT).parse(querySummary);
GraphToProjectConverter converter =
new GraphToProjectConverter(
packageReader,
Expand All @@ -70,7 +71,7 @@ public BlazeProjectSnapshot sync(TestData testProject) throws IOException, Build
Project project = converter.createProject(buildGraphData);
return BlazeProjectSnapshot.builder()
.queryData(pqsd)
.graph(new BlazeQueryParser(context).parse(querySummary))
.graph(new BlazeQueryParser(context, AlwaysBuildRuleTypes.DEFAULT).parse(querySummary))
.project(project)
.build();
}
Expand Down
Loading

0 comments on commit 64d46f4

Please sign in to comment.