Merge "soong_ui: Do not find a build file if targets are specified."
This commit is contained in:
@@ -61,6 +61,8 @@ type configImpl struct {
|
|||||||
|
|
||||||
const srcDirFileCheck = "build/soong/root.bp"
|
const srcDirFileCheck = "build/soong/root.bp"
|
||||||
|
|
||||||
|
var buildFiles = []string{"Android.mk", "Android.bp"}
|
||||||
|
|
||||||
type BuildAction uint
|
type BuildAction uint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -344,6 +346,20 @@ func convertToTarget(dir string, targetNamePrefix string) string {
|
|||||||
return targetNamePrefix + strings.ReplaceAll(dir, "/", "-")
|
return targetNamePrefix + strings.ReplaceAll(dir, "/", "-")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hasBuildFile returns true if dir contains an Android build file.
|
||||||
|
func hasBuildFile(ctx Context, dir string) bool {
|
||||||
|
for _, buildFile := range buildFiles {
|
||||||
|
_, err := os.Stat(filepath.Join(dir, buildFile))
|
||||||
|
if err == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if !os.IsNotExist(err) {
|
||||||
|
ctx.Fatalf("Error retrieving the build file stats: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// findBuildFile finds a build file (makefile or blueprint file) by looking at dir first. If not
|
// findBuildFile finds a build file (makefile or blueprint file) by looking at dir first. If not
|
||||||
// found, go up one level and repeat again until one is found and the path of that build file
|
// found, go up one level and repeat again until one is found and the path of that build file
|
||||||
// relative to the root directory of the source tree is returned. The returned filename of build
|
// relative to the root directory of the source tree is returned. The returned filename of build
|
||||||
@@ -355,15 +371,8 @@ func findBuildFile(ctx Context, dir string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for ; dir != "."; dir = filepath.Dir(dir) {
|
for ; dir != "."; dir = filepath.Dir(dir) {
|
||||||
for _, buildFile := range []string{"Android.bp", "Android.mk"} {
|
if hasBuildFile(ctx, dir) {
|
||||||
_, err := os.Stat(filepath.Join(dir, buildFile))
|
return filepath.Join(dir, "Android.mk")
|
||||||
if err == nil {
|
|
||||||
// Returning the filename Android.mk as it might be used for ONE_SHOT_MAKEFILE variable.
|
|
||||||
return filepath.Join(dir, "Android.mk")
|
|
||||||
}
|
|
||||||
if !os.IsNotExist(err) {
|
|
||||||
ctx.Fatalf("Error retrieving the build file stats: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,24 +437,23 @@ func getTargetsFromDirs(ctx Context, relDir string, dirs []string, targetNamePre
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildFile := findBuildFile(ctx, dir)
|
// If there are specified targets to build in dir, an android build file must exist for the one
|
||||||
if buildFile == "" {
|
// shot build. For the non-targets case, find the appropriate build file and build all the
|
||||||
ctx.Fatalf("Build file not found for %s directory", dir)
|
// modules in dir (or the closest one in the dir path).
|
||||||
}
|
|
||||||
buildFileDir := filepath.Dir(buildFile)
|
|
||||||
|
|
||||||
// If there are specified targets, find the build file in the directory. If dir does not
|
|
||||||
// contain the build file, bail out as it is required for one shot build. If there are no
|
|
||||||
// target specified, build all the modules in dir (or the closest one in the dir path).
|
|
||||||
if len(newTargets) > 0 {
|
if len(newTargets) > 0 {
|
||||||
if buildFileDir != dir {
|
if !hasBuildFile(ctx, dir) {
|
||||||
ctx.Fatalf("Couldn't locate a build file from %s directory", dir)
|
ctx.Fatalf("Couldn't locate a build file from %s directory", dir)
|
||||||
}
|
}
|
||||||
|
buildFiles = append(buildFiles, filepath.Join(dir, "Android.mk"))
|
||||||
} else {
|
} else {
|
||||||
newTargets = []string{convertToTarget(buildFileDir, targetNamePrefix)}
|
buildFile := findBuildFile(ctx, dir)
|
||||||
|
if buildFile == "" {
|
||||||
|
ctx.Fatalf("Build file not found for %s directory", dir)
|
||||||
|
}
|
||||||
|
newTargets = []string{convertToTarget(filepath.Dir(buildFile), targetNamePrefix)}
|
||||||
|
buildFiles = append(buildFiles, buildFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
buildFiles = append(buildFiles, buildFile)
|
|
||||||
targets = append(targets, newTargets...)
|
targets = append(targets, newTargets...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -441,7 +441,7 @@ func TestConfigGetTargets(t *testing.T) {
|
|||||||
buildFiles: []string{},
|
buildFiles: []string{},
|
||||||
dirs: []string{"1/2/3:t1"},
|
dirs: []string{"1/2/3:t1"},
|
||||||
curDir: "0",
|
curDir: "0",
|
||||||
errStr: "Build file not found for 0/1/2/3 directory",
|
errStr: "Couldn't locate a build file from 0/1/2/3 directory",
|
||||||
}, {
|
}, {
|
||||||
description: "one target dir specified, one target specified, build file not in target dir",
|
description: "one target dir specified, one target specified, build file not in target dir",
|
||||||
dirsInTrees: []string{"0/1/2/3"},
|
dirsInTrees: []string{"0/1/2/3"},
|
||||||
|
Reference in New Issue
Block a user