aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorPatrice Arruda <patricearruda@google.com>2019-07-08 11:06:46 -0700
committerLuca Stefani <luca.stefani.ge1@gmail.com>2019-09-04 15:35:06 +0200
commitbb478e87cdf5be7e63a945a91c76657777a50915 (patch)
tree9a532aed4f5d50c2439ab5855971e434e84abef8 /ui
parenta1971725d3213c182ed6d73b4cdaaa5a5858b032 (diff)
downloadbuild_soong-bb478e87cdf5be7e63a945a91c76657777a50915.tar.gz
build_soong-bb478e87cdf5be7e63a945a91c76657777a50915.tar.bz2
build_soong-bb478e87cdf5be7e63a945a91c76657777a50915.zip
soong_ui: Do not find a build file if targets are specified.
For mmma and mmm, the findBuildFile function in config.go is invoked every time for specified directories and directories with targets. For directories with targets, an Android build file must exist in the directory where mmma and mmm was invoked. There is no need to invoke findBuildFile function as a simple check of the build file exists in the specified directory. This is also refactoring the code for b/118730755 Bug: b/118730755 Test: Executed unit test cases through Intellij and executed mmma command: "mmma external/protobuf:aprotoc external/bzip2". Change-Id: I5428e3a3c36f77ff740617564b7853705521f29f
Diffstat (limited to 'ui')
-rw-r--r--ui/build/config.go50
-rw-r--r--ui/build/config_test.go2
2 files changed, 30 insertions, 22 deletions
diff --git a/ui/build/config.go b/ui/build/config.go
index 7148c177..b3c11900 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -62,6 +62,8 @@ type configImpl struct {
const srcDirFileCheck = "build/soong/root.bp"
+var buildFiles = []string{"Android.mk", "Android.bp"}
+
type BuildAction uint
const (
@@ -345,6 +347,20 @@ func convertToTarget(dir string, targetNamePrefix string) string {
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
// 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
@@ -356,15 +372,8 @@ func findBuildFile(ctx Context, dir string) string {
}
for ; dir != "."; dir = filepath.Dir(dir) {
- for _, buildFile := range []string{"Android.bp", "Android.mk"} {
- _, err := os.Stat(filepath.Join(dir, buildFile))
- 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)
- }
+ if hasBuildFile(ctx, dir) {
+ return filepath.Join(dir, "Android.mk")
}
}
@@ -429,24 +438,23 @@ func getTargetsFromDirs(ctx Context, relDir string, dirs []string, targetNamePre
}
}
- buildFile := findBuildFile(ctx, dir)
- if buildFile == "" {
- ctx.Fatalf("Build file not found for %s directory", dir)
- }
- 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 there are specified targets to build in dir, an android build file must exist for the one
+ // shot build. For the non-targets case, find the appropriate build file and build all the
+ // modules in dir (or the closest one in the dir path).
if len(newTargets) > 0 {
- if buildFileDir != dir {
+ if !hasBuildFile(ctx, dir) {
ctx.Fatalf("Couldn't locate a build file from %s directory", dir)
}
+ buildFiles = append(buildFiles, filepath.Join(dir, "Android.mk"))
} 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...)
}
diff --git a/ui/build/config_test.go b/ui/build/config_test.go
index 7a1ee170..18dd151c 100644
--- a/ui/build/config_test.go
+++ b/ui/build/config_test.go
@@ -441,7 +441,7 @@ func TestConfigGetTargets(t *testing.T) {
buildFiles: []string{},
dirs: []string{"1/2/3:t1"},
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",
dirsInTrees: []string{"0/1/2/3"},