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

Commit d3b2e26e authored by Alexander Smundak's avatar Alexander Smundak Committed by Automerger Merge Worker
Browse files

Merge "Check missing uncoditionally loaded missing modules at runtime" am:...

Merge "Check missing uncoditionally loaded missing modules at runtime" am: 3f008894 am: 3b542981

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1944624

Change-Id: Ib7800264675bb034bdb323ab7925bfc4d79339b0
parents d437de13 3b542981
Loading
Loading
Loading
Loading
+22 −6
Original line number Diff line number Diff line
@@ -254,19 +254,19 @@ func (gctx *generationContext) emitPreamble() {
	gctx.writef("load(%q, %q)", baseUri, baseName)
	// Emit exactly one load statement for each URI.
	loadedSubConfigs := make(map[string]string)
	for _, sc := range gctx.starScript.inherited {
		uri := sc.path
	for _, mi := range gctx.starScript.inherited {
		uri := mi.path
		if m, ok := loadedSubConfigs[uri]; ok {
			// No need to emit load statement, but fix module name.
			sc.moduleLocalName = m
			mi.moduleLocalName = m
			continue
		}
		if sc.optional {
		if mi.optional || mi.missing {
			uri += "|init"
		}
		gctx.newLine()
		gctx.writef("load(%q, %s = \"init\")", uri, sc.entryName())
		loadedSubConfigs[uri] = sc.moduleLocalName
		gctx.writef("load(%q, %s = \"init\")", uri, mi.entryName())
		loadedSubConfigs[uri] = mi.moduleLocalName
	}
	gctx.write("\n")
}
@@ -298,6 +298,20 @@ func (gctx *generationContext) emitConversionError(el ErrorLocation, message str
	gctx.writef(`rblf.mk2rbc_error("%s", %q)`, el, message)
}

func (gctx *generationContext) emitLoadCheck(im inheritedModule) {
	if !im.needsLoadCheck() {
		return
	}
	gctx.newLine()
	gctx.writef("if not %s:", im.entryName())
	gctx.indentLevel++
	gctx.newLine()
	gctx.write(`rblf.mkerror("`, gctx.starScript.mkFile, `", "Cannot find %s" % (`)
	im.pathExpr().emit(gctx)
	gctx.write("))")
	gctx.indentLevel--
}

type knownVariable struct {
	name      string
	class     varClass
@@ -751,11 +765,13 @@ func (ctx *parseContext) newDependentModule(path string, optional bool) *moduleI
		moduleLocalName += fmt.Sprintf("%d", n)
	}
	ctx.moduleNameCount[moduleName] = n + 1
	_, err := fs.Stat(ctx.script.sourceFS, path)
	mi := &moduleInfo{
		path:            modulePath,
		originalPath:    path,
		moduleLocalName: moduleLocalName,
		optional:        optional,
		missing:         err != nil,
	}
	ctx.dependentModules[modulePath] = mi
	ctx.script.inherited = append(ctx.script.inherited, mi)
+6 −2
Original line number Diff line number Diff line
@@ -121,7 +121,7 @@ $(call inherit-product, part.mk)
ifdef PRODUCT_NAME
$(call inherit-product, part1.mk)
else # Comment
$(call inherit-product, $(LOCAL_PATH)/part1.mk)
$(call inherit-product, $(LOCAL_PATH)/part.mk)
endif
`,
		expected: `load("//build/make/core:product_config.rbc", "rblf")
@@ -132,10 +132,12 @@ def init(g, handle):
  cfg = rblf.cfg(handle)
  rblf.inherit(handle, "part", _part_init)
  if g.get("PRODUCT_NAME") != None:
    if not _part1_init:
      rblf.mkerror("product.mk", "Cannot find %s" % (":part1.star"))
    rblf.inherit(handle, "part1", _part1_init)
  else:
    # Comment
    rblf.inherit(handle, "part1", _part1_init)
    rblf.inherit(handle, "part", _part_init)
`,
	},
	{
@@ -173,6 +175,8 @@ def init(g, handle):
  cfg = rblf.cfg(handle)
  _part_init(g, handle)
  if g.get("PRODUCT_NAME") != None:
    if not _part1_init:
      rblf.mkerror("product.mk", "Cannot find %s" % (":part1.star"))
    _part1_init(g, handle)
  else:
    if _part1_init != None:
+22 −18
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ type moduleInfo struct {
	originalPath    string // Makefile file path
	moduleLocalName string
	optional        bool
	missing         bool // a module may not exist if a module that depends on it is loaded dynamically
}

func (im moduleInfo) entryName() string {
@@ -57,7 +58,8 @@ type inheritedModule interface {
	name() string
	entryName() string
	emitSelect(gctx *generationContext)
	shouldExist() bool
	pathExpr() starlarkExpr
	needsLoadCheck() bool
}

type inheritedStaticModule struct {
@@ -72,8 +74,12 @@ func (im inheritedStaticModule) name() string {
func (im inheritedStaticModule) emitSelect(_ *generationContext) {
}

func (im inheritedStaticModule) shouldExist() bool {
	return im.loadAlways
func (im inheritedStaticModule) pathExpr() starlarkExpr {
	return &stringLiteralExpr{im.path}
}

func (im inheritedStaticModule) needsLoadCheck() bool {
	return im.missing
}

type inheritedDynamicModule struct {
@@ -105,20 +111,14 @@ func (i inheritedDynamicModule) emitSelect(gctx *generationContext) {
	gctx.write(")")
	gctx.newLine()
	gctx.writef("(%s, %s) = _entry if _entry else (None, None)", i.name(), i.entryName())
	if i.loadAlways {
		gctx.newLine()
		gctx.writef("if not %s:", i.entryName())
		gctx.indentLevel++
		gctx.newLine()
		gctx.write(`rblf.mkerror("`, gctx.starScript.mkFile, `", "Cannot find %s" % (`)
		i.path.emit(gctx)
		gctx.write("))")
		gctx.indentLevel--
}

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

func (i inheritedDynamicModule) shouldExist() bool {
	return i.loadAlways
func (i inheritedDynamicModule) needsLoadCheck() bool {
	return true
}

type inheritNode struct {
@@ -128,20 +128,22 @@ type inheritNode struct {

func (inn *inheritNode) emit(gctx *generationContext) {
	// Unconditional case:
	//    maybe check that loaded
	//    rblf.inherit(handle, <module>, module_init)
	// Conditional case:
	//    if <module>_init != None:
	//      same as above
	inn.module.emitSelect(gctx)

	name := inn.module.name()
	entry := inn.module.entryName()
	gctx.newLine()
	if inn.loadAlways {
		gctx.emitLoadCheck(inn.module)
		gctx.newLine()
		gctx.writef("%s(handle, %s, %s)", cfnInherit, name, entry)
		return
	}

	gctx.newLine()
	gctx.writef("if %s:", entry)
	gctx.indentLevel++
	gctx.newLine()
@@ -157,12 +159,14 @@ type includeNode struct {
func (inn *includeNode) emit(gctx *generationContext) {
	inn.module.emitSelect(gctx)
	entry := inn.module.entryName()
	gctx.newLine()
	if inn.loadAlways {
		gctx.emitLoadCheck(inn.module)
		gctx.newLine()
		gctx.writef("%s(g, handle)", entry)
		return
	}

	gctx.newLine()
	gctx.writef("if %s != None:", entry)
	gctx.indentLevel++
	gctx.newLine()