Merge "Fix incrementality bug with merged BUILD files"
diff --git a/bp2build/symlink_forest.go b/bp2build/symlink_forest.go
index 023ec96..7c39a11 100644
--- a/bp2build/symlink_forest.go
+++ b/bp2build/symlink_forest.go
@@ -285,6 +285,17 @@
// Neither is a directory. Merge them.
srcBuildFile := shared.JoinPath(topdir, srcChild)
generatedBuildFile := shared.JoinPath(topdir, buildFilesChild)
+ // Add the src and generated build files as dependencies so that bp2build
+ // is rerun when they change. Currently, this is only really necessary
+ // for srcBuildFile, because if we regenerate the generated build files
+ // we will always rerun the symlink forest generation as well. If that
+ // is later split up into separate, fully dependency-tracing steps, then
+ // we'll need srcBuildFile as well. Adding srcBuildFile here today
+ // technically makes it a dependency of bp2build_workspace_marker, which
+ // also implicitly outputs that file, but since bp2build_workspace_marker
+ // will always have a newer timestamp than the generatedBuildFile it
+ // shouldn't be a problem.
+ *acc = append(*acc, srcBuildFile, generatedBuildFile)
err = mergeBuildFiles(shared.JoinPath(topdir, forestChild), srcBuildFile, generatedBuildFile, cfg.IsEnvTrue("BP2BUILD_VERBOSE"))
if err != nil {
fmt.Fprintf(os.Stderr, "Error merging %s and %s: %s",