From dac90d33ca2d09db6fe521b9a509b0a239a5d9e3 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Thu, 25 Oct 2018 22:02:10 -0700 Subject: [PATCH] Add --empty-ninja-file for test usecases In cases that we want to run blueprint-based builds in many configurations to verify all of the logic works without errors, but don't care about running the final ninja file, writing it out only wastes time and disk space. So add a --empty-ninja-file option that writes out an empty ninja file instead. Our specific use case (Soong's build_test / multiproduct_kati) runs Soong several hundred times for different configurations, and the ninja files are around 1GB, which leads to several hundred gigabytes of disk writes (and persistent use during incremental generation). Change-Id: I0198dfb2f744ce22284c05d5214dac2ab5dc9700 --- bootstrap.bash | 5 +++++ bootstrap/bootstrap.go | 3 +++ bootstrap/command.go | 8 ++++++++ bootstrap/config.go | 1 + 4 files changed, 17 insertions(+) diff --git a/bootstrap.bash b/bootstrap.bash index c02fe81..08b85b5 100755 --- a/bootstrap.bash +++ b/bootstrap.bash @@ -93,6 +93,11 @@ done # If RUN_TESTS is set, behave like -t was passed in as an option. [ ! -z "$RUN_TESTS" ] && EXTRA_ARGS="${EXTRA_ARGS} -t" +# If EMPTY_NINJA_FILE is set, have the primary build write out a 0-byte ninja +# file instead of a full length one. Useful if you don't plan on executing the +# build, but want to verify the primary builder execution. +[ ! -z "$EMPTY_NINJA_FILE" ] && EXTRA_ARGS="${EXTRA_ARGS} --empty-ninja-file" + # Allow the caller to pass in a list of module files if [ -z "${BLUEPRINT_LIST_FILE}" ]; then BLUEPRINT_LIST_FILE="${BUILDDIR}/.bootstrap/bplist" diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go index ed33f20..3464c0b 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/bootstrap.go @@ -650,6 +650,9 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) { if s.config.moduleListFile != "" { extraSharedFlagArray = append(extraSharedFlagArray, "-l", s.config.moduleListFile) } + if s.config.emptyNinjaFile { + extraSharedFlagArray = append(extraSharedFlagArray, "--empty-ninja-file") + } extraSharedFlagString := strings.Join(extraSharedFlagArray, " ") var primaryBuilderName, primaryBuilderExtraFlags string diff --git a/bootstrap/command.go b/bootstrap/command.go index ac3fd00..da0191b 100644 --- a/bootstrap/command.go +++ b/bootstrap/command.go @@ -41,6 +41,7 @@ var ( runGoTests bool noGC bool moduleListFile string + emptyNinjaFile bool BuildDir string NinjaBuildDir string @@ -60,6 +61,7 @@ func init() { flag.BoolVar(&noGC, "nogc", false, "turn off GC for debugging") flag.BoolVar(&runGoTests, "t", false, "build and run go tests during bootstrap") flag.StringVar(&moduleListFile, "l", "", "file that lists filepaths to parse") + flag.BoolVar(&emptyNinjaFile, "empty-ninja-file", false, "write out a 0-byte ninja file") } func Main(ctx *blueprint.Context, config interface{}, extraNinjaFileDeps ...string) { @@ -122,7 +124,9 @@ func Main(ctx *blueprint.Context, config interface{}, extraNinjaFileDeps ...stri bootstrapConfig := &Config{ stage: stage, + topLevelBlueprintsFile: flag.Arg(0), + emptyNinjaFile: emptyNinjaFile, runGoTests: runGoTests, moduleListFile: moduleListFile, } @@ -175,6 +179,10 @@ func Main(ctx *blueprint.Context, config interface{}, extraNinjaFileDeps ...stri fatalf("error generating Ninja file contents: %s", err) } + if stage == StageMain && emptyNinjaFile { + buf.Reset() + } + const outFilePermissions = 0666 err = ioutil.WriteFile(outFile, buf.Bytes(), outFilePermissions) if err != nil { diff --git a/bootstrap/config.go b/bootstrap/config.go index 790ac4b..0772b0a 100644 --- a/bootstrap/config.go +++ b/bootstrap/config.go @@ -105,6 +105,7 @@ type Config struct { topLevelBlueprintsFile string + emptyNinjaFile bool runGoTests bool moduleListFile string }