Implement cc_object vendor snapshot

cc_object modules are also necessary for vendor snapshot.

Bug: 157106227
Test: m vendor-snapshot
Change-Id: Idf4fd37a26f6f712f3cbab43133622f9f9bd9372
Merged-In: Idf4fd37a26f6f712f3cbab43133622f9f9bd9372
(cherry picked from commit 502679e061)
This commit is contained in:
Inseob Kim 2020-06-01 23:23:05 +09:00
parent 7f283f4bd0
commit 1042d29705
7 changed files with 186 additions and 15 deletions

View File

@ -548,6 +548,25 @@ func (c *vendorSnapshotBinaryDecorator) AndroidMkEntries(ctx AndroidMkContext, e
})
}
func (c *vendorSnapshotObjectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
entries.Class = "STATIC_LIBRARIES"
if c.androidMkVendorSuffix {
entries.SubName = vendorSuffix
} else {
entries.SubName = ""
}
entries.ExtraFooters = append(entries.ExtraFooters,
func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
out := entries.OutputFile.Path()
varname := fmt.Sprintf("SOONG_%sOBJECT_%s%s", prefix, name, entries.SubName)
fmt.Fprintf(w, "\n%s := %s\n", varname, out.String())
fmt.Fprintln(w, ".KATI_READONLY: "+varname)
})
}
func (c *ndkPrebuiltStlLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
entries.Class = "SHARED_LIBRARIES"
}

View File

