2015-04-29 21:46:49 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2015-05-11 21:26:07 +02:00
|
|
|
"errors"
|
2015-04-29 21:46:49 +02:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path"
|
2015-05-11 21:26:07 +02:00
|
|
|
"path/filepath"
|
2015-04-30 21:14:34 +02:00
|
|
|
"regexp"
|
2015-04-29 21:46:49 +02:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
bpparser "github.com/google/blueprint/parser"
|
|
|
|
)
|
|
|
|
|
2015-05-11 21:26:07 +02:00
|
|
|
var recursiveSubdirRegex *regexp.Regexp = regexp.MustCompile("(.+)/\\*\\*/(.+)")
|
|
|
|
|
2015-04-29 21:46:49 +02:00
|
|
|
type androidMkWriter struct {
|
|
|
|
*bufio.Writer
|
|
|
|
|
2015-04-30 21:14:34 +02:00
|
|
|
blueprint *bpparser.File
|
|
|
|
path string
|
|
|
|
|
2015-06-11 23:34:50 +02:00
|
|
|
printedLocalPath bool
|
|
|
|
|
2015-04-30 21:14:34 +02:00
|
|
|
mapScope map[string][]*bpparser.Property
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
|
|
|
|
2015-04-30 21:14:34 +02:00
|
|
|
func valueToString(value bpparser.Value) string {
|
2015-04-29 21:46:49 +02:00
|
|
|
if value.Variable != "" {
|
|
|
|
return fmt.Sprintf("$(%s)", value.Variable)
|
|
|
|
} else {
|
|
|
|
switch value.Type {
|
|
|
|
case bpparser.Bool:
|
2015-06-03 03:44:59 +02:00
|
|
|
return fmt.Sprintf("%t", value.BoolValue)
|
2015-04-29 21:46:49 +02:00
|
|
|
case bpparser.String:
|
2015-06-03 03:44:59 +02:00
|
|
|
return fmt.Sprintf("%s", processWildcards(value.StringValue))
|
2015-04-29 21:46:49 +02:00
|
|
|
case bpparser.List:
|
2015-04-30 21:14:34 +02:00
|
|
|
return fmt.Sprintf("\\\n%s\n", listToMkString(value.ListValue))
|
2015-04-29 21:46:49 +02:00
|
|
|
case bpparser.Map:
|
2015-04-30 21:14:34 +02:00
|
|
|
return fmt.Sprintf("ERROR can't convert map to string")
|
|
|
|
default:
|
|
|
|
return fmt.Sprintf("ERROR: unsupported type %d", value.Type)
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-30 21:14:34 +02:00
|
|
|
}
|
|
|
|
|
2015-05-11 21:26:07 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2015-04-30 21:14:34 +02:00
|
|
|
// TODO: handle non-recursive wildcards?
|
|
|
|
func processWildcards(s string) string {
|
2015-05-11 21:26:07 +02:00
|
|
|
submatches := recursiveSubdirRegex.FindStringSubmatch(s)
|
|
|
|
if len(submatches) > 2 {
|
2015-04-30 21:14:34 +02:00
|
|
|
// Found a wildcard rule
|
|
|
|
return fmt.Sprintf("$(call find-files-in-subdirs, $(LOCAL_PATH), %s, %s)",
|
2015-05-11 21:26:07 +02:00
|
|
|
submatches[2], submatches[1])
|
2015-04-30 21:14:34 +02:00
|
|
|
}
|
2015-04-29 21:46:49 +02:00
|
|
|
|
2015-04-30 21:14:34 +02:00
|
|
|
return s
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
|
|
|
|
2015-04-30 21:14:34 +02:00
|
|
|
func listToMkString(list []bpparser.Value) string {
|
2015-04-29 21:46:49 +02:00
|
|
|
lines := make([]string, 0, len(list))
|
|
|
|
for _, tok := range list {
|
2015-04-30 21:14:34 +02:00
|
|
|
if tok.Type == bpparser.String {
|
2015-06-03 03:44:59 +02:00
|
|
|
lines = append(lines, fmt.Sprintf(" %s", processWildcards(tok.StringValue)))
|
2015-04-30 21:14:34 +02:00
|
|
|
} else {
|
|
|
|
lines = append(lines, fmt.Sprintf("# ERROR: unsupported type %s in list",
|
|
|
|
tok.Type.String()))
|
|
|
|
}
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Join(lines, " \\\n")
|
|
|
|
}
|
|
|
|
|
2015-04-30 21:14:34 +02:00
|
|
|
func translateTargetConditionals(props []*bpparser.Property,
|
|
|
|
disabledBuilds map[string]bool, isHostRule bool) (computedProps []string) {
|
|
|
|
for _, target := range props {
|
|
|
|
conditionals := targetScopedPropertyConditionals
|
2015-06-11 23:05:01 +02:00
|
|
|
altConditionals := hostScopedPropertyConditionals
|
2015-04-30 21:14:34 +02:00
|
|
|
if isHostRule {
|
2015-06-11 23:05:01 +02:00
|
|
|
conditionals, altConditionals = altConditionals, conditionals
|
2015-04-30 21:14:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
conditional, ok := conditionals[target.Name.Name]
|
|
|
|
if !ok {
|
2015-06-11 23:05:01 +02:00
|
|
|
if _, ok := altConditionals[target.Name.Name]; ok {
|
|
|
|
// This is only for the other build type
|
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
// not found
|
|
|
|
conditional = fmt.Sprintf(
|
|
|
|
"ifeq(true, true) # ERROR: unsupported conditional [%s]",
|
|
|
|
target.Name.Name)
|
|
|
|
}
|
2015-04-30 21:14:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var scopedProps []string
|
|
|
|
for _, targetScopedProp := range target.Value.MapValue {
|
|
|
|
if mkProp, ok := standardProperties[targetScopedProp.Name.Name]; ok {
|
|
|
|
scopedProps = append(scopedProps, fmt.Sprintf("%s += %s",
|
|
|
|
mkProp.string, valueToString(targetScopedProp.Value)))
|
2015-06-11 01:20:14 +02:00
|
|
|
} else if rwProp, ok := rewriteProperties[targetScopedProp.Name.Name]; ok {
|
|
|
|
scopedProps = append(scopedProps, rwProp.f(rwProp.string, targetScopedProp, nil)...)
|
2015-04-30 21:14:34 +02:00
|
|
|
} else if "disabled" == targetScopedProp.Name.Name {
|
|
|
|
if targetScopedProp.Value.BoolValue {
|
|
|
|
disabledBuilds[target.Name.Name] = true
|
|
|
|
} else {
|
|
|
|
delete(disabledBuilds, target.Name.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(scopedProps) > 0 {
|
2015-06-11 23:05:01 +02:00
|
|
|
if conditional != "" {
|
|
|
|
computedProps = append(computedProps, conditional)
|
|
|
|
computedProps = append(computedProps, scopedProps...)
|
|
|
|
computedProps = append(computedProps, "endif")
|
|
|
|
} else {
|
|
|
|
computedProps = append(computedProps, scopedProps...)
|
|
|
|
}
|
2015-04-30 21:14:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func translateSuffixProperties(suffixProps []*bpparser.Property,
|
|
|
|
suffixMap map[string]string) (computedProps []string) {
|
|
|
|
for _, suffixProp := range suffixProps {
|
|
|
|
if suffix, ok := suffixMap[suffixProp.Name.Name]; ok {
|
|
|
|
for _, stdProp := range suffixProp.Value.MapValue {
|
|
|
|
if mkProp, ok := standardProperties[stdProp.Name.Name]; ok {
|
|
|
|
computedProps = append(computedProps, fmt.Sprintf("%s_%s := %s", mkProp.string, suffix, valueToString(stdProp.Value)))
|
2015-06-11 01:20:14 +02:00
|
|
|
} else if rwProp, ok := rewriteProperties[stdProp.Name.Name]; ok {
|
|
|
|
computedProps = append(computedProps, rwProp.f(rwProp.string, stdProp, &suffix)...)
|
2015-04-30 21:14:34 +02:00
|
|
|
} else {
|
|
|
|
computedProps = append(computedProps, fmt.Sprintf("# ERROR: unsupported property %s", stdProp.Name.Name))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
2015-04-30 21:14:34 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-06-11 01:20:14 +02:00
|
|
|
func prependLocalPath(name string, prop *bpparser.Property, suffix *string) (computedProps []string) {
|
|
|
|
includes := make([]string, 0, len(prop.Value.ListValue))
|
|
|
|
for _, tok := range prop.Value.ListValue {
|
|
|
|
if tok.Type == bpparser.String {
|
|
|
|
includes = append(includes, fmt.Sprintf(" $(LOCAL_PATH)/%s", tok.StringValue))
|
|
|
|
} else {
|
|
|
|
includes = append(includes, fmt.Sprintf("# ERROR: unsupported type %s in list",
|
|
|
|
tok.Type.String()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if suffix != nil {
|
|
|
|
name += "_" + *suffix
|
|
|
|
}
|
|
|
|
return append(computedProps, fmt.Sprintf("%s := \\\n%s\n", name, strings.Join(includes, " \\\n")))
|
|
|
|
}
|
|
|
|
|
2015-04-30 21:14:34 +02:00
|
|
|
func (w *androidMkWriter) lookupMap(parent bpparser.Value) (mapValue []*bpparser.Property) {
|
|
|
|
if parent.Variable != "" {
|
|
|
|
mapValue = w.mapScope[parent.Variable]
|
|
|
|
} else {
|
|
|
|
mapValue = parent.MapValue
|
|
|
|
}
|
|
|
|
return
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *androidMkWriter) handleComment(comment *bpparser.Comment) {
|
|
|
|
for _, c := range comment.Comment {
|
2015-04-30 21:14:34 +02:00
|
|
|
fmt.Fprintf(w, "#%s\n", c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *androidMkWriter) writeModule(moduleRule string, props []string,
|
|
|
|
disabledBuilds map[string]bool, isHostRule bool) {
|
|
|
|
disabledConditionals := disabledTargetConditionals
|
|
|
|
if isHostRule {
|
|
|
|
disabledConditionals = disabledHostConditionals
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
2015-04-30 21:14:34 +02:00
|
|
|
for build, _ := range disabledBuilds {
|
|
|
|
if conditional, ok := disabledConditionals[build]; ok {
|
|
|
|
fmt.Fprintf(w, "%s\n", conditional)
|
|
|
|
defer fmt.Fprintf(w, "endif\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, "include $(CLEAR_VARS)\n")
|
|
|
|
fmt.Fprintf(w, "%s\n", strings.Join(props, "\n"))
|
|
|
|
fmt.Fprintf(w, "include $(%s)\n\n", moduleRule)
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
|
|
|
|
2015-06-11 23:05:01 +02:00
|
|
|
func (w *androidMkWriter) parsePropsAndWriteModule(moduleRule string, isHostRule bool, module *bpparser.Module) (hostSupported bool) {
|
2015-04-30 21:14:34 +02:00
|
|
|
standardProps := make([]string, 0, len(module.Properties))
|
|
|
|
disabledBuilds := make(map[string]bool)
|
|
|
|
for _, prop := range module.Properties {
|
|
|
|
if mkProp, ok := standardProperties[prop.Name.Name]; ok {
|
|
|
|
standardProps = append(standardProps, fmt.Sprintf("%s := %s", mkProp.string, valueToString(prop.Value)))
|
2015-06-11 01:20:14 +02:00
|
|
|
} else if rwProp, ok := rewriteProperties[prop.Name.Name]; ok {
|
|
|
|
standardProps = append(standardProps, rwProp.f(rwProp.string, prop, nil)...)
|
2015-04-30 21:14:34 +02:00
|
|
|
} else if suffixMap, ok := suffixProperties[prop.Name.Name]; ok {
|
|
|
|
suffixProps := w.lookupMap(prop.Value)
|
|
|
|
standardProps = append(standardProps, translateSuffixProperties(suffixProps, suffixMap)...)
|
|
|
|
} else if "target" == prop.Name.Name {
|
|
|
|
props := w.lookupMap(prop.Value)
|
|
|
|
standardProps = append(standardProps, translateTargetConditionals(props, disabledBuilds, isHostRule)...)
|
|
|
|
} else if "host_supported" == prop.Name.Name {
|
|
|
|
hostSupported = prop.Value.BoolValue
|
|
|
|
} else {
|
|
|
|
standardProps = append(standardProps, fmt.Sprintf("# ERROR: Unsupported property %s", prop.Name.Name))
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
2015-04-30 21:14:34 +02:00
|
|
|
}
|
2015-04-29 21:46:49 +02:00
|
|
|
|
2015-04-30 21:14:34 +02:00
|
|
|
// write out target build
|
|
|
|
w.writeModule(moduleRule, standardProps, disabledBuilds, isHostRule)
|
2015-06-11 23:05:01 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *androidMkWriter) handleModule(module *bpparser.Module) {
|
|
|
|
moduleRule := fmt.Sprintf(module.Type.Name)
|
|
|
|
if translation, ok := moduleTypeToRule[module.Type.Name]; ok {
|
|
|
|
moduleRule = translation
|
|
|
|
}
|
|
|
|
|
|
|
|
isHostRule := strings.Contains(moduleRule, "HOST")
|
|
|
|
hostSupported := w.parsePropsAndWriteModule(moduleRule, isHostRule, module)
|
|
|
|
|
|
|
|
if !isHostRule && hostSupported {
|
2015-04-30 21:14:34 +02:00
|
|
|
hostModuleRule := "NO CORRESPONDING HOST RULE" + moduleRule
|
|
|
|
if trans, ok := targetToHostModuleRule[moduleRule]; ok {
|
|
|
|
hostModuleRule = trans
|
|
|
|
}
|
2015-06-11 23:05:01 +02:00
|
|
|
|
|
|
|
w.parsePropsAndWriteModule(hostModuleRule, true, module)
|
2015-04-30 21:14:34 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-29 21:46:49 +02:00
|
|
|
|
2015-04-30 21:14:34 +02:00
|
|
|
func (w *androidMkWriter) handleSubdirs(value bpparser.Value) {
|
2015-05-11 21:26:07 +02:00
|
|
|
subdirs := make([]string, 0, len(value.ListValue))
|
|
|
|
for _, tok := range value.ListValue {
|
|
|
|
subdirs = append(subdirs, tok.StringValue)
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
2015-06-03 03:44:59 +02:00
|
|
|
// 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, " "))
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *androidMkWriter) handleAssignment(assignment *bpparser.Assignment) {
|
2015-04-30 21:14:34 +02:00
|
|
|
if "subdirs" == assignment.Name.Name {
|
|
|
|
w.handleSubdirs(assignment.OrigValue)
|
|
|
|
} else if assignment.OrigValue.Type == bpparser.Map {
|
|
|
|
// maps may be assigned in Soong, but can only be translated to .mk
|
|
|
|
// in the context of the module
|
|
|
|
w.mapScope[assignment.Name.Name] = assignment.OrigValue.MapValue
|
|
|
|
} else {
|
|
|
|
assigner := ":="
|
|
|
|
if assignment.Assigner != "=" {
|
|
|
|
assigner = assignment.Assigner
|
|
|
|
}
|
|
|
|
fmt.Fprintf(w, "%s %s %s\n", assignment.Name.Name, assigner,
|
|
|
|
valueToString(assignment.OrigValue))
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *androidMkWriter) iter() <-chan interface{} {
|
2015-04-30 21:14:34 +02:00
|
|
|
ch := make(chan interface{}, len(w.blueprint.Comments)+len(w.blueprint.Defs))
|
2015-04-29 21:46:49 +02:00
|
|
|
go func() {
|
|
|
|
commIdx := 0
|
|
|
|
defsIdx := 0
|
2015-04-30 21:14:34 +02:00
|
|
|
for defsIdx < len(w.blueprint.Defs) || commIdx < len(w.blueprint.Comments) {
|
|
|
|
if defsIdx == len(w.blueprint.Defs) {
|
|
|
|
ch <- w.blueprint.Comments[commIdx]
|
2015-04-29 21:46:49 +02:00
|
|
|
commIdx++
|
2015-04-30 21:14:34 +02:00
|
|
|
} else if commIdx == len(w.blueprint.Comments) {
|
|
|
|
ch <- w.blueprint.Defs[defsIdx]
|
2015-04-29 21:46:49 +02:00
|
|
|
defsIdx++
|
|
|
|
} else {
|
|
|
|
commentsPos := 0
|
|
|
|
defsPos := 0
|
|
|
|
|
2015-04-30 21:14:34 +02:00
|
|
|
def := w.blueprint.Defs[defsIdx]
|
2015-04-29 21:46:49 +02:00
|
|
|
switch def := def.(type) {
|
|
|
|
case *bpparser.Module:
|
|
|
|
defsPos = def.LbracePos.Line
|
|
|
|
case *bpparser.Assignment:
|
|
|
|
defsPos = def.Pos.Line
|
|
|
|
}
|
|
|
|
|
2015-04-30 21:14:34 +02:00
|
|
|
comment := w.blueprint.Comments[commIdx]
|
2015-04-29 21:46:49 +02:00
|
|
|
commentsPos = comment.Pos.Line
|
|
|
|
|
|
|
|
if commentsPos < defsPos {
|
|
|
|
commIdx++
|
|
|
|
ch <- comment
|
|
|
|
} else {
|
|
|
|
defsIdx++
|
|
|
|
ch <- def
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(ch)
|
|
|
|
}()
|
|
|
|
return ch
|
|
|
|
}
|
|
|
|
|
2015-05-11 21:26:07 +02:00
|
|
|
func (w *androidMkWriter) handleLocalPath() error {
|
2015-06-11 23:34:50 +02:00
|
|
|
if w.printedLocalPath {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
w.printedLocalPath = true
|
|
|
|
|
2015-06-03 03:44:59 +02:00
|
|
|
localPath, err := filepath.Abs(w.path)
|
2015-05-11 21:26:07 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-03 03:44:59 +02:00
|
|
|
top, err := getTopOfAndroidTree(localPath)
|
2015-05-11 21:26:07 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-03 03:44:59 +02:00
|
|
|
rel, err := filepath.Rel(top, localPath)
|
2015-05-11 21:26:07 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
w.WriteString("LOCAL_PATH := " + rel + "\n")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-06-03 03:44:59 +02:00
|
|
|
func (w *androidMkWriter) write(androidMk string) error {
|
|
|
|
fmt.Printf("Writing %s\n", androidMk)
|
2015-04-29 21:46:49 +02:00
|
|
|
|
2015-06-03 03:44:59 +02:00
|
|
|
f, err := os.Create(androidMk)
|
2015-04-29 21:46:49 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2015-04-30 21:14:34 +02:00
|
|
|
defer f.Close()
|
2015-04-29 21:46:49 +02:00
|
|
|
|
|
|
|
w.Writer = bufio.NewWriter(f)
|
|
|
|
|
|
|
|
for block := range w.iter() {
|
|
|
|
switch block := block.(type) {
|
|
|
|
case *bpparser.Module:
|
2015-06-11 23:34:50 +02:00
|
|
|
if err := w.handleLocalPath(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-04-29 21:46:49 +02:00
|
|
|
w.handleModule(block)
|
|
|
|
case *bpparser.Assignment:
|
2015-06-11 23:34:50 +02:00
|
|
|
if err := w.handleLocalPath(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-04-29 21:46:49 +02:00
|
|
|
w.handleAssignment(block)
|
|
|
|
case bpparser.Comment:
|
|
|
|
w.handleComment(&block)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = w.Flush(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2015-06-03 03:44:59 +02:00
|
|
|
return nil
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if len(os.Args) < 2 {
|
|
|
|
fmt.Println("No filename supplied")
|
2015-06-03 03:44:59 +02:00
|
|
|
os.Exit(1)
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
|
|
|
|
2015-06-03 03:44:59 +02:00
|
|
|
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)
|
2015-04-29 21:46:49 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
2015-06-03 03:44:59 +02:00
|
|
|
os.Exit(1)
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
scope := bpparser.NewScope(nil)
|
2015-06-03 03:44:59 +02:00
|
|
|
blueprint, errs := bpparser.Parse(androidBp, reader, scope)
|
2015-04-29 21:46:49 +02:00
|
|
|
if len(errs) > 0 {
|
2015-06-03 03:44:59 +02:00
|
|
|
fmt.Println("%d errors parsing %s", len(errs), androidBp)
|
2015-04-29 21:46:49 +02:00
|
|
|
fmt.Println(errs)
|
2015-06-03 03:44:59 +02:00
|
|
|
os.Exit(1)
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
writer := &androidMkWriter{
|
2015-04-30 21:14:34 +02:00
|
|
|
blueprint: blueprint,
|
2015-06-03 03:44:59 +02:00
|
|
|
path: path.Dir(androidBp),
|
2015-04-30 21:14:34 +02:00
|
|
|
mapScope: make(map[string][]*bpparser.Property),
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|
|
|
|
|
2015-06-03 03:44:59 +02:00
|
|
|
err = writer.write(androidMk)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2015-04-29 21:46:49 +02:00
|
|
|
}
|