diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2019-06-04 03:11:51 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2019-06-04 03:11:51 +0000 |
commit | 364d70e29614dd0e787a2598b6da6b0b651b0618 (patch) | |
tree | 1d1217fc45ab7cb1233dca82548996b8affc57cb | |
parent | 722f1c5e8f933202626e4bac7e87d2836dce5e77 (diff) | |
parent | 9bd624c76d9152fbf8bc9cd5c4632e6376481f36 (diff) | |
download | build_soong-364d70e29614dd0e787a2598b6da6b0b651b0618.tar.gz build_soong-364d70e29614dd0e787a2598b6da6b0b651b0618.tar.bz2 build_soong-364d70e29614dd0e787a2598b6da6b0b651b0618.zip |
Snap for 5631427 from 9bd624c76d9152fbf8bc9cd5c4632e6376481f36 to qt-release
Change-Id: I42862862c4d7044a3a16fb7674ba34115c8a4912
-rw-r--r-- | Android.bp | 1 | ||||
-rw-r--r-- | cc/cc_test.go | 22 | ||||
-rw-r--r-- | cc/library.go | 29 | ||||
-rw-r--r-- | cc/prebuilt.go | 11 | ||||
-rw-r--r-- | cc/prebuilt_test.go | 126 | ||||
-rw-r--r-- | cc/sanitize.go | 5 |
6 files changed, 182 insertions, 12 deletions
@@ -193,6 +193,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", diff --git a/cc/cc_test.go b/cc/cc_test.go index f3d5e60d..678f90d2 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -51,7 +51,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)) @@ -75,12 +77,11 @@ func createTestContext(t *testing.T, config android.Config, bp string, os androi ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel() }) - 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, @@ -88,7 +89,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 } @@ -99,7 +107,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) @@ -132,7 +141,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 { diff --git a/cc/library.go b/cc/library.go index cf207473..ca1c1be0 100644 --- a/cc/library.go +++ b/cc/library.go @@ -22,7 +22,6 @@ import ( "strings" "sync" - "github.com/google/blueprint" "github.com/google/blueprint/pathtools" "android/soong/android" @@ -1083,10 +1082,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) @@ -1096,10 +1113,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() } } diff --git a/cc/prebuilt.go b/cc/prebuilt.go index 5ffeb328..48e46671 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -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) {} @@ -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 { diff --git a/cc/prebuilt_test.go b/cc/prebuilt_test.go new file mode 100644 index 00000000..7cc26514 --- /dev/null +++ b/cc/prebuilt_test.go @@ -0,0 +1,126 @@ +// 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") + } +} diff --git a/cc/sanitize.go b/cc/sanitize.go index 89ef7e61..b7a36a60 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -393,6 +393,11 @@ func (sanitize *sanitize) deps(ctx BaseModuleContext, deps Deps) Deps { if ctx.Device() { if Bool(sanitize.Properties.Sanitize.Address) { deps.StaticLibs = append(deps.StaticLibs, asanLibs...) + // Compiling asan and having libc_scudo in the same + // executable will cause the executable to crash. + // Remove libc_scudo since it is only used to override + // allocation functions which asan already overrides. + _, deps.SharedLibs = removeFromList("libc_scudo", deps.SharedLibs) } } |