Handle multi dir all-*-files-under function calls.

This change fixes a bug where androidmk assumes all-*-files-under
function only takes one directory parameter.

Test: androidmk_text.go, manual execution
Change-Id: Ib1614a2ddde7ea1120c1c37126231988f4862165
This commit is contained in:
Jaewoong Jung 2019-01-07 15:29:01 -08:00 committed by Dan Willemsen
parent 06af80e3a4
commit acb529b038
4 changed files with 53 additions and 26 deletions

View File

@ -739,27 +739,31 @@ var conditionalTranslations = map[string]map[bool]string{
true: "product_variables.pdk"},
}
func mydir(args []string) string {
return "."
func mydir(args []string) []string {
return []string{"."}
}
func allFilesUnder(wildcard string) func(args []string) string {
return func(args []string) string {
dir := ""
func allFilesUnder(wildcard string) func(args []string) []string {
return func(args []string) []string {
dirs := []string{""}
if len(args) > 0 {
dir = strings.TrimSpace(args[0])
dirs = strings.Fields(args[0])
}
return fmt.Sprintf("%s/**/"+wildcard, dir)
paths := make([]string, len(dirs))
for i := range paths {
paths[i] = fmt.Sprintf("%s/**/"+wildcard, dirs[i])
}
return paths
}
}
func allSubdirJavaFiles(args []string) string {
return "**/*.java"
func allSubdirJavaFiles(args []string) []string {
return []string{"**/*.java"}
}
func includeIgnored(args []string) string {
return include_ignored
func includeIgnored(args []string) []string {
return []string{include_ignored}
}
var moduleTypes = map[string]string{

View File

@ -554,6 +554,10 @@ include $(call all-makefiles-under,$(LOCAL_PATH))
LOCAL_SRC_FILES := d.java
LOCAL_UNINSTALLABLE_MODULE := false
include $(BUILD_JAVA_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under, src gen)
include $(BUILD_STATIC_JAVA_LIBRARY)
`,
expected: `
java_library {
@ -574,6 +578,13 @@ include $(call all-makefiles-under,$(LOCAL_PATH))
installable: true,
srcs: ["d.java"],
}
java_library {
srcs: [
"src/**/*.java",
"gen/**/*.java",
],
}
`,
},
{

View File

@ -29,6 +29,14 @@ func stringToStringValue(s string) bpparser.Expression {
}
}
func stringListToStringValueList(list []string) []bpparser.Expression {
valList := make([]bpparser.Expression, len(list))
for i, l := range list {
valList[i] = stringToStringValue(l)
}
return valList
}
func addValues(val1, val2 bpparser.Expression) (bpparser.Expression, error) {
if val1 == nil {
return val2, nil
@ -63,7 +71,10 @@ func makeToStringExpression(ms *mkparser.MakeString, scope mkparser.Scope) (bppa
for i, s := range ms.Strings[1:] {
if ret, ok := ms.Variables[i].EvalFunction(scope); ok {
val, err = addValues(val, stringToStringValue(ret))
if len(ret) > 1 {
return nil, fmt.Errorf("Unexpected list value %s", ms.Dump())
}
val, err = addValues(val, stringToStringValue(ret[0]))
} else {
name := ms.Variables[i].Name
if !name.Const() {
@ -125,9 +136,7 @@ func makeToListExpression(ms *mkparser.MakeString, scope mkparser.Scope) (bppars
for _, f := range fields {
if len(f.Variables) == 1 && f.Strings[0] == "" && f.Strings[1] == "" {
if ret, ok := f.Variables[0].EvalFunction(scope); ok {
listValue.Values = append(listValue.Values, &bpparser.String{
Value: ret,
})
listValue.Values = append(listValue.Values, stringListToStringValueList(ret)...)
} else {
// Variable by itself, variable is probably a list
if !f.Variables[0].Name.Const() {

View File

@ -21,13 +21,13 @@ import (
type Scope interface {
Get(name string) string
Set(name, value string)
Call(name string, args []string) string
SetFunc(name string, f func([]string) string)
Call(name string, args []string) []string
SetFunc(name string, f func([]string) []string)
}
type scope struct {
variables map[string]string
functions map[string]func([]string) string
functions map[string]func([]string) []string
parent Scope
}
@ -47,22 +47,22 @@ func (s *scope) Set(name, value string) {
s.variables[name] = value
}
func (s *scope) Call(name string, args []string) string {
func (s *scope) Call(name string, args []string) []string {
if f, ok := s.functions[name]; ok {
return f(args)
}
return "<func:'" + name + "' unset>"
return []string{"<func:'" + name + "' unset>"}
}
func (s *scope) SetFunc(name string, f func([]string) string) {
func (s *scope) SetFunc(name string, f func([]string) []string) {
s.functions[name] = f
}
func NewScope(parent Scope) Scope {
return &scope{
variables: make(map[string]string),
functions: make(map[string]func([]string) string),
functions: make(map[string]func([]string) []string),
parent: parent,
}
}
@ -74,7 +74,7 @@ func init() {
builtinScope[builtinDollar] = "$"
}
func (v Variable) EvalFunction(scope Scope) (string, bool) {
func (v Variable) EvalFunction(scope Scope) ([]string, bool) {
f := v.Name.SplitN(" \t", 2)
if len(f) > 1 && f[0].Const() {
fname := f[0].Value(nil)
@ -88,17 +88,20 @@ func (v Variable) EvalFunction(scope Scope) (string, bool) {
if fname == "call" {
return scope.Call(argVals[0], argVals[1:]), true
} else {
return "__builtin_func:" + fname + " " + strings.Join(argVals, " "), true
return []string{"__builtin_func:" + fname + " " + strings.Join(argVals, " ")}, true
}
}
}
return "", false
return []string{""}, false
}
func (v Variable) Value(scope Scope) string {
if ret, ok := v.EvalFunction(scope); ok {
return ret
if len(ret) > 1 {
panic("Expected a single value, but instead got a list")
}
return ret[0]
}
if scope == nil {
panic("Cannot take the value of a variable in a nil scope")