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

Added build folder action #6615

Merged
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
7 changes: 7 additions & 0 deletions base/src/META-INF/blaze-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
class="com.google.idea.blaze.base.actions.CopyBlazeTargetPathAction"
text="Copy BUILD Target String">
</action>
<action id="Blaze.CompileFolder"
class="com.google.idea.blaze.base.actions.CompileFolderAction"
text="Compiles folder"
icon="AllIcons.Actions.Compile">
</action>
<action id="Blaze.PartialSync"
class="com.google.idea.blaze.base.sync.actions.PartialSyncAction"
text="Partially Sync File"
Expand Down Expand Up @@ -202,6 +207,8 @@
<reference ref="Blaze.BuildDependencies"/>
<reference ref="Blaze.BuildReverseDependencies" />


<reference ref="Blaze.CompileFolder"/>
<reference ref="Blaze.PartialSync"/>
<reference ref="Blaze.AddSourceToProject"/>
<reference ref="Blaze.AddToQuerySyncProjectView"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2024 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.base.actions;

import com.google.idea.blaze.base.build.BlazeBuildService;
import com.google.idea.blaze.base.model.primitives.*;
import com.google.idea.blaze.base.lang.buildfile.search.BlazePackage;
import com.google.idea.common.actions.ActionPresentationHelper;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;

import java.io.File;
import java.util.List;

