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

Commit 3b542981 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: 3f008894

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

Change-Id: I89e4b09f5d5df20fbe93f23ec3342e1d3f6c9a51
parents c1744ee0 3f008894
Loading
Loading
Loading
Loading
+22 −6
Original line number Original line Diff line number Diff line
@@ -254,19 +254,19 @@ func (gctx *generationContext) emitPreamble() {
	gctx.writef("load(%q, %q)", baseUri, baseName)
	gctx.writef("load(%q, %q)", baseUri, baseName)
	// Emit exactly one load statement for each URI.
	// Emit exactly one load statement for each URI.
	loadedSubConfigs := make(map[string]string)
	loadedSubConfigs := make(map[string]string)
	for _, sc := range gctx.starScript.inherited {
	for _, mi := range gctx.starScript.inherited {
		uri := sc.path
		uri := mi.path
		if m, ok := loadedSubConfigs[uri]; ok {
		if m, ok := loadedSubConfigs[uri]; ok {
			// No need to emit load statement, but fix module name.
			// No need to emit load statement, but fix module name.
			sc.moduleLocalName = m
			mi.moduleLocalName = m
			continue
			continue
		}
		}
		if sc.optional {
		if mi.optional || mi.missing {
			uri += "|init"
			uri += "|init"
		}
		}
		gctx.newLine()
		gctx.newLine()
		gctx.writef("load(%q, %s = \"init\")", uri, sc.entryName())
		gctx.writef("load(%q, %s = \"init\")", uri, mi.entryName())
		loadedSubConfigs[uri] = sc.moduleLocalName
		loadedSubConfigs[uri] = mi.moduleLocalName
	}
	}
	gctx.write("\n")
	gctx.write("\n")
}
}
@@ -298,6 +298,20 @@ func (gctx *generationContext) emitConversionError(el ErrorLocation, message str
	gctx.writef(`rblf.mk2rbc_error("%s", %q)`, el, message)
	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 {
type knownVariable struct {
	name      string
	name      string
	class     varClass
	class     varClass
@@ -751,11 +765,13 @@ func (ctx *parseContext) newDependentModule(path string, optional bool) *moduleI
		moduleLocalName += fmt.Sprintf("%d", n)
		moduleLocalName += fmt.Sprintf("%d", n)
	}
	}
	ctx.moduleNameCount[moduleName] = n + 1
	ctx.moduleNameCount[moduleName] = n + 1
	_, err := fs.Stat(ctx.script.sourceFS, path)
	mi := &moduleInfo{
	mi := &moduleInfo{
		path:            modulePath,
		path:            modulePath,
		originalPath:    path,
		originalPath:    path,
		moduleLocalName: moduleLocalName,
		moduleLocalName: moduleLocalName,
		optional:        optional,
		optional:        optional,
		missing:         err != nil,
	}
	}
	ctx.dependentModules[modulePath] = mi
	ctx.dependentModules[modulePath] = mi
	ctx.script.inherited = append(ctx.script.inherited, mi)
	ctx.script.inherited = append(ctx.script.inherited, mi)
+6 −2
Original line number Original line Diff line number Diff line
@@ -121,7 +121,7 @@ $(call inherit-product, part.mk)
ifdef PRODUCT_NAME
ifdef PRODUCT_NAME
$(call inherit-product, part1.mk)
$(call inherit-product, part1.mk)
else # Comment
else # Comment
$(call inherit-product, $(LOCAL_PATH)/part1.mk)
$(call inherit-product, $(LOCAL_PATH)/part.mk)
endif
endif
`,
`,
		expected: `load("//build/make/core:product_config.rbc", "rblf")
		expected: `load("//build/make/core:product_config.rbc", "rblf")
@@ -132,10 +132,12 @@ def init(g, handle):
  cfg = rblf.cfg(handle)
  cfg = rblf.cfg(handle)
  rblf.inherit(handle, "part", _part_init)
  rblf.inherit(handle, "part", _part_init)
  if g.get("PRODUCT_NAME") != None:
  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)
    rblf.inherit(handle, "part1", _part1_init)
  else:
  else:
    # Comment
    # 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)
  cfg = rblf.cfg(handle)
  _part_init(g, handle)
  _part_init(g, handle)
  if g.get("PRODUCT_NAME") != None:
  if g.get("PRODUCT_NAME") != None:
    if not _part1_init:
      rblf.mkerror("product.mk", "Cannot find %s" % (":part1.star"))
    _part1_init(g, handle)
    _part1_init(g, handle)
  else:
  else:
    if _part1_init != None:
    if _part1_init != None:
+22 −18
Original line number Original line Diff line number Diff line
@@ -47,6 +47,7 @@ type moduleInfo struct {
	originalPath    string // Makefile file path
	originalPath    string // Makefile file path
	moduleLocalName string
	moduleLocalName string
	optional        bool
	optional        bool
	missing         bool // a module may not exist if a module that depends on it is loaded dynamically
}
}


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


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


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

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


type inheritedDynamicModule struct {
type inheritedDynamicModule struct {
@@ -105,20 +111,14 @@ func (i inheritedDynamicModule) emitSelect(gctx *generationContext) {
	gctx.write(")")
	gctx.write(")")
	gctx.newLine()
	gctx.newLine()
	gctx.writef("(%s, %s) = _entry if _entry else (None, None)", i.name(), i.entryName())
	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 {
func (i inheritedDynamicModule) needsLoadCheck() bool {
	return i.loadAlways
	return true
}
}


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


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

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


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


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