Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: fix(qsync): NPE when trying to enable analysis for a directory or for… #6992

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public ImmutableSet<DependencyTrackingBehavior> getDependencyTrackingBehaviors(L
* the set of all targets defined in all build packages within the directory (recursively).
*/
public TargetsToBuild getProjectTargets(Context<?> context, Path workspaceRelativePath) {
if (workspaceRelativePath.endsWith("BUILD")) {
if (workspaceRelativePath.endsWith("BUILD") || workspaceRelativePath.endsWith("BUILD.bazel")) {
Path packagePath = workspaceRelativePath.getParent();
return TargetsToBuild.targetGroup(allTargets().get(packagePath));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet;
import com.google.idea.blaze.common.Context;
import com.google.idea.blaze.common.Label;
import com.google.idea.blaze.exception.BuildException;
import com.google.idea.blaze.qsync.deps.ArtifactTracker;
import com.google.idea.blaze.qsync.java.PackageReader;
Expand All @@ -31,7 +32,9 @@
import com.google.idea.blaze.qsync.query.QuerySummary;
import com.google.idea.blaze.qsync.testdata.TestData;
import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* Builds a {@link BlazeProjectSnapshot} for a test project by running the logic from the various
Expand Down Expand Up @@ -59,7 +62,7 @@ public BlazeProjectSnapshot sync(TestData testProject) throws IOException, Build
/* testSources= */ ImmutableSet.of(),
/* systemExcludes = */ ImmutableSet.of()
);
QuerySummary querySummary = getQuerySummary(testProject);
QuerySummary querySummary = adaptQuerySummaryDueToABazelBug(getQuerySummary(testProject));
PostQuerySyncData pqsd =
PostQuerySyncData.builder()
.setProjectDefinition(projectDefinition)
Expand All @@ -85,4 +88,23 @@ public BlazeProjectSnapshot sync(TestData testProject) throws IOException, Build
.project(project)
.build();
}

/**
* We should add --consistent_labels flag to this target and all similar ones
* //querysync/javatests/com/google/idea/blaze/qsync/testdata:java_library_external_dep_query
* Unfortunately, due to a bug in bazel it doesn't work, so we have to adjust the rule names in code
* The bug is reported here. The method should be cleared and inlined after the
* bug <a href="https://github.com/bazelbuild/bazel/issues/24325">#24325</a> is fixed.
*/
private static QuerySummary adaptQuerySummaryDueToABazelBug(QuerySummary querySummary) {
var newRulesMap = querySummary.getRulesMap().entrySet().stream()
.collect(Collectors.toMap(
it -> Label.of(it.getKey().toString().replaceFirst("^//", "@@//")),
Map.Entry::getValue));
return QuerySummary.newBuilder()
.putAllPackagesWithErrors(querySummary.getPackagesWithErrors())
.putAllSourceFiles(querySummary.getSourceFilesMap())
.putAllRules(newRulesMap)
.build();
}
}
2 changes: 1 addition & 1 deletion shared/java/com/google/idea/blaze/common/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static Label of(String label) {
}

public static Label fromPackageAndName(Path packagePath, Path name) {
return of(String.format("//%s:%s", packagePath, name));
return of(String.format("@@//%s:%s", packagePath, name));
}

public static Label fromPackageAndName(Path packagePath, String name) {
Expand Down
Loading