Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1263eef authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Support complicated variable references"

parents 8b9c23ec 1323877b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -234,10 +234,10 @@ func (ms *MakeString) splitNFunc(n int, splitFunc func(s string, n int) []string
		if n != 0 {
			split := splitFunc(s, n)
			if n != -1 {
				if len(split) > n {
				if len(split) > n || len(split) == 0 {
					panic("oops!")
				} else {
					n -= len(split)
					n -= len(split) - 1
				}
			}
			curMs.appendString(split[0])
+10 −0
Original line number Diff line number Diff line
@@ -75,6 +75,16 @@ var splitNTestCases = []struct {
			genMakeString(""),
		},
	},
	{
		// "x$(var1)y bar"
		in:  genMakeString("x", "var1", "y bar"),
		sep: " ",
		n:   2,
		expected: []*MakeString{
			genMakeString("x", "var1", "y"),
			genMakeString("bar"),
		},
	},
}

func TestMakeStringSplitN(t *testing.T) {
+22 −1
Original line number Diff line number Diff line
@@ -1270,8 +1270,29 @@ func (ctx *parseContext) parseReference(node mkparser.Node, ref *mkparser.MakeSt
	// Handle only the case where the first (or only) word is constant
	words := ref.SplitN(" ", 2)
	if !words[0].Const() {
		if len(words) == 1 {
			expr := ctx.parseMakeString(node, ref)
			return &callExpr{
				object: &identifierExpr{"cfg"},
				name:   "get",
				args: []starlarkExpr{
					expr,
					&callExpr{
						object: &identifierExpr{"g"},
						name:   "get",
						args: []starlarkExpr{
							expr,
							&stringLiteralExpr{literal: ""},
						},
						returnType: starlarkTypeUnknown,
					},
				},
				returnType: starlarkTypeUnknown,
			}
		} else {
			return ctx.newBadExpr(node, "reference is too complex: %s", refDump)
		}
	}

	if name, _, ok := ctx.maybeParseFunctionCall(node, ref); ok {
		if _, unsupported := unsupportedFunctions[name]; unsupported {
+21 −0
Original line number Diff line number Diff line
@@ -1597,6 +1597,27 @@ MY_VAR := foo
def init(g, handle):
  cfg = rblf.cfg(handle)
  g["MY_VAR"] = "foo"
`,
	},
	{
		desc:   "Complicated variable references",
		mkname: "product.mk",
		in: `
MY_VAR := foo
MY_VAR_2 := MY_VAR
MY_VAR_3 := $($(MY_VAR_2))
MY_VAR_4 := $(foo bar)
MY_VAR_5 := $($(MY_VAR_2) bar)
`,
		expected: `load("//build/make/core:product_config.rbc", "rblf")

def init(g, handle):
  cfg = rblf.cfg(handle)
  g["MY_VAR"] = "foo"
  g["MY_VAR_2"] = "MY_VAR"
  g["MY_VAR_3"] = (cfg).get(g["MY_VAR_2"], (g).get(g["MY_VAR_2"], ""))
  g["MY_VAR_4"] = rblf.mk2rbc_error("product.mk:5", "cannot handle invoking foo")
  g["MY_VAR_5"] = rblf.mk2rbc_error("product.mk:6", "reference is too complex: $(MY_VAR_2) bar")
`,
	},
}