From 5e4070cb6b57c506eadf6aca7d98b9526e2e8968 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Wed, 24 Jun 2020 09:25:52 -0700 Subject: [PATCH] Add androidmk error for multiple assignments Identify variables that are cleared or reassigned, add an error and prevent reassignment which caused a parser error. Test: go test androidmk_test Bug: 112653593 Change-Id: I0db3372b60812ff4cdaebb38a56ed0af0dbdb27e --- androidmk/androidmk/androidmk.go | 3 +++ androidmk/androidmk/androidmk_test.go | 29 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) 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 := `, }, {