diff options
author | Martin Stjernholm <mast@google.com> | 2020-03-11 21:45:49 +0000 |
---|---|---|
committer | Paul Duffin <paulduffin@google.com> | 2020-05-06 08:16:53 +0100 |
commit | 39978527ce84a4cc82651e9d12efec7a630dfef4 (patch) | |
tree | e32d7e27a069c8f7a2ba5296b4cb56a4d8512e1a /cc | |
parent | d62f376a36175e543c7c8542921aa746e044971f (diff) | |
download | build_soong-39978527ce84a4cc82651e9d12efec7a630dfef4.tar.gz build_soong-39978527ce84a4cc82651e9d12efec7a630dfef4.tar.bz2 build_soong-39978527ce84a4cc82651e9d12efec7a630dfef4.zip |
Add cc_prebuilt_object.
To be used for prebuilt object support in SDK snapshots.
Test: m nothing
Bug: 148934017
Merged-In: I53d58100cc1d410c5cf5b7906de7ed6f7add2035
Change-Id: I53d58100cc1d410c5cf5b7906de7ed6f7add2035
(cherry picked from commit 0b92ac8e43a43945fb5407989093535eb62c681d)
Diffstat (limited to 'cc')
-rw-r--r-- | cc/object.go | 11 | ||||
-rw-r--r-- | cc/prebuilt.go | 45 | ||||
-rw-r--r-- | cc/prebuilt_test.go | 17 |
3 files changed, 70 insertions, 3 deletions
diff --git a/cc/object.go b/cc/object.go index ad31d09f..74badc96 100644 --- a/cc/object.go +++ b/cc/object.go @@ -47,12 +47,18 @@ type ObjectLinkerProperties struct { Linker_script *string `android:"path,arch_variant"` } +func newObject() *Module { + module := newBaseModule(android.HostAndDeviceSupported, android.MultilibBoth) + module.sanitize = &sanitize{} + module.stl = &stl{} + return module +} + // cc_object runs the compiler without running the linker. It is rarely // necessary, but sometimes used to generate .s files from .c files to use as // input to a cc_genrule module. func ObjectFactory() android.Module { - module := newBaseModule(android.HostAndDeviceSupported, android.MultilibBoth) - module.sanitize = &sanitize{} + module := newObject() module.linker = &objectLinker{ baseLinker: NewBaseLinker(module.sanitize), } @@ -61,7 +67,6 @@ func ObjectFactory() android.Module { // Clang's address-significance tables are incompatible with ld -r. module.compiler.appendCflags([]string{"-fno-addrsig"}) - module.stl = &stl{} return module.Init() } diff --git a/cc/prebuilt.go b/cc/prebuilt.go index 3dbd3e34..2ef31950 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -26,6 +26,7 @@ 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_object", prebuiltObjectFactory) ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory) } @@ -222,6 +223,50 @@ func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libr return module, library } +type prebuiltObjectProperties struct { + Srcs []string `android:"path,arch_variant"` +} + +type prebuiltObjectLinker struct { + android.Prebuilt + objectLinker + + properties prebuiltObjectProperties +} + +func (p *prebuiltObjectLinker) prebuilt() *android.Prebuilt { + return &p.Prebuilt +} + +var _ prebuiltLinkerInterface = (*prebuiltObjectLinker)(nil) + +func (p *prebuiltObjectLinker) link(ctx ModuleContext, + flags Flags, deps PathDeps, objs Objects) android.Path { + if len(p.properties.Srcs) > 0 { + return p.Prebuilt.SingleSourcePath(ctx) + } + return nil +} + +func newPrebuiltObject() *Module { + module := newObject() + prebuilt := &prebuiltObjectLinker{ + objectLinker: objectLinker{ + baseLinker: NewBaseLinker(nil), + }, + } + module.linker = prebuilt + module.AddProperties(&prebuilt.properties) + android.InitPrebuiltModule(module, &prebuilt.properties.Srcs) + android.InitSdkAwareModule(module) + return module +} + +func prebuiltObjectFactory() android.Module { + module := newPrebuiltObject() + return module.Init() +} + type prebuiltBinaryLinker struct { *binaryDecorator prebuiltLinker diff --git a/cc/prebuilt_test.go b/cc/prebuilt_test.go index 0eca97f5..242d835e 100644 --- a/cc/prebuilt_test.go +++ b/cc/prebuilt_test.go @@ -73,6 +73,15 @@ func TestPrebuilt(t *testing.T) { srcs: ["libf.so"], }, } + + cc_object { + name: "crtx", + } + + cc_prebuilt_object { + name: "crtx", + srcs: ["crtx.o"], + } ` ctx := testPrebuilt(t, bp) @@ -84,6 +93,7 @@ func TestPrebuilt(t *testing.T) { 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() + crtx := ctx.ModuleForTests("crtx", "android_arm64_armv8-a").Module() prebuiltLiba := ctx.ModuleForTests("prebuilt_liba", "android_arm64_armv8-a_shared").Module() prebuiltLibb := ctx.ModuleForTests("prebuilt_libb", "android_arm64_armv8-a_static").Module() @@ -91,6 +101,7 @@ func TestPrebuilt(t *testing.T) { 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() + prebuiltCrtx := ctx.ModuleForTests("prebuilt_crtx", "android_arm64_armv8-a").Module() hasDep := func(m android.Module, wantDep android.Module) bool { t.Helper() @@ -126,9 +137,14 @@ func TestPrebuilt(t *testing.T) { if !hasDep(libfShared, prebuiltLibfShared) { t.Errorf("libf shared missing dependency on prebuilt_libf") } + + if !hasDep(crtx, prebuiltCrtx) { + t.Errorf("crtx missing dependency on prebuilt_crtx") + } } func testPrebuilt(t *testing.T, bp string) *android.TestContext { + fs := map[string][]byte{ "liba.so": nil, "libb.a": nil, @@ -136,6 +152,7 @@ func testPrebuilt(t *testing.T, bp string) *android.TestContext { "libe.a": nil, "libf.a": nil, "libf.so": nil, + "crtx.o": nil, } config := TestConfig(buildDir, android.Android, nil, bp, fs) ctx := CreateTestContext() |