aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreehugger Robot2019-05-17 17:44:53 -0500
committerGerrit Code Review2019-05-17 17:44:53 -0500
commit77c22bf008c81440243d9b73508dfb5b7e555ed8 (patch)
tree6e22cb2762a5da14527ce3a9a38327913204e988
parentd3104e8c28fa226db57dabce3ff0baed3233aba7 (diff)
parent33b2fb73335547e39bdad764af249f948eb43935 (diff)
downloadplatform-build-soong-77c22bf008c81440243d9b73508dfb5b7e555ed8.tar.gz
platform-build-soong-77c22bf008c81440243d9b73508dfb5b7e555ed8.tar.xz
platform-build-soong-77c22bf008c81440243d9b73508dfb5b7e555ed8.zip
Merge "Support using cc_prebuilt_library_shared with cc_library"
-rw-r--r--Android.bp1
-rw-r--r--cc/cc_test.go22
-rw-r--r--cc/library.go29
-rw-r--r--cc/prebuilt.go11
-rw-r--r--cc/prebuilt_test.go126
5 files changed, 177 insertions, 12 deletions
diff --git a/Android.bp b/Android.bp
index e2d606e8..c9a48b4b 100644
--- a/Android.bp
+++ b/Android.bp
@@ -196,6 +196,7 @@ bootstrap_go_package {
196 "cc/gen_test.go", 196 "cc/gen_test.go",
197 "cc/genrule_test.go", 197 "cc/genrule_test.go",
198 "cc/library_test.go", 198 "cc/library_test.go",
199 "cc/prebuilt_test.go",
199 "cc/proto_test.go", 200 "cc/proto_test.go",
200 "cc/test_data_test.go", 201 "cc/test_data_test.go",
201 "cc/util_test.go", 202 "cc/util_test.go",
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 36d8aa41..ef6364b5 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -52,7 +52,9 @@ func TestMain(m *testing.M) {
52 os.Exit(run()) 52 os.Exit(run())
53} 53}
54 54
55func createTestContext(t *testing.T, config android.Config, bp string, os android.OsType) *android.TestContext { 55func createTestContext(t *testing.T, config android.Config, bp string, fs map[string][]byte,
56 os android.OsType) *android.TestContext {
57
56 ctx := android.NewTestArchContext() 58 ctx := android.NewTestArchContext()
57 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory)) 59 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory))
58 ctx.RegisterModuleType("cc_binary_host", android.ModuleFactoryAdaptor(binaryHostFactory)) 60 ctx.RegisterModuleType("cc_binary_host", android.ModuleFactoryAdaptor(binaryHostFactory))
@@ -77,12 +79,11 @@ func createTestContext(t *testing.T, config android.Config, bp string, os androi
77 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel() 79 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
78 }) 80 })
79 ctx.RegisterSingletonType("vndk-snapshot", android.SingletonFactoryAdaptor(VndkSnapshotSingleton)) 81 ctx.RegisterSingletonType("vndk-snapshot", android.SingletonFactoryAdaptor(VndkSnapshotSingleton))
80 ctx.Register()
81 82
82 // add some modules that are required by the compiler and/or linker 83 // add some modules that are required by the compiler and/or linker
83 bp = bp + GatherRequiredDepsForTest(os) 84 bp = bp + GatherRequiredDepsForTest(os)
84 85
85 ctx.MockFileSystem(map[string][]byte{ 86 mockFS := map[string][]byte{
86 "Android.bp": []byte(bp), 87 "Android.bp": []byte(bp),
87 "foo.c": nil, 88 "foo.c": nil,
88 "bar.c": nil, 89 "bar.c": nil,
@@ -90,7 +91,14 @@ func createTestContext(t *testing.T, config android.Config, bp string, os androi
90 "b.aidl": nil, 91 "b.aidl": nil,
91 "my_include": nil, 92 "my_include": nil,
92 "foo.map.txt": nil, 93 "foo.map.txt": nil,
93 }) 94 "liba.so": nil,
95 }
96
97 for k, v := range fs {
98 mockFS[k] = v
99 }
100
101 ctx.MockFileSystem(mockFS)
94 102
95 return ctx 103 return ctx
96} 104}
@@ -101,7 +109,8 @@ func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.T
101 109
102func testCcWithConfigForOs(t *testing.T, bp string, config android.Config, os android.OsType) *android.TestContext { 110func testCcWithConfigForOs(t *testing.T, bp string, config android.Config, os android.OsType) *android.TestContext {
103 t.Helper() 111 t.Helper()
104 ctx := createTestContext(t, config, bp, os) 112 ctx := createTestContext(t, config, bp, nil, os)
113 ctx.Register()
105 114
106 _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) 115 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
107 android.FailIfErrored(t, errs) 116 android.FailIfErrored(t, errs)
@@ -134,7 +143,8 @@ func testCcError(t *testing.T, pattern string, bp string) {
134 config.TestProductVariables.DeviceVndkVersion = StringPtr("current") 143 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
135 config.TestProductVariables.Platform_vndk_version = StringPtr("VER") 144 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
136 145
137 ctx := createTestContext(t, config, bp, android.Android) 146 ctx := createTestContext(t, config, bp, nil, android.Android)
147 ctx.Register()
138 148
139 _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) 149 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
140 if len(errs) > 0 { 150 if len(errs) > 0 {
diff --git a/cc/library.go b/cc/library.go
index c2ab098f..11c1d90e 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -23,7 +23,6 @@ import (
23 "strings" 23 "strings"
24 "sync" 24 "sync"
25 25
26 "github.com/google/blueprint"
27 "github.com/google/blueprint/pathtools" 26 "github.com/google/blueprint/pathtools"
28 27
29 "android/soong/android" 28 "android/soong/android"
@@ -1106,10 +1105,28 @@ func reuseStaticLibrary(mctx android.BottomUpMutatorContext, static, shared *Mod
1106 1105
1107func LinkageMutator(mctx android.BottomUpMutatorContext) { 1106func LinkageMutator(mctx android.BottomUpMutatorContext) {
1108 if m, ok := mctx.Module().(*Module); ok && m.linker != nil { 1107 if m, ok := mctx.Module().(*Module); ok && m.linker != nil {
1109 if library, ok := m.linker.(libraryInterface); ok { 1108 switch library := m.linker.(type) {
1110 var modules []blueprint.Module 1109 case prebuiltLibraryInterface:
1110 // Always create both the static and shared variants for prebuilt libraries, and then disable the one
1111 // that is not being used. This allows them to share the name of a cc_library module, which requires that
1112 // all the variants of the cc_library also exist on the prebuilt.
1113 modules := mctx.CreateLocalVariations("static", "shared")
1114 static := modules[0].(*Module)
1115 shared := modules[1].(*Module)
1116
1117 static.linker.(prebuiltLibraryInterface).setStatic()
1118 shared.linker.(prebuiltLibraryInterface).setShared()
1119
1120 if !library.buildStatic() {
1121 static.linker.(prebuiltLibraryInterface).disablePrebuilt()
1122 }
1123 if !library.buildShared() {
1124 shared.linker.(prebuiltLibraryInterface).disablePrebuilt()
1125 }
1126
1127 case libraryInterface:
1111 if library.buildStatic() && library.buildShared() { 1128 if library.buildStatic() && library.buildShared() {
1112 modules = mctx.CreateLocalVariations("static", "shared") 1129 modules := mctx.CreateLocalVariations("static", "shared")
1113 static := modules[0].(*Module) 1130 static := modules[0].(*Module)
1114 shared := modules[1].(*Module) 1131 shared := modules[1].(*Module)
1115 1132
@@ -1119,10 +1136,10 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) {
1119 reuseStaticLibrary(mctx, static, shared) 1136 reuseStaticLibrary(mctx, static, shared)
1120 1137
1121 } else if library.buildStatic() { 1138 } else if library.buildStatic() {
1122 modules = mctx.CreateLocalVariations("static") 1139 modules := mctx.CreateLocalVariations("static")
1123 modules[0].(*Module).linker.(libraryInterface).setStatic() 1140 modules[0].(*Module).linker.(libraryInterface).setStatic()
1124 } else if library.buildShared() { 1141 } else if library.buildShared() {
1125 modules = mctx.CreateLocalVariations("shared") 1142 modules := mctx.CreateLocalVariations("shared")
1126 modules[0].(*Module).linker.(libraryInterface).setShared() 1143 modules[0].(*Module).linker.(libraryInterface).setShared()
1127 } 1144 }
1128 } 1145 }
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 {
53 return p.properties.Srcs 53 return p.properties.Srcs
54} 54}
55 55
56type prebuiltLibraryInterface interface {
57 libraryInterface
58 prebuiltLinkerInterface
59 disablePrebuilt()
60}
61
56type prebuiltLibraryLinker struct { 62type prebuiltLibraryLinker struct {
57 *libraryDecorator 63 *libraryDecorator
58 prebuiltLinker 64 prebuiltLinker
59} 65}
60 66
61var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil) 67var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
68var _ prebuiltLibraryInterface = (*prebuiltLibraryLinker)(nil)
62 69
63func (p *prebuiltLibraryLinker) linkerInit(ctx BaseModuleContext) {} 70func (p *prebuiltLibraryLinker) linkerInit(ctx BaseModuleContext) {}
64 71
@@ -116,6 +123,10 @@ func (p *prebuiltLibraryLinker) nativeCoverage() bool {
116 return false 123 return false
117} 124}
118 125
126func (p *prebuiltLibraryLinker) disablePrebuilt() {
127 p.properties.Srcs = nil
128}
129
119// cc_prebuilt_library_shared installs a precompiled shared library that are 130// cc_prebuilt_library_shared installs a precompiled shared library that are
120// listed in the srcs property in the device's directory. 131// listed in the srcs property in the device's directory.
121func prebuiltSharedLibraryFactory() android.Module { 132func 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 @@
1// Copyright 2019 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
18 "testing"
19
20 "android/soong/android"
21
22 "github.com/google/blueprint"
23)
24
25func TestPrebuilt(t *testing.T) {
26 bp := `
27 cc_library {
28 name: "liba",
29 }
30
31 cc_prebuilt_library_shared {
32 name: "liba",
33 srcs: ["liba.so"],
34 }
35
36 cc_library {
37 name: "libb",
38 }
39
40 cc_prebuilt_library_static {
41 name: "libb",
42 srcs: ["libb.a"],
43 }
44
45 cc_library_shared {
46 name: "libd",
47 }
48
49 cc_prebuilt_library_shared {
50 name: "libd",
51 srcs: ["libd.so"],
52 }
53
54 cc_library_static {
55 name: "libe",
56 }
57
58 cc_prebuilt_library_static {
59 name: "libe",
60 srcs: ["libe.a"],
61 }
62 `
63
64 fs := map[string][]byte{
65 "liba.so": nil,
66 "libb.a": nil,
67 "libd.so": nil,
68 "libe.a": nil,
69 }
70
71 config := android.TestArchConfig(buildDir, nil)
72
73 ctx := createTestContext(t, config, bp, fs, android.Android)
74
75 ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(prebuiltSharedLibraryFactory))
76 ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(prebuiltStaticLibraryFactory))
77 ctx.RegisterModuleType("cc_prebuilt_binary", android.ModuleFactoryAdaptor(prebuiltBinaryFactory))
78
79 ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
80 ctx.PostDepsMutators(android.RegisterPrebuiltsPostDepsMutators)
81
82 ctx.Register()
83
84 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
85 android.FailIfErrored(t, errs)
86 _, errs = ctx.PrepareBuildActions(config)
87 android.FailIfErrored(t, errs)
88
89 // Verify that all the modules exist and that their dependencies were connected correctly
90 liba := ctx.ModuleForTests("liba", "android_arm64_armv8-a_core_shared").Module()
91 libb := ctx.ModuleForTests("libb", "android_arm64_armv8-a_core_static").Module()
92 libd := ctx.ModuleForTests("libd", "android_arm64_armv8-a_core_shared").Module()
93 libe := ctx.ModuleForTests("libe", "android_arm64_armv8-a_core_static").Module()
94
95 prebuiltLiba := ctx.ModuleForTests("prebuilt_liba", "android_arm64_armv8-a_core_shared").Module()
96 prebuiltLibb := ctx.ModuleForTests("prebuilt_libb", "android_arm64_armv8-a_core_static").Module()
97 prebuiltLibd := ctx.ModuleForTests("prebuilt_libd", "android_arm64_armv8-a_core_shared").Module()
98 prebuiltLibe := ctx.ModuleForTests("prebuilt_libe", "android_arm64_armv8-a_core_static").Module()
99
100 hasDep := func(m android.Module, wantDep android.Module) bool {
101 t.Helper()
102 var found bool
103 ctx.VisitDirectDeps(m, func(dep blueprint.Module) {
104 if dep == wantDep {
105 found = true
106 }
107 })
108 return found
109 }
110
111 if !hasDep(liba, prebuiltLiba) {
112 t.Errorf("liba missing dependency on prebuilt_liba")
113 }
114
115 if !hasDep(libb, prebuiltLibb) {
116 t.Errorf("libb missing dependency on prebuilt_libb")
117 }
118
119 if !hasDep(libd, prebuiltLibd) {
120 t.Errorf("libd missing dependency on prebuilt_libd")
121 }
122
123 if !hasDep(libe, prebuiltLibe) {
124 t.Errorf("libe missing dependency on prebuilt_libe")
125 }
126}