Skip to content

Commit

Permalink
Update CompileCorrespondingBuildFilesAction.java
Browse files Browse the repository at this point in the history
Project Status API integration with bazel for CLion (#6585)

Integration with the new Project Status Widget that is added in CLion 242.

Implement py imports handling (#6606)

Some `py_...` rules allow for an `imports` attribute. The attribute
allows control over how the Python files are vended in terms of
modules. This change will mean that the use of the `imports`
attribute in Bazel targets is reflected in how the modules are
auto-completed and recognized in the IDE.

Update CompileCorrespondingBuildFilesAction.java

button name change

Update CompileCorrespondingBuildFilesAction.java

Added build folder action

Update BlazeBuildService.java

review remarks fix
  • Loading branch information
kitbuilder587 committed Aug 13, 2024
1 parent 90f0f5f commit 9f87422
Show file tree
Hide file tree
Showing 39 changed files with 1,524 additions and 575 deletions.
2 changes: 2 additions & 0 deletions aspect/intellij_info_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,15 @@ def collect_py_info(target, ctx, semantics, ide_info, ide_info_file, output_grou
args = getattr(ctx.rule.attr, "args", [])
data_deps = getattr(ctx.rule.attr, "data", [])
args = _do_starlark_string_expansion(ctx, "args", args, data_deps)
imports = getattr(ctx.rule.attr, "imports", [])

ide_info["py_ide_info"] = struct_omit_none(
launcher = py_launcher,
python_version = _get_python_version(ctx),
sources = sources,
srcs_version = _get_python_srcs_version(ctx),
args = args,
imports = imports,
)

update_sync_output_groups(output_groups, "intellij-info-py", depset([ide_info_file]))
Expand Down
13 changes: 7 additions & 6 deletions base/src/META-INF/blaze-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@
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"
icon="BlazeIcons.Logo">
</action>
<action id="Blaze.CompileCorrespondingBuildFiles"
class="com.google.idea.blaze.base.actions.CompileCorrespondingBuildFilesAction"
text="Compiles corresponding build files"
icon="BlazeIcons.BuildFile">
</action>
<action id="Blaze.UpdateDirectories"
class="com.google.idea.blaze.base.sync.actions.UpdateDirectoriesSyncAction"
text="Sync Directories"
Expand Down Expand Up @@ -207,8 +207,9 @@
<reference ref="Blaze.BuildDependencies"/>
<reference ref="Blaze.BuildReverseDependencies" />


<reference ref="Blaze.CompileFolder"/>
<reference ref="Blaze.PartialSync"/>
<reference ref="Blaze.CompileCorrespondingBuildFiles"/>
<reference ref="Blaze.AddSourceToProject"/>
<reference ref="Blaze.AddToQuerySyncProjectView"/>
<reference ref="Blaze.OpenCorrespondingBuildFile"/>
Expand Down

This file was deleted.

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
39 changes: 35 additions & 4 deletions base/src/com/google/idea/blaze/base/build/BlazeBuildService.java
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
28 changes: 23 additions & 5 deletions base/src/com/google/idea/blaze/base/ideinfo/PyIdeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ public final class PyIdeInfo implements ProtoWrapper<IntellijIdeInfo.PyIdeInfo>
private final PythonVersion version;
private final PythonSrcsVersion srcsVersion;
private final ImmutableList<String> args;
private final ImmutableList<String> imports;

private PyIdeInfo(
ImmutableList<ArtifactLocation> sources,
@Nullable Label launcher,
PythonVersion version,
PythonSrcsVersion srcsVersion,
ImmutableList<String> args) {
ImmutableList<String> args,
ImmutableList<String> imports) {
this.sources = sources;
this.launcher = launcher;
this.version = version;
this.srcsVersion = srcsVersion;
this.args = args;
this.imports = imports;
}

static PyIdeInfo fromProto(IntellijIdeInfo.PyIdeInfo proto) {
Expand All @@ -60,7 +63,8 @@ static PyIdeInfo fromProto(IntellijIdeInfo.PyIdeInfo proto) {
launcher,
proto.getPythonVersion(),
proto.getSrcsVersion(),
parseArgs(proto.getArgsList()));
parseArgs(proto.getArgsList()),
ImmutableList.copyOf(proto.getImportsList()));
}

/** Blaze has a layer of bash-like parsing to args - apply that here. */
Expand All @@ -87,6 +91,7 @@ public IntellijIdeInfo.PyIdeInfo toProto() {
builder.setPythonVersion(version);
builder.setSrcsVersion(srcsVersion);
builder.addAllArgs(encodeArgs(args));
builder.addAllImports(imports);
return builder.build();
}

Expand All @@ -111,6 +116,10 @@ public ImmutableList<String> getArgs() {
return args;
}

public ImmutableList<String> getImports() {
return imports;
}

public static Builder builder() {
return new Builder();
}
Expand All @@ -122,6 +131,7 @@ public static class Builder {
private PythonVersion version;
private PythonSrcsVersion srcsVersion;
private final ImmutableList.Builder<String> args = ImmutableList.builder();
private final ImmutableList.Builder<String> imports = ImmutableList.builder();

@CanIgnoreReturnValue
public Builder addSources(Iterable<ArtifactLocation> sources) {
Expand Down Expand Up @@ -153,8 +163,14 @@ public Builder addArgs(Iterable<String> args) {
return this;
}

@CanIgnoreReturnValue
public Builder addImports(Iterable<String> imports) {
this.imports.addAll(imports);
return this;
}

public PyIdeInfo build() {
return new PyIdeInfo(sources.build(), launcher, version, srcsVersion, args.build());
return new PyIdeInfo(sources.build(), launcher, version, srcsVersion, args.build(), imports.build());
}
}

Expand All @@ -170,6 +186,7 @@ public String toString() {
s.append(" python_version = ").append(version).append("\n");
s.append(" srcs_version = ").append(srcsVersion).append("\n");
s.append(" args = ").append(getArgs()).append("\n");
s.append(" imports = ").append(getImports()).append("\n");
s.append("}");
return s.toString();
}
Expand All @@ -187,11 +204,12 @@ public boolean equals(Object o) {
&& Objects.equals(launcher, pyIdeInfo.launcher)
&& Objects.equals(version, pyIdeInfo.version)
&& Objects.equals(srcsVersion, pyIdeInfo.srcsVersion)
&& Objects.equals(args, pyIdeInfo.args);
&& Objects.equals(args, pyIdeInfo.args)
&& Objects.equals(imports, pyIdeInfo.imports);
}

@Override
public int hashCode() {
return Objects.hash(sources, launcher, version, srcsVersion, args);
return Objects.hash(sources, launcher, version, srcsVersion, args, imports);
}
}
Loading

0 comments on commit 9f87422

Please sign in to comment.