Skip to content

Commit

Permalink
Merge branch 'master' into son/copy_java_info_to_project_side
Browse files Browse the repository at this point in the history
  • Loading branch information
xuansontrinh authored Oct 4, 2024
2 parents 0907230 + fb7e43e commit 35552df
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.google.idea.blaze.base.MockProjectViewManager;
import com.google.idea.blaze.base.async.executor.BlazeExecutor;
import com.google.idea.blaze.base.async.executor.MockBlazeExecutor;
import com.google.idea.blaze.base.bazel.BazelBuildSystemProvider;
import com.google.idea.blaze.base.bazel.BuildSystemProvider;
import com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifactWithoutDigest;
import com.google.idea.blaze.base.filecache.FileCache;
import com.google.idea.blaze.base.ideinfo.AndroidIdeInfo;
Expand Down Expand Up @@ -153,6 +155,8 @@ public File decode(ArtifactLocation artifactLocation) {

intellijRule.registerApplicationService(BlazeExecutor.class, new MockBlazeExecutor());

intellijRule.registerExtensionPoint(BuildSystemProvider.EP_NAME, BuildSystemProvider.class);
intellijRule.registerExtension(BuildSystemProvider.EP_NAME, new BazelBuildSystemProvider());
setupProjectData();
setProjectView(
"directories:",
Expand Down
5 changes: 4 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 @@ -23,6 +23,7 @@
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.idea.blaze.base.bazel.BuildSystem;
import com.google.idea.blaze.base.bazel.BuildSystemProvider;
import com.google.idea.blaze.base.model.primitives.WorkspacePath;
import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
import com.google.idea.blaze.base.projectview.ProjectViewManager;
import com.google.idea.blaze.base.projectview.ProjectViewSet;
Expand All @@ -34,6 +35,7 @@
import com.google.idea.blaze.base.scope.BlazeContext;
import com.google.idea.blaze.base.settings.BlazeImportSettings;
import com.google.idea.blaze.base.settings.BlazeImportSettingsManager;
import com.google.idea.blaze.base.settings.BuildSystemName;
import com.google.idea.blaze.base.sync.data.BlazeDataStorage;
import com.google.idea.blaze.base.sync.projectview.ImportRoots;
import com.google.idea.blaze.base.sync.projectview.LanguageSupport;
Expand Down Expand Up @@ -122,7 +124,8 @@ public QuerySyncProject loadProject(BlazeContext context) throws BuildException
importRoots.rootPaths(),
importRoots.excludePaths(),
LanguageClasses.toQuerySync(workspaceLanguageSettings.getActiveLanguages()),
testSourceGlobs);
testSourceGlobs,
importRoots.systemExcludes());

Path snapshotFilePath = getSnapshotFilePath(importSettings);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,14 @@ public boolean isDefinitionCurrent(BlazeContext context) throws BuildException {
projectViewSet.listItems(TestSourceSection.KEY).stream()
.map(Glob::toString)
.collect(ImmutableSet.toImmutableSet());

ProjectDefinition projectDefinition =
ProjectDefinition.create(
importRoots.rootPaths(),
importRoots.excludePaths(),
LanguageClasses.toQuerySync(workspaceLanguageSettings.getActiveLanguages()),
testSourceGlobs);
testSourceGlobs,
importRoots.systemExcludes());

