Skip to content

Commit

Permalink
Full sync on build file changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mildagle committed Jan 30, 2023
1 parent 0ebf436 commit 7400844
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions aspect/fast_build_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def _fast_build_info_impl(target, ctx):
"workspace_name": ctx.workspace_name,
"label": stringify_label(target.label),
"dependencies": [stringify_label(t.label) for t in dep_targets],
"build_file_path": ctx.build_file_path,
}

write_output = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public abstract class FastBuildBlazeData {

public abstract Optional<ProtoInfo> protoInfo();

public abstract String buildFilePath();

public static Builder builder() {
return new AutoValue_FastBuildBlazeData.Builder()
.setDependencies(ImmutableList.of())
Expand All @@ -87,6 +89,8 @@ public abstract static class Builder {
public abstract Builder setProtoInfo(ProtoInfo protoInfo);

public abstract FastBuildBlazeData build();

public abstract Builder setBuildFilePath(String label);
}

static FastBuildBlazeData fromProto(FastBuildInfo.FastBuildBlazeData proto) {
Expand All @@ -97,7 +101,8 @@ static FastBuildBlazeData fromProto(FastBuildInfo.FastBuildBlazeData proto) {
.setWorkspaceName(proto.getWorkspaceName())
.setDependencies(
proto.getDependenciesList().stream().map(Label::fromProto).collect(toSet()))
.setData(convertDataToMap(proto.getDataList()));
.setData(convertDataToMap(proto.getDataList()))
.setBuildFilePath(proto.getBuildFilePath());
if (proto.hasAndroidInfo()) {
builder.setAndroidInfo(AndroidInfo.fromProto(proto.getAndroidInfo()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.idea.blaze.base.model.primitives.Label;
import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
import com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder;
import com.google.idea.blaze.java.fastbuild.FastBuildState.BuildOutput;
Expand Down Expand Up @@ -248,20 +249,20 @@ public void after(List<? extends VFileEvent> events) {
.map(File::new)
.collect(toImmutableSet());

ImmutableSet<File> changedProtoFiles =
ImmutableSet<File> changedNonCompilableFiles =
changedFilePaths.stream()
.filter(f -> f.endsWith(".proto"))
.filter(f -> f.endsWith(".proto") || f.endsWith(".bazel"))
.map(File::new)
.collect(toImmutableSet());

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

if (!changedCompilableFiles.isEmpty() || !changedProtoFiles.isEmpty()) {
if (!changedCompilableFiles.isEmpty() || !changedNonCompilableFiles.isEmpty()) {
labelData.values()
.forEach(data -> data.updateChangedSources(changedCompilableFiles,
changedProtoFiles));
changedNonCompilableFiles));
}

return null;
Expand Down Expand Up @@ -309,6 +310,9 @@ private ImmutableSet<File> getSourceFilesRecursively(
Set<File> sourceFiles = new HashSet<>();
ArtifactLocationDecoder decoder =
projectDataManager.getBlazeProjectData().getArtifactLocationDecoder();

String workSpaceRootPath = WorkspaceRoot.fromProject(project).directory().getAbsolutePath();

SuccessorsFunction<FastBuildBlazeData> graph = l -> getDependencies(blazeData, l);
Traverser.forGraph(graph)
.breadthFirst(data)
Expand All @@ -319,15 +323,24 @@ private ImmutableSet<File> getSourceFilesRecursively(
.map(decoder::decode)
.filter(f -> f.getName().endsWith(".java") || f.getName().endsWith(".scala"))
.forEach(sourceFiles::add);
addBuildFile(sourceFiles, workSpaceRootPath, d.buildFilePath());
} else if (d.protoInfo().isPresent()) {
d.protoInfo().get().sources().stream()
.map(decoder::decode)
.forEach(sourceFiles::add);
addBuildFile(sourceFiles, workSpaceRootPath, d.buildFilePath());
}
});
return ImmutableSet.copyOf(sourceFiles);
}

private static void addBuildFile(Set<File> sourceFiles ,String workSpaceRootPath, String buildFilePath) {
File buildFile = new File(workSpaceRootPath, buildFilePath);
if (buildFile.exists()) {
sourceFiles.add(buildFile);
}
}

private static ImmutableSet<FastBuildBlazeData> getDependencies(
Map<Label, FastBuildBlazeData> map, FastBuildBlazeData labelData) {
return labelData.dependencies().stream()
Expand Down
1 change: 1 addition & 0 deletions proto/fast_build_info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ message FastBuildBlazeData {
JavaInfo java_info = 6;
JavaToolchainInfo java_toolchain_info = 7;
ProtoInfo proto_info = 8;
string build_file_path = 9;
}

message Data {
Expand Down

0 comments on commit 7400844

Please sign in to comment.