Loading Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -196,6 +196,7 @@ bootstrap_go_package { "cc/gen_test.go", "cc/genrule_test.go", "cc/library_test.go", "cc/prebuilt_test.go", "cc/proto_test.go", "cc/test_data_test.go", "cc/util_test.go", Loading cc/cc_test.go +16 −6 Original line number Diff line number Diff line Loading @@ -52,7 +52,9 @@ func TestMain(m *testing.M) { os.Exit(run()) } func createTestContext(t *testing.T, config android.Config, bp string, os android.OsType) *android.TestContext { func createTestContext(t *testing.T, config android.Config, bp string, fs map[string][]byte, os android.OsType) *android.TestContext { ctx := android.NewTestArchContext() ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory)) ctx.RegisterModuleType("cc_binary_host", android.ModuleFactoryAdaptor(binaryHostFactory)) Loading @@ -77,12 +79,11 @@ func createTestContext(t *testing.T, config android.Config, bp string, os androi ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel() }) ctx.RegisterSingletonType("vndk-snapshot", android.SingletonFactoryAdaptor(VndkSnapshotSingleton)) ctx.Register() // add some modules that are required by the compiler and/or linker bp = bp + GatherRequiredDepsForTest(os) ctx.MockFileSystem(map[string][]byte{ mockFS := map[string][]byte{ "Android.bp": []byte(bp), "foo.c": nil, "bar.c": nil, Loading @@ -90,7 +91,14 @@ func createTestContext(t *testing.T, config android.Config, bp string, os androi "b.aidl": nil, "my_include": nil, "foo.map.txt": nil, }) "liba.so": nil, } for k, v := range fs { mockFS[k] = v } ctx.MockFileSystem(mockFS) return ctx } Loading @@ -101,7 +109,8 @@ func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.T func testCcWithConfigForOs(t *testing.T, bp string, config android.Config, os android.OsType) *android.TestContext { t.Helper() ctx := createTestContext(t, config, bp, os) ctx := createTestContext(t, config, bp, nil, os) ctx.Register() _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) android.FailIfErrored(t, errs) Loading Loading @@ -134,7 +143,8 @@ func testCcError(t *testing.T, pattern string, bp string) { config.TestProductVariables.DeviceVndkVersion = StringPtr("current") config.TestProductVariables.Platform_vndk_version = StringPtr("VER") ctx := createTestContext(t, config, bp, android.Android) ctx := createTestContext(t, config, bp, nil, android.Android) ctx.Register() _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) if len(errs) > 0 { Loading cc/library.go +23 −6 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import ( "strings" "sync" "github.com/google/blueprint" "github.com/google/blueprint/pathtools" "android/soong/android" Loading Loading @@ -1106,10 +1105,28 @@ func reuseStaticLibrary(mctx android.BottomUpMutatorContext, static, shared *Mod func LinkageMutator(mctx android.BottomUpMutatorContext) { if m, ok := mctx.Module().(*Module); ok && m.linker != nil { if library, ok := m.linker.(libraryInterface); ok { var modules []blueprint.Module switch library := m.linker.(type) { case prebuiltLibraryInterface: // Always create both the static and shared variants for prebuilt libraries, and then disable the one // that is not being used. This allows them to share the name of a cc_library module, which requires that // all the variants of the cc_library also exist on the prebuilt. modules := mctx.CreateLocalVariations("static", "shared") static := modules[0].(*Module) shared := modules[1].(*Module) static.linker.(prebuiltLibraryInterface).setStatic() shared.linker.(prebuiltLibraryInterface).setShared() if !library.buildStatic() { static.linker.(prebuiltLibraryInterface).disablePrebuilt() } if !library.buildShared() { shared.linker.(prebuiltLibraryInterface).disablePrebuilt() } case libraryInterface: if library.buildStatic() && library.buildShared() { modules = mctx.CreateLocalVariations("static", "shared") modules := mctx.CreateLocalVariations("static", "shared") static := modules[0].(*Module) shared := modules[1].(*Module) Loading @@ -1119,10 +1136,10 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) { reuseStaticLibrary(mctx, static, shared) } else if library.buildStatic() { modules = mctx.CreateLocalVariations("static") modules := mctx.CreateLocalVariations("static") modules[0].(*Module).linker.(libraryInterface).setStatic() } else if library.buildShared() { modules = mctx.CreateLocalVariations("shared") modules := mctx.CreateLocalVariations("shared") modules[0].(*Module).linker.(libraryInterface).setShared() } } Loading cc/prebuilt.go +11 −0 Original line number Diff line number Diff line Loading @@ -53,12 +53,19 @@ func (p *prebuiltLinker) PrebuiltSrcs() []string { return p.properties.Srcs } type prebuiltLibraryInterface interface { libraryInterface prebuiltLinkerInterface disablePrebuilt() } type prebuiltLibraryLinker struct { *libraryDecorator prebuiltLinker } var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil) var _ prebuiltLibraryInterface = (*prebuiltLibraryLinker)(nil) func (p *prebuiltLibraryLinker) linkerInit(ctx BaseModuleContext) {} Loading Loading @@ -116,6 +123,10 @@ func (p *prebuiltLibraryLinker) nativeCoverage() bool { return false } func (p *prebuiltLibraryLinker) disablePrebuilt() { p.properties.Srcs = nil } // 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 { Loading cc/prebuilt_test.go 0 → 100644 +126 −0 Original line number Diff line number Diff line // Copyright 2019 Google Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package cc import ( "testing" "android/soong/android" "github.com/google/blueprint" ) func TestPrebuilt(t *testing.T) { bp := ` cc_library { name: "liba", } cc_prebuilt_library_shared { name: "liba", srcs: ["liba.so"], } cc_library { name: "libb", } cc_prebuilt_library_static { name: "libb", srcs: ["libb.a"], } cc_library_shared { name: "libd", } cc_prebuilt_library_shared { name: "libd", srcs: ["libd.so"], } cc_library_static { name: "libe", } cc_prebuilt_library_static { name: "libe", srcs: ["libe.a"], } ` fs := map[string][]byte{ "liba.so": nil, "libb.a": nil, "libd.so": nil, "libe.a": nil, } config := android.TestArchConfig(buildDir, nil) ctx := createTestContext(t, config, bp, fs, android.Android) ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(prebuiltSharedLibraryFactory)) ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(prebuiltStaticLibraryFactory)) ctx.RegisterModuleType("cc_prebuilt_binary", android.ModuleFactoryAdaptor(prebuiltBinaryFactory)) ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) ctx.PostDepsMutators(android.RegisterPrebuiltsPostDepsMutators) ctx.Register() _, 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 liba := ctx.ModuleForTests("liba", "android_arm64_armv8-a_core_shared").Module() libb := ctx.ModuleForTests("libb", "android_arm64_armv8-a_core_static").Module() libd := ctx.ModuleForTests("libd", "android_arm64_armv8-a_core_shared").Module() libe := ctx.ModuleForTests("libe", "android_arm64_armv8-a_core_static").Module() prebuiltLiba := ctx.ModuleForTests("prebuilt_liba", "android_arm64_armv8-a_core_shared").Module() prebuiltLibb := ctx.ModuleForTests("prebuilt_libb", "android_arm64_armv8-a_core_static").Module() prebuiltLibd := ctx.ModuleForTests("prebuilt_libd", "android_arm64_armv8-a_core_shared").Module() prebuiltLibe := ctx.ModuleForTests("prebuilt_libe", "android_arm64_armv8-a_core_static").Module() hasDep := func(m android.Module, wantDep android.Module) bool { t.Helper() var found bool ctx.VisitDirectDeps(m, func(dep blueprint.Module) { if dep == wantDep { found = true } }) return found } if !hasDep(liba, prebuiltLiba) { t.Errorf("liba missing dependency on prebuilt_liba") } if !hasDep(libb, prebuiltLibb) { t.Errorf("libb missing dependency on prebuilt_libb") } if !hasDep(libd, prebuiltLibd) { t.Errorf("libd missing dependency on prebuilt_libd") } if !hasDep(libe, prebuiltLibe) { t.Errorf("libe missing dependency on prebuilt_libe") } } Loading
Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -196,6 +196,7 @@ bootstrap_go_package { "cc/gen_test.go", "cc/genrule_test.go", "cc/library_test.go", "cc/prebuilt_test.go", "cc/proto_test.go", "cc/test_data_test.go", "cc/util_test.go", Loading
cc/cc_test.go +16 −6 Original line number Diff line number Diff line Loading @@ -52,7 +52,9 @@ func TestMain(m *testing.M) { os.Exit(run()) } func createTestContext(t *testing.T, config android.Config, bp string, os android.OsType) *android.TestContext { func createTestContext(t *testing.T, config android.Config, bp string, fs map[string][]byte, os android.OsType) *android.TestContext { ctx := android.NewTestArchContext() ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory)) ctx.RegisterModuleType("cc_binary_host", android.ModuleFactoryAdaptor(binaryHostFactory)) Loading @@ -77,12 +79,11 @@ func createTestContext(t *testing.T, config android.Config, bp string, os androi ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel() }) ctx.RegisterSingletonType("vndk-snapshot", android.SingletonFactoryAdaptor(VndkSnapshotSingleton)) ctx.Register() // add some modules that are required by the compiler and/or linker bp = bp + GatherRequiredDepsForTest(os) ctx.MockFileSystem(map[string][]byte{ mockFS := map[string][]byte{ "Android.bp": []byte(bp), "foo.c": nil, "bar.c": nil, Loading @@ -90,7 +91,14 @@ func createTestContext(t *testing.T, config android.Config, bp string, os androi "b.aidl": nil, "my_include": nil, "foo.map.txt": nil, }) "liba.so": nil, } for k, v := range fs { mockFS[k] = v } ctx.MockFileSystem(mockFS) return ctx } Loading @@ -101,7 +109,8 @@ func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.T func testCcWithConfigForOs(t *testing.T, bp string, config android.Config, os android.OsType) *android.TestContext { t.Helper() ctx := createTestContext(t, config, bp, os) ctx := createTestContext(t, config, bp, nil, os) ctx.Register() _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) android.FailIfErrored(t, errs) Loading Loading @@ -134,7 +143,8 @@ func testCcError(t *testing.T, pattern string, bp string) { config.TestProductVariables.DeviceVndkVersion = StringPtr("current") config.TestProductVariables.Platform_vndk_version = StringPtr("VER") ctx := createTestContext(t, config, bp, android.Android) ctx := createTestContext(t, config, bp, nil, android.Android) ctx.Register() _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) if len(errs) > 0 { Loading
cc/library.go +23 −6 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import ( "strings" "sync" "github.com/google/blueprint" "github.com/google/blueprint/pathtools" "android/soong/android" Loading Loading @@ -1106,10 +1105,28 @@ func reuseStaticLibrary(mctx android.BottomUpMutatorContext, static, shared *Mod func LinkageMutator(mctx android.BottomUpMutatorContext) { if m, ok := mctx.Module().(*Module); ok && m.linker != nil { if library, ok := m.linker.(libraryInterface); ok { var modules []blueprint.Module switch library := m.linker.(type) { case prebuiltLibraryInterface: // Always create both the static and shared variants for prebuilt libraries, and then disable the one // that is not being used. This allows them to share the name of a cc_library module, which requires that // all the variants of the cc_library also exist on the prebuilt. modules := mctx.CreateLocalVariations("static", "shared") static := modules[0].(*Module) shared := modules[1].(*Module) static.linker.(prebuiltLibraryInterface).setStatic() shared.linker.(prebuiltLibraryInterface).setShared() if !library.buildStatic() { static.linker.(prebuiltLibraryInterface).disablePrebuilt() } if !library.buildShared() { shared.linker.(prebuiltLibraryInterface).disablePrebuilt() } case libraryInterface: if library.buildStatic() && library.buildShared() { modules = mctx.CreateLocalVariations("static", "shared") modules := mctx.CreateLocalVariations("static", "shared") static := modules[0].(*Module) shared := modules[1].(*Module) Loading @@ -1119,10 +1136,10 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) { reuseStaticLibrary(mctx, static, shared) } else if library.buildStatic() { modules = mctx.CreateLocalVariations("static") modules := mctx.CreateLocalVariations("static") modules[0].(*Module).linker.(libraryInterface).setStatic() } else if library.buildShared() { modules = mctx.CreateLocalVariations("shared") modules := mctx.CreateLocalVariations("shared") modules[0].(*Module).linker.(libraryInterface).setShared() } } Loading
cc/prebuilt.go +11 −0 Original line number Diff line number Diff line Loading @@ -53,12 +53,19 @@ func (p *prebuiltLinker) PrebuiltSrcs() []string { return p.properties.Srcs } type prebuiltLibraryInterface interface { libraryInterface prebuiltLinkerInterface disablePrebuilt() } type prebuiltLibraryLinker struct { *libraryDecorator prebuiltLinker } var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil) var _ prebuiltLibraryInterface = (*prebuiltLibraryLinker)(nil) func (p *prebuiltLibraryLinker) linkerInit(ctx BaseModuleContext) {} Loading Loading @@ -116,6 +123,10 @@ func (p *prebuiltLibraryLinker) nativeCoverage() bool { return false } func (p *prebuiltLibraryLinker) disablePrebuilt() { p.properties.Srcs = nil } // 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 { Loading
cc/prebuilt_test.go 0 → 100644 +126 −0 Original line number Diff line number Diff line // Copyright 2019 Google Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package cc import ( "testing" "android/soong/android" "github.com/google/blueprint" ) func TestPrebuilt(t *testing.T) { bp := ` cc_library { name: "liba", } cc_prebuilt_library_shared { name: "liba", srcs: ["liba.so"], } cc_library { name: "libb", } cc_prebuilt_library_static { name: "libb", srcs: ["libb.a"], } cc_library_shared { name: "libd", } cc_prebuilt_library_shared { name: "libd", srcs: ["libd.so"], } cc_library_static { name: "libe", } cc_prebuilt_library_static { name: "libe", srcs: ["libe.a"], } ` fs := map[string][]byte{ "liba.so": nil, "libb.a": nil, "libd.so": nil, "libe.a": nil, } config := android.TestArchConfig(buildDir, nil) ctx := createTestContext(t, config, bp, fs, android.Android) ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(prebuiltSharedLibraryFactory)) ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(prebuiltStaticLibraryFactory)) ctx.RegisterModuleType("cc_prebuilt_binary", android.ModuleFactoryAdaptor(prebuiltBinaryFactory)) ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) ctx.PostDepsMutators(android.RegisterPrebuiltsPostDepsMutators) ctx.Register() _, 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 liba := ctx.ModuleForTests("liba", "android_arm64_armv8-a_core_shared").Module() libb := ctx.ModuleForTests("libb", "android_arm64_armv8-a_core_static").Module() libd := ctx.ModuleForTests("libd", "android_arm64_armv8-a_core_shared").Module() libe := ctx.ModuleForTests("libe", "android_arm64_armv8-a_core_static").Module() prebuiltLiba := ctx.ModuleForTests("prebuilt_liba", "android_arm64_armv8-a_core_shared").Module() prebuiltLibb := ctx.ModuleForTests("prebuilt_libb", "android_arm64_armv8-a_core_static").Module() prebuiltLibd := ctx.ModuleForTests("prebuilt_libd", "android_arm64_armv8-a_core_shared").Module() prebuiltLibe := ctx.ModuleForTests("prebuilt_libe", "android_arm64_armv8-a_core_static").Module() hasDep := func(m android.Module, wantDep android.Module) bool { t.Helper() var found bool ctx.VisitDirectDeps(m, func(dep blueprint.Module) { if dep == wantDep { found = true } }) return found } if !hasDep(liba, prebuiltLiba) { t.Errorf("liba missing dependency on prebuilt_liba") } if !hasDep(libb, prebuiltLibb) { t.Errorf("libb missing dependency on prebuilt_libb") } if !hasDep(libd, prebuiltLibd) { t.Errorf("libd missing dependency on prebuilt_libd") } if !hasDep(libe, prebuiltLibe) { t.Errorf("libe missing dependency on prebuilt_libe") } }