Use ModuleInfoJSONProvider for cc modules

LOCAL_STATIC_LIBRARIES, LOCAL_WHOLE_STATIC_LIBRARIES,
and LOCAL_HEADER_LIBRARIES are only  exported to Make
so that it can generate module-info.json.  Export
ModuleInfoJSONProvider from cc modules so that Soong can
generate the module-info.json entries, and remove the
properties from the generated Android.mk.  This will prevent
Kati reanalysis when making some Android.bp changes.

Bug: 309006256
Test: Compare module-info.json
Test: Compare Kati's build.ninja
Change-Id: I6660f6802b9cea46eed553cac12f09a373eeb019
This commit is contained in:
Colin Cross 2023-12-18 15:29:41 -08:00
parent d6fd013394
commit 4a9e6ec903
10 changed files with 174 additions and 9 deletions

View file

@ -101,15 +101,6 @@ func (c *Module) AndroidMkEntries() []android.AndroidMkEntries {
if len(c.Properties.AndroidMkSharedLibs) > 0 { if len(c.Properties.AndroidMkSharedLibs) > 0 {
entries.AddStrings("LOCAL_SHARED_LIBRARIES", c.Properties.AndroidMkSharedLibs...) entries.AddStrings("LOCAL_SHARED_LIBRARIES", c.Properties.AndroidMkSharedLibs...)
} }
if len(c.Properties.AndroidMkStaticLibs) > 0 {
entries.AddStrings("LOCAL_STATIC_LIBRARIES", c.Properties.AndroidMkStaticLibs...)
}
if len(c.Properties.AndroidMkWholeStaticLibs) > 0 {
entries.AddStrings("LOCAL_WHOLE_STATIC_LIBRARIES", c.Properties.AndroidMkWholeStaticLibs...)
}
if len(c.Properties.AndroidMkHeaderLibs) > 0 {
entries.AddStrings("LOCAL_HEADER_LIBRARIES", c.Properties.AndroidMkHeaderLibs...)
}
if len(c.Properties.AndroidMkRuntimeLibs) > 0 { if len(c.Properties.AndroidMkRuntimeLibs) > 0 {
entries.AddStrings("LOCAL_RUNTIME_LIBRARIES", c.Properties.AndroidMkRuntimeLibs...) entries.AddStrings("LOCAL_RUNTIME_LIBRARIES", c.Properties.AndroidMkRuntimeLibs...)
} }

View file

@ -541,6 +541,11 @@ func (binary *binaryDecorator) overriddenModules() []string {
return binary.Properties.Overrides return binary.Properties.Overrides
} }
func (binary *binaryDecorator) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) {
moduleInfoJSON.Class = []string{"EXECUTABLES"}
binary.baseLinker.moduleInfoJSON(ctx, moduleInfoJSON)
}
var _ overridable = (*binaryDecorator)(nil) var _ overridable = (*binaryDecorator)(nil)
func init() { func init() {

View file

@ -544,6 +544,7 @@ type ModuleContextIntf interface {
isPreventInstall() bool isPreventInstall() bool
isCfiAssemblySupportEnabled() bool isCfiAssemblySupportEnabled() bool
getSharedFlags() *SharedFlags getSharedFlags() *SharedFlags
notInPlatform() bool
} }
type SharedFlags struct { type SharedFlags struct {
@ -624,6 +625,8 @@ type linker interface {
// Get the deps that have been explicitly specified in the properties. // Get the deps that have been explicitly specified in the properties.
linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON)
} }
// specifiedDeps is a tuple struct representing dependencies of a linked binary owned by the linker. // specifiedDeps is a tuple struct representing dependencies of a linked binary owned by the linker.
@ -1786,6 +1789,10 @@ func (ctx *moduleContextImpl) isCfiAssemblySupportEnabled() bool {
return ctx.mod.isCfiAssemblySupportEnabled() return ctx.mod.isCfiAssemblySupportEnabled()
} }
func (ctx *moduleContextImpl) notInPlatform() bool {
return ctx.mod.NotInPlatform()
}
func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
return &Module{ return &Module{
hod: hod, hod: hod,
@ -2140,6 +2147,39 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
aconfig.CollectDependencyAconfigFiles(ctx, &c.mergedAconfigFiles) aconfig.CollectDependencyAconfigFiles(ctx, &c.mergedAconfigFiles)
c.maybeInstall(ctx, apexInfo) c.maybeInstall(ctx, apexInfo)
if c.linker != nil {
moduleInfoJSON := ctx.ModuleInfoJSON()
c.linker.moduleInfoJSON(ctx, moduleInfoJSON)
moduleInfoJSON.SharedLibs = c.Properties.AndroidMkSharedLibs
moduleInfoJSON.StaticLibs = c.Properties.AndroidMkStaticLibs
moduleInfoJSON.SystemSharedLibs = c.Properties.AndroidMkSystemSharedLibs
moduleInfoJSON.RuntimeDependencies = c.Properties.AndroidMkRuntimeLibs
moduleInfoJSON.Dependencies = append(moduleInfoJSON.Dependencies, c.Properties.AndroidMkSharedLibs...)
moduleInfoJSON.Dependencies = append(moduleInfoJSON.Dependencies, c.Properties.AndroidMkStaticLibs...)
moduleInfoJSON.Dependencies = append(moduleInfoJSON.Dependencies, c.Properties.AndroidMkHeaderLibs...)
moduleInfoJSON.Dependencies = append(moduleInfoJSON.Dependencies, c.Properties.AndroidMkWholeStaticLibs...)
if c.sanitize != nil && len(moduleInfoJSON.Class) > 0 &&
(moduleInfoJSON.Class[0] == "STATIC_LIBRARIES" || moduleInfoJSON.Class[0] == "HEADER_LIBRARIES") {
if Bool(c.sanitize.Properties.SanitizeMutated.Cfi) {
moduleInfoJSON.SubName += ".cfi"
}
if Bool(c.sanitize.Properties.SanitizeMutated.Hwaddress) {
moduleInfoJSON.SubName += ".hwasan"
}
if Bool(c.sanitize.Properties.SanitizeMutated.Scs) {
moduleInfoJSON.SubName += ".scs"
}
}
moduleInfoJSON.SubName += c.Properties.SubName
if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake {
moduleInfoJSON.Uninstallable = true
}
}
} }
func (c *Module) maybeUnhideFromMake() { func (c *Module) maybeUnhideFromMake() {

View file

@ -163,6 +163,11 @@ func (fuzz *fuzzBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
return flags return flags
} }
func (fuzz *fuzzBinary) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) {
fuzz.binaryDecorator.moduleInfoJSON(ctx, moduleInfoJSON)
moduleInfoJSON.Class = []string{"EXECUTABLES"}
}
// IsValidSharedDependency takes a module and determines if it is a unique shared library // IsValidSharedDependency takes a module and determines if it is a unique shared library
// that should be installed in the fuzz target output directories. This function // that should be installed in the fuzz target output directories. This function
// returns true, unless: // returns true, unless:

