diff --git a/base/src/com/google/idea/blaze/base/qsync/ProjectLoader.java b/base/src/com/google/idea/blaze/base/qsync/ProjectLoader.java index 61e55929c09..440d06ee0c0 100644 --- a/base/src/com/google/idea/blaze/base/qsync/ProjectLoader.java +++ b/base/src/com/google/idea/blaze/base/qsync/ProjectLoader.java @@ -153,9 +153,10 @@ public QuerySyncProject loadProject(BlazeContext context) throws BuildException ProjectProtoTransform.Registry projectTransformRegistry = new Registry(); SnapshotHolder graph = new SnapshotHolder(); graph.addListener((c, i) -> projectModificationTracker.incModificationCount()); + Path buildCachePath = getBuildCachePath(project); BuildArtifactCache artifactCache = BuildArtifactCache.create( - ideProjectBasePath.resolve(".buildcache"), + buildCachePath, createArtifactFetcher(), executor, QuerySyncManager.getInstance(project).cacheCleanRequest()); @@ -266,6 +267,10 @@ public QuerySyncProject loadProject(BlazeContext context) throws BuildException return querySyncProject; } + public static Path getBuildCachePath(Project project) { + return Paths.get(checkNotNull(project.getBasePath())).resolve(".buildcache"); + } + private ParallelPackageReader createWorkspaceRelativePackageReader() { return new ParallelPackageReader(executor, new PackageStatementParser()); } diff --git a/base/src/com/google/idea/blaze/base/sync/data/BlazeDataStorage.java b/base/src/com/google/idea/blaze/base/sync/data/BlazeDataStorage.java index f8d803c46b1..011544d4441 100644 --- a/base/src/com/google/idea/blaze/base/sync/data/BlazeDataStorage.java +++ b/base/src/com/google/idea/blaze/base/sync/data/BlazeDataStorage.java @@ -15,17 +15,26 @@ */ package com.google.idea.blaze.base.sync.data; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.idea.blaze.base.logging.LoggedDirectoryProvider; +import com.google.idea.blaze.base.model.primitives.WorkspaceRoot; +import com.google.idea.blaze.base.qsync.ProjectLoader; import com.google.idea.blaze.base.settings.Blaze; import com.google.idea.blaze.base.settings.BlazeImportSettings; import com.google.idea.blaze.base.settings.BlazeImportSettingsManager; +import com.google.idea.blaze.qsync.deps.ArtifactDirectories; +import com.google.idea.blaze.qsync.project.ProjectPath; import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.project.Project; import java.io.File; +import java.nio.file.Path; +import java.util.Collection; import java.util.Optional; /** Defines where we store our blaze project data. */ @@ -66,6 +75,28 @@ private static File getProjectConfigurationDir() { return new File(PathManager.getSystemPath(), "blaze/projects").getAbsoluteFile(); } + /** + * DO NOT USE: Returns a best-effort list of all project data directories used by the IDE. + */ + public static Collection getMaybeAllProjectDataDirs(Project project) { + BlazeImportSettings importSettings = BlazeImportSettingsManager.getInstance(project) + .getImportSettings(); + if (importSettings == null) { + throw new IllegalStateException("BlazeImportSettings unavailable"); + } + final var pathResolver = + ProjectPath.Resolver.create( + WorkspaceRoot.fromImportSettings(importSettings).path(), + Path.of( + importSettings + .getProjectDataDirectory())); + return ImmutableList.of( + getProjectDataDir(importSettings).toPath(), + pathResolver.resolve(ArtifactDirectories.ROOT), + ProjectLoader.getBuildCachePath(project) + ); + } + /** * Configuration which includes the plugin's own project-specific data directory (used for * artifacts related to IntelliJ's project setup - module configurations, locally cached jars, diff --git a/querysync/java/com/google/idea/blaze/qsync/deps/ArtifactDirectories.java b/querysync/java/com/google/idea/blaze/qsync/deps/ArtifactDirectories.java index 2289faf2450..f26a8f2ce06 100644 --- a/querysync/java/com/google/idea/blaze/qsync/deps/ArtifactDirectories.java +++ b/querysync/java/com/google/idea/blaze/qsync/deps/ArtifactDirectories.java @@ -21,7 +21,7 @@ /** Static helpers for managing directories in the project artifact store. */ public class ArtifactDirectories { - private static final ProjectPath ROOT = ProjectPath.projectRelative(".bazel"); + public static final ProjectPath ROOT = ProjectPath.projectRelative(".bazel"); /** * By default, all project artifacts go in this directory, at a path matching their bazel output