diff options
author | Ying Wang <wangying@google.com> | 2015-06-02 18:44:59 -0700 |
---|---|---|
committer | Ying Wang <wangying@google.com> | 2015-06-03 11:14:13 -0700 |
commit | 3828490eef079c1d51d9565799b8c8b68ce7899d (patch) | |
tree | eaa46daa60ef7f930b9820fe1fc9969266993d67 /androidbp | |
parent | 199ee3943eb07c75d7f6ae3dd189f20215c81b8f (diff) | |
download | build_soong-3828490eef079c1d51d9565799b8c8b68ce7899d.tar.gz build_soong-3828490eef079c1d51d9565799b8c8b68ce7899d.tar.bz2 build_soong-3828490eef079c1d51d9565799b8c8b68ce7899d.zip |
Allow to specify the output Android.mk file path.
- Allow to specify the output Android.mk file path.
We need this to generate Android.mk into the out diretory.
- Makefile strings don't need quotes.
- Return non-zero exit code if it fails.
- Other trivial format changes.
Change-Id: I460083f6e0a2707cd4a6fe0bef3f8ae7562e9edb
Diffstat (limited to 'androidbp')
-rw-r--r-- | androidbp/cmd/androidbp.go | 55 | ||||
-rw-r--r-- | androidbp/cmd/soong.go | 4 |
2 files changed, 36 insertions, 23 deletions
diff --git a/androidbp/cmd/androidbp.go b/androidbp/cmd/androidbp.go index a68b11c2..6e0bc7f7 100644 --- a/androidbp/cmd/androidbp.go +++ b/androidbp/cmd/androidbp.go @@ -30,9 +30,9 @@ func valueToString(value bpparser.Value) string { } else { switch value.Type { case bpparser.Bool: - return fmt.Sprintf(`"%t"`, value.BoolValue) + return fmt.Sprintf("%t", value.BoolValue) case bpparser.String: - return fmt.Sprintf(`"%s"`, processWildcards(value.StringValue)) + return fmt.Sprintf("%s", processWildcards(value.StringValue)) case bpparser.List: return fmt.Sprintf("\\\n%s\n", listToMkString(value.ListValue)) case bpparser.Map: @@ -80,7 +80,7 @@ func listToMkString(list []bpparser.Value) string { lines := make([]string, 0, len(list)) for _, tok := range list { if tok.Type == bpparser.String { - lines = append(lines, fmt.Sprintf("\t\"%s\"", processWildcards(tok.StringValue))) + lines = append(lines, fmt.Sprintf(" %s", processWildcards(tok.StringValue))) } else { lines = append(lines, fmt.Sprintf("# ERROR: unsupported type %s in list", tok.Type.String())) @@ -222,7 +222,9 @@ func (w *androidMkWriter) handleSubdirs(value bpparser.Value) { for _, tok := range value.ListValue { subdirs = append(subdirs, tok.StringValue) } - fmt.Fprintf(w, "include $(wildcard $(addsuffix %s, Android.mk))\n", strings.Join(subdirs, " ")) + // The current makefile may be generated to outside the source tree (such as the out directory), with a different structure. + fmt.Fprintf(w, "# Uncomment the following line if you really want to include subdir Android.mks.\n") + fmt.Fprintf(w, "# include $(wildcard $(addsuffix $(LOCAL_PATH)/%s/, Android.mk))\n", strings.Join(subdirs, " ")) } func (w *androidMkWriter) handleAssignment(assignment *bpparser.Assignment) { @@ -284,17 +286,17 @@ func (w *androidMkWriter) iter() <-chan interface{} { } func (w *androidMkWriter) handleLocalPath() error { - androidMkDir, err := filepath.Abs(w.path) + localPath, err := filepath.Abs(w.path) if err != nil { return err } - top, err := getTopOfAndroidTree(androidMkDir) + top, err := getTopOfAndroidTree(localPath) if err != nil { return err } - rel, err := filepath.Rel(top, androidMkDir) + rel, err := filepath.Rel(top, localPath) if err != nil { return err } @@ -303,11 +305,10 @@ func (w *androidMkWriter) handleLocalPath() error { return nil } -func (w *androidMkWriter) write() { - outFilePath := fmt.Sprintf("%s/Androidbp.mk", w.path) - fmt.Printf("Writing %s\n", outFilePath) +func (w *androidMkWriter) write(androidMk string) error { + fmt.Printf("Writing %s\n", androidMk) - f, err := os.Create(outFilePath) + f, err := os.Create(androidMk) if err != nil { panic(err) } @@ -317,8 +318,7 @@ func (w *androidMkWriter) write() { w.Writer = bufio.NewWriter(f) if err := w.handleLocalPath(); err != nil { - fmt.Println(err.Error()) - return + return err } for block := range w.iter() { @@ -335,33 +335,46 @@ func (w *androidMkWriter) write() { if err = w.Flush(); err != nil { panic(err) } + return nil } func main() { if len(os.Args) < 2 { fmt.Println("No filename supplied") - return + os.Exit(1) } - reader, err := os.Open(os.Args[1]) + androidBp := os.Args[1] + var androidMk string + if len(os.Args) >= 3 { + androidMk = os.Args[2] + } else { + androidMk = androidBp + ".mk" + } + + reader, err := os.Open(androidBp) if err != nil { fmt.Println(err.Error()) - return + os.Exit(1) } scope := bpparser.NewScope(nil) - blueprint, errs := bpparser.Parse(os.Args[1], reader, scope) + blueprint, errs := bpparser.Parse(androidBp, reader, scope) if len(errs) > 0 { - fmt.Println("%d errors parsing %s", len(errs), os.Args[1]) + fmt.Println("%d errors parsing %s", len(errs), androidBp) fmt.Println(errs) - return + os.Exit(1) } writer := &androidMkWriter{ blueprint: blueprint, - path: path.Dir(os.Args[1]), + path: path.Dir(androidBp), mapScope: make(map[string][]*bpparser.Property), } - writer.write() + err = writer.write(androidMk) + if err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } } diff --git a/androidbp/cmd/soong.go b/androidbp/cmd/soong.go index b8d7e0ee..9b5a6885 100644 --- a/androidbp/cmd/soong.go +++ b/androidbp/cmd/soong.go @@ -99,10 +99,10 @@ var hostScopedPropertyConditionals = map[string]string{ // TODO: host target? var targetScopedPropertyConditionals = map[string]string{ - "android32": "ifeq($(TARGET_IS_64_BIT), false)", + "android32": "ifneq($(TARGET_IS_64_BIT), true)", "not_android32": "ifeq($(TARGET_IS_64_BIT), true)", "android64": "ifeq($(TARGET_IS_64_BIT), true)", - "not_android64": "ifeq($(TARGET_IS_64_BIT), false)", + "not_android64": "ifneq($(TARGET_IS_64_BIT), true)", } var disabledHostConditionals = map[string]string{ |