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

Commit 16bb2d04 authored by Cole Faust's avatar Cole Faust Committed by Gerrit Code Review
Browse files

Merge "Allow seeing include $(x) when there is an include_top comment"

parents e8f19f3d 9df1d736
Loading
Loading
Loading
Loading
+33 −18
Original line number Diff line number Diff line
@@ -817,13 +817,10 @@ func (ctx *parseContext) handleSubConfig(
	//       rblf.inherit(handle, _e[0], _e[1])
	//
	var matchingPaths []string
	varPath, ok := pathExpr.(*interpolateExpr)
	if !ok {
		return []starlarkNode{ctx.newBadNode(v, "inherit-product/include argument is too complex")}
	}

	pathPattern := []string{varPath.chunks[0]}
	for _, chunk := range varPath.chunks[1:] {
	var needsWarning = false
	if interpolate, ok := pathExpr.(*interpolateExpr); ok {
		pathPattern := []string{interpolate.chunks[0]}
		for _, chunk := range interpolate.chunks[1:] {
			if chunk != "" {
				pathPattern = append(pathPattern, chunk)
			}
@@ -838,14 +835,22 @@ func (ctx *parseContext) handleSubConfig(
		} else {
			matchingPaths = ctx.findMatchingPaths(pathPattern)
		}
		needsWarning = pathPattern[0] == "" && len(ctx.includeTops) == 0
	} else if len(ctx.includeTops) > 0 {
		for _, p := range ctx.includeTops {
			matchingPaths = append(matchingPaths, ctx.findMatchingPaths([]string{p, ""})...)
		}
	} else {
		return []starlarkNode{ctx.newBadNode(v, "inherit-product/include argument is too complex")}
	}

	// Safeguard against $(call inherit-product,$(PRODUCT_PATH))
	const maxMatchingFiles = 150
	if len(matchingPaths) > maxMatchingFiles {
		return []starlarkNode{ctx.newBadNode(v, "there are >%d files matching the pattern, please rewrite it", maxMatchingFiles)}
	}

	needsWarning := pathPattern[0] == "" && len(ctx.includeTops) == 0
	res := inheritedDynamicModule{*varPath, []*moduleInfo{}, loadAlways, ctx.errorLocation(v), needsWarning}
	res := inheritedDynamicModule{pathExpr, []*moduleInfo{}, loadAlways, ctx.errorLocation(v), needsWarning}
	for _, p := range matchingPaths {
		// A product configuration files discovered dynamically may attempt to inherit
		// from another one which does not exist in this source tree. Prevent load errors
@@ -1588,6 +1593,16 @@ func transformNode(node starlarkNode, transformer func(expr starlarkExpr) starla
		for _, n := range a.actions {
			transformNode(n, transformer)
		}
	case *inheritNode:
		if b, ok := a.module.(inheritedDynamicModule); ok {
			b.path = b.path.transform(transformer)
			a.module = b
		}
	case *includeNode:
		if b, ok := a.module.(inheritedDynamicModule); ok {
			b.path = b.path.transform(transformer)
			a.module = b
		}
	}
}

+20 −0
Original line number Diff line number Diff line
@@ -1146,6 +1146,11 @@ def init(g, handle):
MY_PATH:=foo
#RBC# include_top vendor/foo1
$(call inherit-product,$(MY_PATH)/cfg.mk)
#RBC# include_top vendor/foo1
$(call inherit-product,$(MY_OTHER_PATH))
#RBC# include_top vendor/foo1
$(foreach f,$(MY_MAKEFILES), \
	$(call inherit-product,$(f)))
`,
		expected: `load("//build/make/core:product_config.rbc", "rblf")
load("//vendor/foo1:cfg.star|init", _cfg_init = "init")
@@ -1160,6 +1165,21 @@ def init(g, handle):
  if not _varmod_init:
    rblf.mkerror("product.mk", "Cannot find %s" % ("%s/cfg.mk" % g["MY_PATH"]))
  rblf.inherit(handle, _varmod, _varmod_init)
  _entry = {
    "vendor/foo1/cfg.mk": ("vendor/foo1/cfg", _cfg_init),
  }.get(g.get("MY_OTHER_PATH", ""))
  (_varmod, _varmod_init) = _entry if _entry else (None, None)
  if not _varmod_init:
    rblf.mkerror("product.mk", "Cannot find %s" % (g.get("MY_OTHER_PATH", "")))
  rblf.inherit(handle, _varmod, _varmod_init)
  for f in rblf.words(g.get("MY_MAKEFILES", "")):
    _entry = {
      "vendor/foo1/cfg.mk": ("vendor/foo1/cfg", _cfg_init),
    }.get(f)
    (_varmod, _varmod_init) = _entry if _entry else (None, None)
    if not _varmod_init:
      rblf.mkerror("product.mk", "Cannot find %s" % (f))
    rblf.inherit(handle, _varmod, _varmod_init)
`,
	},
	{
+2 −2
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ func (im inheritedStaticModule) needsLoadCheck() bool {
}

type inheritedDynamicModule struct {
	path             interpolateExpr
	path             starlarkExpr
	candidateModules []*moduleInfo
	loadAlways       bool
	location         ErrorLocation
@@ -120,7 +120,7 @@ func (i inheritedDynamicModule) emitSelect(gctx *generationContext) {
}

func (i inheritedDynamicModule) pathExpr() starlarkExpr {
	return &i.path
	return i.path
}

func (i inheritedDynamicModule) needsLoadCheck() bool {