Create internal bootstrap Config struct
Change-Id: If5c5ce3d5c46196cf9b77ff9f5c68b8849474823
diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go
index ead4ceb..5b02032 100644
--- a/bootstrap/bootstrap.go
+++ b/bootstrap/bootstrap.go
@@ -124,14 +124,6 @@
return isBinary
}
-func generatingBootstrapper(config interface{}) bool {
- bootstrapConfig, ok := config.(Config)
- if ok {
- return bootstrapConfig.GeneratingBootstrapper()
- }
- return false
-}
-
// ninjaHasMultipass returns true if Ninja will perform multiple passes
// that can regenerate the build manifest.
func ninjaHasMultipass(config interface{}) bool {
@@ -156,13 +148,20 @@
// The path of the .a file that is to be built.
archiveFile string
+
+ // The bootstrap Config
+ config *Config
}
var _ goPackageProducer = (*goPackage)(nil)
-func newGoPackageModule() (blueprint.Module, []interface{}) {
- module := &goPackage{}
- return module, []interface{}{&module.properties}
+func newGoPackageModuleFactory(config *Config) func() (blueprint.Module, []interface{}) {
+ return func() (blueprint.Module, []interface{}) {
+ module := &goPackage{
+ config: config,
+ }
+ return module, []interface{}{&module.properties}
+ }
}
func (g *goPackage) GoPkgRoot() string {
@@ -190,7 +189,7 @@
// the circular dependence that occurs when the builder requires a new Ninja
// file to be built, but building a new ninja file requires the builder to
// be built.
- if generatingBootstrapper(ctx.Config()) {
+ if g.config.generatingBootstrapper {
buildGoPackage(ctx, g.pkgRoot, g.properties.PkgPath, g.archiveFile,
g.properties.Srcs)
} else {
@@ -204,11 +203,18 @@
Srcs []string
PrimaryBuilder bool
}
+
+ // The bootstrap Config
+ config *Config
}
-func newGoBinaryModule() (blueprint.Module, []interface{}) {
- module := &goBinary{}
- return module, []interface{}{&module.properties}
+func newGoBinaryModuleFactory(config *Config) func() (blueprint.Module, []interface{}) {
+ return func() (blueprint.Module, []interface{}) {
+ module := &goBinary{
+ config: config,
+ }
+ return module, []interface{}{&module.properties}
+ }
}
func (g *goBinary) GenerateBuildActions(ctx blueprint.ModuleContext) {
@@ -225,7 +231,7 @@
// the circular dependence that occurs when the builder requires a new Ninja
// file to be built, but building a new ninja file requires the builder to
// be built.
- if generatingBootstrapper(ctx.Config()) {
+ if g.config.generatingBootstrapper {
buildGoPackage(ctx, objDir, name, archiveFile, g.properties.Srcs)
var libDirFlags []string
@@ -339,10 +345,17 @@
}
-type singleton struct{}
+type singleton struct {
+ // The bootstrap Config
+ config *Config
+}
-func newSingleton() blueprint.Singleton {
- return &singleton{}
+func newSingletonFactory(config *Config) func() blueprint.Singleton {
+ return func() blueprint.Singleton {
+ return &singleton{
+ config: config,
+ }
+ }
}
func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
@@ -388,13 +401,13 @@
// Get the filename of the top-level Blueprints file to pass to minibp.
// This comes stored in a global variable that's set by Main.
topLevelBlueprints := filepath.Join("$srcDir",
- filepath.Base(topLevelBlueprintsFile))
+ filepath.Base(s.config.topLevelBlueprintsFile))
mainNinjaFile := filepath.Join(bootstrapDir, "main.ninja.in")
mainNinjaDepFile := mainNinjaFile + ".d"
bootstrapNinjaFile := filepath.Join(bootstrapDir, "bootstrap.ninja.in")
- if generatingBootstrapper(ctx.Config()) {
+ if s.config.generatingBootstrapper {
// We're generating a bootstrapper Ninja file, so we need to set things
// up to rebuild the build.ninja file using the primary builder.
diff --git a/bootstrap/cleanup.go b/bootstrap/cleanup.go
index 5f53d5d..f3cb634 100644
--- a/bootstrap/cleanup.go
+++ b/bootstrap/cleanup.go
@@ -29,11 +29,11 @@
// removeAbandonedFiles removes any files that appear in the Ninja log that are
// not currently build targets.
-func removeAbandonedFiles(ctx *blueprint.Context, config interface{},
+func removeAbandonedFiles(ctx *blueprint.Context, config *Config,
srcDir, manifestFile string) error {
buildDir := "."
- if generatingBootstrapper(config) {
+ if config.generatingBootstrapper {
buildDir = bootstrapDir
}
diff --git a/bootstrap/command.go b/bootstrap/command.go
index 05a3e9d..354a692 100644
--- a/bootstrap/command.go
+++ b/bootstrap/command.go
@@ -36,12 +36,6 @@
cpuprofile string
)
-// topLevelBlueprintsFile is set by Main as a way to pass this information on to
-// the bootstrap build manifest generators. This information was not passed via
-// the config object so as to allow the caller of Main to use whatever Config
-// object it wants.
-var topLevelBlueprintsFile string
-
func init() {
flag.StringVar(&outFile, "o", "build.ninja.in", "the Ninja file to output")
flag.StringVar(&depFile, "d", "", "the dependency file to output")
@@ -67,17 +61,25 @@
defer pprof.StopCPUProfile()
}
- ctx.RegisterModuleType("bootstrap_go_package", newGoPackageModule)
- ctx.RegisterModuleType("bootstrap_go_binary", newGoBinaryModule)
- ctx.RegisterSingletonType("bootstrap", newSingleton)
-
if flag.NArg() != 1 {
fatalf("no Blueprints file specified")
}
- topLevelBlueprintsFile = flag.Arg(0)
+ generatingBootstrapper := false
+ if c, ok := config.(ConfigInterface); ok {
+ generatingBootstrapper = c.GeneratingBootstrapper()
+ }
- deps, errs := ctx.ParseBlueprintsFiles(topLevelBlueprintsFile)
+ bootstrapConfig := &Config{
+ generatingBootstrapper: generatingBootstrapper,
+ topLevelBlueprintsFile: flag.Arg(0),
+ }
+
+ ctx.RegisterModuleType("bootstrap_go_package", newGoPackageModuleFactory(bootstrapConfig))
+ ctx.RegisterModuleType("bootstrap_go_binary", newGoBinaryModuleFactory(bootstrapConfig))
+ ctx.RegisterSingletonType("bootstrap", newSingletonFactory(bootstrapConfig))
+
+ deps, errs := ctx.ParseBlueprintsFiles(bootstrapConfig.topLevelBlueprintsFile)
if len(errs) > 0 {
fatalErrors(errs)
}
@@ -142,8 +144,8 @@
}
}
- srcDir := filepath.Dir(topLevelBlueprintsFile)
- err = removeAbandonedFiles(ctx, config, srcDir, manifestFile)
+ srcDir := filepath.Dir(bootstrapConfig.topLevelBlueprintsFile)
+ err = removeAbandonedFiles(ctx, bootstrapConfig, srcDir, manifestFile)
if err != nil {
fatalf("error removing abandoned files: %s", err)
}
diff --git a/bootstrap/config.go b/bootstrap/config.go
index 4763f50..a47bc11 100644
--- a/bootstrap/config.go
+++ b/bootstrap/config.go
@@ -31,9 +31,18 @@
"$goRoot/pkg/tool/${goOS}_$goArch")
)
-type Config interface {
+type ConfigInterface interface {
// GeneratingBootstrapper should return true if this build invocation is
// creating a build.ninja.in file to be used in a build bootstrapping
// sequence.
GeneratingBootstrapper() bool
}
+
+type Config struct {
+ // generatingBootstrapper should be true if this build invocation is
+ // creating a build.ninja.in file to be used in a build bootstrapping
+ // sequence.
+ generatingBootstrapper bool
+
+ topLevelBlueprintsFile string
+}
diff --git a/build.ninja.in b/build.ninja.in
index ab32834..d72f8ef 100644
--- a/build.ninja.in
+++ b/build.ninja.in
@@ -52,7 +52,7 @@
# Module: blueprint
# Variant:
# Type: bootstrap_go_package
-# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
+# Factory: github.com/google/blueprint/bootstrap.func·002
# Defined: Blueprints:1:1
build .bootstrap/blueprint/pkg/github.com/google/blueprint.a: g.bootstrap.gc $
@@ -75,7 +75,7 @@
# Module: blueprint-bootstrap
# Variant:
# Type: bootstrap_go_package
-# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
+# Factory: github.com/google/blueprint/bootstrap.func·002
# Defined: Blueprints:56:1
build $
@@ -99,7 +99,7 @@
# Module: blueprint-deptools
# Variant:
# Type: bootstrap_go_package
-# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
+# Factory: github.com/google/blueprint/bootstrap.func·002
# Defined: Blueprints:35:1
build .bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
@@ -113,7 +113,7 @@
# Module: blueprint-parser
# Variant:
# Type: bootstrap_go_package
-# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
+# Factory: github.com/google/blueprint/bootstrap.func·002
# Defined: Blueprints:24:1
build .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a: $
@@ -128,7 +128,7 @@
# Module: blueprint-pathtools
# Variant:
# Type: bootstrap_go_package
-# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
+# Factory: github.com/google/blueprint/bootstrap.func·002
# Defined: Blueprints:41:1
build $
@@ -143,7 +143,7 @@
# Module: blueprint-proptools
# Variant:
# Type: bootstrap_go_package
-# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
+# Factory: github.com/google/blueprint/bootstrap.func·002
# Defined: Blueprints:50:1
build $
@@ -158,7 +158,7 @@
# Module: bpfmt
# Variant:
# Type: bootstrap_go_binary
-# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModule
+# Factory: github.com/google/blueprint/bootstrap.func·003
# Defined: Blueprints:82:1
build .bootstrap/bpfmt/obj/bpfmt.a: g.bootstrap.gc $
@@ -180,7 +180,7 @@
# Module: bpmodify
# Variant:
# Type: bootstrap_go_binary
-# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModule
+# Factory: github.com/google/blueprint/bootstrap.func·003
# Defined: Blueprints:88:1
build .bootstrap/bpmodify/obj/bpmodify.a: g.bootstrap.gc $
@@ -202,7 +202,7 @@
# Module: minibp
# Variant:
# Type: bootstrap_go_binary
-# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModule
+# Factory: github.com/google/blueprint/bootstrap.func·003
# Defined: Blueprints:73:1
build .bootstrap/minibp/obj/minibp.a: g.bootstrap.gc $
@@ -227,7 +227,7 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Singleton: bootstrap
-# Factory: github.com/google/blueprint/bootstrap.newSingleton
+# Factory: github.com/google/blueprint/bootstrap.func·007
rule s.bootstrap.bigbp
command = .bootstrap/bin/minibp -p -d .bootstrap/main.ninja.in.d -m ${g.bootstrap.bootstrapManifest} -o ${out} ${in}