Merge "Use HINT_FROM_SOONG if ninja_log doesn't exist"
This commit is contained in:
@@ -16,6 +16,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@@ -135,12 +136,24 @@ func runMixedModeBuild(ctx *android.Context, extraNinjaDeps []string) string {
|
|||||||
|
|
||||||
writeDepFile(cmdlineArgs.OutFile, ctx.EventHandler, ninjaDeps)
|
writeDepFile(cmdlineArgs.OutFile, ctx.EventHandler, ninjaDeps)
|
||||||
|
|
||||||
if ctx.Config().IsEnvTrue("SOONG_GENERATES_NINJA_HINT") {
|
if needToWriteNinjaHint(ctx) {
|
||||||
writeNinjaHint(ctx)
|
writeNinjaHint(ctx)
|
||||||
}
|
}
|
||||||
return cmdlineArgs.OutFile
|
return cmdlineArgs.OutFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func needToWriteNinjaHint(ctx *android.Context) bool {
|
||||||
|
switch ctx.Config().GetenvWithDefault("SOONG_GENERATES_NINJA_HINT", "") {
|
||||||
|
case "always":
|
||||||
|
return true
|
||||||
|
case "depend":
|
||||||
|
if _, err := os.Stat(filepath.Join(ctx.Config().OutDir(), ".ninja_log")); errors.Is(err, os.ErrNotExist) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Run the code-generation phase to convert BazelTargetModules to BUILD files.
|
// Run the code-generation phase to convert BazelTargetModules to BUILD files.
|
||||||
func runQueryView(queryviewDir, queryviewMarker string, ctx *android.Context) {
|
func runQueryView(queryviewDir, queryviewMarker string, ctx *android.Context) {
|
||||||
ctx.EventHandler.Begin("queryview")
|
ctx.EventHandler.Begin("queryview")
|
||||||
@@ -460,7 +473,7 @@ func runSoongOnlyBuild(ctx *android.Context, extraNinjaDeps []string) string {
|
|||||||
// The actual output (build.ninja) was written in the RunBlueprint() call
|
// The actual output (build.ninja) was written in the RunBlueprint() call
|
||||||
// above
|
// above
|
||||||
writeDepFile(cmdlineArgs.OutFile, ctx.EventHandler, ninjaDeps)
|
writeDepFile(cmdlineArgs.OutFile, ctx.EventHandler, ninjaDeps)
|
||||||
if ctx.Config().IsEnvTrue("SOONG_GENERATES_NINJA_HINT") {
|
if needToWriteNinjaHint(ctx) {
|
||||||
writeNinjaHint(ctx)
|
writeNinjaHint(ctx)
|
||||||
}
|
}
|
||||||
return cmdlineArgs.OutFile
|
return cmdlineArgs.OutFile
|
||||||
|
@@ -16,6 +16,7 @@ package build
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@@ -136,6 +137,9 @@ const (
|
|||||||
EXTERNAL_FILE
|
EXTERNAL_FILE
|
||||||
// ninja uses a prioritized module list from Soong
|
// ninja uses a prioritized module list from Soong
|
||||||
HINT_FROM_SOONG
|
HINT_FROM_SOONG
|
||||||
|
// If ninja log exists, use NINJA_LOG, if not, use HINT_FROM_SOONG instead.
|
||||||
|
// We can assume it is an incremental build if ninja log exists.
|
||||||
|
DEFAULT
|
||||||
)
|
)
|
||||||
const srcDirFileCheck = "build/soong/root.bp"
|
const srcDirFileCheck = "build/soong/root.bp"
|
||||||
|
|
||||||
@@ -233,7 +237,7 @@ func NewConfig(ctx Context, args ...string) Config {
|
|||||||
ret := &configImpl{
|
ret := &configImpl{
|
||||||
environ: OsEnvironment(),
|
environ: OsEnvironment(),
|
||||||
sandboxConfig: &SandboxConfig{},
|
sandboxConfig: &SandboxConfig{},
|
||||||
ninjaWeightListSource: NINJA_LOG,
|
ninjaWeightListSource: DEFAULT,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default matching ninja
|
// Default matching ninja
|
||||||
@@ -244,8 +248,21 @@ func NewConfig(ctx Context, args ...string) Config {
|
|||||||
ret.parseArgs(ctx, args)
|
ret.parseArgs(ctx, args)
|
||||||
|
|
||||||
if ret.ninjaWeightListSource == HINT_FROM_SOONG {
|
if ret.ninjaWeightListSource == HINT_FROM_SOONG {
|
||||||
ret.environ.Set("SOONG_GENERATES_NINJA_HINT", "true")
|
ret.environ.Set("SOONG_GENERATES_NINJA_HINT", "always")
|
||||||
|
} else if ret.ninjaWeightListSource == DEFAULT {
|
||||||
|
defaultNinjaWeightListSource := NINJA_LOG
|
||||||
|
if _, err := os.Stat(filepath.Join(ret.OutDir(), ninjaLogFileName)); errors.Is(err, os.ErrNotExist) {
|
||||||
|
ctx.Verboseln("$OUT/.ninja_log doesn't exist, use HINT_FROM_SOONG instead")
|
||||||
|
defaultNinjaWeightListSource = HINT_FROM_SOONG
|
||||||
|
} else {
|
||||||
|
ctx.Verboseln("$OUT/.ninja_log exist, use NINJA_LOG")
|
||||||
}
|
}
|
||||||
|
ret.ninjaWeightListSource = defaultNinjaWeightListSource
|
||||||
|
// soong_build generates ninja hint depending on ninja log existence.
|
||||||
|
// Set it "depend" to avoid soong re-run due to env variable change.
|
||||||
|
ret.environ.Set("SOONG_GENERATES_NINJA_HINT", "depend")
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure OUT_DIR is set appropriately
|
// Make sure OUT_DIR is set appropriately
|
||||||
if outDir, ok := ret.environ.Get("OUT_DIR"); ok {
|
if outDir, ok := ret.environ.Get("OUT_DIR"); ok {
|
||||||
ret.environ.Set("OUT_DIR", filepath.Clean(outDir))
|
ret.environ.Set("OUT_DIR", filepath.Clean(outDir))
|
||||||
|
Reference in New Issue
Block a user