Merge changes from topics 'soong_ui_installclean', 'soong_ui_version', 'soong_ui_clean'
* changes: Move auto installclean to soong_ui Move version checking from Make into soong_ui Move clean/clobber to soong_ui
This commit is contained in:
commit
63b599a7a0
|
@ -25,6 +25,7 @@ bootstrap_go_package {
|
|||
"context.go",
|
||||
"environment.go",
|
||||
"exec.go",
|
||||
"java.go",
|
||||
"kati.go",
|
||||
"make.go",
|
||||
"ninja.go",
|
||||
|
|
|
@ -15,8 +15,10 @@
|
|||
package build
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
|
@ -59,6 +61,93 @@ const (
|
|||
BuildAll = BuildProductConfig | BuildSoong | BuildKati | BuildNinja
|
||||
)
|
||||
|
||||
func checkCaseSensitivity(ctx Context, config Config) {
|
||||
outDir := config.OutDir()
|
||||
lowerCase := filepath.Join(outDir, "casecheck.txt")
|
||||
upperCase := filepath.Join(outDir, "CaseCheck.txt")
|
||||
lowerData := "a"
|
||||
upperData := "B"
|
||||
|
||||
err := ioutil.WriteFile(lowerCase, []byte(lowerData), 0777)
|
||||
if err != nil {
|
||||
ctx.Fatalln("Failed to check case sensitivity:", err)
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(upperCase, []byte(upperData), 0777)
|
||||
if err != nil {
|
||||
ctx.Fatalln("Failed to check case sensitivity:", err)
|
||||
}
|
||||
|
||||
res, err := ioutil.ReadFile(lowerCase)
|
||||
if err != nil {
|
||||
ctx.Fatalln("Failed to check case sensitivity:", err)
|
||||
}
|
||||
|
||||
if string(res) != lowerData {
|
||||
ctx.Println("************************************************************")
|
||||
ctx.Println("You are building on a case-insensitive filesystem.")
|
||||
ctx.Println("Please move your source tree to a case-sensitive filesystem.")
|
||||
ctx.Println("************************************************************")
|
||||
ctx.Fatalln("Case-insensitive filesystems not supported")
|
||||
}
|
||||
}
|
||||
|
||||
// Since products and build variants (unfortunately) shared the same
|
||||
// PRODUCT_OUT staging directory, things can get out of sync if different
|
||||
// build configurations are built in the same tree. This function will
|
||||
// notice when the configuration has changed and call installclean to
|
||||
// remove the files necessary to keep things consistent.
|
||||
func installcleanIfNecessary(ctx Context, config Config) {
|
||||
if inList("installclean", config.Arguments()) {
|
||||
return
|
||||
}
|
||||
|
||||
configFile := config.DevicePreviousProductConfig()
|
||||
prefix := "PREVIOUS_BUILD_CONFIG := "
|
||||
suffix := "\n"
|
||||
currentProduct := prefix + config.TargetProduct() + "-" + config.TargetBuildVariant() + suffix
|
||||
|
||||
writeConfig := func() {
|
||||
err := ioutil.WriteFile(configFile, []byte(currentProduct), 0777)
|
||||
if err != nil {
|
||||
ctx.Fatalln("Failed to write product config:", err)
|
||||
}
|
||||
}
|
||||
|
||||
prev, err := ioutil.ReadFile(configFile)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
writeConfig()
|
||||
return
|
||||
} else {
|
||||
ctx.Fatalln("Failed to read previous product config:", err)
|
||||
}
|
||||
} else if string(prev) == currentProduct {
|
||||
return
|
||||
}
|
||||
|
||||
if disable, _ := config.Environment().Get("DISABLE_AUTO_INSTALLCLEAN"); disable == "true" {
|
||||
ctx.Println("DISABLE_AUTO_INSTALLCLEAN is set; skipping auto-clean. Your tree may be in an inconsistent state.")
|
||||
return
|
||||
}
|
||||
|
||||
ctx.BeginTrace("installclean")
|
||||
defer ctx.EndTrace()
|
||||
|
||||
prevConfig := strings.TrimPrefix(strings.TrimSuffix(string(prev), suffix), prefix)
|
||||
currentConfig := strings.TrimPrefix(strings.TrimSuffix(currentProduct, suffix), prefix)
|
||||
|
||||
ctx.Printf("Build configuration changed: %q -> %q, forcing installclean\n", prevConfig, currentConfig)
|
||||
|
||||
cleanConfig := CopyConfig(ctx, config, "installclean")
|
||||
cleanConfig.SetKatiArgs([]string{"installclean"})
|
||||
cleanConfig.SetNinjaArgs([]string{"installclean"})
|
||||
|
||||
Build(ctx, cleanConfig, BuildKati|BuildNinja)
|
||||
|
||||
writeConfig()
|
||||
}
|
||||
|
||||
// Build the tree. The 'what' argument can be used to chose which components of
|
||||
// the build to run.
|
||||
func Build(ctx Context, config Config, what int) {
|
||||
|
@ -73,10 +162,26 @@ func Build(ctx Context, config Config, what int) {
|
|||
cmd.Stderr = ctx.Stderr()
|
||||
cmd.RunOrFatal()
|
||||
return
|
||||
} else if inList("clean", config.Arguments()) || inList("clobber", config.Arguments()) {
|
||||
// We can't use os.RemoveAll, since we don't want to remove the
|
||||
// output directory itself, in case it's a symlink. So just do
|
||||
// exactly what make used to do.
|
||||
cmd := Command(ctx, config, "rm -rf $OUT_DIR/*",
|
||||
"/bin/bash", "-c", "rm -rf "+config.OutDir()+"/*")
|
||||
cmd.Stdout = ctx.Stdout()
|
||||
cmd.Stderr = ctx.Stderr()
|
||||
cmd.RunOrFatal()
|
||||
ctx.Println("Entire build directory removed.")
|
||||
return
|
||||
}
|
||||
|
||||
// Start getting java version as early as possible
|
||||
getJavaVersions(ctx, config)
|
||||
|
||||
SetupOutDir(ctx, config)
|
||||
|
||||
checkCaseSensitivity(ctx, config)
|
||||
|
||||
if what&BuildProductConfig != 0 {
|
||||
// Run make for product config
|
||||
runMakeProductConfig(ctx, config)
|
||||
|
@ -88,12 +193,17 @@ func Build(ctx Context, config Config, what int) {
|
|||
runSoong(ctx, config)
|
||||
}
|
||||
|
||||
// Check the java versions we read earlier
|
||||
checkJavaVersion(ctx, config)
|
||||
|
||||
if what&BuildKati != 0 {
|
||||
// Run ckati
|
||||
runKati(ctx, config)
|
||||
}
|
||||
|
||||
if what&BuildNinja != 0 {
|
||||
installcleanIfNecessary(ctx, config)
|
||||
|
||||
// Write combined ninja file
|
||||
createCombinedBuildNinjaFile(ctx, config)
|
||||
|
||||
|
|
|
@ -38,9 +38,10 @@ type configImpl struct {
|
|||
dist bool
|
||||
|
||||
// From the product config
|
||||
katiArgs []string
|
||||
ninjaArgs []string
|
||||
katiSuffix string
|
||||
katiArgs []string
|
||||
ninjaArgs []string
|
||||
katiSuffix string
|
||||
targetDevice string
|
||||
}
|
||||
|
||||
const srcDirFileCheck = "build/soong/root.bp"
|
||||
|
@ -106,6 +107,32 @@ func NewConfig(ctx Context, args ...string) Config {
|
|||
log.Fatalln("Error verifying tree state:", err)
|
||||
}
|
||||
|
||||
if srcDir, err := filepath.Abs("."); err == nil {
|
||||
if strings.ContainsRune(srcDir, ' ') {
|
||||
log.Println("You are building in a directory whose absolute path contains a space character:")
|
||||
log.Println()
|
||||
log.Printf("%q\n", srcDir)
|
||||
log.Println()
|
||||
log.Fatalln("Directory names containing spaces are not supported")
|
||||
}
|
||||
}
|
||||
|
||||
if outDir := ret.OutDir(); strings.ContainsRune(outDir, ' ') {
|
||||
log.Println("The absolute path of your output directory ($OUT_DIR) contains a space character:")
|
||||
log.Println()
|
||||
log.Printf("%q\n", outDir)
|
||||
log.Println()
|
||||
log.Fatalln("Directory names containing spaces are not supported")
|
||||
}
|
||||
|
||||
if distDir := ret.DistDir(); strings.ContainsRune(distDir, ' ') {
|
||||
log.Println("The absolute path of your dist directory ($DIST_DIR) contains a space character:")
|
||||
log.Println()
|
||||
log.Printf("%q\n", distDir)
|
||||
log.Println()
|
||||
log.Fatalln("Directory names containing spaces are not supported")
|
||||
}
|
||||
|
||||
for _, arg := range args {
|
||||
arg = strings.TrimSpace(arg)
|
||||
if arg == "--make-mode" {
|
||||
|
@ -140,6 +167,22 @@ func NewConfig(ctx Context, args ...string) Config {
|
|||
return Config{ret}
|
||||
}
|
||||
|
||||
// CopyConfig copies the configuration from an existing configuration, but replaces
|
||||
// the Arguments() list with a new set. Useful if you need to run a different build
|
||||
// with the same state as an existing build config.
|
||||
func CopyConfig(ctx Context, config Config, args ...string) Config {
|
||||
return Config{&configImpl{
|
||||
arguments: args,
|
||||
goma: config.goma,
|
||||
environ: config.environ.Copy(),
|
||||
|
||||
parallel: config.parallel,
|
||||
keepGoing: config.keepGoing,
|
||||
verbose: config.verbose,
|
||||
dist: config.dist,
|
||||
}}
|
||||
}
|
||||
|
||||
// Lunch configures the environment for a specific product similarly to the
|
||||
// `lunch` bash function.
|
||||
func (c *configImpl) Lunch(ctx Context, product, variant string) {
|
||||
|
@ -245,6 +288,21 @@ func (c *configImpl) TargetProduct() string {
|
|||
panic("TARGET_PRODUCT is not defined")
|
||||
}
|
||||
|
||||
func (c *configImpl) TargetDevice() string {
|
||||
return c.targetDevice
|
||||
}
|
||||
|
||||
func (c *configImpl) SetTargetDevice(device string) {
|
||||
c.targetDevice = device
|
||||
}
|
||||
|
||||
func (c *configImpl) TargetBuildVariant() string {
|
||||
if v, ok := c.environ.Get("TARGET_BUILD_VARIANT"); ok {
|
||||
return v
|
||||
}
|
||||
panic("TARGET_BUILD_VARIANT is not defined")
|
||||
}
|
||||
|
||||
func (c *configImpl) KatiArgs() []string {
|
||||
return c.katiArgs
|
||||
}
|
||||
|
@ -311,6 +369,10 @@ func (c *configImpl) SoongMakeVarsMk() string {
|
|||
return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+".mk")
|
||||
}
|
||||
|
||||
func (c *configImpl) DevicePreviousProductConfig() string {
|
||||
return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice(), "previous_build_config.mk")
|
||||
}
|
||||
|
||||
func (c *configImpl) HostPrebuiltTag() string {
|
||||
if runtime.GOOS == "linux" {
|
||||
return "linux-x86"
|
||||
|
|
|
@ -84,24 +84,38 @@ func (c *Cmd) StartOrFatal() {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *Cmd) reportError(err error) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
if e, ok := err.(*exec.ExitError); ok {
|
||||
c.ctx.Fatalf("%s failed with: %v", c.name, e.ProcessState.String())
|
||||
} else {
|
||||
c.ctx.Fatalf("Failed to run %s: %v", c.name, err)
|
||||
}
|
||||
}
|
||||
|
||||
// RunOrFatal is equivalent to Run, but handles the error with a call to ctx.Fatal
|
||||
func (c *Cmd) RunOrFatal() {
|
||||
if err := c.Run(); err != nil {
|
||||
if e, ok := err.(*exec.ExitError); ok {
|
||||
c.ctx.Fatalf("%s failed with: %v", c.name, e.ProcessState.String())
|
||||
} else {
|
||||
c.ctx.Fatalf("Failed to run %s: %v", c.name, err)
|
||||
}
|
||||
}
|
||||
c.reportError(c.Run())
|
||||
}
|
||||
|
||||
// WaitOrFatal is equivalent to Wait, but handles the error with a call to ctx.Fatal
|
||||
func (c *Cmd) WaitOrFatal() {
|
||||
if err := c.Wait(); err != nil {
|
||||
if e, ok := err.(*exec.ExitError); ok {
|
||||
c.ctx.Fatalf("%s failed with: %v", c.name, e.ProcessState.String())
|
||||
} else {
|
||||
c.ctx.Fatalf("Failed to run %s: %v", c.name, err)
|
||||
}
|
||||
}
|
||||
c.reportError(c.Wait())
|
||||
}
|
||||
|
||||
// OutputOrFatal is equivalent to Output, but handles the error with a call to ctx.Fatal
|
||||
func (c *Cmd) OutputOrFatal() []byte {
|
||||
ret, err := c.Output()
|
||||
c.reportError(err)
|
||||
return ret
|
||||
}
|
||||
|
||||
// CombinedOutputOrFatal is equivalent to CombinedOutput, but handles the error with
|
||||
// a call to ctx.Fatal
|
||||
func (c *Cmd) CombinedOutputOrFatal() []byte {
|
||||
ret, err := c.CombinedOutput()
|
||||
c.reportError(err)
|
||||
return ret
|
||||
}
|
||||
|
|
|
@ -0,0 +1,156 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
package build
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const incompatibleJavacStr = "google"
|
||||
|
||||
var javaVersionInfo = struct {
|
||||
once sync.Once
|
||||
startOnce sync.Once
|
||||
|
||||
java_version_output string
|
||||
javac_version_output string
|
||||
}{}
|
||||
|
||||
func getJavaVersions(ctx Context, config Config) {
|
||||
javaVersionInfo.startOnce.Do(func() {
|
||||
go func() {
|
||||
if ctx.Tracer != nil {
|
||||
thread := ctx.Tracer.NewThread("java_version")
|
||||
ctx.Tracer.Begin("get version", thread)
|
||||
defer ctx.Tracer.End(thread)
|
||||
}
|
||||
|
||||
getJavaVersionsImpl(ctx, config)
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
func getJavaVersionsImpl(ctx Context, config Config) {
|
||||
javaVersionInfo.once.Do(func() {
|
||||
cmd := Command(ctx, config, "java", "java", "-version")
|
||||
cmd.Environment.Unset("_JAVA_OPTIONS")
|
||||
javaVersionInfo.java_version_output = string(cmd.CombinedOutputOrFatal())
|
||||
|
||||
cmd = Command(ctx, config, "javac", "javac", "-version")
|
||||
cmd.Environment.Unset("_JAVA_OPTIONS")
|
||||
javaVersionInfo.javac_version_output = string(cmd.CombinedOutputOrFatal())
|
||||
})
|
||||
}
|
||||
|
||||
func checkJavaVersion(ctx Context, config Config) {
|
||||
ctx.BeginTrace("java_version_check")
|
||||
defer ctx.EndTrace()
|
||||
|
||||
getJavaVersionsImpl(ctx, config)
|
||||
|
||||
var required_java_version string
|
||||
var java_version_regexp *regexp.Regexp
|
||||
var javac_version_regexp *regexp.Regexp
|
||||
if legacy, _ := config.Environment().Get("LEGACY_USE_JAVA7"); legacy != "" {
|
||||
required_java_version = "1.7"
|
||||
java_version_regexp = regexp.MustCompile(`^java .*[ "]1\.7[\. "$]`)
|
||||
javac_version_regexp = regexp.MustCompile(`[ "]1\.7[\. "$]`)
|
||||
} else {
|
||||
required_java_version = "1.8"
|
||||
java_version_regexp = regexp.MustCompile(`[ "]1\.8[\. "$]`)
|
||||
javac_version_regexp = java_version_regexp
|
||||
}
|
||||
|
||||
java_version := javaVersionInfo.java_version_output
|
||||
javac_version := javaVersionInfo.javac_version_output
|
||||
|
||||
found := false
|
||||
for _, l := range strings.Split(java_version, "\n") {
|
||||
if java_version_regexp.MatchString(l) {
|
||||
java_version = l
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
ctx.Println("***************************************************************")
|
||||
ctx.Println("You are attempting to build with the incorrect version of java.")
|
||||
ctx.Println()
|
||||
ctx.Println("Your version is:", java_version)
|
||||
ctx.Println("The required version is:", required_java_version+".x")
|
||||
ctx.Println()
|
||||
ctx.Println("Please follow the machine setup instructions at:")
|
||||
ctx.Println(" https://source.android.com/source/initializing.html")
|
||||
ctx.Println("***************************************************************")
|
||||
ctx.Fatalln("stop")
|
||||
}
|
||||
|
||||
if runtime.GOOS == "linux" {
|
||||
if !strings.Contains(java_version, "openjdk") {
|
||||
ctx.Println("*******************************************************")
|
||||
ctx.Println("You are attempting to build with an unsupported JDK.")
|
||||
ctx.Println()
|
||||
ctx.Println("Only an OpenJDK based JDK is supported.")
|
||||
ctx.Println()
|
||||
ctx.Println("Please follow the machine setup instructions at:")
|
||||
ctx.Println(" https://source.android.com/source/initializing.html")
|
||||
ctx.Println("*******************************************************")
|
||||
ctx.Fatalln("stop")
|
||||
}
|
||||
} else { // darwin
|
||||
if strings.Contains(java_version, "openjdk") {
|
||||
ctx.Println("*******************************************************")
|
||||
ctx.Println("You are attempting to build with an unsupported JDK.")
|
||||
ctx.Println()
|
||||
ctx.Println("You use OpenJDK, but only Sun/Oracle JDK is supported.")
|
||||
ctx.Println()
|
||||
ctx.Println("Please follow the machine setup instructions at:")
|
||||
ctx.Println(" https://source.android.com/source/initializing.html")
|
||||
ctx.Println("*******************************************************")
|
||||
ctx.Fatalln("stop")
|
||||
}
|
||||
}
|
||||
|
||||
incompatible_javac := strings.Contains(javac_version, incompatibleJavacStr)
|
||||
|
||||
found = false
|
||||
for _, l := range strings.Split(javac_version, "\n") {
|
||||
if javac_version_regexp.MatchString(l) {
|
||||
javac_version = l
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found || incompatible_javac {
|
||||
ctx.Println("****************************************************************")
|
||||
ctx.Println("You are attempting to build with the incorrect version of javac.")
|
||||
ctx.Println()
|
||||
ctx.Println("Your version is:", javac_version)
|
||||
if incompatible_javac {
|
||||
ctx.Println("The '" + incompatibleJavacStr + "' version is not supported for Android platform builds.")
|
||||
ctx.Println("Use a publically available JDK and make sure you have run envsetup.sh / lunch.")
|
||||
} else {
|
||||
ctx.Println("The required version is:", required_java_version)
|
||||
}
|
||||
ctx.Println()
|
||||
ctx.Println("Please follow the machine setup instructions at:")
|
||||
ctx.Println(" https://source.android.com/source/initializing.html")
|
||||
ctx.Println("****************************************************************")
|
||||
ctx.Fatalln("stop")
|
||||
}
|
||||
}
|
|
@ -83,6 +83,7 @@ func runMakeProductConfig(ctx Context, config Config) {
|
|||
// So that we can use the correct TARGET_PRODUCT if it's been
|
||||
// modified by PRODUCT-* arguments
|
||||
"TARGET_PRODUCT",
|
||||
"TARGET_BUILD_VARIANT",
|
||||
|
||||
// compiler wrappers set up by make
|
||||
"CC_WRAPPER",
|
||||
|
@ -129,6 +130,9 @@ func runMakeProductConfig(ctx Context, config Config) {
|
|||
// Used to execute Kati and Ninja
|
||||
"NINJA_GOALS",
|
||||
"KATI_GOALS",
|
||||
|
||||
// To find target/product/<DEVICE>
|
||||
"TARGET_DEVICE",
|
||||
}, exportEnvVars...), bannerVars...)
|
||||
|
||||
make_vars, err := DumpMakeVars(ctx, config, config.Arguments(), []string{
|
||||
|
@ -159,4 +163,5 @@ func runMakeProductConfig(ctx Context, config Config) {
|
|||
|
||||
config.SetKatiArgs(strings.Fields(make_vars["KATI_GOALS"]))
|
||||
config.SetNinjaArgs(strings.Fields(make_vars["NINJA_GOALS"]))
|
||||
config.SetTargetDevice(make_vars["TARGET_DEVICE"])
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@ type Tracer interface {
|
|||
Complete(name string, thread Thread, begin, end uint64)
|
||||
|
||||
ImportNinjaLog(thread Thread, filename string, startOffset time.Time)
|
||||
|
||||
NewThread(name string) Thread
|
||||
}
|
||||
|
||||
type tracerImpl struct {
|
||||
|
|
Loading…
Reference in New Issue