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
This commit is contained in:
parent
09ef474b6f
commit
28f527c3da
2 changed files with 18 additions and 13 deletions
|
@ -33,6 +33,15 @@ func SetupOutDir(ctx Context, config Config) {
|
||||||
// can be parsed as ninja output.
|
// can be parsed as ninja output.
|
||||||
ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), "ninja_build"))
|
ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), "ninja_build"))
|
||||||
ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), ".out-dir"))
|
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(`
|
var combinedBuildNinjaTemplate = template.Must(template.New("combined").Parse(`
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -30,10 +29,11 @@ type Config struct{ *configImpl }
|
||||||
|
|
||||||
type configImpl struct {
|
type configImpl struct {
|
||||||
// From the environment
|
// From the environment
|
||||||
arguments []string
|
arguments []string
|
||||||
goma bool
|
goma bool
|
||||||
environ *Environment
|
environ *Environment
|
||||||
distDir string
|
distDir string
|
||||||
|
buildDateTime string
|
||||||
|
|
||||||
// From the arguments
|
// From the arguments
|
||||||
parallel int
|
parallel int
|
||||||
|
@ -244,18 +244,14 @@ func NewConfig(ctx Context, args ...string) Config {
|
||||||
|
|
||||||
outDir := ret.OutDir()
|
outDir := ret.OutDir()
|
||||||
buildDateTimeFile := filepath.Join(outDir, "build_date.txt")
|
buildDateTimeFile := filepath.Join(outDir, "build_date.txt")
|
||||||
var content string
|
|
||||||
if buildDateTime, ok := ret.environ.Get("BUILD_DATETIME"); ok && buildDateTime != "" {
|
if buildDateTime, ok := ret.environ.Get("BUILD_DATETIME"); ok && buildDateTime != "" {
|
||||||
content = buildDateTime
|
ret.buildDateTime = buildDateTime
|
||||||
} else {
|
} else {
|
||||||
content = strconv.FormatInt(time.Now().Unix(), 10)
|
ret.buildDateTime = strconv.FormatInt(time.Now().Unix(), 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Metrics != nil {
|
if ctx.Metrics != nil {
|
||||||
ctx.Metrics.SetBuildDateTime(content)
|
ctx.Metrics.SetBuildDateTime(ret.buildDateTime)
|
||||||
}
|
|
||||||
err := ioutil.WriteFile(buildDateTimeFile, []byte(content), 0777)
|
|
||||||
if err != nil {
|
|
||||||
ctx.Fatalln("Failed to write BUILD_DATETIME to file:", err)
|
|
||||||
}
|
}
|
||||||
ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)
|
ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue