Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrgodsey committed May 10, 2023
1 parent 7b83070 commit c8a906c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public void compileFilesAndDependencies(Collection<? extends VirtualFile> files)
//BlazeSyncManager.getInstance(project).workingSetSync("Compile files and dependencies");
// TODO: use partialSync with targets verived from `files` (see logic in
// BlazeSyncParams.sourceFilesToSync
compileProject();
//project.putUserData(PROJECT_LAST_BUILD_TIMESTAMP_KEY, System.currentTimeMillis());
//compileProject();
BlazeBuildService.getInstance(project).buildFiles(files);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ public ImmutableList<File> getClassFiles(BlazeProjectData blazeProjectData) {

@Override
public ImmutableList<File> getSourceFiles(BlazeProjectData blazeProjectData) {
// TODO: look into for source resolution
// Unconditionally add any linked to source jars. BlazeJarLibrary doesn't do this - it only
// attaches sources for libraries that the user explicitly asks for. We don't do that for two
// reasons: 1) all the logic for attaching sources to a library (AttachSourceJarAction,
Expand Down
57 changes: 57 additions & 0 deletions base/src/com/google/idea/blaze/base/build/BlazeBuildService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.idea.blaze.base.build;

import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.FutureCallback;
Expand All @@ -27,12 +28,14 @@
import com.google.idea.blaze.base.bazel.BuildSystem.BuildInvoker;
import com.google.idea.blaze.base.bazel.BuildSystem.SyncStrategy;
import com.google.idea.blaze.base.command.BlazeInvocationContext;
import com.google.idea.blaze.base.dependencies.BlazeQuerySourceToTargetProvider;
import com.google.idea.blaze.base.experiments.ExperimentScope;
import com.google.idea.blaze.base.filecache.FileCaches;
import com.google.idea.blaze.base.issueparser.BlazeIssueParser;
import com.google.idea.blaze.base.model.BlazeProjectData;
import com.google.idea.blaze.base.model.primitives.Label;
import com.google.idea.blaze.base.model.primitives.TargetExpression;
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 @@ -58,16 +61,23 @@
import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
import com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder;
import com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder.ShardedTargetsResult;
import com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver;
import com.google.idea.blaze.base.toolwindow.Task;
import com.google.idea.blaze.base.util.SaveUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.VirtualFile;

import java.io.File;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Future;
import javax.annotation.Nullable;

import static com.google.common.collect.ImmutableList.toImmutableList;

/** Utility to build various collections of targets. */
public class BlazeBuildService {
private static final Key<Long> PROJECT_LAST_BUILD_TIMESTAMP_KEY =
Expand Down Expand Up @@ -112,6 +122,53 @@ public void buildFile(String fileName, ImmutableCollection<Label> targets) {
buildSystem);
}

public void buildFiles(Collection<? extends VirtualFile> files) {
if (!Blaze.isBlazeProject(project)) {
return;
}
ProjectViewSet projectView = ProjectViewManager.getInstance(project).getProjectViewSet();
BlazeProjectData projectData =
BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (projectView == null || projectData == null) {
return;
}
WorkspacePathResolver resolver = projectData.getWorkspacePathResolver();

ImmutableList.Builder<WorkspacePath> pathsToQuery = ImmutableList.builder();
for (VirtualFile file : files) {
WorkspacePath path = resolver.getWorkspacePath(new File(file.getPath()));
if (path == null) {
continue;
}
pathsToQuery.add(path);
}

ScopedFunction<List<TargetExpression>> targets =
context ->
BlazeQuerySourceToTargetProvider.getTargetsBuildingSourceFiles(
project, pathsToQuery.build(), context, BlazeInvocationContext.ContextType.Other
).stream().map(t -> t.label).collect(toImmutableList());

buildTargetExpressions(
project,
projectView,
projectData,
targets,
new NotificationScope(
project,
"Make",
"Make project",
"Make project completed successfully",
"Make project failed"),
"Make project",
buildSystem);

// In case the user touched a file, but didn't change its content. The user will get a false
// positive for class file out of date. We need a way for the user to suppress the false
// message. Clicking the "build project" link should at least make the message go away.
project.putUserData(PROJECT_LAST_BUILD_TIMESTAMP_KEY, System.currentTimeMillis());
}

public void buildProject() {
if (!Blaze.isBlazeProject(project)) {
return;
Expand Down

0 comments on commit c8a906c

Please sign in to comment.