Skip to content

Commit 5b4f4a6

Browse files
committed
Full sync on build file changes
1 parent 60b5109 commit 5b4f4a6

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

aspect/fast_build_info.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def _fast_build_info_impl(target, ctx):
2323
"workspace_name": ctx.workspace_name,
2424
"label": stringify_label(target.label),
2525
"dependencies": [stringify_label(t.label) for t in dep_targets],
26+
"build_file_path": ctx.build_file_path,
2627
}
2728

2829
write_output = False

java/src/com/google/idea/blaze/java/fastbuild/FastBuildBlazeData.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public abstract class FastBuildBlazeData {
6161

6262
public abstract Optional<ProtoInfo> protoInfo();
6363

64+
public abstract String buildFilePath();
65+
6466
public static Builder builder() {
6567
return new AutoValue_FastBuildBlazeData.Builder()
6668
.setDependencies(ImmutableList.of())
@@ -87,6 +89,8 @@ public abstract static class Builder {
8789
public abstract Builder setProtoInfo(ProtoInfo protoInfo);
8890

8991
public abstract FastBuildBlazeData build();
92+
93+
public abstract Builder setBuildFilePath(String label);
9094
}
9195

9296
static FastBuildBlazeData fromProto(FastBuildInfo.FastBuildBlazeData proto) {
@@ -97,7 +101,8 @@ static FastBuildBlazeData fromProto(FastBuildInfo.FastBuildBlazeData proto) {
97101
.setWorkspaceName(proto.getWorkspaceName())
98102
.setDependencies(
99103
proto.getDependenciesList().stream().map(Label::fromProto).collect(toSet()))
100-
.setData(convertDataToMap(proto.getDataList()));
104+
.setData(convertDataToMap(proto.getDataList()))
105+
.setBuildFilePath(proto.getBuildFilePath());
101106
if (proto.hasAndroidInfo()) {
102107
builder.setAndroidInfo(AndroidInfo.fromProto(proto.getAndroidInfo()));
103108
}

java/src/com/google/idea/blaze/java/fastbuild/FastBuildChangedFilesService.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.google.common.util.concurrent.ListenableFuture;
3232
import com.google.common.util.concurrent.ListeningExecutorService;
3333
import com.google.idea.blaze.base.model.primitives.Label;
34+
import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
3435
import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
3536
import com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder;
3637
import com.google.idea.blaze.java.fastbuild.FastBuildState.BuildOutput;
@@ -248,20 +249,20 @@ public void after(List<? extends VFileEvent> events) {
248249
.map(File::new)
249250
.collect(toImmutableSet());
250251

251-
ImmutableSet<File> changedProtoFiles =
252+
ImmutableSet<File> changedNonCompilableFiles =
252253
changedFilePaths.stream()
253-
.filter(f -> f.endsWith(".proto"))
254+
.filter(f -> f.endsWith(".proto") || f.endsWith(".bazel"))
254255
.map(File::new)
255256
.collect(toImmutableSet());
256257

257258
// TODO(b/145386688): Access should be guarded by enclosing instance
258259
// 'com.google.idea.blaze.java.fastbuild.FastBuildChangedFilesService' of 'data',
259260
// which is not accessible in this scope
260261

261-
if (!changedCompilableFiles.isEmpty() || !changedProtoFiles.isEmpty()) {
262+
if (!changedCompilableFiles.isEmpty() || !changedNonCompilableFiles.isEmpty()) {
262263
labelData.values()
263264
.forEach(data -> data.updateChangedSources(changedCompilableFiles,
264-
changedProtoFiles));
265+
changedNonCompilableFiles));
265266
}
266267

267268
return null;
@@ -309,6 +310,9 @@ private ImmutableSet<File> getSourceFilesRecursively(
309310
Set<File> sourceFiles = new HashSet<>();
310311
ArtifactLocationDecoder decoder =
311312
projectDataManager.getBlazeProjectData().getArtifactLocationDecoder();
313+
314+
String workSpaceRootPath = WorkspaceRoot.fromProject(project).directory().getAbsolutePath();
315+
312316
SuccessorsFunction<FastBuildBlazeData> graph = l -> getDependencies(blazeData, l);
313317
Traverser.forGraph(graph)
314318
.breadthFirst(data)
@@ -319,15 +323,24 @@ private ImmutableSet<File> getSourceFilesRecursively(
319323
.map(decoder::decode)
320324
.filter(f -> f.getName().endsWith(".java") || f.getName().endsWith(".scala"))
321325
.forEach(sourceFiles::add);
326+
addBuildFile(sourceFiles, workSpaceRootPath, d.buildFilePath());
322327
} else if (d.protoInfo().isPresent()) {
323328
d.protoInfo().get().sources().stream()
324329
.map(decoder::decode)
325330
.forEach(sourceFiles::add);
331+
addBuildFile(sourceFiles, workSpaceRootPath, d.buildFilePath());
326332
}
327333
});
328334
return ImmutableSet.copyOf(sourceFiles);
329335
}
330336

337+
private static void addBuildFile(Set<File> sourceFiles ,String workSpaceRootPath, String buildFilePath) {
338+
File buildFile = new File(workSpaceRootPath, buildFilePath);
339+
if (buildFile.exists()) {
340+
sourceFiles.add(buildFile);
341+
}
342+
}
343+
331344
private static ImmutableSet<FastBuildBlazeData> getDependencies(
332345
Map<Label, FastBuildBlazeData> map, FastBuildBlazeData labelData) {
333346
return labelData.dependencies().stream()

proto/fast_build_info.proto

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ message FastBuildBlazeData {
3030
JavaInfo java_info = 6;
3131
JavaToolchainInfo java_toolchain_info = 7;
3232
ProtoInfo proto_info = 8;
33+
string build_file_path = 9;
3334
}
3435

3536
message Data {

0 commit comments

Comments
 (0)