View file

@ -1041,6 +1041,40 @@ func (library *libraryDecorator) linkerSpecifiedDeps(specifiedDeps specifiedDeps
return specifiedDeps return specifiedDeps
} }
func (library *libraryDecorator) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) {
if library.static() {
moduleInfoJSON.Class = []string{"STATIC_LIBRARIES"}
moduleInfoJSON.Uninstallable = true
} else if library.shared() {
moduleInfoJSON.Class = []string{"SHARED_LIBRARIES"}
} else if library.header() {
moduleInfoJSON.Class = []string{"HEADER_LIBRARIES"}
moduleInfoJSON.Uninstallable = true
}
if library.buildStubs() && library.stubsVersion() != "" {
moduleInfoJSON.SubName += "." + library.stubsVersion()
}
// If a library providing a stub is included in an APEX, the private APIs of the library
// is accessible only inside the APEX. From outside of the APEX, clients can only use the
// public APIs via the stub. To enforce this, the (latest version of the) stub gets the
// name of the library. The impl library instead gets the `.bootstrap` suffix to so that
// they can be exceptionally used directly when APEXes are not available (e.g. during the
// very early stage in the boot process).
if len(library.Properties.Stubs.Versions) > 0 && !ctx.Host() && ctx.notInPlatform() &&
!ctx.inRamdisk() && !ctx.inVendorRamdisk() && !ctx.inRecovery() && !ctx.useVndk() && !ctx.static() {
if library.buildStubs() && library.isLatestStubVersion() {
moduleInfoJSON.SubName = ""
}
if !library.buildStubs() {
moduleInfoJSON.SubName = ".bootstrap"
}
}
library.baseLinker.moduleInfoJSON(ctx, moduleInfoJSON)
}
func (library *libraryDecorator) linkStatic(ctx ModuleContext, func (library *libraryDecorator) linkStatic(ctx ModuleContext,
flags Flags, deps PathDeps, objs Objects) android.Path { flags Flags, deps PathDeps, objs Objects) android.Path {

View file

@ -648,6 +648,9 @@ func (linker *baseLinker) linkerSpecifiedDeps(specifiedDeps specifiedDeps) speci
return specifiedDeps return specifiedDeps
} }
func (linker *baseLinker) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) {
}
// Injecting version symbols // Injecting version symbols
// Some host modules want a version number, but we don't want to rebuild it every time. Optionally add a step // Some host modules want a version number, but we don't want to rebuild it every time. Optionally add a step
// after linking that injects a constant placeholder with the current version number. // after linking that injects a constant placeholder with the current version number.

