Merge "Add support for cc_prebuilt_library" am: 28e28ed2f6
Change-Id: I4a53b80294187421f76837a570d296f52570734c
This commit is contained in:
@@ -23,6 +23,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RegisterPrebuiltBuildComponents(ctx android.RegistrationContext) {
|
func RegisterPrebuiltBuildComponents(ctx android.RegistrationContext) {
|
||||||
|
ctx.RegisterModuleType("cc_prebuilt_library", PrebuiltLibraryFactory)
|
||||||
ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory)
|
ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory)
|
||||||
ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory)
|
ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory)
|
||||||
ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory)
|
ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory)
|
||||||
@@ -96,10 +97,16 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
|
|||||||
p.libraryDecorator.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...)
|
p.libraryDecorator.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...)
|
||||||
|
|
||||||
// TODO(ccross): verify shared library dependencies
|
// TODO(ccross): verify shared library dependencies
|
||||||
if len(p.properties.Srcs) > 0 {
|
srcs := p.prebuiltSrcs()
|
||||||
|
if len(srcs) > 0 {
|
||||||
builderFlags := flagsToBuilderFlags(flags)
|
builderFlags := flagsToBuilderFlags(flags)
|
||||||
|
|
||||||
in := p.Prebuilt.SingleSourcePath(ctx)
|
if len(srcs) > 1 {
|
||||||
|
ctx.PropertyErrorf("srcs", "multiple prebuilt source files")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
in := android.PathForModuleSrc(ctx, srcs[0])
|
||||||
|
|
||||||
if p.shared() {
|
if p.shared() {
|
||||||
p.unstrippedOutputFile = in
|
p.unstrippedOutputFile = in
|
||||||
@@ -123,6 +130,18 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *prebuiltLibraryLinker) prebuiltSrcs() []string {
|
||||||
|
srcs := p.properties.Srcs
|
||||||
|
if p.static() {
|
||||||
|
srcs = append(srcs, p.libraryDecorator.StaticProperties.Static.Srcs...)
|
||||||
|
}
|
||||||
|
if p.shared() {
|
||||||
|
srcs = append(srcs, p.libraryDecorator.SharedProperties.Shared.Srcs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return srcs
|
||||||
|
}
|
||||||
|
|
||||||
func (p *prebuiltLibraryLinker) shared() bool {
|
func (p *prebuiltLibraryLinker) shared() bool {
|
||||||
return p.libraryDecorator.shared()
|
return p.libraryDecorator.shared()
|
||||||
}
|
}
|
||||||
@@ -146,13 +165,28 @@ func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDec
|
|||||||
|
|
||||||
module.AddProperties(&prebuilt.properties)
|
module.AddProperties(&prebuilt.properties)
|
||||||
|
|
||||||
android.InitPrebuiltModule(module, &prebuilt.properties.Srcs)
|
srcsSupplier := func() []string {
|
||||||
|
return prebuilt.prebuiltSrcs()
|
||||||
|
}
|
||||||
|
|
||||||
|
android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "srcs")
|
||||||
|
|
||||||
// Prebuilt libraries can be used in SDKs.
|
// Prebuilt libraries can be used in SDKs.
|
||||||
android.InitSdkAwareModule(module)
|
android.InitSdkAwareModule(module)
|
||||||
return module, library
|
return module, library
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cc_prebuilt_library installs a precompiled shared library that are
|
||||||
|
// listed in the srcs property in the device's directory.
|
||||||
|
func PrebuiltLibraryFactory() android.Module {
|
||||||
|
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
|
||||||
|
|
||||||
|
// Prebuilt shared libraries can be included in APEXes
|
||||||
|
android.InitApexModule(module)
|
||||||
|
|
||||||
|
return module.Init()
|
||||||
|
}
|
||||||
|
|
||||||
// cc_prebuilt_library_shared installs a precompiled shared library that are
|
// cc_prebuilt_library_shared installs a precompiled shared library that are
|
||||||
// listed in the srcs property in the device's directory.
|
// listed in the srcs property in the device's directory.
|
||||||
func PrebuiltSharedLibraryFactory() android.Module {
|
func PrebuiltSharedLibraryFactory() android.Module {
|
||||||
|
@@ -59,36 +59,38 @@ func TestPrebuilt(t *testing.T) {
|
|||||||
name: "libe",
|
name: "libe",
|
||||||
srcs: ["libe.a"],
|
srcs: ["libe.a"],
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
|
||||||
fs := map[string][]byte{
|
cc_library {
|
||||||
"liba.so": nil,
|
name: "libf",
|
||||||
"libb.a": nil,
|
|
||||||
"libd.so": nil,
|
|
||||||
"libe.a": nil,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config := TestConfig(buildDir, android.Android, nil, bp, fs)
|
cc_prebuilt_library {
|
||||||
|
name: "libf",
|
||||||
|
static: {
|
||||||
|
srcs: ["libf.a"],
|
||||||
|
},
|
||||||
|
shared: {
|
||||||
|
srcs: ["libf.so"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
ctx := CreateTestContext()
|
ctx := testPrebuilt(t, bp)
|
||||||
|
|
||||||
ctx.Register(config)
|
|
||||||
|
|
||||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
|
||||||
android.FailIfErrored(t, errs)
|
|
||||||
_, errs = ctx.PrepareBuildActions(config)
|
|
||||||
android.FailIfErrored(t, errs)
|
|
||||||
|
|
||||||
// Verify that all the modules exist and that their dependencies were connected correctly
|
// Verify that all the modules exist and that their dependencies were connected correctly
|
||||||
liba := ctx.ModuleForTests("liba", "android_arm64_armv8-a_shared").Module()
|
liba := ctx.ModuleForTests("liba", "android_arm64_armv8-a_shared").Module()
|
||||||
libb := ctx.ModuleForTests("libb", "android_arm64_armv8-a_static").Module()
|
libb := ctx.ModuleForTests("libb", "android_arm64_armv8-a_static").Module()
|
||||||
libd := ctx.ModuleForTests("libd", "android_arm64_armv8-a_shared").Module()
|
libd := ctx.ModuleForTests("libd", "android_arm64_armv8-a_shared").Module()
|
||||||
libe := ctx.ModuleForTests("libe", "android_arm64_armv8-a_static").Module()
|
libe := ctx.ModuleForTests("libe", "android_arm64_armv8-a_static").Module()
|
||||||
|
libfStatic := ctx.ModuleForTests("libf", "android_arm64_armv8-a_static").Module()
|
||||||
|
libfShared := ctx.ModuleForTests("libf", "android_arm64_armv8-a_shared").Module()
|
||||||
|
|
||||||
prebuiltLiba := ctx.ModuleForTests("prebuilt_liba", "android_arm64_armv8-a_shared").Module()
|
prebuiltLiba := ctx.ModuleForTests("prebuilt_liba", "android_arm64_armv8-a_shared").Module()
|
||||||
prebuiltLibb := ctx.ModuleForTests("prebuilt_libb", "android_arm64_armv8-a_static").Module()
|
prebuiltLibb := ctx.ModuleForTests("prebuilt_libb", "android_arm64_armv8-a_static").Module()
|
||||||
prebuiltLibd := ctx.ModuleForTests("prebuilt_libd", "android_arm64_armv8-a_shared").Module()
|
prebuiltLibd := ctx.ModuleForTests("prebuilt_libd", "android_arm64_armv8-a_shared").Module()
|
||||||
prebuiltLibe := ctx.ModuleForTests("prebuilt_libe", "android_arm64_armv8-a_static").Module()
|
prebuiltLibe := ctx.ModuleForTests("prebuilt_libe", "android_arm64_armv8-a_static").Module()
|
||||||
|
prebuiltLibfStatic := ctx.ModuleForTests("prebuilt_libf", "android_arm64_armv8-a_static").Module()
|
||||||
|
prebuiltLibfShared := ctx.ModuleForTests("prebuilt_libf", "android_arm64_armv8-a_shared").Module()
|
||||||
|
|
||||||
hasDep := func(m android.Module, wantDep android.Module) bool {
|
hasDep := func(m android.Module, wantDep android.Module) bool {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
@@ -116,4 +118,89 @@ func TestPrebuilt(t *testing.T) {
|
|||||||
if !hasDep(libe, prebuiltLibe) {
|
if !hasDep(libe, prebuiltLibe) {
|
||||||
t.Errorf("libe missing dependency on prebuilt_libe")
|
t.Errorf("libe missing dependency on prebuilt_libe")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !hasDep(libfStatic, prebuiltLibfStatic) {
|
||||||
|
t.Errorf("libf static missing dependency on prebuilt_libf")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !hasDep(libfShared, prebuiltLibfShared) {
|
||||||
|
t.Errorf("libf shared missing dependency on prebuilt_libf")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testPrebuilt(t *testing.T, bp string) *android.TestContext {
|
||||||
|
fs := map[string][]byte{
|
||||||
|
"liba.so": nil,
|
||||||
|
"libb.a": nil,
|
||||||
|
"libd.so": nil,
|
||||||
|
"libe.a": nil,
|
||||||
|
"libf.a": nil,
|
||||||
|
"libf.so": nil,
|
||||||
|
}
|
||||||
|
config := TestConfig(buildDir, android.Android, nil, bp, fs)
|
||||||
|
ctx := CreateTestContext()
|
||||||
|
|
||||||
|
// Enable androidmk support.
|
||||||
|
// * Register the singleton
|
||||||
|
// * Configure that we are inside make
|
||||||
|
// * Add CommonOS to ensure that androidmk processing works.
|
||||||
|
android.RegisterAndroidMkBuildComponents(ctx)
|
||||||
|
android.SetInMakeForTests(config)
|
||||||
|
|
||||||
|
ctx.Register(config)
|
||||||
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||||
|
android.FailIfErrored(t, errs)
|
||||||
|
_, errs = ctx.PrepareBuildActions(config)
|
||||||
|
android.FailIfErrored(t, errs)
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrebuiltLibraryShared(t *testing.T) {
|
||||||
|
ctx := testPrebuilt(t, `
|
||||||
|
cc_prebuilt_library_shared {
|
||||||
|
name: "libtest",
|
||||||
|
srcs: ["libf.so"],
|
||||||
|
strip: {
|
||||||
|
none: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
shared := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_shared").Module().(*Module)
|
||||||
|
assertString(t, shared.OutputFile().String(), "libf.so")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrebuiltLibraryStatic(t *testing.T) {
|
||||||
|
ctx := testPrebuilt(t, `
|
||||||
|
cc_prebuilt_library_static {
|
||||||
|
name: "libtest",
|
||||||
|
srcs: ["libf.a"],
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
static := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_static").Module().(*Module)
|
||||||
|
assertString(t, static.OutputFile().String(), "libf.a")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrebuiltLibrary(t *testing.T) {
|
||||||
|
ctx := testPrebuilt(t, `
|
||||||
|
cc_prebuilt_library {
|
||||||
|
name: "libtest",
|
||||||
|
static: {
|
||||||
|
srcs: ["libf.a"],
|
||||||
|
},
|
||||||
|
shared: {
|
||||||
|
srcs: ["libf.so"],
|
||||||
|
},
|
||||||
|
strip: {
|
||||||
|
none: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
shared := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_shared").Module().(*Module)
|
||||||
|
assertString(t, shared.OutputFile().String(), "libf.so")
|
||||||
|
|
||||||
|
static := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_static").Module().(*Module)
|
||||||
|
assertString(t, static.OutputFile().String(), "libf.a")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user