Minor cleanup of build.go.
Test: TH presubmit. Change-Id: I3a41130b25d39276162850e417f036f9ce6a2ec0
This commit is contained in:
@@ -44,7 +44,7 @@ func SetupOutDir(ctx Context, config Config) {
|
|||||||
ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), ".out-dir"))
|
ensureEmptyFileExists(ctx, filepath.Join(config.OutDir(), ".out-dir"))
|
||||||
|
|
||||||
if buildDateTimeFile, ok := config.environ.Get("BUILD_DATETIME_FILE"); ok {
|
if buildDateTimeFile, ok := config.environ.Get("BUILD_DATETIME_FILE"); ok {
|
||||||
err := ioutil.WriteFile(buildDateTimeFile, []byte(config.buildDateTime), 0777)
|
err := ioutil.WriteFile(buildDateTimeFile, []byte(config.buildDateTime), 0666) // a+rw
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Fatalln("Failed to write BUILD_DATETIME to file:", err)
|
ctx.Fatalln("Failed to write BUILD_DATETIME to file:", err)
|
||||||
}
|
}
|
||||||
@@ -85,6 +85,7 @@ func createCombinedBuildNinjaFile(ctx Context, config Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These are bitmasks which can be used to check whether various flags are set e.g. whether to use Bazel.
|
||||||
const (
|
const (
|
||||||
BuildNone = iota
|
BuildNone = iota
|
||||||
BuildProductConfig = 1 << iota
|
BuildProductConfig = 1 << iota
|
||||||
@@ -97,6 +98,7 @@ const (
|
|||||||
BuildAllWithBazel = BuildProductConfig | BuildSoong | BuildKati | BuildBazel
|
BuildAllWithBazel = BuildProductConfig | BuildSoong | BuildKati | BuildBazel
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// checkProblematicFiles fails the build if existing Android.mk or CleanSpec.mk files are found at the root of the tree.
|
||||||
func checkProblematicFiles(ctx Context) {
|
func checkProblematicFiles(ctx Context) {
|
||||||
files := []string{"Android.mk", "CleanSpec.mk"}
|
files := []string{"Android.mk", "CleanSpec.mk"}
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
@@ -108,6 +110,7 @@ func checkProblematicFiles(ctx Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkCaseSensitivity issues a warning if a case-insensitive file system is being used.
|
||||||
func checkCaseSensitivity(ctx Context, config Config) {
|
func checkCaseSensitivity(ctx Context, config Config) {
|
||||||
outDir := config.OutDir()
|
outDir := config.OutDir()
|
||||||
lowerCase := filepath.Join(outDir, "casecheck.txt")
|
lowerCase := filepath.Join(outDir, "casecheck.txt")
|
||||||
@@ -115,13 +118,11 @@ func checkCaseSensitivity(ctx Context, config Config) {
|
|||||||
lowerData := "a"
|
lowerData := "a"
|
||||||
upperData := "B"
|
upperData := "B"
|
||||||
|
|
||||||
err := ioutil.WriteFile(lowerCase, []byte(lowerData), 0777)
|
if err := ioutil.WriteFile(lowerCase, []byte(lowerData), 0666); err != nil { // a+rw
|
||||||
if err != nil {
|
|
||||||
ctx.Fatalln("Failed to check case sensitivity:", err)
|
ctx.Fatalln("Failed to check case sensitivity:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(upperCase, []byte(upperData), 0777)
|
if err := ioutil.WriteFile(upperCase, []byte(upperData), 0666); err != nil { // a+rw
|
||||||
if err != nil {
|
|
||||||
ctx.Fatalln("Failed to check case sensitivity:", err)
|
ctx.Fatalln("Failed to check case sensitivity:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,18 +140,15 @@ func checkCaseSensitivity(ctx Context, config Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func help(ctx Context, config Config, what int) {
|
// help prints a help/usage message, via the build/make/help.sh script.
|
||||||
|
func help(ctx Context, config Config) {
|
||||||
cmd := Command(ctx, config, "help.sh", "build/make/help.sh")
|
cmd := Command(ctx, config, "help.sh", "build/make/help.sh")
|
||||||
cmd.Sandbox = dumpvarsSandbox
|
cmd.Sandbox = dumpvarsSandbox
|
||||||
cmd.RunAndPrintOrFatal()
|
cmd.RunAndPrintOrFatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the tree. The 'what' argument can be used to chose which components of
|
// checkRAM warns if there probably isn't enough RAM to complete a build.
|
||||||
// the build to run.
|
func checkRAM(ctx Context, config Config) {
|
||||||
func Build(ctx Context, config Config, what int) {
|
|
||||||
ctx.Verboseln("Starting build with args:", config.Arguments())
|
|
||||||
ctx.Verboseln("Environment:", config.Environment().Environ())
|
|
||||||
|
|
||||||
if totalRAM := config.TotalRAM(); totalRAM != 0 {
|
if totalRAM := config.TotalRAM(); totalRAM != 0 {
|
||||||
ram := float32(totalRAM) / (1024 * 1024 * 1024)
|
ram := float32(totalRAM) / (1024 * 1024 * 1024)
|
||||||
ctx.Verbosef("Total RAM: %.3vGB", ram)
|
ctx.Verbosef("Total RAM: %.3vGB", ram)
|
||||||
@@ -166,24 +164,24 @@ func Build(ctx Context, config Config, what int) {
|
|||||||
ctx.Println("-j value.")
|
ctx.Println("-j value.")
|
||||||
ctx.Println("************************************************************")
|
ctx.Println("************************************************************")
|
||||||
} else if ram <= float32(config.Parallel()) {
|
} else if ram <= float32(config.Parallel()) {
|
||||||
|
// Want at least 1GB of RAM per job.
|
||||||
ctx.Printf("Warning: high -j%d count compared to %.3vGB of RAM", config.Parallel(), ram)
|
ctx.Printf("Warning: high -j%d count compared to %.3vGB of RAM", config.Parallel(), ram)
|
||||||
ctx.Println("If you run into segfaults or other errors, try a lower -j value")
|
ctx.Println("If you run into segfaults or other errors, try a lower -j value")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the tree. The 'what' argument can be used to chose which components of
|
||||||
|
// the build to run, via checking various bitmasks.
|
||||||
|
func Build(ctx Context, config Config, what int) {
|
||||||
|
ctx.Verboseln("Starting build with args:", config.Arguments())
|
||||||
|
ctx.Verboseln("Environment:", config.Environment().Environ())
|
||||||
|
|
||||||
ctx.BeginTrace(metrics.Total, "total")
|
ctx.BeginTrace(metrics.Total, "total")
|
||||||
defer ctx.EndTrace()
|
defer ctx.EndTrace()
|
||||||
|
|
||||||
if config.SkipMake() {
|
|
||||||
ctx.Verboseln("Skipping Make/Kati as requested")
|
|
||||||
what = what & (BuildSoong | BuildNinja)
|
|
||||||
}
|
|
||||||
|
|
||||||
if inList("help", config.Arguments()) {
|
if inList("help", config.Arguments()) {
|
||||||
help(ctx, config, what)
|
help(ctx, config)
|
||||||
return
|
|
||||||
} else if inList("clean", config.Arguments()) || inList("clobber", config.Arguments()) {
|
|
||||||
clean(ctx, config)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,16 +189,31 @@ func Build(ctx Context, config Config, what int) {
|
|||||||
buildLock := BecomeSingletonOrFail(ctx, config)
|
buildLock := BecomeSingletonOrFail(ctx, config)
|
||||||
defer buildLock.Unlock()
|
defer buildLock.Unlock()
|
||||||
|
|
||||||
|
if inList("clean", config.Arguments()) || inList("clobber", config.Arguments()) {
|
||||||
|
clean(ctx, config)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkProblematicFiles aborts the build if Android.mk or CleanSpec.mk are found at the root of the tree.
|
||||||
checkProblematicFiles(ctx)
|
checkProblematicFiles(ctx)
|
||||||
|
|
||||||
|
checkRAM(ctx, config)
|
||||||
|
|
||||||
SetupOutDir(ctx, config)
|
SetupOutDir(ctx, config)
|
||||||
|
|
||||||
|
// checkCaseSensitivity issues a warning if a case-insensitive file system is being used.
|
||||||
checkCaseSensitivity(ctx, config)
|
checkCaseSensitivity(ctx, config)
|
||||||
|
|
||||||
ensureEmptyDirectoriesExist(ctx, config.TempDir())
|
ensureEmptyDirectoriesExist(ctx, config.TempDir())
|
||||||
|
|
||||||
SetupPath(ctx, config)
|
SetupPath(ctx, config)
|
||||||
|
|
||||||
|
if config.SkipMake() {
|
||||||
|
ctx.Verboseln("Skipping Make/Kati as requested")
|
||||||
|
// If Make/Kati is disabled, then explicitly build using Soong and Ninja.
|
||||||
|
what = what & (BuildSoong | BuildNinja)
|
||||||
|
}
|
||||||
|
|
||||||
if config.StartGoma() {
|
if config.StartGoma() {
|
||||||
// Ensure start Goma compiler_proxy
|
// Ensure start Goma compiler_proxy
|
||||||
startGoma(ctx, config)
|
startGoma(ctx, config)
|
||||||
@@ -216,12 +229,16 @@ func Build(ctx Context, config Config, what int) {
|
|||||||
runMakeProductConfig(ctx, config)
|
runMakeProductConfig(ctx, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Everything below here depends on product config.
|
||||||
|
|
||||||
if inList("installclean", config.Arguments()) ||
|
if inList("installclean", config.Arguments()) ||
|
||||||
inList("install-clean", config.Arguments()) {
|
inList("install-clean", config.Arguments()) {
|
||||||
installClean(ctx, config)
|
installClean(ctx, config)
|
||||||
ctx.Println("Deleted images and staging directories.")
|
ctx.Println("Deleted images and staging directories.")
|
||||||
return
|
return
|
||||||
} else if inList("dataclean", config.Arguments()) ||
|
}
|
||||||
|
|
||||||
|
if inList("dataclean", config.Arguments()) ||
|
||||||
inList("data-clean", config.Arguments()) {
|
inList("data-clean", config.Arguments()) {
|
||||||
dataClean(ctx, config)
|
dataClean(ctx, config)
|
||||||
ctx.Println("Deleted data files.")
|
ctx.Println("Deleted data files.")
|
||||||
@@ -240,7 +257,7 @@ func Build(ctx Context, config Config, what int) {
|
|||||||
runKatiBuild(ctx, config)
|
runKatiBuild(ctx, config)
|
||||||
runKatiPackage(ctx, config)
|
runKatiPackage(ctx, config)
|
||||||
|
|
||||||
ioutil.WriteFile(config.LastKatiSuffixFile(), []byte(config.KatiSuffix()), 0777)
|
ioutil.WriteFile(config.LastKatiSuffixFile(), []byte(config.KatiSuffix()), 0666) // a+rw
|
||||||
} else {
|
} else {
|
||||||
// Load last Kati Suffix if it exists
|
// Load last Kati Suffix if it exists
|
||||||
if katiSuffix, err := ioutil.ReadFile(config.LastKatiSuffixFile()); err == nil {
|
if katiSuffix, err := ioutil.ReadFile(config.LastKatiSuffixFile()); err == nil {
|
||||||
@@ -267,6 +284,7 @@ func Build(ctx Context, config Config, what int) {
|
|||||||
runNinja(ctx, config)
|
runNinja(ctx, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Currently, using Bazel requires Kati and Soong to run first, so check whether to run Bazel last.
|
||||||
if what&BuildBazel != 0 {
|
if what&BuildBazel != 0 {
|
||||||
runBazel(ctx, config)
|
runBazel(ctx, config)
|
||||||
}
|
}
|
||||||
@@ -282,14 +300,11 @@ func distGzipFile(ctx Context, config Config, src string, subDirs ...string) {
|
|||||||
subDir := filepath.Join(subDirs...)
|
subDir := filepath.Join(subDirs...)
|
||||||
destDir := filepath.Join(config.DistDir(), "soong_ui", subDir)
|
destDir := filepath.Join(config.DistDir(), "soong_ui", subDir)
|
||||||
|
|
||||||
err := os.MkdirAll(destDir, 0777)
|
if err := os.MkdirAll(destDir, 0777); err != nil { // a+rwx
|
||||||
if err != nil {
|
|
||||||
ctx.Printf("failed to mkdir %s: %s", destDir, err.Error())
|
ctx.Printf("failed to mkdir %s: %s", destDir, err.Error())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = gzipFileToDir(src, destDir)
|
if err := gzipFileToDir(src, destDir); err != nil {
|
||||||
if err != nil {
|
|
||||||
ctx.Printf("failed to dist %s: %s", filepath.Base(src), err.Error())
|
ctx.Printf("failed to dist %s: %s", filepath.Base(src), err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -304,14 +319,11 @@ func distFile(ctx Context, config Config, src string, subDirs ...string) {
|
|||||||
subDir := filepath.Join(subDirs...)
|
subDir := filepath.Join(subDirs...)
|
||||||
destDir := filepath.Join(config.DistDir(), "soong_ui", subDir)
|
destDir := filepath.Join(config.DistDir(), "soong_ui", subDir)
|
||||||
|
|
||||||
err := os.MkdirAll(destDir, 0777)
|
if err := os.MkdirAll(destDir, 0777); err != nil { // a+rwx
|
||||||
if err != nil {
|
|
||||||
ctx.Printf("failed to mkdir %s: %s", destDir, err.Error())
|
ctx.Printf("failed to mkdir %s: %s", destDir, err.Error())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = copyFile(src, filepath.Join(destDir, filepath.Base(src)))
|
if _, err := copyFile(src, filepath.Join(destDir, filepath.Base(src))); err != nil {
|
||||||
if err != nil {
|
|
||||||
ctx.Printf("failed to dist %s: %s", filepath.Base(src), err.Error())
|
ctx.Printf("failed to dist %s: %s", filepath.Base(src), err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user