Merge "Fix androidmk crash if no CLEAR_VARS is detected"
This commit is contained in:
@@ -48,10 +48,11 @@ func (f *bpFile) insertExtraComment(s string) {
|
|||||||
f.bpPos.Line++
|
f.bpPos.Line++
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *bpFile) errorf(node mkparser.Node, s string, args ...interface{}) {
|
// records that the given node failed to be converted and includes an explanatory message
|
||||||
orig := node.Dump()
|
func (f *bpFile) errorf(failedNode mkparser.Node, message string, args ...interface{}) {
|
||||||
s = fmt.Sprintf(s, args...)
|
orig := failedNode.Dump()
|
||||||
f.insertExtraComment(fmt.Sprintf("// ANDROIDMK TRANSLATION ERROR: %s", s))
|
message = fmt.Sprintf(message, args...)
|
||||||
|
f.addErrorText(fmt.Sprintf("// ANDROIDMK TRANSLATION ERROR: %s", message))
|
||||||
|
|
||||||
lines := strings.Split(orig, "\n")
|
lines := strings.Split(orig, "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
@@ -59,6 +60,17 @@ func (f *bpFile) errorf(node mkparser.Node, s string, args ...interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// records that something unexpected occurred
|
||||||
|
func (f *bpFile) warnf(message string, args ...interface{}) {
|
||||||
|
message = fmt.Sprintf(message, args...)
|
||||||
|
f.addErrorText(fmt.Sprintf("// ANDROIDMK TRANSLATION WARNING: %s", message))
|
||||||
|
}
|
||||||
|
|
||||||
|
// adds the given error message as-is to the bottom of the (in-progress) file
|
||||||
|
func (f *bpFile) addErrorText(message string) {
|
||||||
|
f.insertExtraComment(message)
|
||||||
|
}
|
||||||
|
|
||||||
func (f *bpFile) setMkPos(pos, end scanner.Position) {
|
func (f *bpFile) setMkPos(pos, end scanner.Position) {
|
||||||
if pos.Line < f.mkPos.Line {
|
if pos.Line < f.mkPos.Line {
|
||||||
panic(fmt.Errorf("out of order lines, %q after %q", pos, f.mkPos))
|
panic(fmt.Errorf("out of order lines, %q after %q", pos, f.mkPos))
|
||||||
@@ -358,6 +370,10 @@ func setVariable(file *bpFile, plusequals bool, prefix, name string, value bppar
|
|||||||
*oldValue = val
|
*oldValue = val
|
||||||
} else {
|
} else {
|
||||||
names := strings.Split(name, ".")
|
names := strings.Split(name, ".")
|
||||||
|
if file.module == nil {
|
||||||
|
file.warnf("No 'include $(CLEAR_VARS)' detected before first assignment; clearing vars now")
|
||||||
|
resetModule(file)
|
||||||
|
}
|
||||||
container := &file.module.Properties
|
container := &file.module.Properties
|
||||||
|
|
||||||
for i, n := range names[:len(names)-1] {
|
for i, n := range names[:len(names)-1] {
|
||||||
|
@@ -393,6 +393,20 @@ cc_library_shared {
|
|||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
|
||||||
|
desc: "Don't fail on missing CLEAR_VARS",
|
||||||
|
in: `
|
||||||
|
LOCAL_MODULE := iAmAModule
|
||||||
|
include $(BUILD_SHARED_LIBRARY)`,
|
||||||
|
|
||||||
|
expected: `
|
||||||
|
// ANDROIDMK TRANSLATION WARNING: No 'include $(CLEAR_VARS)' detected before first assignment; clearing vars now
|
||||||
|
cc_library_shared {
|
||||||
|
name: "iAmAModule",
|
||||||
|
|
||||||
|
}`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func reformatBlueprint(input string) string {
|
func reformatBlueprint(input string) string {
|
||||||
|
Reference in New Issue
Block a user