diff options
author | Jeff Gaston <jeffrygaston@google.com> | 2017-10-17 18:25:32 -0700 |
---|---|---|
committer | Jeff Gaston <jeffrygaston@google.com> | 2017-10-19 13:22:56 -0700 |
commit | af7d3ef81dace8c65d7eff9e80611eb4e21c2f31 (patch) | |
tree | 7f42d275d257a0ee1bfca45d03eaf60eabfd839d /androidmk | |
parent | e87ae20e2593015c7d30359311a64ef96b941680 (diff) | |
download | build_soong-af7d3ef81dace8c65d7eff9e80611eb4e21c2f31.tar.gz build_soong-af7d3ef81dace8c65d7eff9e80611eb4e21c2f31.tar.bz2 build_soong-af7d3ef81dace8c65d7eff9e80611eb4e21c2f31.zip |
Prevent androidmk crash on art/tools/ahat/Android.mk
Because a directive can exist within a rule's recipe,
there may not exist an ordering of nodes such that
nodes[i].End() <= nodes[i+1].Start()
This disables that assertion.
Test: androidmk art/tools/ahat/Android.mk
Bug: 67906386
Change-Id: I84ea6ebdbc01c1600b1fa188463aae56270f0135
Diffstat (limited to 'androidmk')
-rw-r--r-- | androidmk/cmd/androidmk/androidmk.go | 20 | ||||
-rw-r--r-- | androidmk/cmd/androidmk/androidmk_test.go | 35 |
2 files changed, 51 insertions, 4 deletions
diff --git a/androidmk/cmd/androidmk/androidmk.go b/androidmk/cmd/androidmk/androidmk.go index a49f6200..5cb3f7ac 100644 --- a/androidmk/cmd/androidmk/androidmk.go +++ b/androidmk/cmd/androidmk/androidmk.go @@ -80,11 +80,23 @@ func (f *bpFile) addErrorText(message string) { } 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)) + // It is unusual but not forbidden for pos.Line to be smaller than f.mkPos.Line + // For example: + // + // if true # this line is emitted 1st + // if true # this line is emitted 2nd + // some-target: some-file # this line is emitted 3rd + // echo doing something # this recipe is emitted 6th + // endif #some comment # this endif is emitted 4th; this comment is part of the recipe + // echo doing more stuff # this is part of the recipe + // endif # this endif is emitted 5th + // + // However, if pos.Line < f.mkPos.Line, we treat it as though it were equal + if pos.Line >= f.mkPos.Line { + f.bpPos.Line += (pos.Line - f.mkPos.Line) + f.mkPos = end } - f.bpPos.Line += (pos.Line - f.mkPos.Line) - f.mkPos = end + } type conditional struct { diff --git a/androidmk/cmd/androidmk/androidmk_test.go b/androidmk/cmd/androidmk/androidmk_test.go index 4681a7d2..0b865409 100644 --- a/androidmk/cmd/androidmk/androidmk_test.go +++ b/androidmk/cmd/androidmk/androidmk_test.go @@ -425,6 +425,41 @@ cc_library_shared { } }`, }, + { + // the important part of this test case is that it confirms that androidmk doesn't + // panic in this case + desc: "multiple directives inside recipe", + in: ` +ifeq ($(a),true) +ifeq ($(b),false) +imABuildStatement: somefile + echo begin +endif # a==true + echo middle +endif # b==false + echo end +`, + expected: ` +// ANDROIDMK TRANSLATION ERROR: unsupported conditional +// ifeq ($(a),true) + +// ANDROIDMK TRANSLATION ERROR: unsupported conditional +// ifeq ($(b),false) + +// ANDROIDMK TRANSLATION ERROR: unsupported line +// rule: imABuildStatement: somefile +// echo begin +// # a==true +// echo middle +// # b==false +// echo end +// +// ANDROIDMK TRANSLATION ERROR: endif from unsupported contitional +// endif +// ANDROIDMK TRANSLATION ERROR: endif from unsupported contitional +// endif + `, + }, } func reformatBlueprint(input string) string { |