Run globs during earlier bootstrap phases
Instead of sometimes re-running minibp/the primary builder during the next phase, run bpglob earlier to check dependencies. We've run into issues where the environment is slightly different between bootstrapping phase and the main build phase. It's also a problem because our primary builder (Soong) exports information used by another tool (Kati) that runs in between the bootstrapping phases and the main phase. When Soong would run in the main phase, it could get out of sync, and would require the build to be run again. To do this, add a "subninja" include a build-globs.ninja file to each build.ninja file. The first time, this will be an empty file, but we'll always run minibp / the primary builder anyway. When the builder runs, in addition to writing a dependency file, write out the build-globs.ninja file with the rules to run bpglob. Since bpglob may need to be run very early, before it would normally be built, build it with microfactory. Change-Id: I89fcd849a8729e892f163d40060ab90b5d4dfa5d
This commit is contained in:
parent
9cbbb8b91d
commit
ab223a512b
14 changed files with 160 additions and 48 deletions
|
@ -28,6 +28,8 @@ source "${BLUEPRINTDIR}/microfactory/microfactory.bash"
|
||||||
|
|
||||||
BUILDDIR="${BUILDDIR}/.minibootstrap" build_go minibp github.com/google/blueprint/bootstrap/minibp
|
BUILDDIR="${BUILDDIR}/.minibootstrap" build_go minibp github.com/google/blueprint/bootstrap/minibp
|
||||||
|
|
||||||
|
BUILDDIR="${BUILDDIR}/.minibootstrap" build_go bpglob github.com/google/blueprint/bootstrap/bpglob
|
||||||
|
|
||||||
# Build the bootstrap build.ninja
|
# Build the bootstrap build.ninja
|
||||||
"${NINJA}" -w dupbuild=err -f "${BUILDDIR}/.minibootstrap/build.ninja"
|
"${NINJA}" -w dupbuild=err -f "${BUILDDIR}/.minibootstrap/build.ninja"
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,10 @@ echo "extraArgs = $EXTRA_ARGS" >> $BUILDDIR/.minibootstrap/build.ninja
|
||||||
echo "builddir = $NINJA_BUILDDIR" >> $BUILDDIR/.minibootstrap/build.ninja
|
echo "builddir = $NINJA_BUILDDIR" >> $BUILDDIR/.minibootstrap/build.ninja
|
||||||
echo "include $BLUEPRINTDIR/bootstrap/build.ninja" >> $BUILDDIR/.minibootstrap/build.ninja
|
echo "include $BLUEPRINTDIR/bootstrap/build.ninja" >> $BUILDDIR/.minibootstrap/build.ninja
|
||||||
|
|
||||||
|
if [ ! -f "$BUILDDIR/.minibootstrap/build-globs.ninja" ]; then
|
||||||
|
touch "$BUILDDIR/.minibootstrap/build-globs.ninja"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "BLUEPRINT_BOOTSTRAP_VERSION=2" > $BUILDDIR/.blueprint.bootstrap
|
echo "BLUEPRINT_BOOTSTRAP_VERSION=2" > $BUILDDIR/.blueprint.bootstrap
|
||||||
echo "SRCDIR=\"${SRCDIR}\"" >> $BUILDDIR/.blueprint.bootstrap
|
echo "SRCDIR=\"${SRCDIR}\"" >> $BUILDDIR/.blueprint.bootstrap
|
||||||
echo "BLUEPRINTDIR=\"${BLUEPRINTDIR}\"" >> $BUILDDIR/.blueprint.bootstrap
|
echo "BLUEPRINTDIR=\"${BLUEPRINTDIR}\"" >> $BUILDDIR/.blueprint.bootstrap
|
||||||
|
|
|
@ -17,6 +17,8 @@ package bootstrap
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/build"
|
"go/build"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -118,14 +120,14 @@ var (
|
||||||
|
|
||||||
generateBuildNinja = pctx.StaticRule("build.ninja",
|
generateBuildNinja = pctx.StaticRule("build.ninja",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: "$builder $extra -b $buildDir -n $ninjaBuildDir -d $out.d -o $out $in",
|
Command: "$builder $extra -b $buildDir -n $ninjaBuildDir -d $out.d -globFile $globFile -o $out $in",
|
||||||
CommandDeps: []string{"$builder"},
|
CommandDeps: []string{"$builder"},
|
||||||
Description: "$builder $out",
|
Description: "$builder $out",
|
||||||
Deps: blueprint.DepsGCC,
|
Deps: blueprint.DepsGCC,
|
||||||
Depfile: "$out.d",
|
Depfile: "$out.d",
|
||||||
Restat: true,
|
Restat: true,
|
||||||
},
|
},
|
||||||
"builder", "extra", "generator")
|
"builder", "extra", "generator", "globFile")
|
||||||
|
|
||||||
// Work around a Ninja issue. See https://github.com/martine/ninja/pull/634
|
// Work around a Ninja issue. See https://github.com/martine/ninja/pull/634
|
||||||
phony = pctx.StaticRule("phony",
|
phony = pctx.StaticRule("phony",
|
||||||
|
@ -668,32 +670,33 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
|
||||||
topLevelBlueprints := filepath.Join("$srcDir",
|
topLevelBlueprints := filepath.Join("$srcDir",
|
||||||
filepath.Base(s.config.topLevelBlueprintsFile))
|
filepath.Base(s.config.topLevelBlueprintsFile))
|
||||||
|
|
||||||
mainNinjaFile := filepath.Join("$buildDir", "build.ninja")
|
|
||||||
primaryBuilderNinjaFile := filepath.Join(bootstrapDir, "build.ninja")
|
|
||||||
|
|
||||||
ctx.SetNinjaBuildDir(pctx, "${ninjaBuildDir}")
|
ctx.SetNinjaBuildDir(pctx, "${ninjaBuildDir}")
|
||||||
|
|
||||||
// Build the main build.ninja
|
if s.config.stage == StagePrimary {
|
||||||
ctx.Build(pctx, blueprint.BuildParams{
|
mainNinjaFile := filepath.Join("$buildDir", "build.ninja")
|
||||||
Rule: generateBuildNinja,
|
primaryBuilderNinjaGlobFile := filepath.Join(BuildDir, bootstrapSubDir, "build-globs.ninja")
|
||||||
Outputs: []string{mainNinjaFile},
|
|
||||||
Inputs: []string{topLevelBlueprints},
|
|
||||||
Args: map[string]string{
|
|
||||||
"builder": primaryBuilderFile,
|
|
||||||
"extra": primaryBuilderExtraFlags,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
// Add a way to rebuild the primary build.ninja so that globs works
|
if _, err := os.Stat(primaryBuilderNinjaGlobFile); os.IsNotExist(err) {
|
||||||
ctx.Build(pctx, blueprint.BuildParams{
|
err = ioutil.WriteFile(primaryBuilderNinjaGlobFile, nil, 0666)
|
||||||
Rule: generateBuildNinja,
|
if err != nil {
|
||||||
Outputs: []string{primaryBuilderNinjaFile},
|
ctx.Errorf("Failed to create empty ninja file: %s", err)
|
||||||
Inputs: []string{topLevelBlueprints},
|
}
|
||||||
Args: map[string]string{
|
}
|
||||||
"builder": minibpFile,
|
|
||||||
"extra": extraSharedFlagString,
|
ctx.AddSubninja(primaryBuilderNinjaGlobFile)
|
||||||
},
|
|
||||||
})
|
// Build the main build.ninja
|
||||||
|
ctx.Build(pctx, blueprint.BuildParams{
|
||||||
|
Rule: generateBuildNinja,
|
||||||
|
Outputs: []string{mainNinjaFile},
|
||||||
|
Inputs: []string{topLevelBlueprints},
|
||||||
|
Args: map[string]string{
|
||||||
|
"builder": primaryBuilderFile,
|
||||||
|
"extra": primaryBuilderExtraFlags,
|
||||||
|
"globFile": primaryBuilderNinjaGlobFile,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if s.config.stage == StageMain {
|
if s.config.stage == StageMain {
|
||||||
if primaryBuilderName == "minibp" {
|
if primaryBuilderName == "minibp" {
|
||||||
|
|
|
@ -7,8 +7,11 @@
|
||||||
|
|
||||||
ninja_required_version = 1.7.0
|
ninja_required_version = 1.7.0
|
||||||
|
|
||||||
|
myGlobs = ${bootstrapBuildDir}/.minibootstrap/build-globs.ninja
|
||||||
|
subninja ${myGlobs}
|
||||||
|
|
||||||
rule build.ninja
|
rule build.ninja
|
||||||
command = ${builder} ${extraArgs} -b ${bootstrapBuildDir} -n ${builddir} -d ${out}.d -o ${out} ${in}
|
command = ${builder} ${extraArgs} -b ${bootstrapBuildDir} -n ${builddir} -d ${out}.d -globFile ${myGlobs} -o ${out} ${in}
|
||||||
deps = gcc
|
deps = gcc
|
||||||
depfile = ${out}.d
|
depfile = ${out}.d
|
||||||
description = ${builder} ${out}
|
description = ${builder} ${out}
|
||||||
|
|
|
@ -30,9 +30,9 @@ const logFileName = ".ninja_log"
|
||||||
|
|
||||||
// removeAbandonedFilesUnder removes any files that appear in the Ninja log, and
|
// removeAbandonedFilesUnder removes any files that appear in the Ninja log, and
|
||||||
// are prefixed with one of the `under` entries, but that are not currently
|
// are prefixed with one of the `under` entries, but that are not currently
|
||||||
// build targets.
|
// build targets, or in `exempt`
|
||||||
func removeAbandonedFilesUnder(ctx *blueprint.Context, config *Config,
|
func removeAbandonedFilesUnder(ctx *blueprint.Context, config *Config,
|
||||||
srcDir string, under []string) error {
|
srcDir string, under, exempt []string) error {
|
||||||
|
|
||||||
if len(under) == 0 {
|
if len(under) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@ -57,6 +57,10 @@ func removeAbandonedFilesUnder(ctx *blueprint.Context, config *Config,
|
||||||
replacedTarget := replacer.Replace(target)
|
replacedTarget := replacer.Replace(target)
|
||||||
targets[filepath.Clean(replacedTarget)] = true
|
targets[filepath.Clean(replacedTarget)] = true
|
||||||
}
|
}
|
||||||
|
for _, target := range exempt {
|
||||||
|
replacedTarget := replacer.Replace(target)
|
||||||
|
targets[filepath.Clean(replacedTarget)] = true
|
||||||
|
}
|
||||||
|
|
||||||
filePaths, err := parseNinjaLog(ninjaBuildDir, under)
|
filePaths, err := parseNinjaLog(ninjaBuildDir, under)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -32,6 +32,7 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
outFile string
|
outFile string
|
||||||
|
globFile string
|
||||||
depFile string
|
depFile string
|
||||||
docFile string
|
docFile string
|
||||||
cpuprofile string
|
cpuprofile string
|
||||||
|
@ -48,6 +49,7 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.StringVar(&outFile, "o", "build.ninja", "the Ninja file to output")
|
flag.StringVar(&outFile, "o", "build.ninja", "the Ninja file to output")
|
||||||
|
flag.StringVar(&globFile, "globFile", "build-globs.ninja", "the Ninja file of globs to output")
|
||||||
flag.StringVar(&BuildDir, "b", ".", "the build output directory")
|
flag.StringVar(&BuildDir, "b", ".", "the build output directory")
|
||||||
flag.StringVar(&NinjaBuildDir, "n", "", "the ninja builddir directory")
|
flag.StringVar(&NinjaBuildDir, "n", "", "the ninja builddir directory")
|
||||||
flag.StringVar(&depFile, "d", "", "the dependency file to output")
|
flag.StringVar(&depFile, "d", "", "the dependency file to output")
|
||||||
|
@ -179,6 +181,18 @@ func Main(ctx *blueprint.Context, config interface{}, extraNinjaFileDeps ...stri
|
||||||
fatalf("error writing %s: %s", outFile, err)
|
fatalf("error writing %s: %s", outFile, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if globFile != "" {
|
||||||
|
buffer, errs := generateGlobNinjaFile(ctx.Globs)
|
||||||
|
if len(errs) > 0 {
|
||||||
|
fatalErrors(errs)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = ioutil.WriteFile(globFile, buffer, outFilePermissions)
|
||||||
|
if err != nil {
|
||||||
|
fatalf("error writing %s: %s", outFile, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if depFile != "" {
|
if depFile != "" {
|
||||||
err := deptools.WriteDepFile(depFile, outFile, deps)
|
err := deptools.WriteDepFile(depFile, outFile, deps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -187,8 +201,8 @@ func Main(ctx *blueprint.Context, config interface{}, extraNinjaFileDeps ...stri
|
||||||
}
|
}
|
||||||
|
|
||||||
if c, ok := config.(ConfigRemoveAbandonedFilesUnder); ok {
|
if c, ok := config.(ConfigRemoveAbandonedFilesUnder); ok {
|
||||||
under := c.RemoveAbandonedFilesUnder()
|
under, except := c.RemoveAbandonedFilesUnder()
|
||||||
err := removeAbandonedFilesUnder(ctx, bootstrapConfig, SrcDir, under)
|
err := removeAbandonedFilesUnder(ctx, bootstrapConfig, SrcDir, under, except)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatalf("error removing abandoned files: %s", err)
|
fatalf("error removing abandoned files: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,10 +69,11 @@ type ConfigInterface interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigRemoveAbandonedFilesUnder interface {
|
type ConfigRemoveAbandonedFilesUnder interface {
|
||||||
// RemoveAbandonedFilesUnder should return a slice of path prefixes that
|
// RemoveAbandonedFilesUnder should return two slices:
|
||||||
// will be cleaned of files that are no longer active targets, but are
|
// - a slice of path prefixes that will be cleaned of files that are no
|
||||||
// listed in the .ninja_log.
|
// longer active targets, but are listed in the .ninja_log.
|
||||||
RemoveAbandonedFilesUnder() []string
|
// - a slice of paths that are exempt from cleaning
|
||||||
|
RemoveAbandonedFilesUnder() (under, except []string)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigBlueprintToolLocation interface {
|
type ConfigBlueprintToolLocation interface {
|
||||||
|
|
|
@ -120,23 +120,27 @@
|
||||||
// - Runs .bootstrap/build.ninja to build and run the primary builder
|
// - Runs .bootstrap/build.ninja to build and run the primary builder
|
||||||
// - Runs build.ninja to build your code
|
// - Runs build.ninja to build your code
|
||||||
//
|
//
|
||||||
// Microfactory takes care of building an up to date version of `minibp` under
|
// Microfactory takes care of building an up to date version of `minibp` and
|
||||||
// the .minibootstrap/ directory.
|
// `bpglob` under the .minibootstrap/ directory.
|
||||||
//
|
//
|
||||||
// During <builddir>/.minibootstrap/build.ninja, the following actions are
|
// During <builddir>/.minibootstrap/build.ninja, the following actions are
|
||||||
// taken, if necessary:
|
// taken, if necessary:
|
||||||
//
|
//
|
||||||
// - Run minibp to generate .bootstrap/build.ninja (Primary stage)
|
// - Run minibp to generate .bootstrap/build.ninja (Primary stage)
|
||||||
|
// - Includes .minibootstrap/build-globs.ninja, which defines rules to
|
||||||
|
// run bpglob during incremental builds. These outputs are listed in
|
||||||
|
// the dependency file output by minibp.
|
||||||
//
|
//
|
||||||
// During the <builddir>/.bootstrap/build.ninja, the following actions are
|
// During the <builddir>/.bootstrap/build.ninja, the following actions are
|
||||||
// taken, if necessary:
|
// taken, if necessary:
|
||||||
//
|
//
|
||||||
// - Rebuild .bootstrap/build.ninja, usually due to globs changing --
|
|
||||||
// other dependencies will trigger it to be built during minibootstrap
|
|
||||||
// - Build the primary builder, anything marked `default: true`, and
|
// - Build the primary builder, anything marked `default: true`, and
|
||||||
// any dependencies.
|
// any dependencies.
|
||||||
// - Run the primary builder to generate build.ninja
|
// - Run the primary builder to generate build.ninja
|
||||||
// - Run the primary builder to extract documentation
|
// - Run the primary builder to extract documentation
|
||||||
|
// - Includes .bootstrap/build-globs.ninja, which defines rules to run
|
||||||
|
// bpglob during incremental builds. These outputs are listed in the
|
||||||
|
// dependency file output by the primary builder.
|
||||||
//
|
//
|
||||||
// Then the main stage is at <builddir>/build.ninja, and will contain all the
|
// Then the main stage is at <builddir>/build.ninja, and will contain all the
|
||||||
// rules generated by the primary builder. In addition, the bootstrap code
|
// rules generated by the primary builder. In addition, the bootstrap code
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package bootstrap
|
package bootstrap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -40,7 +41,7 @@ import (
|
||||||
// in a build failure with a "missing and no known rule to make it" error.
|
// in a build failure with a "missing and no known rule to make it" error.
|
||||||
|
|
||||||
var (
|
var (
|
||||||
globCmd = filepath.Join("$BinDir", "bpglob")
|
globCmd = filepath.Join(miniBootstrapDir, "bpglob")
|
||||||
|
|
||||||
// globRule rule traverses directories to produce a list of files that match $glob
|
// globRule rule traverses directories to produce a list of files that match $glob
|
||||||
// and writes it to $out if it has changed, and writes the directories to $out.d
|
// and writes it to $out if it has changed, and writes the directories to $out.d
|
||||||
|
@ -111,6 +112,7 @@ func joinWithPrefixAndQuote(strs []string, prefix string) string {
|
||||||
// primary builder if the results change.
|
// primary builder if the results change.
|
||||||
type globSingleton struct {
|
type globSingleton struct {
|
||||||
globLister func() []blueprint.GlobPath
|
globLister func() []blueprint.GlobPath
|
||||||
|
writeRule bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func globSingletonFactory(ctx *blueprint.Context) func() blueprint.Singleton {
|
func globSingletonFactory(ctx *blueprint.Context) func() blueprint.Singleton {
|
||||||
|
@ -124,15 +126,52 @@ func globSingletonFactory(ctx *blueprint.Context) func() blueprint.Singleton {
|
||||||
func (s *globSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
|
func (s *globSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
|
||||||
for _, g := range s.globLister() {
|
for _, g := range s.globLister() {
|
||||||
fileListFile := filepath.Join(BuildDir, ".glob", g.Name)
|
fileListFile := filepath.Join(BuildDir, ".glob", g.Name)
|
||||||
depFile := fileListFile + ".d"
|
|
||||||
|
|
||||||
fileList := strings.Join(g.Files, "\n") + "\n"
|
if s.writeRule {
|
||||||
pathtools.WriteFileIfChanged(fileListFile, []byte(fileList), 0666)
|
depFile := fileListFile + ".d"
|
||||||
deptools.WriteDepFile(depFile, fileListFile, g.Deps)
|
|
||||||
|
|
||||||
GlobFile(ctx, g.Pattern, g.Excludes, fileListFile, depFile)
|
fileList := strings.Join(g.Files, "\n") + "\n"
|
||||||
|
pathtools.WriteFileIfChanged(fileListFile, []byte(fileList), 0666)
|
||||||
|
deptools.WriteDepFile(depFile, fileListFile, g.Deps)
|
||||||
|
|
||||||
// Make build.ninja depend on the fileListFile
|
GlobFile(ctx, g.Pattern, g.Excludes, fileListFile, depFile)
|
||||||
ctx.AddNinjaFileDeps(fileListFile)
|
} else {
|
||||||
|
// Make build.ninja depend on the fileListFile
|
||||||
|
ctx.AddNinjaFileDeps(fileListFile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateGlobNinjaFile(globLister func() []blueprint.GlobPath) ([]byte, []error) {
|
||||||
|
ctx := blueprint.NewContext()
|
||||||
|
ctx.RegisterSingletonType("glob", func() blueprint.Singleton {
|
||||||
|
return &globSingleton{
|
||||||
|
globLister: globLister,
|
||||||
|
writeRule: true,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
extraDeps, errs := ctx.ResolveDependencies(nil)
|
||||||
|
if len(extraDeps) > 0 {
|
||||||
|
return nil, []error{fmt.Errorf("shouldn't have extra deps")}
|
||||||
|
}
|
||||||
|
if len(errs) > 0 {
|
||||||
|
return nil, errs
|
||||||
|
}
|
||||||
|
|
||||||
|
extraDeps, errs = ctx.PrepareBuildActions(nil)
|
||||||
|
if len(extraDeps) > 0 {
|
||||||
|
return nil, []error{fmt.Errorf("shouldn't have extra deps")}
|
||||||
|
}
|
||||||
|
if len(errs) > 0 {
|
||||||
|
return nil, errs
|
||||||
|
}
|
||||||
|
|
||||||
|
buf := bytes.NewBuffer(nil)
|
||||||
|
err := ctx.WriteBuildFile(buf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, []error{err}
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
|
@ -37,8 +37,12 @@ func (c Config) GeneratingPrimaryBuilder() bool {
|
||||||
return c.generatingPrimaryBuilder
|
return c.generatingPrimaryBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) RemoveAbandonedFilesUnder() []string {
|
func (c Config) RemoveAbandonedFilesUnder() (under, exempt []string) {
|
||||||
return []string{filepath.Join(bootstrap.BuildDir, ".bootstrap")}
|
if c.generatingPrimaryBuilder {
|
||||||
|
under = []string{filepath.Join(bootstrap.BuildDir, ".bootstrap")}
|
||||||
|
exempt = []string{filepath.Join(bootstrap.BuildDir, ".bootstrap", "build.ninja")}
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
14
context.go
14
context.go
|
@ -102,6 +102,8 @@ type Context struct {
|
||||||
requiredNinjaMinor int // For the ninja_required_version variable
|
requiredNinjaMinor int // For the ninja_required_version variable
|
||||||
requiredNinjaMicro int // For the ninja_required_version variable
|
requiredNinjaMicro int // For the ninja_required_version variable
|
||||||
|
|
||||||
|
subninjas []string
|
||||||
|
|
||||||
// set lazily by sortedModuleGroups
|
// set lazily by sortedModuleGroups
|
||||||
cachedSortedModuleGroups []*moduleGroup
|
cachedSortedModuleGroups []*moduleGroup
|
||||||
|
|
||||||
|
@ -2939,6 +2941,11 @@ func (c *Context) WriteBuildFile(w io.Writer) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = c.writeSubninjas(nw)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Group the globals by package.
|
// TODO: Group the globals by package.
|
||||||
|
|
||||||
err = c.writeGlobalVariables(nw)
|
err = c.writeGlobalVariables(nw)
|
||||||
|
@ -3048,6 +3055,13 @@ func (c *Context) writeNinjaRequiredVersion(nw *ninjaWriter) error {
|
||||||
return nw.BlankLine()
|
return nw.BlankLine()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Context) writeSubninjas(nw *ninjaWriter) error {
|
||||||
|
for _, subninja := range c.subninjas {
|
||||||
|
nw.Subninja(subninja)
|
||||||
|
}
|
||||||
|
return nw.BlankLine()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Context) writeBuildDir(nw *ninjaWriter) error {
|
func (c *Context) writeBuildDir(nw *ninjaWriter) error {
|
||||||
if c.ninjaBuildDir != nil {
|
if c.ninjaBuildDir != nil {
|
||||||
err := nw.Assign("builddir", c.ninjaBuildDir.Value(c.pkgNames))
|
err := nw.Assign("builddir", c.ninjaBuildDir.Value(c.pkgNames))
|
||||||
|
|
|
@ -193,6 +193,12 @@ func (n *ninjaWriter) Default(targets ...string) error {
|
||||||
return wrapper.Flush()
|
return wrapper.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *ninjaWriter) Subninja(file string) error {
|
||||||
|
n.justDidBlankLine = false
|
||||||
|
_, err := fmt.Fprintf(n.writer, "subninja %s\n", file)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (n *ninjaWriter) BlankLine() (err error) {
|
func (n *ninjaWriter) BlankLine() (err error) {
|
||||||
// We don't output multiple blank lines in a row.
|
// We don't output multiple blank lines in a row.
|
||||||
if !n.justDidBlankLine {
|
if !n.justDidBlankLine {
|
||||||
|
|
|
@ -72,6 +72,12 @@ var ninjaWriterTestCases = []struct {
|
||||||
},
|
},
|
||||||
output: " foo = bar\n",
|
output: " foo = bar\n",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: func(w *ninjaWriter) {
|
||||||
|
ck(w.Subninja("build.ninja"))
|
||||||
|
},
|
||||||
|
output: "subninja build.ninja\n",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
input: func(w *ninjaWriter) {
|
input: func(w *ninjaWriter) {
|
||||||
ck(w.BlankLine())
|
ck(w.BlankLine())
|
||||||
|
|
|
@ -47,6 +47,10 @@ type SingletonContext interface {
|
||||||
// set at most one time for a single build, later calls are ignored.
|
// set at most one time for a single build, later calls are ignored.
|
||||||
SetNinjaBuildDir(pctx PackageContext, value string)
|
SetNinjaBuildDir(pctx PackageContext, value string)
|
||||||
|
|
||||||
|
// AddSubninja adds a ninja file to include with subninja. This should likely
|
||||||
|
// only ever be used inside bootstrap to handle glob rules.
|
||||||
|
AddSubninja(file string)
|
||||||
|
|
||||||
// Eval takes a string with embedded ninja variables, and returns a string
|
// Eval takes a string with embedded ninja variables, and returns a string
|
||||||
// with all of the variables recursively expanded. Any variables references
|
// with all of the variables recursively expanded. Any variables references
|
||||||
// are expanded in the scope of the PackageContext.
|
// are expanded in the scope of the PackageContext.
|
||||||
|
@ -203,6 +207,10 @@ func (s *singletonContext) SetNinjaBuildDir(pctx PackageContext, value string) {
|
||||||
s.context.setNinjaBuildDir(ninjaValue)
|
s.context.setNinjaBuildDir(ninjaValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *singletonContext) AddSubninja(file string) {
|
||||||
|
s.context.subninjas = append(s.context.subninjas, file)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *singletonContext) VisitAllModules(visit func(Module)) {
|
func (s *singletonContext) VisitAllModules(visit func(Module)) {
|
||||||
s.context.VisitAllModules(visit)
|
s.context.VisitAllModules(visit)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue