Add --skip-make to replace Soong's blueprint wrapper with soong_ui

This way we only have one way to start a build, which always has logging
/ tracing / etc, even if we don't need Kati.

There's two ways to use this:

As a direct replacement for mkdir out; cd out; ../bootstrap.bash;
./soong -- as long as --skip-make is always passed, we'll never run
Kati, and Soong will run outside of it's "make" mode. This preserves
most of the speed, and allows full user control over the Soong
configuration.

A (experimental, dangerous) way to temporarily bypass the product
variable and kati steps of a build. As long as a user is sure that
nothing has changed from the last build, and they know exactly which
Ninja targets they want to build (which may not be the same as the
arguments normally passed to 'm'), this can lead to shorter build
startup times.

Test: rm -rf out; m --skip-make libc
Test: rm -rf out; m libc; m --skip-make libc
Test: rm -rf out; mkdir out; cd out; ../bootstrap.bash; ./soong libc
Test: build/soong/scripts/build-ndk-prebuilts.sh
Change-Id: Ic0f91167b5779dba3f248a379fbaac67a75a946e
This commit is contained in:
Dan Willemsen 2017-08-04 15:06:27 -07:00
parent 8d6aed7ed7
commit e0879fc3ae
8 changed files with 77 additions and 12 deletions

View File

@ -2,6 +2,14 @@
set -e
if [ -z "$NO_DEPRECATION_WARNING" ]; then
echo '== WARNING: bootstrap.bash & ./soong are deprecated ==' >&2
echo 'Use `m --skip-make` with a standalone OUT_DIR instead.' >&2
echo 'Without envsetup.sh, use:' >&2
echo ' build/soong/soong_ui.bash --make-mode --skip-make' >&2
echo '======================================================' >&2
fi
ORIG_SRCDIR=$(dirname "${BASH_SOURCE[0]}")
if [[ "$ORIG_SRCDIR" != "." ]]; then
if [[ ! -z "$BUILDDIR" ]]; then

View File

@ -54,8 +54,7 @@ cat > ${SOONG_OUT}/soong.variables << EOF
"Safestack": false
}
EOF
BUILDDIR=${SOONG_OUT} ./bootstrap.bash
${SOONG_OUT}/soong ${SOONG_OUT}/ndk.timestamp
m --skip-make ${SOONG_OUT}/ndk.timestamp
if [ -n "${DIST_DIR}" ]; then
mkdir -p ${DIST_DIR} || true

View File

@ -5,6 +5,14 @@ set -e
# Switch to the build directory
cd $(dirname "${BASH_SOURCE[0]}")
if [ -z "$NO_DEPRECATION_WARNING" ]; then
echo '== WARNING: bootstrap.bash & ./soong are deprecated ==' >&2
echo 'Use `m --skip-make` with a standalone OUT_DIR instead.' >&2
echo 'Without envsetup.sh, use:' >&2
echo ' build/soong/soong_ui.bash --make-mode --skip-make' >&2
echo '======================================================' >&2
fi
# The source directory path and operating system will get written to
# .soong.bootstrap by the bootstrap script.

View File

@ -26,7 +26,9 @@ import (
func SetupOutDir(ctx Context, config Config) {
ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), "Android.mk"))
ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), "CleanSpec.mk"))
ensureEmptyFileExists(ctx, filepath.Join(config.SoongOutDir(), ".soong.in_make"))
if !config.SkipMake() {
ensureEmptyFileExists(ctx, filepath.Join(config.SoongOutDir(), ".soong.in_make"))
}
// The ninja_build file is used by our buildbots to understand that the output
// can be parsed as ninja output.
ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), "ninja_build"))
@ -34,12 +36,20 @@ func SetupOutDir(ctx Context, config Config) {
var combinedBuildNinjaTemplate = template.Must(template.New("combined").Parse(`
builddir = {{.OutDir}}
include {{.KatiNinjaFile}}
{{if .HasKatiSuffix}}include {{.KatiNinjaFile}}
{{end -}}
include {{.SoongNinjaFile}}
build {{.CombinedNinjaFile}}: phony {{.SoongNinjaFile}}
`))
func createCombinedBuildNinjaFile(ctx Context, config Config) {
// If we're in SkipMake mode, skip creating this file if it already exists
if config.SkipMake() {
if _, err := os.Stat(config.CombinedNinjaFile()); err == nil || !os.IsNotExist(err) {
return
}
}
file, err := os.Create(config.CombinedNinjaFile())
if err != nil {
ctx.Fatalln("Failed to create combined ninja file:", err)
@ -106,6 +116,11 @@ func Build(ctx Context, config Config, what int) {
ctx.Verboseln("Starting build with args:", config.Arguments())
ctx.Verboseln("Environment:", config.Environment().Environ())
if config.SkipMake() {
ctx.Verboseln("Skipping Make/Kati as requested")
what = what & (BuildSoong | BuildNinja)
}
if inList("help", config.Arguments()) {
help(ctx, config, what)
return
@ -148,10 +163,20 @@ func Build(ctx Context, config Config, what int) {
if what&BuildKati != 0 {
// Run ckati
runKati(ctx, config)
ioutil.WriteFile(config.LastKatiSuffixFile(), []byte(config.KatiSuffix()), 0777)
} else {
// Load last Kati Suffix if it exists
if katiSuffix, err := ioutil.ReadFile(config.LastKatiSuffixFile()); err == nil {
ctx.Verboseln("Loaded previous kati config:", string(katiSuffix))
config.SetKatiSuffix(string(katiSuffix))
}
}
if what&BuildNinja != 0 {
installCleanIfNecessary(ctx, config)
if !config.SkipMake() {
installCleanIfNecessary(ctx, config)
}
// Write combined ninja file
createCombinedBuildNinjaFile(ctx, config)

View File

@ -129,6 +129,8 @@ func installCleanIfNecessary(ctx Context, config Config) {
suffix := "\n"
currentProduct := prefix + config.TargetProduct() + "-" + config.TargetBuildVariant() + suffix
ensureDirectoriesExist(ctx, filepath.Dir(configFile))
writeConfig := func() {
err := ioutil.WriteFile(configFile, []byte(currentProduct), 0666)
if err != nil {

View File

@ -38,6 +38,7 @@ type configImpl struct {
keepGoing int
verbose bool
dist bool
skipMake bool
// From the product config
katiArgs []string
@ -149,14 +150,11 @@ func (c *configImpl) parseArgs(ctx Context, args []string) {
for i := 0; i < len(args); i++ {
arg := strings.TrimSpace(args[i])
if arg == "--make-mode" {
continue
} else if arg == "showcommands" {
c.verbose = true
continue
} else if arg == "dist" {
c.dist = true
}
if arg[0] == '-' {
} else if arg == "--skip-make" {
c.skipMake = true
} else if arg[0] == '-' {
parseArgNum := func(def int) int {
if len(arg) > 2 {
p, err := strconv.ParseUint(arg[2:], 10, 31)
@ -184,6 +182,9 @@ func (c *configImpl) parseArgs(ctx Context, args []string) {
} else if k, v, ok := decodeKeyValue(arg); ok && len(k) > 0 {
c.environ.Set(k, v)
} else {
if arg == "dist" {
c.dist = true
}
c.arguments = append(c.arguments, arg)
}
}
@ -265,6 +266,9 @@ func (c *configImpl) DistDir() string {
}
func (c *configImpl) NinjaArgs() []string {
if c.skipMake {
return c.arguments
}
return c.ninjaArgs
}
@ -291,6 +295,10 @@ func (c *configImpl) IsVerbose() bool {
return c.verbose
}
func (c *configImpl) SkipMake() bool {
return c.skipMake
}
func (c *configImpl) TargetProduct() string {
if v, ok := c.environ.Get("TARGET_PRODUCT"); ok {
return v
@ -355,6 +363,14 @@ func (c *configImpl) SetKatiSuffix(suffix string) {
c.katiSuffix = suffix
}
func (c *configImpl) LastKatiSuffixFile() string {
return filepath.Join(c.OutDir(), "last_kati_suffix")
}
func (c *configImpl) HasKatiSuffix() bool {
return c.katiSuffix != ""
}
func (c *configImpl) KatiEnvFile() string {
return filepath.Join(c.OutDir(), "env"+c.KatiSuffix()+".sh")
}
@ -368,6 +384,9 @@ func (c *configImpl) SoongNinjaFile() string {
}
func (c *configImpl) CombinedNinjaFile() string {
if c.katiSuffix == "" {
return filepath.Join(c.OutDir(), "combined.ninja")
}
return filepath.Join(c.OutDir(), "combined"+c.KatiSuffix()+".ninja")
}

View File

@ -53,7 +53,9 @@ func runNinja(ctx Context, config Config) {
args = append(args, "-w", "dupbuild=err")
cmd := Command(ctx, config, "ninja", executable, args...)
cmd.Environment.AppendFromKati(config.KatiEnvFile())
if config.HasKatiSuffix() {
cmd.Environment.AppendFromKati(config.KatiEnvFile())
}
// Allow both NINJA_ARGS and NINJA_EXTRA_ARGS, since both have been
// used in the past to specify extra ninja arguments.

View File

@ -25,6 +25,7 @@ func runSoongBootstrap(ctx Context, config Config) {
cmd := Command(ctx, config, "soong bootstrap", "./bootstrap.bash")
cmd.Environment.Set("BUILDDIR", config.SoongOutDir())
cmd.Environment.Set("NINJA_BUILDDIR", config.OutDir())
cmd.Environment.Set("NO_DEPRECATION_WARNING", "true")
cmd.Sandbox = soongSandbox
cmd.Stdout = ctx.Stdout()
cmd.Stderr = ctx.Stderr()
@ -41,6 +42,7 @@ func runSoong(ctx Context, config Config) {
cmd.Args = append(cmd.Args, "-v")
}
cmd.Environment.Set("SKIP_NINJA", "true")
cmd.Environment.Set("NO_DEPRECATION_WARNING", "true")
cmd.Sandbox = soongSandbox
cmd.Stdin = ctx.Stdin()
cmd.Stdout = ctx.Stdout()