Merge "Add support for cc_prebuilt_library"
This commit is contained in:
commit
28e28ed2f6
|
@ -23,6 +23,7 @@ func init() {
|
|||
}
|
||||
|
||||
func RegisterPrebuiltBuildComponents(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("cc_prebuilt_library", PrebuiltLibraryFactory)
|
||||
ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory)
|
||||
ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory)
|
||||
ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory)
|
||||
|
@ -96,10 +97,16 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
|
|||
p.libraryDecorator.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...)
|
||||
|
||||
// TODO(ccross): verify shared library dependencies
|
||||
if len(p.properties.Srcs) > 0 {
|
||||
srcs := p.prebuiltSrcs()
|
||||
if len(srcs) > 0 {
|
||||
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() {
|
||||
p.unstrippedOutputFile = in
|
||||
|
@ -123,6 +130,18 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
|
|||
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 {
|
||||
return p.libraryDecorator.shared()
|
||||
}
|
||||
|
@ -146,13 +165,28 @@ func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDec
|
|||
|
||||
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.
|
||||
android.InitSdkAwareModule(module)
|
||||
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
|
||||
// listed in the srcs property in the device's directory.
|
||||
func PrebuiltSharedLibraryFactory() android.Module {
|
||||
|
|
|
@ -59,36 +59,38 @@ func TestPrebuilt(t *testing.T) {
|
|||
name: "libe",
|
||||
srcs: ["libe.a"],
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "libf",
|
||||
}
|
||||
|
||||
cc_prebuilt_library {
|
||||
name: "libf",
|
||||
static: {
|
||||
srcs: ["libf.a"],
|
||||
},
|
||||
shared: {
|
||||
srcs: ["libf.so"],
|
||||
},
|
||||
}
|
||||
`
|
||||
|
||||
fs := map[string][]byte{
|
||||
"liba.so": nil,
|
||||
"libb.a": nil,
|
||||
"libd.so": nil,
|
||||
"libe.a": nil,
|
||||
}
|
||||
|
||||
config := TestConfig(buildDir, android.Android, nil, bp, fs)
|
||||
|
||||
ctx := CreateTestContext()
|
||||
|
||||
ctx.Register(config)
|
||||
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
android.FailIfErrored(t, errs)
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
android.FailIfErrored(t, errs)
|
||||
ctx := testPrebuilt(t, bp)
|
||||
|
||||
// Verify that all the modules exist and that their dependencies were connected correctly
|
||||
liba := ctx.ModuleForTests("liba", "android_arm64_armv8-a_shared").Module()
|
||||
libb := ctx.ModuleForTests("libb", "android_arm64_armv8-a_static").Module()
|
||||
libd := ctx.ModuleForTests("libd", "android_arm64_armv8-a_shared").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()
|
||||
prebuiltLibb := ctx.ModuleForTests("prebuilt_libb", "android_arm64_armv8-a_static").Module()
|
||||
prebuiltLibd := ctx.ModuleForTests("prebuilt_libd", "android_arm64_armv8-a_shared").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 {
|
||||
t.Helper()
|
||||
|
@ -116,4 +118,89 @@ func TestPrebuilt(t *testing.T) {
|
|||
if !hasDep(libe, prebuiltLibe) {
|
||||
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")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue