Merge remote-tracking branch 'aosp/upstream'

* aosp/upstream:
  Stop writing depfiles from Glob singleton

Bug: 159845846
Test: manually check that changes to directories cause glob re-execution
Test: second build after a clean does not rerun soong_build
Change-Id: I1f257f3f11f70cb407397854fd85292dd0d0b08e
diff --git a/bootstrap/glob.go b/bootstrap/glob.go
index 52dbf2f..207db5b 100644
--- a/bootstrap/glob.go
+++ b/bootstrap/glob.go
@@ -21,7 +21,6 @@
 	"strings"
 
 	"github.com/google/blueprint"
-	"github.com/google/blueprint/deptools"
 	"github.com/google/blueprint/pathtools"
 )
 
@@ -130,15 +129,18 @@
 		if s.writeRule {
 			depFile := fileListFile + ".d"
 
+			// We need to write the file list here so that it has an older modified date
+			// than the build.ninja (otherwise we'd run the primary builder twice on
+			// every new glob)
+			//
+			// We don't need to write the depfile because we're guaranteed that ninja
+			// will run the command at least once (to record it into the ninja_log), so
+			// the depfile will be loaded from that execution.
 			fileList := strings.Join(g.Files, "\n") + "\n"
 			err := pathtools.WriteFileIfChanged(absolutePath(fileListFile), []byte(fileList), 0666)
 			if err != nil {
 				panic(fmt.Errorf("error writing %s: %s", fileListFile, err))
 			}
-			err = deptools.WriteDepFile(absolutePath(depFile), fileListFile, g.Deps)
-			if err != nil {
-				panic(fmt.Errorf("error writing %s: %s", depFile, err))
-			}
 
 			GlobFile(ctx, g.Pattern, g.Excludes, fileListFile, depFile)
 		} else {