aboutsummaryrefslogtreecommitdiffstats
path: root/androidbp
diff options
context:
space:
mode:
authorAndres Morales <anmorales@google.com>2015-05-11 12:26:07 -0700
committerAndres Morales <anmorales@google.com>2015-05-11 17:54:50 -0700
commit8ae47de451a6a5861a1ab8b7a75f323306959f4e (patch)
treec5289e10c441ec7fc5a7290488adc48e1301abfa /androidbp
parentd3ba039f74da29fc3d4184850e6e29acba58057c (diff)
downloadbuild_soong-8ae47de451a6a5861a1ab8b7a75f323306959f4e.tar.gz
build_soong-8ae47de451a6a5861a1ab8b7a75f323306959f4e.tar.bz2
build_soong-8ae47de451a6a5861a1ab8b7a75f323306959f4e.zip
[androidbp] address comments aosp/149217
Change-Id: I8b4bbbeef6c2c11080a4bc30820b2200ba78b7e9
Diffstat (limited to 'androidbp')
-rw-r--r--androidbp/cmd/androidbp.go68
1 files changed, 56 insertions, 12 deletions
diff --git a/androidbp/cmd/androidbp.go b/androidbp/cmd/androidbp.go
index 2e0d25c4..a68b11c2 100644
--- a/androidbp/cmd/androidbp.go
+++ b/androidbp/cmd/androidbp.go
@@ -2,15 +2,19 @@ package main
import (
"bufio"
+ "errors"
"fmt"
"os"
"path"
+ "path/filepath"
"regexp"
"strings"
bpparser "github.com/google/blueprint/parser"
)
+var recursiveSubdirRegex *regexp.Regexp = regexp.MustCompile("(.+)/\\*\\*/(.+)")
+
type androidMkWriter struct {
*bufio.Writer
@@ -39,14 +43,34 @@ func valueToString(value bpparser.Value) string {
}
}
+func getTopOfAndroidTree(wd string) (string, error) {
+ if !filepath.IsAbs(wd) {
+ return "", errors.New("path must be absolute: " + wd)
+ }
+
+ topfile := "build/soong/bootstrap.bash"
+
+ for "/" != wd {
+ expected := filepath.Join(wd, topfile)
+
+ if _, err := os.Stat(expected); err == nil {
+ // Found the top
+ return wd, nil
+ }
+
+ wd = filepath.Join(wd, "..")
+ }
+
+ return "", errors.New("couldn't find top of tree from " + wd)
+}
+
// TODO: handle non-recursive wildcards?
func processWildcards(s string) string {
- re := regexp.MustCompile("(.*)/\\*\\*/(.*)")
- submatches := re.FindAllStringSubmatch(s, -1)
- if submatches != nil && len(submatches[0]) > 2 {
+ submatches := recursiveSubdirRegex.FindStringSubmatch(s)
+ if len(submatches) > 2 {
// Found a wildcard rule
return fmt.Sprintf("$(call find-files-in-subdirs, $(LOCAL_PATH), %s, %s)",
- submatches[0][2], submatches[0][1])
+ submatches[2], submatches[1])
}
return s
@@ -194,14 +218,11 @@ func (w *androidMkWriter) handleModule(module *bpparser.Module) {
}
func (w *androidMkWriter) handleSubdirs(value bpparser.Value) {
- switch value.Type {
- case bpparser.String:
- fmt.Fprintf(w, "$(call all-makefiles-under, %s)\n", value.StringValue)
- case bpparser.List:
- for _, tok := range value.ListValue {
- fmt.Fprintf(w, "$(call all-makefiles-under, %s)\n", tok.StringValue)
- }
+ subdirs := make([]string, 0, len(value.ListValue))
+ for _, tok := range value.ListValue {
+ subdirs = append(subdirs, tok.StringValue)
}
+ fmt.Fprintf(w, "include $(wildcard $(addsuffix %s, Android.mk))\n", strings.Join(subdirs, " "))
}
func (w *androidMkWriter) handleAssignment(assignment *bpparser.Assignment) {
@@ -262,6 +283,26 @@ func (w *androidMkWriter) iter() <-chan interface{} {
return ch
}
+func (w *androidMkWriter) handleLocalPath() error {
+ androidMkDir, err := filepath.Abs(w.path)
+ if err != nil {
+ return err
+ }
+
+ top, err := getTopOfAndroidTree(androidMkDir)
+ if err != nil {
+ return err
+ }
+
+ rel, err := filepath.Rel(top, androidMkDir)
+ if err != nil {
+ return err
+ }
+
+ w.WriteString("LOCAL_PATH := " + rel + "\n")
+ return nil
+}
+
func (w *androidMkWriter) write() {
outFilePath := fmt.Sprintf("%s/Androidbp.mk", w.path)
fmt.Printf("Writing %s\n", outFilePath)
@@ -275,7 +316,10 @@ func (w *androidMkWriter) write() {
w.Writer = bufio.NewWriter(f)
- w.WriteString("LOCAL_PATH := $(call my-dir)\n")
+ if err := w.handleLocalPath(); err != nil {
+ fmt.Println(err.Error())
+ return
+ }
for block := range w.iter() {
switch block := block.(type) {