From c99c947c88a5050ed54ea19e80912adeec155738 Mon Sep 17 00:00:00 2001 From: "Lukacs T. Berki" Date: Wed, 24 Mar 2021 10:50:06 +0100 Subject: [PATCH] Make null builds always be null builds. Previously, soong.environment.used was written after build.ninja and if the amount of time that passed between the two was long enough, Ninja would decide that build.ninja is older than soong.environment.used and rebuild it. Test: test_null_build in bootstrap_test.sh in a loop. Change-Id: I5467da487e8e8f2646644b8a7fb9549b9ff18276 --- cmd/soong_build/main.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index 94efa4d7e..cd92b9b10 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -21,6 +21,7 @@ import ( "os" "path/filepath" "strings" + "time" "android/soong/shared" "github.com/google/blueprint/bootstrap" @@ -191,13 +192,24 @@ func main() { func writeUsedVariablesFile(path string, configuration android.Config) { data, err := shared.EnvFileContents(configuration.EnvDeps()) if err != nil { - fmt.Fprintf(os.Stderr, "error writing used variables file %s: %s", path, err) + fmt.Fprintf(os.Stderr, "error writing used variables file %s: %s\n", path, err) os.Exit(1) } err = ioutil.WriteFile(path, data, 0666) if err != nil { - fmt.Fprintf(os.Stderr, "error writing used variables file %s: %s", path, err) + fmt.Fprintf(os.Stderr, "error writing used variables file %s: %s\n", path, err) + os.Exit(1) + } + + // Touch the output Ninja file so that it's not older than the file we just + // wrote. We can't write the environment file earlier because one an access + // new environment variables while writing it. + outputNinjaFile := shared.JoinPath(topDir, bootstrap.CmdlineOutFile()) + currentTime := time.Now().Local() + err = os.Chtimes(outputNinjaFile, currentTime, currentTime) + if err != nil { + fmt.Fprintf(os.Stderr, "error touching output file %s: %s\n", outputNinjaFile, err) os.Exit(1) } }