diff --git a/androidmk/androidmk/androidmk.go b/androidmk/androidmk/androidmk.go index dcd67d871..03cf74d83 100644 --- a/androidmk/androidmk/androidmk.go +++ b/androidmk/androidmk/androidmk.go @@ -458,6 +458,9 @@ func setVariable(file *bpFile, plusequals bool, prefix, name string, value bppar } file.defs = append(file.defs, a) } else { + if _, ok := file.globalAssignments[name]; ok { + return fmt.Errorf("cannot assign a variable multiple times: \"%s\"", name) + } a := &bpparser.Assignment{ Name: name, NamePos: pos, diff --git a/androidmk/androidmk/androidmk_test.go b/androidmk/androidmk/androidmk_test.go index 4f307c4fb..726746bdd 100644 --- a/androidmk/androidmk/androidmk_test.go +++ b/androidmk/androidmk/androidmk_test.go @@ -1386,6 +1386,35 @@ cc_binary { name: "test", srcs: dashed_dash_variable, } +`, + }, + { + desc: "variableReassigned", + in: ` +include $(CLEAR_VARS) + +src_files:= a.cpp + +LOCAL_SRC_FILES:= $(src_files) +LOCAL_MODULE:= test +include $(BUILD_EXECUTABLE) + +# clear locally used variable +src_files:= +`, + expected: ` + + +src_files = ["a.cpp"] +cc_binary { + name: "test", + + srcs: src_files, +} + +// clear locally used variable +// ANDROIDMK TRANSLATION ERROR: cannot assign a variable multiple times: "src_files" +// src_files := `, }, {