@ -317,6 +317,7 @@ type ModuleContextIntf interface {
staticBinary() bool
header() bool
binary() bool
object() bool
toolchain() config.Toolchain
canUseSdk() bool
useSdk() bool
@ -1018,14 +1019,8 @@ func (c *Module) nativeCoverage() bool {
}
func (c *Module) isSnapshotPrebuilt() bool {
if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
return true
}
if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
return true
}
if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
return true
if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
return p.isSnapshotPrebuilt()
}
return false
}
@ -1134,6 +1129,10 @@ func (ctx *moduleContextImpl) binary() bool {
return ctx.mod.binary()
}
func (ctx *moduleContextImpl) object() bool {
return ctx.mod.object()
}
func (ctx *moduleContextImpl) canUseSdk() bool {
return ctx.mod.canUseSdk()
}
@ -2011,11 +2010,13 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
if deps.CrtBegin != "" {
actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
actx.AddVariationDependencies(nil, CrtBeginDepTag, rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
}
if deps.CrtEnd != "" {
actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
actx.AddVariationDependencies(nil, CrtEndDepTag, rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
}
if deps.LinkerFlagsFile != "" {
actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
@ -2766,6 +2767,15 @@ func (c *Module) binary() bool {
return false
}
func (c *Module) object() bool {
if o, ok := c.linker.(interface {
object() bool
}); ok {
return o.object()
}
return false
}
func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
if c.UseVndk() {
if lib, ok := c.linker.(*llndkStubDecorator); ok {

View File

@ -845,6 +845,11 @@ func TestVendorSnapshot(t *testing.T) {
vendor_available: true,
src: "libb.a",
}
cc_object {
name: "obj",
vendor_available: true,
}
`
config := TestConfig(buildDir, android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
@ -903,6 +908,12 @@ func TestVendorSnapshot(t *testing.T) {
// For header libraries, all vendor:true and vendor_available modules are captured.
headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json"))
// For object modules, all vendor:true and vendor_available modules are captured.
objectVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
}
for _, jsonFile := range jsonFiles {

View File

@ -158,3 +158,7 @@ func (object *objectLinker) nativeCoverage() bool {
func (object *objectLinker) coverageOutputFilePath() android.OptionalPath {
return android.OptionalPath{}
}
func (object *objectLinker) object() bool {
return true
}

View File

@ -291,6 +291,10 @@ func (p *prebuiltObjectLinker) link(ctx ModuleContext,
return nil
}
func (p *prebuiltObjectLinker) object() bool {
return true
}
func newPrebuiltObject() *Module {
module := newObject()
prebuilt := &prebuiltObjectLinker{

View File

@ -30,6 +30,7 @@ const (
vendorSnapshotSharedSuffix = ".vendor_shared."
vendorSnapshotStaticSuffix = ".vendor_static."
vendorSnapshotBinarySuffix = ".vendor_binary."
vendorSnapshotObjectSuffix = ".vendor_object."
)
var (
@ -39,6 +40,7 @@ var (
vendorSnapshotStaticLibsKey = android.NewOnceKey("vendorSnapshotStaticLibs")
vendorSnapshotSharedLibsKey = android.NewOnceKey("vendorSnapshotSharedLibs")
vendorSnapshotBinariesKey = android.NewOnceKey("vendorSnapshotBinaries")
vendorSnapshotObjectsKey = android.NewOnceKey("vendorSnapshotObjects")
)
// vendor snapshot maps hold names of vendor snapshot modules per arch
@ -72,6 +74,12 @@ func vendorSnapshotBinaries(config android.Config) *snapshotMap {
}).(*snapshotMap)
}
func vendorSnapshotObjects(config android.Config) *snapshotMap {
return config.Once(vendorSnapshotObjectsKey, func() interface{} {
return newSnapshotMap()
}).(*snapshotMap)
}
type vendorSnapshotLibraryProperties struct {
// snapshot version.
Version string
@ -185,6 +193,10 @@ func (p *vendorSnapshotLibraryDecorator) nativeCoverage() bool {
return false
}
func (p *vendorSnapshotLibraryDecorator) isSnapshotPrebuilt() bool {
return true
}
func (p *vendorSnapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) {
if p.matchesWithDevice(ctx.DeviceConfig()) && (p.shared() || p.static()) {
p.baseInstaller.install(ctx, file)
@ -337,6 +349,10 @@ func (p *vendorSnapshotBinaryDecorator) link(ctx ModuleContext,
return outputFile
}
func (p *vendorSnapshotBinaryDecorator) isSnapshotPrebuilt() bool {
return true
}
func VendorSnapshotBinaryFactory() android.Module {
module, binary := NewBinary(android.DeviceSupported)
binary.baseLinker.Properties.No_libcrt = BoolPtr(true)
@ -364,12 +380,98 @@ func VendorSnapshotBinaryFactory() android.Module {
return module.Init()
}
type vendorSnapshotObjectProperties struct {
// snapshot version.
Version string
// Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64_ab')
Target_arch string
// Prebuilt file for each arch.
Src *string `android:"arch_variant"`
}
type vendorSnapshotObjectLinker struct {
objectLinker
properties vendorSnapshotObjectProperties
androidMkVendorSuffix bool
}
func (p *vendorSnapshotObjectLinker) Name(name string) string {
return name + p.NameSuffix()
}
func (p *vendorSnapshotObjectLinker) NameSuffix() string {
versionSuffix := p.version()
if p.arch() != "" {
versionSuffix += "." + p.arch()
}
return vendorSnapshotObjectSuffix + versionSuffix
}
func (p *vendorSnapshotObjectLinker) version() string {
return p.properties.Version
}
func (p *vendorSnapshotObjectLinker) arch() string {
return p.properties.Target_arch
}
func (p *vendorSnapshotObjectLinker) matchesWithDevice(config android.DeviceConfig) bool {
if config.DeviceArch() != p.arch() {
return false
}
if p.properties.Src == nil {
return false
}
return true
}
func (p *vendorSnapshotObjectLinker) link(ctx ModuleContext,
flags Flags, deps PathDeps, objs Objects) android.Path {
if !p.matchesWithDevice(ctx.DeviceConfig()) {
return nil
}
m := ctx.Module().(*Module)
p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()]
return android.PathForModuleSrc(ctx, *p.properties.Src)
}
func (p *vendorSnapshotObjectLinker) nativeCoverage() bool {
return false
}
func (p *vendorSnapshotObjectLinker) isSnapshotPrebuilt() bool {
return true
}
func VendorSnapshotObjectFactory() android.Module {
module := newObject()
prebuilt := &vendorSnapshotObjectLinker{
objectLinker: objectLinker{
baseLinker: NewBaseLinker(nil),
},
}
module.linker = prebuilt
android.AddLoadHook(module, func(ctx android.LoadHookContext) {
vendorSnapshotLoadHook(ctx, prebuilt)
})
module.AddProperties(&prebuilt.properties)
return module.Init()
}
func init() {
android.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
android.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory)
android.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory)
android.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory)
android.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory)
android.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory)
}
func VendorSnapshotSingleton() android.Singleton {
@ -468,8 +570,8 @@ func isVendorSnapshotModule(m *Module, moduleDir string) bool {
return true
}
// Binaries
if m.binary() {
// Binaries and Objects
if m.binary() || m.object() {
return m.outputFile.Valid() && proptools.BoolDefault(m.VendorProperties.Vendor_available, true)
}
@ -496,6 +598,8 @@ func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonCont
(header only libraries)
binary/
(executable binaries)
object/
(.o object files)
arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
shared/
(.so shared libraries)
@ -505,6 +609,8 @@ func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonCont
(header only libraries)
binary/
(executable binaries)
object/
(.o object files)
NOTICE_FILES/
(notice files, e.g. libbase.txt)
configs/
@ -630,6 +736,14 @@ func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonCont
snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base())
ret = append(ret, copyFile(ctx, binPath, snapshotBinOut))
propOut = snapshotBinOut + ".json"
} else if m.object() {
// object files aren't installed to the device, so their names can conflict.
// Use module name as stem.
objPath := m.outputFile.Path()
snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object",
ctx.ModuleName(m)+filepath.Ext(objPath.Base()))
ret = append(ret, copyFile(ctx, objPath, snapshotObjOut))
propOut = snapshotObjOut + ".json"
} else {
ctx.Errorf("unknown module %q in vendor snapshot", m.String())
return nil
@ -719,6 +833,7 @@ type snapshotInterface interface {
var _ snapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil)
var _ snapshotInterface = (*vendorSnapshotLibraryDecorator)(nil)
var _ snapshotInterface = (*vendorSnapshotBinaryDecorator)(nil)
var _ snapshotInterface = (*vendorSnapshotObjectLinker)(nil)
// gathers all snapshot modules for vendor, and disable unnecessary snapshots
// TODO(b/145966707): remove mutator and utilize android.Prebuilt to override source modules
@ -734,12 +849,12 @@ func VendorSnapshotMutator(ctx android.BottomUpMutatorContext) {
return
}
snapshot, ok := module.linker.(snapshotInterface)
if !ok {
if !module.isSnapshotPrebuilt() {
return
}
if !snapshot.matchesWithDevice(ctx.DeviceConfig()) {
// isSnapshotPrebuilt ensures snapshotInterface
if !module.linker.(snapshotInterface).matchesWithDevice(ctx.DeviceConfig()) {
// Disable unnecessary snapshot module, but do not disable
// vndk_prebuilt_shared because they might be packed into vndk APEX
if !module.IsVndk() {
@ -761,6 +876,8 @@ func VendorSnapshotMutator(ctx android.BottomUpMutatorContext) {
}
} else if _, ok := module.linker.(*vendorSnapshotBinaryDecorator); ok {
snapshotMap = vendorSnapshotBinaries(ctx.Config())
} else if _, ok := module.linker.(*vendorSnapshotObjectLinker); ok {
snapshotMap = vendorSnapshotObjects(ctx.Config())
} else {
return
}
@ -820,6 +937,8 @@ func VendorSnapshotSourceMutator(ctx android.BottomUpMutatorContext) {
}
} else if module.binary() {
snapshotMap = vendorSnapshotBinaries(ctx.Config())
} else if module.object() {
snapshotMap = vendorSnapshotObjects(ctx.Config())
} else {
return
}

View File

@ -186,6 +186,10 @@ func (p *vndkPrebuiltLibraryDecorator) nativeCoverage() bool {
return false
}
func (p *vndkPrebuiltLibraryDecorator) isSnapshotPrebuilt() bool {
return true
}
func (p *vndkPrebuiltLibraryDecorator) install(ctx ModuleContext, file android.Path) {
arches := ctx.DeviceConfig().Arches()
if len(arches) == 0 || arches[0].ArchType.String() != p.arch() {