return this.projectDefinition.equals(projectDefinition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ public Builder exclude(WorkspacePath entry) {
return this;
}

public ImmutableSet<String> systemExcludes(WorkspaceRoot workspaceRoot) {
var buildArtifactDirectories = BuildSystemProvider
.getBuildSystemProvider(BuildSystemName.Bazel)
.buildArtifactDirectories(workspaceRoot);
var projectDataSubdirectory = new WorkspacePath(BlazeDataStorage.PROJECT_DATA_SUBDIRECTORY).toString();
var systemExcludedDirectories = ImmutableSet.<String>builder().addAll(buildArtifactDirectories).add(projectDataSubdirectory).build();
return systemExcludedDirectories;

}

public ImportRoots build() {
if (viewProjectRoot) {
rootDirectoriesBuilder.add(workspaceRoot.workspacePathFor(workspaceRoot.directory()));
Expand Down Expand Up @@ -166,8 +176,11 @@ public ImportRoots build() {
//Paths in .bazelignore are already excluded by Bazel, excluding them explicitly in "bazel query" produces a warning
ImmutableSet<WorkspacePath> excludePathsForBazelQuery = Sets.difference(minimalExcludes, bazelIgnorePathsBuilder.build()).immutableCopy();


ImmutableSet<String> systemExcludes = systemExcludes(workspaceRoot);

ProjectDirectoriesHelper directories =
new ProjectDirectoriesHelper(minimalRootDirectories, minimalExcludes, excludePathsForBazelQuery);
new ProjectDirectoriesHelper(minimalRootDirectories, minimalExcludes, excludePathsForBazelQuery, systemExcludes);

TargetExpressionList targets =
deriveTargetsFromDirectories
Expand Down Expand Up @@ -248,6 +261,10 @@ public ImmutableSet<Path> rootPaths() {
.collect(toImmutableSet());
}

public ImmutableSet<String> systemExcludes() {
return projectDirectories.systemExcludes;
}

public Set<WorkspacePath> excludeDirectories() {
return projectDirectories.excludeDirectories;
}
Expand Down Expand Up @@ -291,13 +308,15 @@ static class ProjectDirectoriesHelper {
private final ImmutableSet<WorkspacePath> rootDirectories;
private final ImmutableSet<WorkspacePath> excludeDirectories;
private final ImmutableSet<WorkspacePath> excludePathsForBazelQuery;
private final ImmutableSet<String> systemExcludes;

@VisibleForTesting
ProjectDirectoriesHelper(
Collection<WorkspacePath> rootDirectories, Collection<WorkspacePath> excludeDirectories, Collection<WorkspacePath> excludePathsForBazelQuery) {
Collection<WorkspacePath> rootDirectories, Collection<WorkspacePath> excludeDirectories, Collection<WorkspacePath> excludePathsForBazelQuery, ImmutableSet<String> systemExcludes) {
this.rootDirectories = ImmutableSet.copyOf(rootDirectories);
this.excludeDirectories = ImmutableSet.copyOf(excludeDirectories);
this.excludePathsForBazelQuery = ImmutableSet.copyOf(excludePathsForBazelQuery);
this.systemExcludes = systemExcludes;
}

boolean containsWorkspacePath(WorkspacePath workspacePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ public void testInferringTargetsFromDirectoriesSimple() throws Exception {
new ProjectDirectoriesHelper(
/* rootDirectories= */ ImmutableList.of(new WorkspacePath("foo")),
/* excludeDirectories= */ ImmutableSet.of(),
/* excludePathsForBazelQuery= */ ImmutableSet.of()
/* excludePathsForBazelQuery= */ ImmutableSet.of(),
ImmutableSet.of()

));

assertThat(helper.includesTarget(Label.create("//foo:target"))).isTrue();
Expand All @@ -203,7 +205,8 @@ public void testExplictTargetsOverrideInferredTargets() throws Exception {
new ProjectDirectoriesHelper(
/* rootDirectories= */ ImmutableList.of(new WorkspacePath("foo")),
/* excludeDirectories= */ ImmutableSet.of(new WorkspacePath("bar")),
/* excludePathsForBazelQuery= */ ImmutableSet.of()
/* excludePathsForBazelQuery= */ ImmutableSet.of(),
ImmutableSet.of()
));

assertThat(helper.includesTarget(Label.create("//foo:target"))).isFalse();
Expand All @@ -224,7 +227,8 @@ public void testInferredTargetsWithExcludedSubdirectories() {
new ProjectDirectoriesHelper(
/* rootDirectories= */ ImmutableList.of(new WorkspacePath("foo")),
/* excludeDirectories= */ ImmutableSet.of(new WorkspacePath("foo/bar")),
/* excludePathsForBazelQuery= */ ImmutableSet.of()
/* excludePathsForBazelQuery= */ ImmutableSet.of(),
ImmutableSet.of()
));

assertThat(helper.includesTarget(Label.create("//foo:target"))).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public abstract class PostQuerySyncData {
/* includes= */ ImmutableSet.of(),
/* excludes= */ ImmutableSet.of(),
/* languageClasses= */ ImmutableSet.of(),
/* testSources= */ ImmutableSet.of()))
/* testSources= */ ImmutableSet.of(),
/* systemExcludes = */ ImmutableSet.of()))
.setVcsState(Optional.empty())
.setBazelVersion(Optional.empty())
.setQuerySummary(QuerySummary.EMPTY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public abstract class ProjectDefinition {
/* includes= */ ImmutableSet.of(),
/* excludes= */ ImmutableSet.of(),
/* languageClasses= */ ImmutableSet.of(),
/* testSources= */ ImmutableSet.of());
/* testSources= */ ImmutableSet.of(),
/* systemExcludes = */ ImmutableSet.of());

/**
* Project includes, also know as root directories. Taken from the users {@code .blazeproject}
Expand All @@ -65,12 +66,16 @@ public abstract class ProjectDefinition {
*/
public abstract ImmutableSet<String> testSources();

public abstract ImmutableSet<String> systemExcludes();

public static ProjectDefinition create(
ImmutableSet<Path> includes,
ImmutableSet<Path> excludes,
ImmutableSet<QuerySyncLanguage> languageClasses,
ImmutableSet<String> testSources) {
return new AutoValue_ProjectDefinition(includes, excludes, languageClasses, testSources);
ImmutableSet<String> testSources,
ImmutableSet<String> systemExcludes
) {
return new AutoValue_ProjectDefinition(includes, excludes, languageClasses, testSources, systemExcludes);
}

/**
Expand All @@ -85,6 +90,11 @@ public QuerySpec deriveQuerySpec(Context<?> context, Path workspaceRoot) throws
}
}
for (Path exclude : projectExcludes()) {
if(systemExcludes().contains(exclude.toString())){
// We don't have to check if these dirs are valid for queries, because they also don't fall into //... wildcard
continue;
}

if (isValidPathForQuery(context, workspaceRoot.resolve(exclude))) {
result.excludePath(exclude);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ private void visitProjectDefinition(SnapshotProto.ProjectDefinition proto) {
proto.getIncludePathsList().stream().map(Path::of).collect(toImmutableSet()),
proto.getExcludePathsList().stream().map(Path::of).collect(toImmutableSet()),
QuerySyncLanguage.fromProtoList(proto.getLanguageClassesList()),
ImmutableSet.copyOf(proto.getTestSourcesList())));
ImmutableSet.copyOf(proto.getTestSourcesList()),
ImmutableSet.copyOf(proto.getSystemExcludesList())));
}

private void visitVcsState(SnapshotProto.VcsState proto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ message ProjectDefinition {
repeated string exclude_paths = 2;
repeated LanguageClass language_classes = 3;
repeated string test_sources = 4;
repeated string system_excludes = 5;
}

message VcsState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ abstract class GraphToProjectConverters {

public abstract ImmutableSet<String> testSources();

public abstract ImmutableSet<String> systemExcludes();

static Builder builder() {
return new AutoValue_GraphToProjectConverters.Builder()
.setPackageReader(EMPTY_PACKAGE_READER)
.setFileExistenceCheck(Predicates.alwaysTrue())
.setLanguageClasses(ImmutableSet.of())
.setProjectIncludes(ImmutableSet.of())
.setProjectExcludes(ImmutableSet.of())
.setSystemExcludes(ImmutableSet.of())
.setTestSources(ImmutableSet.of());
}

Expand All @@ -67,6 +70,8 @@ abstract static class Builder {

abstract Builder setTestSources(ImmutableSet<String> value);

abstract Builder setSystemExcludes(ImmutableSet<String> value);

abstract GraphToProjectConverters autoBuild();

public GraphToProjectConverter build() {
Expand All @@ -79,7 +84,8 @@ public GraphToProjectConverter build() {
info.projectIncludes(),
info.projectExcludes(),
info.languageClasses(),
info.testSources()),
info.testSources(),
info.systemExcludes()),
newDirectExecutorService(),
false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public BlazeProjectSnapshot sync(TestData testProject) throws IOException, Build
/* includes= */ ImmutableSet.copyOf(testProject.getRelativeSourcePaths()),
/* excludes= */ ImmutableSet.of(),
/* languageClasses= */ ImmutableSet.of(),
/* testSources= */ ImmutableSet.of());
/* testSources= */ ImmutableSet.of(),
/* systemExcludes = */ ImmutableSet.of()
);
QuerySummary querySummary = getQuerySummary(testProject);
PostQuerySyncData pqsd =
PostQuerySyncData.builder()
Expand Down

0 comments on commit 35552df

Please sign in to comment.