2015-01-23 23:15:10 +01:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
package bootstrap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-07-25 05:28:41 +02:00
|
|
|
"go/build"
|
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
2018-07-06 06:56:59 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2014-05-28 01:34:41 +02:00
|
|
|
"path/filepath"
|
2017-02-06 23:00:10 +01:00
|
|
|
"runtime"
|
2014-05-28 01:34:41 +02:00
|
|
|
"strings"
|
2015-05-13 23:36:24 +02:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
"github.com/google/blueprint/pathtools"
|
2014-05-28 01:34:41 +02:00
|
|
|
)
|
|
|
|
|
2015-09-12 01:55:53 +02:00
|
|
|
const bootstrapSubDir = ".bootstrap"
|
|
|
|
const miniBootstrapSubDir = ".minibootstrap"
|
2014-06-06 23:21:57 +02:00
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
var (
|
2015-03-21 03:39:29 +01:00
|
|
|
pctx = blueprint.NewPackageContext("github.com/google/blueprint/bootstrap")
|
2014-05-28 01:34:41 +02:00
|
|
|
|
2015-07-25 01:53:27 +02:00
|
|
|
goTestMainCmd = pctx.StaticVariable("goTestMainCmd", filepath.Join(bootstrapDir, "bin", "gotestmain"))
|
2015-09-18 05:59:51 +02:00
|
|
|
goTestRunnerCmd = pctx.StaticVariable("goTestRunnerCmd", filepath.Join(bootstrapDir, "bin", "gotestrunner"))
|
2015-07-25 01:53:27 +02:00
|
|
|
pluginGenSrcCmd = pctx.StaticVariable("pluginGenSrcCmd", filepath.Join(bootstrapDir, "bin", "loadplugins"))
|
2014-10-03 11:49:58 +02:00
|
|
|
|
2017-07-25 05:28:41 +02:00
|
|
|
parallelCompile = pctx.StaticVariable("parallelCompile", func() string {
|
|
|
|
// Parallel compilation is only supported on >= go1.9
|
|
|
|
for _, r := range build.Default.ReleaseTags {
|
|
|
|
if r == "go1.9" {
|
2018-03-03 00:03:24 +01:00
|
|
|
numCpu := runtime.NumCPU()
|
|
|
|
// This will cause us to recompile all go programs if the
|
|
|
|
// number of cpus changes. We don't get a lot of benefit from
|
|
|
|
// higher values, so cap this to make it cheaper to move trees
|
|
|
|
// between machines.
|
|
|
|
if numCpu > 8 {
|
|
|
|
numCpu = 8
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("-c %d", numCpu)
|
2017-07-25 05:28:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}())
|
|
|
|
|
2015-08-02 00:07:27 +02:00
|
|
|
compile = pctx.StaticRule("compile",
|
2014-05-28 01:34:41 +02:00
|
|
|
blueprint.RuleParams{
|
2018-09-29 01:15:58 +02:00
|
|
|
Command: "GOROOT='$goRoot' $compileCmd $parallelCompile -o $out.tmp " +
|
|
|
|
"-p $pkgPath -complete $incFlags -pack $in && " +
|
|
|
|
"if cmp --quiet $out.tmp $out; then rm $out.tmp; else mv -f $out.tmp $out; fi",
|
2015-11-17 23:21:45 +01:00
|
|
|
CommandDeps: []string{"$compileCmd"},
|
2015-08-02 00:07:27 +02:00
|
|
|
Description: "compile $out",
|
2018-09-29 01:15:58 +02:00
|
|
|
Restat: true,
|
2014-05-28 01:34:41 +02:00
|
|
|
},
|
|
|
|
"pkgPath", "incFlags")
|
|
|
|
|
2014-10-03 11:49:58 +02:00
|
|
|
link = pctx.StaticRule("link",
|
2014-05-28 01:34:41 +02:00
|
|
|
blueprint.RuleParams{
|
2018-09-29 01:15:58 +02:00
|
|
|
Command: "GOROOT='$goRoot' $linkCmd -o $out.tmp $libDirFlags $in && " +
|
|
|
|
"if cmp --quiet $out.tmp $out; then rm $out.tmp; else mv -f $out.tmp $out; fi",
|
2015-11-17 23:21:45 +01:00
|
|
|
CommandDeps: []string{"$linkCmd"},
|
2015-08-02 00:07:27 +02:00
|
|
|
Description: "link $out",
|
2018-09-29 01:15:58 +02:00
|
|
|
Restat: true,
|
2014-05-28 01:34:41 +02:00
|
|
|
},
|
|
|
|
"libDirFlags")
|
|
|
|
|
2015-06-24 02:21:00 +02:00
|
|
|
goTestMain = pctx.StaticRule("gotestmain",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$goTestMainCmd -o $out -pkg $pkg $in",
|
2015-11-17 23:21:45 +01:00
|
|
|
CommandDeps: []string{"$goTestMainCmd"},
|
2015-06-24 02:21:00 +02:00
|
|
|
Description: "gotestmain $out",
|
|
|
|
},
|
|
|
|
"pkg")
|
|
|
|
|
2015-07-25 01:53:27 +02:00
|
|
|
pluginGenSrc = pctx.StaticRule("pluginGenSrc",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$pluginGenSrcCmd -o $out -p $pkg $plugins",
|
2015-11-17 23:21:45 +01:00
|
|
|
CommandDeps: []string{"$pluginGenSrcCmd"},
|
2015-07-25 01:53:27 +02:00
|
|
|
Description: "create $out",
|
|
|
|
},
|
|
|
|
"pkg", "plugins")
|
|
|
|
|
2015-06-24 02:21:00 +02:00
|
|
|
test = pctx.StaticRule("test",
|
|
|
|
blueprint.RuleParams{
|
2015-09-18 05:59:51 +02:00
|
|
|
Command: "$goTestRunnerCmd -p $pkgSrcDir -f $out -- $in -test.short",
|
2015-11-17 23:21:45 +01:00
|
|
|
CommandDeps: []string{"$goTestRunnerCmd"},
|
2015-06-24 02:21:00 +02:00
|
|
|
Description: "test $pkg",
|
|
|
|
},
|
|
|
|
"pkg", "pkgSrcDir")
|
|
|
|
|
2014-10-03 11:49:58 +02:00
|
|
|
cp = pctx.StaticRule("cp",
|
2014-05-28 01:34:41 +02:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "cp $in $out",
|
|
|
|
Description: "cp $out",
|
2014-06-06 05:00:22 +02:00
|
|
|
},
|
|
|
|
"generator")
|
2014-05-28 01:34:41 +02:00
|
|
|
|
2014-10-03 11:49:58 +02:00
|
|
|
bootstrap = pctx.StaticRule("bootstrap",
|
2014-05-28 01:34:41 +02:00
|
|
|
blueprint.RuleParams{
|
2015-09-18 07:48:04 +02:00
|
|
|
Command: "BUILDDIR=$buildDir $bootstrapCmd -i $in",
|
2015-11-17 23:21:45 +01:00
|
|
|
CommandDeps: []string{"$bootstrapCmd"},
|
2014-05-28 01:34:41 +02:00
|
|
|
Description: "bootstrap $in",
|
|
|
|
Generator: true,
|
|
|
|
})
|
|
|
|
|
Enhance bootstrap stage selection
This simplifies the bootstrap process while making it more flexible by
moving the stage selection into a go binary(choosestage). It will now be
possible to have more than two build stages.
Now each stage has a ninja template(main.ninja.in) and a timestamp
file(main.ninja.in.timestamp). The timestamp file may be updated by any
build stage that wishes to regenerate the ninja template. If the
choosestage binaries sees that the timestamp is newer than the template,
it will choose the prior stage.
The main stage no longer writes to the source tree to update the
build.ninja.in file. This was a problem for read-only source trees.
Instead, the choosestage binary first checks to see if that file is
newer than the last bootstrap.ninja.in, copies it in place, and starts
the boostrap stage.
The bootstrap stage regenerates it's own ninja template, but that
required a loop through the main stage to actually run it. The
choosestage binary now detects if the template has changed for the
current stage, and will restart the stage.
One change is that if dependencies do get messed up, instead of silently
failing, there's a higher chance that the bootstrap step will just
continue looping, doing nothing. This can happen if the main stage
has a dependency that triggers the bootstrap stage, but the bootstrap
stage doesn't see anything required to rebuild the main ninja file. A
side effect of this requirement is that changes to test code will now
rebuild the main ninja file.
Change-Id: I9965cfba79dc0dbbd3af05f5944f7653054455a2
2015-07-23 02:05:59 +02:00
|
|
|
touch = pctx.StaticRule("touch",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "touch $out",
|
|
|
|
Description: "touch $out",
|
|
|
|
},
|
|
|
|
"depfile", "generator")
|
|
|
|
|
2016-11-02 01:12:28 +01:00
|
|
|
generateBuildNinja = pctx.StaticRule("build.ninja",
|
|
|
|
blueprint.RuleParams{
|
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
2018-07-06 06:56:59 +02:00
|
|
|
Command: "$builder $extra -b $buildDir -n $ninjaBuildDir -d $out.d -globFile $globFile -o $out $in",
|
2016-11-02 01:12:28 +01:00
|
|
|
CommandDeps: []string{"$builder"},
|
|
|
|
Description: "$builder $out",
|
2017-12-18 18:14:16 +01:00
|
|
|
Deps: blueprint.DepsGCC,
|
2016-11-02 01:12:28 +01:00
|
|
|
Depfile: "$out.d",
|
|
|
|
Restat: true,
|
|
|
|
},
|
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
2018-07-06 06:56:59 +02:00
|
|
|
"builder", "extra", "generator", "globFile")
|
2016-11-02 01:12:28 +01:00
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
// Work around a Ninja issue. See https://github.com/martine/ninja/pull/634
|
2014-10-03 11:49:58 +02:00
|
|
|
phony = pctx.StaticRule("phony",
|
2014-05-28 01:34:41 +02:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "# phony $out",
|
|
|
|
Description: "phony $out",
|
|
|
|
Generator: true,
|
|
|
|
},
|
|
|
|
"depfile")
|
|
|
|
|
2017-09-14 00:19:22 +02:00
|
|
|
_ = pctx.VariableFunc("BinDir", func(config interface{}) (string, error) {
|
|
|
|
return binDir(), nil
|
|
|
|
})
|
2015-05-13 23:36:24 +02:00
|
|
|
|
2017-09-14 00:19:22 +02:00
|
|
|
_ = pctx.VariableFunc("ToolDir", func(config interface{}) (string, error) {
|
|
|
|
return toolDir(config), nil
|
2016-05-26 19:07:59 +02:00
|
|
|
})
|
2015-09-12 01:55:53 +02:00
|
|
|
|
2017-09-14 00:19:22 +02:00
|
|
|
docsDir = filepath.Join(bootstrapDir, "docs")
|
|
|
|
|
2015-09-18 05:59:51 +02:00
|
|
|
bootstrapDir = filepath.Join("$buildDir", bootstrapSubDir)
|
2015-09-12 01:55:53 +02:00
|
|
|
miniBootstrapDir = filepath.Join("$buildDir", miniBootstrapSubDir)
|
2017-07-19 04:37:37 +02:00
|
|
|
|
|
|
|
minibpFile = filepath.Join(miniBootstrapDir, "minibp")
|
2014-05-28 01:34:41 +02:00
|
|
|
)
|
|
|
|
|
2017-09-14 00:19:22 +02:00
|
|
|
type GoBinaryTool interface {
|
|
|
|
InstallPath() string
|
|
|
|
|
|
|
|
// So that other packages can't implement this interface
|
|
|
|
isGoBinary()
|
|
|
|
}
|
|
|
|
|
|
|
|
func binDir() string {
|
|
|
|
return filepath.Join(BuildDir, bootstrapSubDir, "bin")
|
|
|
|
}
|
|
|
|
|
|
|
|
func toolDir(config interface{}) string {
|
|
|
|
if c, ok := config.(ConfigBlueprintToolLocation); ok {
|
|
|
|
return filepath.Join(c.BlueprintToolLocation())
|
|
|
|
}
|
|
|
|
return filepath.Join(BuildDir, "bin")
|
|
|
|
}
|
|
|
|
|
2015-07-25 01:53:27 +02:00
|
|
|
func pluginDeps(ctx blueprint.BottomUpMutatorContext) {
|
|
|
|
if pkg, ok := ctx.Module().(*goPackage); ok {
|
|
|
|
for _, plugin := range pkg.properties.PluginFor {
|
2016-04-12 00:47:28 +02:00
|
|
|
ctx.AddReverseDependency(ctx.Module(), nil, plugin)
|
2015-07-25 01:53:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
type goPackageProducer interface {
|
|
|
|
GoPkgRoot() string
|
|
|
|
GoPackageTarget() string
|
2016-11-02 08:43:00 +01:00
|
|
|
GoTestTargets() []string
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func isGoPackageProducer(module blueprint.Module) bool {
|
|
|
|
_, ok := module.(goPackageProducer)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2015-07-25 01:53:27 +02:00
|
|
|
type goPluginProvider interface {
|
|
|
|
GoPkgPath() string
|
|
|
|
IsPluginFor(string) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func isGoPluginFor(name string) func(blueprint.Module) bool {
|
|
|
|
return func(module blueprint.Module) bool {
|
|
|
|
if plugin, ok := module.(goPluginProvider); ok {
|
|
|
|
return plugin.IsPluginFor(name)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
func isBootstrapModule(module blueprint.Module) bool {
|
|
|
|
_, isPackage := module.(*goPackage)
|
|
|
|
_, isBinary := module.(*goBinary)
|
|
|
|
return isPackage || isBinary
|
|
|
|
}
|
|
|
|
|
|
|
|
func isBootstrapBinaryModule(module blueprint.Module) bool {
|
|
|
|
_, isBinary := module.(*goBinary)
|
|
|
|
return isBinary
|
|
|
|
}
|
|
|
|
|
|
|
|
// A goPackage is a module for building Go packages.
|
|
|
|
type goPackage struct {
|
2016-05-17 23:58:05 +02:00
|
|
|
blueprint.SimpleName
|
2014-05-28 01:34:41 +02:00
|
|
|
properties struct {
|
2016-05-17 23:58:05 +02:00
|
|
|
Deps []string
|
2015-07-25 01:53:27 +02:00
|
|
|
PkgPath string
|
|
|
|
Srcs []string
|
|
|
|
TestSrcs []string
|
|
|
|
PluginFor []string
|
2016-04-12 00:41:52 +02:00
|
|
|
|
2017-02-06 23:00:10 +01:00
|
|
|
Darwin struct {
|
|
|
|
Srcs []string
|
|
|
|
TestSrcs []string
|
|
|
|
}
|
|
|
|
Linux struct {
|
|
|
|
Srcs []string
|
|
|
|
TestSrcs []string
|
|
|
|
}
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// The root dir in which the package .a file is located. The full .a file
|
|
|
|
// path will be "packageRoot/PkgPath.a"
|
|
|
|
pkgRoot string
|
|
|
|
|
|
|
|
// The path of the .a file that is to be built.
|
|
|
|
archiveFile string
|
2015-06-25 04:21:21 +02:00
|
|
|
|
2016-11-02 08:43:00 +01:00
|
|
|
// The path of the test result file.
|
|
|
|
testResultFile []string
|
2015-06-24 02:21:00 +02:00
|
|
|
|
2015-06-25 04:21:21 +02:00
|
|
|
// The bootstrap Config
|
|
|
|
config *Config
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ goPackageProducer = (*goPackage)(nil)
|
|
|
|
|
2015-06-25 04:21:21 +02:00
|
|
|
func newGoPackageModuleFactory(config *Config) func() (blueprint.Module, []interface{}) {
|
|
|
|
return func() (blueprint.Module, []interface{}) {
|
|
|
|
module := &goPackage{
|
2016-04-12 00:41:52 +02:00
|
|
|
config: config,
|
2015-06-25 04:21:21 +02:00
|
|
|
}
|
2016-05-17 23:58:05 +02:00
|
|
|
return module, []interface{}{&module.properties, &module.SimpleName.Properties}
|
2015-06-25 04:21:21 +02:00
|
|
|
}
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
2016-05-17 23:58:05 +02:00
|
|
|
func (g *goPackage) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string {
|
|
|
|
return g.properties.Deps
|
|
|
|
}
|
|
|
|
|
2015-07-25 01:53:27 +02:00
|
|
|
func (g *goPackage) GoPkgPath() string {
|
|
|
|
return g.properties.PkgPath
|
|
|
|
}
|
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
func (g *goPackage) GoPkgRoot() string {
|
|
|
|
return g.pkgRoot
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *goPackage) GoPackageTarget() string {
|
|
|
|
return g.archiveFile
|
|
|
|
}
|
|
|
|
|
2016-11-02 08:43:00 +01:00
|
|
|
func (g *goPackage) GoTestTargets() []string {
|
|
|
|
return g.testResultFile
|
2015-06-24 02:21:00 +02:00
|
|
|
}
|
|
|
|
|
2015-07-25 01:53:27 +02:00
|
|
|
func (g *goPackage) IsPluginFor(name string) bool {
|
|
|
|
for _, plugin := range g.properties.PluginFor {
|
|
|
|
if plugin == name {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
func (g *goPackage) GenerateBuildActions(ctx blueprint.ModuleContext) {
|
2015-07-25 01:53:27 +02:00
|
|
|
var (
|
|
|
|
name = ctx.ModuleName()
|
|
|
|
hasPlugins = false
|
|
|
|
pluginSrc = ""
|
|
|
|
genSrcs = []string{}
|
|
|
|
)
|
2014-05-28 01:34:41 +02:00
|
|
|
|
|
|
|
if g.properties.PkgPath == "" {
|
|
|
|
ctx.ModuleErrorf("module %s did not specify a valid pkgPath", name)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
g.pkgRoot = packageRoot(ctx)
|
2015-06-24 02:21:00 +02:00
|
|
|
g.archiveFile = filepath.Join(g.pkgRoot,
|
|
|
|
filepath.FromSlash(g.properties.PkgPath)+".a")
|
2014-05-28 01:34:41 +02:00
|
|
|
|
2015-07-25 01:53:27 +02:00
|
|
|
ctx.VisitDepsDepthFirstIf(isGoPluginFor(name),
|
|
|
|
func(module blueprint.Module) { hasPlugins = true })
|
|
|
|
if hasPlugins {
|
|
|
|
pluginSrc = filepath.Join(moduleGenSrcDir(ctx), "plugin.go")
|
|
|
|
genSrcs = append(genSrcs, pluginSrc)
|
|
|
|
}
|
|
|
|
|
2017-07-20 04:22:34 +02:00
|
|
|
if hasPlugins && !buildGoPluginLoader(ctx, g.properties.PkgPath, pluginSrc) {
|
|
|
|
return
|
|
|
|
}
|
2017-02-06 23:00:10 +01:00
|
|
|
|
2017-07-20 04:22:34 +02:00
|
|
|
var srcs, testSrcs []string
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
srcs = append(g.properties.Srcs, g.properties.Darwin.Srcs...)
|
|
|
|
testSrcs = append(g.properties.TestSrcs, g.properties.Darwin.TestSrcs...)
|
|
|
|
} else if runtime.GOOS == "linux" {
|
|
|
|
srcs = append(g.properties.Srcs, g.properties.Linux.Srcs...)
|
|
|
|
testSrcs = append(g.properties.TestSrcs, g.properties.Linux.TestSrcs...)
|
|
|
|
}
|
2015-06-24 02:21:00 +02:00
|
|
|
|
2017-07-20 04:22:34 +02:00
|
|
|
if g.config.runGoTests {
|
|
|
|
testArchiveFile := filepath.Join(testRoot(ctx),
|
|
|
|
filepath.FromSlash(g.properties.PkgPath)+".a")
|
|
|
|
g.testResultFile = buildGoTest(ctx, testRoot(ctx), testArchiveFile,
|
|
|
|
g.properties.PkgPath, srcs, genSrcs,
|
|
|
|
testSrcs)
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
2017-07-20 04:22:34 +02:00
|
|
|
|
|
|
|
buildGoPackage(ctx, g.pkgRoot, g.properties.PkgPath, g.archiveFile,
|
|
|
|
srcs, genSrcs)
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// A goBinary is a module for building executable binaries from Go sources.
|
|
|
|
type goBinary struct {
|
2016-05-17 23:58:05 +02:00
|
|
|
blueprint.SimpleName
|
2014-05-28 01:34:41 +02:00
|
|
|
properties struct {
|
2016-05-17 23:58:05 +02:00
|
|
|
Deps []string
|
2014-05-28 01:34:41 +02:00
|
|
|
Srcs []string
|
2015-06-24 02:21:00 +02:00
|
|
|
TestSrcs []string
|
2014-05-28 01:34:41 +02:00
|
|
|
PrimaryBuilder bool
|
2017-07-20 03:48:01 +02:00
|
|
|
Default bool
|
2016-04-12 00:41:52 +02:00
|
|
|
|
2017-02-06 23:00:10 +01:00
|
|
|
Darwin struct {
|
|
|
|
Srcs []string
|
|
|
|
TestSrcs []string
|
|
|
|
}
|
|
|
|
Linux struct {
|
|
|
|
Srcs []string
|
|
|
|
TestSrcs []string
|
|
|
|
}
|
|
|
|
|
2018-07-21 22:03:35 +02:00
|
|
|
Tool_dir bool `blueprint:"mutated"`
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
2015-06-25 04:21:21 +02:00
|
|
|
|
2017-09-14 00:19:22 +02:00
|
|
|
installPath string
|
|
|
|
|
2015-06-25 04:21:21 +02:00
|
|
|
// The bootstrap Config
|
|
|
|
config *Config
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
2017-09-14 00:19:22 +02:00
|
|
|
var _ GoBinaryTool = (*goBinary)(nil)
|
|
|
|
|
2017-07-20 04:22:34 +02:00
|
|
|
func newGoBinaryModuleFactory(config *Config, tooldir bool) func() (blueprint.Module, []interface{}) {
|
2015-06-25 04:21:21 +02:00
|
|
|
return func() (blueprint.Module, []interface{}) {
|
|
|
|
module := &goBinary{
|
2016-04-12 00:41:52 +02:00
|
|
|
config: config,
|
2015-06-25 04:21:21 +02:00
|
|
|
}
|
2017-07-20 04:22:34 +02:00
|
|
|
module.properties.Tool_dir = tooldir
|
2016-05-17 23:58:05 +02:00
|
|
|
return module, []interface{}{&module.properties, &module.SimpleName.Properties}
|
2015-06-25 04:21:21 +02:00
|
|
|
}
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
2016-05-17 23:58:05 +02:00
|
|
|
func (g *goBinary) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string {
|
|
|
|
return g.properties.Deps
|
|
|
|
}
|
|
|
|
|
2017-09-14 00:19:22 +02:00
|
|
|
func (g *goBinary) isGoBinary() {}
|
2016-05-26 19:07:59 +02:00
|
|
|
func (g *goBinary) InstallPath() string {
|
2017-09-14 00:19:22 +02:00
|
|
|
return g.installPath
|
2016-05-26 19:07:59 +02:00
|
|
|
}
|
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
func (g *goBinary) GenerateBuildActions(ctx blueprint.ModuleContext) {
|
|
|
|
var (
|
2016-11-02 08:43:00 +01:00
|
|
|
name = ctx.ModuleName()
|
|
|
|
objDir = moduleObjDir(ctx)
|
|
|
|
archiveFile = filepath.Join(objDir, name+".a")
|
|
|
|
testArchiveFile = filepath.Join(testRoot(ctx), name+".a")
|
|
|
|
aoutFile = filepath.Join(objDir, "a.out")
|
|
|
|
hasPlugins = false
|
|
|
|
pluginSrc = ""
|
|
|
|
genSrcs = []string{}
|
2014-05-28 01:34:41 +02:00
|
|
|
)
|
|
|
|
|
2017-09-14 00:19:22 +02:00
|
|
|
if g.properties.Tool_dir {
|
|
|
|
g.installPath = filepath.Join(toolDir(ctx.Config()), name)
|
|
|
|
} else {
|
|
|
|
g.installPath = filepath.Join(binDir(), name)
|
|
|
|
}
|
|
|
|
|
2015-07-25 01:53:27 +02:00
|
|
|
ctx.VisitDepsDepthFirstIf(isGoPluginFor(name),
|
|
|
|
func(module blueprint.Module) { hasPlugins = true })
|
|
|
|
if hasPlugins {
|
|
|
|
pluginSrc = filepath.Join(moduleGenSrcDir(ctx), "plugin.go")
|
|
|
|
genSrcs = append(genSrcs, pluginSrc)
|
|
|
|
}
|
|
|
|
|
2017-07-20 04:22:34 +02:00
|
|
|
var deps []string
|
2017-02-06 23:00:10 +01:00
|
|
|
|
2017-07-20 04:22:34 +02:00
|
|
|
if hasPlugins && !buildGoPluginLoader(ctx, "main", pluginSrc) {
|
|
|
|
return
|
|
|
|
}
|
2015-06-24 02:21:00 +02:00
|
|
|
|
2017-07-20 04:22:34 +02:00
|
|
|
var srcs, testSrcs []string
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
srcs = append(g.properties.Srcs, g.properties.Darwin.Srcs...)
|
|
|
|
testSrcs = append(g.properties.TestSrcs, g.properties.Darwin.TestSrcs...)
|
|
|
|
} else if runtime.GOOS == "linux" {
|
|
|
|
srcs = append(g.properties.Srcs, g.properties.Linux.Srcs...)
|
|
|
|
testSrcs = append(g.properties.TestSrcs, g.properties.Linux.TestSrcs...)
|
|
|
|
}
|
2014-05-28 01:34:41 +02:00
|
|
|
|
2017-07-20 04:22:34 +02:00
|
|
|
if g.config.runGoTests {
|
|
|
|
deps = buildGoTest(ctx, testRoot(ctx), testArchiveFile,
|
|
|
|
name, srcs, genSrcs, testSrcs)
|
|
|
|
}
|
2014-05-28 01:34:41 +02:00
|
|
|
|
2017-07-20 04:22:34 +02:00
|
|
|
buildGoPackage(ctx, objDir, name, archiveFile, srcs, genSrcs)
|
2014-05-28 01:34:41 +02:00
|
|
|
|
2018-09-29 01:15:58 +02:00
|
|
|
var linkDeps []string
|
2017-07-20 04:22:34 +02:00
|
|
|
var libDirFlags []string
|
|
|
|
ctx.VisitDepsDepthFirstIf(isGoPackageProducer,
|
|
|
|
func(module blueprint.Module) {
|
|
|
|
dep := module.(goPackageProducer)
|
2018-09-29 01:15:58 +02:00
|
|
|
linkDeps = append(linkDeps, dep.GoPackageTarget())
|
2017-07-20 04:22:34 +02:00
|
|
|
libDir := dep.GoPkgRoot()
|
|
|
|
libDirFlags = append(libDirFlags, "-L "+libDir)
|
|
|
|
deps = append(deps, dep.GoTestTargets()...)
|
2014-05-28 01:34:41 +02:00
|
|
|
})
|
|
|
|
|
2017-07-20 04:22:34 +02:00
|
|
|
linkArgs := map[string]string{}
|
|
|
|
if len(libDirFlags) > 0 {
|
|
|
|
linkArgs["libDirFlags"] = strings.Join(libDirFlags, " ")
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
2017-07-20 04:22:34 +02:00
|
|
|
|
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
2018-09-29 01:15:58 +02:00
|
|
|
Rule: link,
|
|
|
|
Outputs: []string{aoutFile},
|
|
|
|
Inputs: []string{archiveFile},
|
|
|
|
Implicits: linkDeps,
|
|
|
|
Args: linkArgs,
|
|
|
|
Optional: true,
|
2017-07-20 04:22:34 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
|
|
|
Rule: cp,
|
2017-09-14 00:19:22 +02:00
|
|
|
Outputs: []string{g.installPath},
|
2017-07-20 04:22:34 +02:00
|
|
|
Inputs: []string{aoutFile},
|
|
|
|
OrderOnly: deps,
|
|
|
|
Optional: !g.properties.Default,
|
|
|
|
})
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 04:22:34 +02:00
|
|
|
func buildGoPluginLoader(ctx blueprint.ModuleContext, pkgPath, pluginSrc string) bool {
|
2015-07-25 01:53:27 +02:00
|
|
|
ret := true
|
|
|
|
name := ctx.ModuleName()
|
|
|
|
|
|
|
|
var pluginPaths []string
|
|
|
|
ctx.VisitDepsDepthFirstIf(isGoPluginFor(name),
|
|
|
|
func(module blueprint.Module) {
|
|
|
|
plugin := module.(goPluginProvider)
|
|
|
|
pluginPaths = append(pluginPaths, plugin.GoPkgPath())
|
|
|
|
})
|
|
|
|
|
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
2015-11-17 23:21:45 +01:00
|
|
|
Rule: pluginGenSrc,
|
|
|
|
Outputs: []string{pluginSrc},
|
2015-07-25 01:53:27 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"pkg": pkgPath,
|
|
|
|
"plugins": strings.Join(pluginPaths, " "),
|
|
|
|
},
|
2017-07-20 03:48:01 +02:00
|
|
|
Optional: true,
|
2015-07-25 01:53:27 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
func buildGoPackage(ctx blueprint.ModuleContext, pkgRoot string,
|
2016-11-02 08:43:00 +01:00
|
|
|
pkgPath string, archiveFile string, srcs []string, genSrcs []string) {
|
2014-05-28 01:34:41 +02:00
|
|
|
|
2014-11-09 20:52:56 +01:00
|
|
|
srcDir := moduleSrcDir(ctx)
|
2014-06-06 23:37:07 +02:00
|
|
|
srcFiles := pathtools.PrefixPaths(srcs, srcDir)
|
2015-07-25 01:53:27 +02:00
|
|
|
srcFiles = append(srcFiles, genSrcs...)
|
2014-05-28 01:34:41 +02:00
|
|
|
|
|
|
|
var incFlags []string
|
2015-11-17 23:21:45 +01:00
|
|
|
var deps []string
|
2014-05-28 01:34:41 +02:00
|
|
|
ctx.VisitDepsDepthFirstIf(isGoPackageProducer,
|
|
|
|
func(module blueprint.Module) {
|
|
|
|
dep := module.(goPackageProducer)
|
|
|
|
incDir := dep.GoPkgRoot()
|
|
|
|
target := dep.GoPackageTarget()
|
|
|
|
incFlags = append(incFlags, "-I "+incDir)
|
2014-10-22 22:22:22 +02:00
|
|
|
deps = append(deps, target)
|
2014-05-28 01:34:41 +02:00
|
|
|
})
|
|
|
|
|
2015-08-02 00:07:27 +02:00
|
|
|
compileArgs := map[string]string{
|
2014-05-28 01:34:41 +02:00
|
|
|
"pkgPath": pkgPath,
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(incFlags) > 0 {
|
2015-08-02 00:07:27 +02:00
|
|
|
compileArgs["incFlags"] = strings.Join(incFlags, " ")
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
2014-10-03 11:49:58 +02:00
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
2015-08-02 00:07:27 +02:00
|
|
|
Rule: compile,
|
2014-10-22 19:55:28 +02:00
|
|
|
Outputs: []string{archiveFile},
|
2014-05-28 01:34:41 +02:00
|
|
|
Inputs: srcFiles,
|
2014-10-22 22:22:22 +02:00
|
|
|
Implicits: deps,
|
2015-08-02 00:07:27 +02:00
|
|
|
Args: compileArgs,
|
2017-07-20 03:48:01 +02:00
|
|
|
Optional: true,
|
2014-05-28 01:34:41 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-07-25 01:53:27 +02:00
|
|
|
func buildGoTest(ctx blueprint.ModuleContext, testRoot, testPkgArchive,
|
|
|
|
pkgPath string, srcs, genSrcs, testSrcs []string) []string {
|
2015-06-24 02:21:00 +02:00
|
|
|
|
|
|
|
if len(testSrcs) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
srcDir := moduleSrcDir(ctx)
|
|
|
|
testFiles := pathtools.PrefixPaths(testSrcs, srcDir)
|
|
|
|
|
|
|
|
mainFile := filepath.Join(testRoot, "test.go")
|
|
|
|
testArchive := filepath.Join(testRoot, "test.a")
|
|
|
|
testFile := filepath.Join(testRoot, "test")
|
|
|
|
testPassed := filepath.Join(testRoot, "test.passed")
|
|
|
|
|
|
|
|
buildGoPackage(ctx, testRoot, pkgPath, testPkgArchive,
|
2016-11-02 08:43:00 +01:00
|
|
|
append(srcs, testSrcs...), genSrcs)
|
2015-06-24 02:21:00 +02:00
|
|
|
|
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
2015-11-17 23:21:45 +01:00
|
|
|
Rule: goTestMain,
|
|
|
|
Outputs: []string{mainFile},
|
|
|
|
Inputs: testFiles,
|
2015-06-24 02:21:00 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"pkg": pkgPath,
|
|
|
|
},
|
2017-07-20 03:48:01 +02:00
|
|
|
Optional: true,
|
2015-06-24 02:21:00 +02:00
|
|
|
})
|
|
|
|
|
2018-10-24 22:11:33 +02:00
|
|
|
linkDeps := []string{testPkgArchive}
|
2015-06-24 02:21:00 +02:00
|
|
|
libDirFlags := []string{"-L " + testRoot}
|
2016-11-02 08:43:00 +01:00
|
|
|
testDeps := []string{}
|
2015-06-24 02:21:00 +02:00
|
|
|
ctx.VisitDepsDepthFirstIf(isGoPackageProducer,
|
|
|
|
func(module blueprint.Module) {
|
|
|
|
dep := module.(goPackageProducer)
|
2018-10-05 20:12:53 +02:00
|
|
|
linkDeps = append(linkDeps, dep.GoPackageTarget())
|
2015-06-24 02:21:00 +02:00
|
|
|
libDir := dep.GoPkgRoot()
|
|
|
|
libDirFlags = append(libDirFlags, "-L "+libDir)
|
2016-11-02 08:43:00 +01:00
|
|
|
testDeps = append(testDeps, dep.GoTestTargets()...)
|
2015-06-24 02:21:00 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
2015-08-02 00:07:27 +02:00
|
|
|
Rule: compile,
|
2015-06-24 02:21:00 +02:00
|
|
|
Outputs: []string{testArchive},
|
|
|
|
Inputs: []string{mainFile},
|
2015-11-17 23:21:45 +01:00
|
|
|
Implicits: []string{testPkgArchive},
|
2015-06-24 02:21:00 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"pkgPath": "main",
|
|
|
|
"incFlags": "-I " + testRoot,
|
|
|
|
},
|
2017-07-20 03:48:01 +02:00
|
|
|
Optional: true,
|
2015-06-24 02:21:00 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
2018-10-05 20:12:53 +02:00
|
|
|
Rule: link,
|
|
|
|
Outputs: []string{testFile},
|
|
|
|
Inputs: []string{testArchive},
|
|
|
|
Implicits: linkDeps,
|
2015-06-24 02:21:00 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"libDirFlags": strings.Join(libDirFlags, " "),
|
|
|
|
},
|
2017-07-20 03:48:01 +02:00
|
|
|
Optional: true,
|
2015-06-24 02:21:00 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
2016-11-02 08:43:00 +01:00
|
|
|
Rule: test,
|
|
|
|
Outputs: []string{testPassed},
|
|
|
|
Inputs: []string{testFile},
|
|
|
|
OrderOnly: testDeps,
|
2015-06-24 02:21:00 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"pkg": pkgPath,
|
|
|
|
"pkgSrcDir": filepath.Dir(testFiles[0]),
|
|
|
|
},
|
2017-07-20 03:48:01 +02:00
|
|
|
Optional: true,
|
2015-06-24 02:21:00 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
return []string{testPassed}
|
|
|
|
}
|
|
|
|
|
2015-06-25 04:21:21 +02:00
|
|
|
type singleton struct {
|
|
|
|
// The bootstrap Config
|
|
|
|
config *Config
|
|
|
|
}
|
2014-05-28 01:34:41 +02:00
|
|
|
|
2015-06-25 04:21:21 +02:00
|
|
|
func newSingletonFactory(config *Config) func() blueprint.Singleton {
|
|
|
|
return func() blueprint.Singleton {
|
|
|
|
return &singleton{
|
|
|
|
config: config,
|
|
|
|
}
|
|
|
|
}
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
|
|
|
|
// Find the module that's marked as the "primary builder", which means it's
|
|
|
|
// creating the binary that we'll use to generate the non-bootstrap
|
|
|
|
// build.ninja file.
|
|
|
|
var primaryBuilders []*goBinary
|
2016-05-26 19:07:59 +02:00
|
|
|
// blueprintTools contains blueprint go binaries that will be built in StageMain
|
|
|
|
var blueprintTools []string
|
2014-05-28 01:34:41 +02:00
|
|
|
ctx.VisitAllModulesIf(isBootstrapBinaryModule,
|
|
|
|
func(module blueprint.Module) {
|
|
|
|
binaryModule := module.(*goBinary)
|
2016-05-26 19:07:59 +02:00
|
|
|
|
2017-07-20 04:22:34 +02:00
|
|
|
if binaryModule.properties.Tool_dir {
|
2017-09-14 00:19:22 +02:00
|
|
|
blueprintTools = append(blueprintTools, binaryModule.InstallPath())
|
2015-07-23 02:06:06 +02:00
|
|
|
}
|
2014-05-28 01:34:41 +02:00
|
|
|
if binaryModule.properties.PrimaryBuilder {
|
|
|
|
primaryBuilders = append(primaryBuilders, binaryModule)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-08-10 00:13:12 +02:00
|
|
|
var extraSharedFlagArray []string
|
2016-11-02 01:12:28 +01:00
|
|
|
if s.config.runGoTests {
|
2017-08-10 00:13:12 +02:00
|
|
|
extraSharedFlagArray = append(extraSharedFlagArray, "-t")
|
2016-11-02 01:12:28 +01:00
|
|
|
}
|
2017-08-10 00:13:12 +02:00
|
|
|
if s.config.moduleListFile != "" {
|
|
|
|
extraSharedFlagArray = append(extraSharedFlagArray, "-l", s.config.moduleListFile)
|
|
|
|
}
|
|
|
|
extraSharedFlagString := strings.Join(extraSharedFlagArray, " ")
|
2016-11-02 01:12:28 +01:00
|
|
|
|
2014-05-28 01:34:41 +02:00
|
|
|
var primaryBuilderName, primaryBuilderExtraFlags string
|
|
|
|
switch len(primaryBuilders) {
|
|
|
|
case 0:
|
|
|
|
// If there's no primary builder module then that means we'll use minibp
|
|
|
|
// as the primary builder. We can trigger its primary builder mode with
|
|
|
|
// the -p flag.
|
|
|
|
primaryBuilderName = "minibp"
|
2017-08-10 00:13:12 +02:00
|
|
|
primaryBuilderExtraFlags = "-p " + extraSharedFlagString
|
2014-05-28 01:34:41 +02:00
|
|
|
|
|
|
|
case 1:
|
|
|
|
primaryBuilderName = ctx.ModuleName(primaryBuilders[0])
|
2017-08-10 00:13:12 +02:00
|
|
|
primaryBuilderExtraFlags = extraSharedFlagString
|
2014-05-28 01:34:41 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
ctx.Errorf("multiple primary builder modules present:")
|
|
|
|
for _, primaryBuilder := range primaryBuilders {
|
|
|
|
ctx.ModuleErrorf(primaryBuilder, "<-- module %s",
|
|
|
|
ctx.ModuleName(primaryBuilder))
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-07-14 08:28:37 +02:00
|
|
|
primaryBuilderFile := filepath.Join("$BinDir", primaryBuilderName)
|
2014-05-28 01:34:41 +02:00
|
|
|
|
|
|
|
// Get the filename of the top-level Blueprints file to pass to minibp.
|
2014-11-09 20:52:56 +01:00
|
|
|
topLevelBlueprints := filepath.Join("$srcDir",
|
2015-06-25 04:21:21 +02:00
|
|
|
filepath.Base(s.config.topLevelBlueprintsFile))
|
2014-05-28 01:34:41 +02:00
|
|
|
|
2017-07-20 07:43:30 +02:00
|
|
|
ctx.SetNinjaBuildDir(pctx, "${ninjaBuildDir}")
|
Enhance bootstrap stage selection
This simplifies the bootstrap process while making it more flexible by
moving the stage selection into a go binary(choosestage). It will now be
possible to have more than two build stages.
Now each stage has a ninja template(main.ninja.in) and a timestamp
file(main.ninja.in.timestamp). The timestamp file may be updated by any
build stage that wishes to regenerate the ninja template. If the
choosestage binaries sees that the timestamp is newer than the template,
it will choose the prior stage.
The main stage no longer writes to the source tree to update the
build.ninja.in file. This was a problem for read-only source trees.
Instead, the choosestage binary first checks to see if that file is
newer than the last bootstrap.ninja.in, copies it in place, and starts
the boostrap stage.
The bootstrap stage regenerates it's own ninja template, but that
required a loop through the main stage to actually run it. The
choosestage binary now detects if the template has changed for the
current stage, and will restart the stage.
One change is that if dependencies do get messed up, instead of silently
failing, there's a higher chance that the bootstrap step will just
continue looping, doing nothing. This can happen if the main stage
has a dependency that triggers the bootstrap stage, but the bootstrap
stage doesn't see anything required to rebuild the main ninja file. A
side effect of this requirement is that changes to test code will now
rebuild the main ninja file.
Change-Id: I9965cfba79dc0dbbd3af05f5944f7653054455a2
2015-07-23 02:05:59 +02:00
|
|
|
|
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
2018-07-06 06:56:59 +02:00
|
|
|
if s.config.stage == StagePrimary {
|
|
|
|
mainNinjaFile := filepath.Join("$buildDir", "build.ninja")
|
|
|
|
primaryBuilderNinjaGlobFile := filepath.Join(BuildDir, bootstrapSubDir, "build-globs.ninja")
|
2015-05-13 23:36:24 +02:00
|
|
|
|
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
2018-07-06 06:56:59 +02:00
|
|
|
if _, err := os.Stat(primaryBuilderNinjaGlobFile); os.IsNotExist(err) {
|
|
|
|
err = ioutil.WriteFile(primaryBuilderNinjaGlobFile, nil, 0666)
|
|
|
|
if err != nil {
|
|
|
|
ctx.Errorf("Failed to create empty ninja file: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2016-11-02 01:12:28 +01:00
|
|
|
|
2017-07-20 04:22:34 +02:00
|
|
|
if s.config.stage == StageMain {
|
2014-06-12 00:51:08 +02:00
|
|
|
if primaryBuilderName == "minibp" {
|
|
|
|
// This is a standalone Blueprint build, so we copy the minibp
|
|
|
|
// binary to the "bin" directory to make it easier to find.
|
2015-07-14 03:11:49 +02:00
|
|
|
finalMinibp := filepath.Join("$buildDir", "bin", primaryBuilderName)
|
2014-10-03 11:49:58 +02:00
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
2014-06-12 00:51:08 +02:00
|
|
|
Rule: cp,
|
|
|
|
Inputs: []string{primaryBuilderFile},
|
|
|
|
Outputs: []string{finalMinibp},
|
|
|
|
})
|
|
|
|
}
|
2016-05-26 19:07:59 +02:00
|
|
|
|
2017-12-11 23:58:45 +01:00
|
|
|
// Generate build system docs for the primary builder. Generating docs reads the source
|
|
|
|
// files used to build the primary builder, but that dependency will be picked up through
|
|
|
|
// the dependency on the primary builder itself. There are no dependencies on the
|
|
|
|
// Blueprints files, as any relevant changes to the Blueprints files would have caused
|
|
|
|
// a rebuild of the primary builder.
|
|
|
|
docsFile := filepath.Join(docsDir, primaryBuilderName+".html")
|
|
|
|
bigbpDocs := ctx.Rule(pctx, "bigbpDocs",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: fmt.Sprintf("%s %s -b $buildDir --docs $out %s", primaryBuilderFile,
|
|
|
|
primaryBuilderExtraFlags, topLevelBlueprints),
|
|
|
|
CommandDeps: []string{primaryBuilderFile},
|
|
|
|
Description: fmt.Sprintf("%s docs $out", primaryBuilderName),
|
|
|
|
})
|
|
|
|
|
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
|
|
|
Rule: bigbpDocs,
|
|
|
|
Outputs: []string{docsFile},
|
|
|
|
})
|
|
|
|
|
|
|
|
// Add a phony target for building the documentation
|
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
|
|
|
Rule: blueprint.Phony,
|
|
|
|
Outputs: []string{"blueprint_docs"},
|
|
|
|
Inputs: []string{docsFile},
|
|
|
|
})
|
|
|
|
|
|
|
|
// Add a phony target for building various tools that are part of blueprint
|
2016-05-26 19:07:59 +02:00
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
|
|
|
Rule: blueprint.Phony,
|
|
|
|
Outputs: []string{"blueprint_tools"},
|
|
|
|
Inputs: blueprintTools,
|
|
|
|
})
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// packageRoot returns the module-specific package root directory path. This
|
|
|
|
// directory is where the final package .a files are output and where dependant
|
|
|
|
// modules search for this package via -I arguments.
|
|
|
|
func packageRoot(ctx blueprint.ModuleContext) string {
|
2014-06-06 23:21:57 +02:00
|
|
|
return filepath.Join(bootstrapDir, ctx.ModuleName(), "pkg")
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
2015-06-24 02:21:00 +02:00
|
|
|
// testRoot returns the module-specific package root directory path used for
|
|
|
|
// building tests. The .a files generated here will include everything from
|
|
|
|
// packageRoot, plus the test-only code.
|
|
|
|
func testRoot(ctx blueprint.ModuleContext) string {
|
|
|
|
return filepath.Join(bootstrapDir, ctx.ModuleName(), "test")
|
|
|
|
}
|
|
|
|
|
2014-11-09 20:52:56 +01:00
|
|
|
// moduleSrcDir returns the path of the directory that all source file paths are
|
2014-05-28 01:34:41 +02:00
|
|
|
// specified relative to.
|
2014-11-09 20:52:56 +01:00
|
|
|
func moduleSrcDir(ctx blueprint.ModuleContext) string {
|
|
|
|
return filepath.Join("$srcDir", ctx.ModuleDir())
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
|
|
|
|
2014-11-09 20:52:56 +01:00
|
|
|
// moduleObjDir returns the module-specific object directory path.
|
|
|
|
func moduleObjDir(ctx blueprint.ModuleContext) string {
|
2014-06-06 23:21:57 +02:00
|
|
|
return filepath.Join(bootstrapDir, ctx.ModuleName(), "obj")
|
2014-05-28 01:34:41 +02:00
|
|
|
}
|
2015-07-25 01:53:27 +02:00
|
|
|
|
|
|
|
// moduleGenSrcDir returns the module-specific generated sources path.
|
|
|
|
func moduleGenSrcDir(ctx blueprint.ModuleContext) string {
|
|
|
|
return filepath.Join(bootstrapDir, ctx.ModuleName(), "gen")
|
|
|
|
}
|