From 28f527c3daf850c784defd5994ed6486a285ffce Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 26 Nov 2019 16:19:04 -0800 Subject: [PATCH] Write BUILD_DATETIME_FILE after SetupOutDir Delay writing the BUILD_DATETIME_FILE until after the out directory has been created. Test: cuj_tests Change-Id: Ice6f34d003f93c26b5d2d0b64f92b11efe16c2d4 --- ui/build/build.go | 9 +++++++++ ui/build/config.go | 22 +++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ui/build/build.go b/ui/build/build.go index 6a1931419..7dfb900ef 100644 --- a/ui/build/build.go +++ b/ui/build/build.go @@ -33,6 +33,15 @@ func SetupOutDir(ctx Context, config Config) { // can be parsed as ninja output. ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), "ninja_build")) ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), ".out-dir")) + + if buildDateTimeFile, ok := config.environ.Get("BUILD_DATETIME_FILE"); ok { + err := ioutil.WriteFile(buildDateTimeFile, []byte(config.buildDateTime), 0777) + if err != nil { + ctx.Fatalln("Failed to write BUILD_DATETIME to file:", err) + } + } else { + ctx.Fatalln("Missing BUILD_DATETIME_FILE") + } } var combinedBuildNinjaTemplate = template.Must(template.New("combined").Parse(` diff --git a/ui/build/config.go b/ui/build/config.go index 876bfe024..565f0333f 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -15,7 +15,6 @@ package build import ( - "io/ioutil" "os" "path/filepath" "runtime" @@ -30,10 +29,11 @@ type Config struct{ *configImpl } type configImpl struct { // From the environment - arguments []string - goma bool - environ *Environment - distDir string + arguments []string + goma bool + environ *Environment + distDir string + buildDateTime string // From the arguments parallel int @@ -244,18 +244,14 @@ func NewConfig(ctx Context, args ...string) Config { outDir := ret.OutDir() buildDateTimeFile := filepath.Join(outDir, "build_date.txt") - var content string if buildDateTime, ok := ret.environ.Get("BUILD_DATETIME"); ok && buildDateTime != "" { - content = buildDateTime + ret.buildDateTime = buildDateTime } else { - content = strconv.FormatInt(time.Now().Unix(), 10) + ret.buildDateTime = strconv.FormatInt(time.Now().Unix(), 10) } + if ctx.Metrics != nil { - ctx.Metrics.SetBuildDateTime(content) - } - err := ioutil.WriteFile(buildDateTimeFile, []byte(content), 0777) - if err != nil { - ctx.Fatalln("Failed to write BUILD_DATETIME to file:", err) + ctx.Metrics.SetBuildDateTime(ret.buildDateTime) } ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)