Merge "Fix androidmk crash if no CLEAR_VARS is detected"

This commit is contained in:
Treehugger Robot 2017-08-18 00:19:29 +00:00 committed by Gerrit Code Review
commit d5476b11f3
2 changed files with 34 additions and 4 deletions

View file

@ -48,10 +48,11 @@ func (f *bpFile) insertExtraComment(s string) {
f.bpPos.Line++
}
func (f *bpFile) errorf(node mkparser.Node, s string, args ...interface{}) {
orig := node.Dump()
s = fmt.Sprintf(s, args...)
f.insertExtraComment(fmt.Sprintf("// ANDROIDMK TRANSLATION ERROR: %s", s))
// records that the given node failed to be converted and includes an explanatory message
func (f *bpFile) errorf(failedNode mkparser.Node, message string, args ...interface{}) {
orig := failedNode.Dump()
message = fmt.Sprintf(message, args...)
f.addErrorText(fmt.Sprintf("// ANDROIDMK TRANSLATION ERROR: %s", message))
lines := strings.Split(orig, "\n")
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) {
if pos.Line < f.mkPos.Line {
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
} else {
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
for i, n := range names[:len(names)-1] {

View file

@ -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 {