View file

@ -486,6 +486,12 @@ func (linker *stubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
} }
} }
func (linker *stubDecorator) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) {
linker.libraryDecorator.moduleInfoJSON(ctx, moduleInfoJSON)
// Overwrites the SubName computed by libraryDecorator
moduleInfoJSON.SubName = ndkLibrarySuffix + "." + linker.apiLevel.String()
}
func (linker *stubDecorator) Name(name string) string { func (linker *stubDecorator) Name(name string) string {
return name + ndkLibrarySuffix return name + ndkLibrarySuffix
} }

View file

@ -238,3 +238,8 @@ func (object *objectLinker) object() bool {
func (object *objectLinker) isCrt() bool { func (object *objectLinker) isCrt() bool {
return Bool(object.Properties.Crt) return Bool(object.Properties.Crt)
} }
func (object *objectLinker) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) {
object.baseLinker.moduleInfoJSON(ctx, moduleInfoJSON)
moduleInfoJSON.Class = []string{"STATIC_LIBRARIES"}
}

View file

@ -321,6 +321,13 @@ func (test *testDecorator) installerProps() []interface{} {
return []interface{}{&test.InstallerProperties} return []interface{}{&test.InstallerProperties}
} }
func (test *testDecorator) moduleInfoJSON(ctx android.ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) {
if android.PrefixInList(moduleInfoJSON.CompatibilitySuites, "mts-") &&
!android.InList("mts", moduleInfoJSON.CompatibilitySuites) {
moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, "mts")
}
}
func NewTestInstaller() *baseInstaller { func NewTestInstaller() *baseInstaller {
return NewBaseInstaller("nativetest", "nativetest64", InstallInData) return NewBaseInstaller("nativetest", "nativetest64", InstallInData)
} }
@ -355,6 +362,38 @@ func (test *testBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
return flags return flags
} }
func (test *testBinary) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) {
if ctx.Host() && Bool(test.Properties.Test_options.Unit_test) {
moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, "host-unit-tests")
}
moduleInfoJSON.TestOptionsTags = append(moduleInfoJSON.TestOptionsTags, test.Properties.Test_options.Tags...)
moduleInfoJSON.TestMainlineModules = append(moduleInfoJSON.TestMainlineModules, test.Properties.Test_mainline_modules...)
if test.testConfig != nil {
if _, ok := test.testConfig.(android.WritablePath); ok {
moduleInfoJSON.AutoTestConfig = []string{"true"}
}
moduleInfoJSON.TestConfig = append(moduleInfoJSON.TestConfig, test.testConfig.String())
}
moduleInfoJSON.TestConfig = append(moduleInfoJSON.TestConfig, test.extraTestConfigs.Strings()...)
if Bool(test.Properties.Test_per_src) {
moduleInfoJSON.SubName = "_" + String(test.binaryDecorator.Properties.Stem)
}
moduleInfoJSON.DataDependencies = append(moduleInfoJSON.DataDependencies, test.Properties.Data_bins...)
if len(test.InstallerProperties.Test_suites) > 0 {
moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, test.InstallerProperties.Test_suites...)
} else {
moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, "null-suite")
}
test.binaryDecorator.moduleInfoJSON(ctx, moduleInfoJSON)
test.testDecorator.moduleInfoJSON(ctx, moduleInfoJSON)
moduleInfoJSON.Class = []string{"NATIVE_TESTS"}
}
func (test *testBinary) installerProps() []interface{} { func (test *testBinary) installerProps() []interface{} {
return append(test.baseInstaller.installerProps(), test.testDecorator.installerProps()...) return append(test.baseInstaller.installerProps(), test.testDecorator.installerProps()...)
} }
@ -532,6 +571,15 @@ func (test *testLibrary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
return flags return flags
} }
func (test *testLibrary) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) {
if len(test.InstallerProperties.Test_suites) > 0 {
moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, test.InstallerProperties.Test_suites...)
}
test.libraryDecorator.moduleInfoJSON(ctx, moduleInfoJSON)
test.testDecorator.moduleInfoJSON(ctx, moduleInfoJSON)
}
func (test *testLibrary) installerProps() []interface{} { func (test *testLibrary) installerProps() []interface{} {
return append(test.baseInstaller.installerProps(), test.testDecorator.installerProps()...) return append(test.baseInstaller.installerProps(), test.testDecorator.installerProps()...)
} }
@ -626,6 +674,29 @@ func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Pat
benchmark.binaryDecorator.baseInstaller.install(ctx, file) benchmark.binaryDecorator.baseInstaller.install(ctx, file)
} }
func (benchmark *benchmarkDecorator) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) {
benchmark.binaryDecorator.moduleInfoJSON(ctx, moduleInfoJSON)
moduleInfoJSON.Class = []string{"NATIVE_TESTS"}
if len(benchmark.Properties.Test_suites) > 0 {
moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, benchmark.Properties.Test_suites...)
} else {
moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, "null-suite")
}
if android.PrefixInList(moduleInfoJSON.CompatibilitySuites, "mts-") &&
!android.InList("mts", moduleInfoJSON.CompatibilitySuites) {
moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, "mts")
}
if benchmark.testConfig != nil {
if _, ok := benchmark.testConfig.(android.WritablePath); ok {
moduleInfoJSON.AutoTestConfig = []string{"true"}
}
moduleInfoJSON.TestConfig = []string{benchmark.testConfig.String()}
}
}
func NewBenchmark(hod android.HostOrDeviceSupported) *Module { func NewBenchmark(hod android.HostOrDeviceSupported) *Module {
module, binary := newBinary(hod) module, binary := newBinary(hod)
module.multilib = android.MultilibBoth module.multilib = android.MultilibBoth

View file

@ -187,6 +187,11 @@ func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext,
return nil return nil
} }
func (p *vndkPrebuiltLibraryDecorator) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) {
p.libraryDecorator.moduleInfoJSON(ctx, moduleInfoJSON)
moduleInfoJSON.SubName += p.androidMkSuffix
}
func (p *vndkPrebuiltLibraryDecorator) MatchesWithDevice(config android.DeviceConfig) bool { func (p *vndkPrebuiltLibraryDecorator) MatchesWithDevice(config android.DeviceConfig) bool {
arches := config.Arches() arches := config.Arches()
if len(arches) == 0 || arches[0].ArchType.String() != p.arch() { if len(arches) == 0 || arches[0].ArchType.String() != p.arch() {