diff options
author | Jeff Gaston <jeffrygaston@google.com> | 2017-05-19 15:15:30 -0700 |
---|---|---|
committer | Jeff Gaston <jeffrygaston@google.com> | 2017-08-17 15:08:06 -0700 |
commit | 15e8e75a05911c432b99ee4592a812e760e22ce5 (patch) | |
tree | f76c96fc950e5738e075d0c0a607e28bda06a997 /androidmk | |
parent | 8cd393688b94a5d40ace5c76abae805530409ccc (diff) | |
download | build_soong-15e8e75a05911c432b99ee4592a812e760e22ce5.tar.gz build_soong-15e8e75a05911c432b99ee4592a812e760e22ce5.tar.bz2 build_soong-15e8e75a05911c432b99ee4592a812e760e22ce5.zip |
Fix androidmk crash if no CLEAR_VARS is detected
Bug: 38459493
Test: make blueprint_tools
Change-Id: I968a2e46160c6c04091412e6d5450f9917ec8b67
Diffstat (limited to 'androidmk')
-rw-r--r-- | androidmk/cmd/androidmk/androidmk.go | 24 | ||||
-rw-r--r-- | androidmk/cmd/androidmk/androidmk_test.go | 14 |
2 files changed, 34 insertions, 4 deletions
diff --git a/androidmk/cmd/androidmk/androidmk.go b/androidmk/cmd/androidmk/androidmk.go index d26643ae..5fad5860 100644 --- a/androidmk/cmd/androidmk/androidmk.go +++ b/androidmk/cmd/androidmk/androidmk.go @@ -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] { diff --git a/androidmk/cmd/androidmk/androidmk_test.go b/androidmk/cmd/androidmk/androidmk_test.go index 07d1c109..037ce26a 100644 --- a/androidmk/cmd/androidmk/androidmk_test.go +++ b/androidmk/cmd/androidmk/androidmk_test.go @@ -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 { |