/** Action to compile all build files in folder if folder picked or compile corresponding build file if file picked */
public class CompileFolderAction extends BlazeProjectAction {

@Override
protected void actionPerformedInBlazeProject(Project project, AnActionEvent e) {
runBuild(project, e);
}

protected void runBuild(Project project, AnActionEvent e) {
VirtualFile vf = e.getData(CommonDataKeys.VIRTUAL_FILE);
WorkspaceRoot root = WorkspaceRoot.fromProject(project);
WorkspacePath path = root.workspacePathForSafe(new File(vf.getPath()));
try {
List<TargetExpression> dt = List.of(TargetExpression.fromString("//" + path.toString() + "/..."));
BlazeBuildService.getInstance(project).buildFolder(vf.getName(),dt);
} catch (InvalidTargetException ex) {
throw new RuntimeException(ex);
}
}

@Override
protected void updateForBlazeProject(Project project, AnActionEvent e) {
Presentation presentation = e.getPresentation();

DataContext dataContext = e.getDataContext();
VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
BlazePackage blazePackage = BuildFileUtils.getBuildFile(project, virtualFile);

boolean enabled = blazePackage != null;
presentation.setVisible(enabled || !ActionPlaces.isPopupPlace(e.getPlace()));
presentation.setEnabled(enabled);

ActionPresentationHelper.of(e)
.disableIf(virtualFile == null)
.disableIf(!virtualFile.isDirectory())
.setText("Compile " + virtualFile.getName() + "/...:all")
.hideInContextMenuIfDisabled()
.commit();
}

@Override
protected QuerySyncStatus querySyncSupport() {
return QuerySyncStatus.SUPPORTED;
}
}
2 changes: 2 additions & 0 deletions base/src/com/google/idea/blaze/base/bazel/BuildSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public interface BuildSystem {
enum SyncStrategy {
/** Never parallelize sync builds. */
SERIAL,
/* Never parallelize and expand builds */
SERIAL_NOT_EXPAND,
/** Parallelize sync builds if it's deemed likely that doing so will be faster. */
DECIDE_AUTOMATICALLY,
/** Always parallelize sync builds. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,36 @@ public void buildFile(String fileName, ImmutableCollection<Label> targets) {
new NotificationScope(
project, "Make", title, title + " completed successfully", title + " failed"),
title,
buildSystem);
buildSystem,
SyncStrategy.SERIAL);
}


public void buildFolder(String folderName,List<TargetExpression> targets) {
if (!Blaze.isBlazeProject(project)) {
return;
}
ProjectViewSet projectView = ProjectViewManager.getInstance(project).getProjectViewSet();
BlazeProjectData projectData =
BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (projectView == null || projectData == null) {
return;
}

buildTargetExpressions(
project,
projectView,
projectData,
context -> targets,
new NotificationScope(
project,
"Make",
"Make " + folderName + "/...:all",
"Make" + folderName + "/...:all completed successfully",
"Make" + folderName + "/...:all failed"),
"Make " + folderName + "/...:all",
buildSystem,
SyncStrategy.SERIAL_NOT_EXPAND);
}

public void buildProject() {
Expand Down Expand Up @@ -161,7 +190,8 @@ public void buildProject() {
"Make project completed successfully",
"Make project failed"),
"Make project",
buildSystem);
buildSystem,
SyncStrategy.SERIAL);

// 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
Expand All @@ -176,7 +206,8 @@ private static void buildTargetExpressions(
ScopedFunction<List<TargetExpression>> targetsFunction,
NotificationScope notificationScope,
String taskName,
BuildSystem buildSystem) {
BuildSystem buildSystem,
SyncStrategy syncStrategy) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
// a gross hack to avoid breaking change detector tests. We had a few tests which relied on
// this never being called *and* relied on PROJECT_LAST_BUILD_TIMESTAMP_KEY being set
Expand Down Expand Up @@ -226,7 +257,7 @@ public Void execute(BlazeContext context) {
projectData.getWorkspacePathResolver(),
targets,
buildInvoker,
SyncStrategy.SERIAL);
syncStrategy);
if (shardedTargets.buildResult.status == BuildResult.Status.FATAL_ERROR) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver;
import com.google.idea.common.experiments.IntExperiment;
import com.intellij.openapi.project.Project;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -111,6 +112,9 @@ private enum ShardingApproach {

private static ShardingApproach getShardingApproach(
SyncStrategy parallelStrategy, ProjectViewSet viewSet) {
if (parallelStrategy == SyncStrategy.SERIAL_NOT_EXPAND) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this overrides the shard_sync setting in the PV, how about just keeping the old behavior here?

Copy link
Contributor Author

@kitbuilder587 kitbuilder587 Aug 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue here is that compile folder with shard_sync=true takes sooo much more time. For example, one of our project's folder compiles in 17s with shard_sync=true and in 1s with shard_sync=false. The main reason why we added this button was that sync time was very slow, and we wanted to speed up compile errors check. Ordinary user won't set shard_sync to false without any reason. We can add another setting to set shard_sync for build folder action, but I think in cases when OOM happens, you can just use Partial Sync instead

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's a good point. Btw what do you think about setting the default PV in tools/intellij/.managed.bazelproject with shard_sync: true?.

Example here https://github.com/bazelbuild/bazel/blob/master/tools/intellij/.managed.bazelproject

Copy link
Contributor Author

@kitbuilder587 kitbuilder587 Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I think It's a good idea, but I don't have a lot of knowledge about how often people want to use shard_sync=true. In our project we use it quite rarely, but I can't expand my PV on all users of the plugin.
Should I create another PR here or we can stay on current realization or may be another ideas?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeFrosch what do you think about it?

Copy link
Contributor Author

@kitbuilder587 kitbuilder587 Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, actually if I am not mistaken, shard-sync=false by default. We can delete this property in enum

Copy link
Contributor Author

@kitbuilder587 kitbuilder587 Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But anyway logically it would be better if shard-sync won't affect build. Oftenshard-sync=true is used for full sync of project if OOM happens. shard-sync=true will affect the build folder speed. (17s and 1s is big diff) I don't think that it will be used for the whole project often. With shard-sync=true build folder action is useless, because the diff between build and sync time isn't big. I think SERIAL_NOT_EXPAND anyway will be better

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but I can't guarantee it will be permanent. If it turns out to be misleading, we’ll adjust it to align with the shard_sync setting.

return ShardingApproach.SHARD_WITHOUT_EXPANDING;
}
if (shardingRequested(viewSet)) {
return ShardingApproach.EXPAND_AND_SHARD;
}
Expand Down
Loading