Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame^] | 18 | "regexp" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 19 | "strings" |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame^] | 20 | "sync" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 21 | |
| 22 | "github.com/google/blueprint" |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint/pathtools" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 24 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 25 | "android/soong/android" |
Dan Albert | ea4b7b9 | 2018-04-25 16:05:30 -0700 | [diff] [blame] | 26 | "android/soong/cc/config" |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 27 | "android/soong/genrule" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 28 | ) |
| 29 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 30 | type LibraryProperties struct { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 31 | Static struct { |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 32 | Srcs []string `android:"arch_variant"` |
| 33 | Cflags []string `android:"arch_variant"` |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 34 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 35 | Enabled *bool `android:"arch_variant"` |
| 36 | Whole_static_libs []string `android:"arch_variant"` |
| 37 | Static_libs []string `android:"arch_variant"` |
| 38 | Shared_libs []string `android:"arch_variant"` |
| 39 | } `android:"arch_variant"` |
| 40 | Shared struct { |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 41 | Srcs []string `android:"arch_variant"` |
| 42 | Cflags []string `android:"arch_variant"` |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 43 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 44 | Enabled *bool `android:"arch_variant"` |
| 45 | Whole_static_libs []string `android:"arch_variant"` |
| 46 | Static_libs []string `android:"arch_variant"` |
| 47 | Shared_libs []string `android:"arch_variant"` |
| 48 | } `android:"arch_variant"` |
| 49 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 50 | // local file name to pass to the linker as -unexported_symbols_list |
| 51 | Unexported_symbols_list *string `android:"arch_variant"` |
| 52 | // local file name to pass to the linker as -force_symbols_not_weak_list |
| 53 | Force_symbols_not_weak_list *string `android:"arch_variant"` |
| 54 | // local file name to pass to the linker as -force_symbols_weak_list |
| 55 | Force_symbols_weak_list *string `android:"arch_variant"` |
| 56 | |
| 57 | // rename host libraries to prevent overlap with system installed libraries |
| 58 | Unique_host_soname *bool |
| 59 | |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 60 | Aidl struct { |
| 61 | // export headers generated from .aidl sources |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 62 | Export_aidl_headers *bool |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 65 | Proto struct { |
| 66 | // export headers generated from .proto sources |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 67 | Export_proto_headers *bool |
Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 68 | } |
Dan Albert | f563d25 | 2017-10-13 00:29:00 -0700 | [diff] [blame] | 69 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 70 | Static_ndk_lib *bool |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 71 | |
| 72 | Stubs struct { |
| 73 | // Relative path to the symbol map. The symbol map provides the list of |
| 74 | // symbols that are exported for stubs variant of this library. |
| 75 | Symbol_file *string |
| 76 | |
| 77 | // List versions to generate stubs libs for. |
| 78 | Versions []string |
| 79 | } |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 80 | } |
Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 81 | |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 82 | type LibraryMutatedProperties struct { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 83 | VariantName string `blueprint:"mutated"` |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 84 | |
| 85 | // Build a static variant |
| 86 | BuildStatic bool `blueprint:"mutated"` |
| 87 | // Build a shared variant |
| 88 | BuildShared bool `blueprint:"mutated"` |
| 89 | // This variant is shared |
| 90 | VariantIsShared bool `blueprint:"mutated"` |
| 91 | // This variant is static |
| 92 | VariantIsStatic bool `blueprint:"mutated"` |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 93 | |
| 94 | // This variant is a stubs lib |
| 95 | BuildStubs bool `blueprint:"mutated"` |
| 96 | // Version of the stubs lib |
| 97 | StubsVersion string `blueprint:"mutated"` |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | type FlagExporterProperties struct { |
| 101 | // list of directories relative to the Blueprints file that will |
Dan Willemsen | 273af7f | 2016-11-03 15:53:42 -0700 | [diff] [blame] | 102 | // be added to the include path (using -I) for this module and any module that links |
Colin Cross | 5d19560 | 2017-10-17 16:15:50 -0700 | [diff] [blame] | 103 | // against this module. Directories listed in export_include_dirs do not need to be |
| 104 | // listed in local_include_dirs. |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 105 | Export_include_dirs []string `android:"arch_variant"` |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 106 | |
| 107 | Target struct { |
| 108 | Vendor struct { |
| 109 | // list of exported include directories, like |
| 110 | // export_include_dirs, that will be applied to the |
| 111 | // vendor variant of this library. This will overwrite |
| 112 | // any other declarations. |
Steven Moreland | b21df8f | 2018-01-05 14:42:54 -0800 | [diff] [blame] | 113 | Override_export_include_dirs []string |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 114 | } |
| 115 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | func init() { |
Steven Moreland | f9e6216 | 2017-11-02 17:00:50 -0700 | [diff] [blame] | 119 | android.RegisterModuleType("cc_library_static", LibraryStaticFactory) |
| 120 | android.RegisterModuleType("cc_library_shared", LibrarySharedFactory) |
| 121 | android.RegisterModuleType("cc_library", LibraryFactory) |
| 122 | android.RegisterModuleType("cc_library_host_static", LibraryHostStaticFactory) |
| 123 | android.RegisterModuleType("cc_library_host_shared", LibraryHostSharedFactory) |
| 124 | android.RegisterModuleType("cc_library_headers", LibraryHeaderFactory) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | // Module factory for combined static + shared libraries, device by default but with possible host |
| 128 | // support |
Steven Moreland | f9e6216 | 2017-11-02 17:00:50 -0700 | [diff] [blame] | 129 | func LibraryFactory() android.Module { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 130 | module, _ := NewLibrary(android.HostAndDeviceSupported) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 131 | return module.Init() |
| 132 | } |
| 133 | |
| 134 | // Module factory for static libraries |
Steven Moreland | f9e6216 | 2017-11-02 17:00:50 -0700 | [diff] [blame] | 135 | func LibraryStaticFactory() android.Module { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 136 | module, library := NewLibrary(android.HostAndDeviceSupported) |
| 137 | library.BuildOnlyStatic() |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 138 | return module.Init() |
| 139 | } |
| 140 | |
| 141 | // Module factory for shared libraries |
Steven Moreland | f9e6216 | 2017-11-02 17:00:50 -0700 | [diff] [blame] | 142 | func LibrarySharedFactory() android.Module { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 143 | module, library := NewLibrary(android.HostAndDeviceSupported) |
| 144 | library.BuildOnlyShared() |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 145 | return module.Init() |
| 146 | } |
| 147 | |
| 148 | // Module factory for host static libraries |
Steven Moreland | f9e6216 | 2017-11-02 17:00:50 -0700 | [diff] [blame] | 149 | func LibraryHostStaticFactory() android.Module { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 150 | module, library := NewLibrary(android.HostSupported) |
| 151 | library.BuildOnlyStatic() |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 152 | return module.Init() |
| 153 | } |
| 154 | |
| 155 | // Module factory for host shared libraries |
Steven Moreland | f9e6216 | 2017-11-02 17:00:50 -0700 | [diff] [blame] | 156 | func LibraryHostSharedFactory() android.Module { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 157 | module, library := NewLibrary(android.HostSupported) |
| 158 | library.BuildOnlyShared() |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 159 | return module.Init() |
| 160 | } |
| 161 | |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 162 | // Module factory for header-only libraries |
Steven Moreland | f9e6216 | 2017-11-02 17:00:50 -0700 | [diff] [blame] | 163 | func LibraryHeaderFactory() android.Module { |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 164 | module, library := NewLibrary(android.HostAndDeviceSupported) |
| 165 | library.HeaderOnly() |
| 166 | return module.Init() |
| 167 | } |
| 168 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 169 | type flagExporter struct { |
| 170 | Properties FlagExporterProperties |
| 171 | |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 172 | flags []string |
| 173 | flagsDeps android.Paths |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 176 | func (f *flagExporter) exportedIncludes(ctx ModuleContext) android.Paths { |
Steven Moreland | b21df8f | 2018-01-05 14:42:54 -0800 | [diff] [blame] | 177 | if ctx.useVndk() && f.Properties.Target.Vendor.Override_export_include_dirs != nil { |
| 178 | return android.PathsForModuleSrc(ctx, f.Properties.Target.Vendor.Override_export_include_dirs) |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 179 | } else { |
| 180 | return android.PathsForModuleSrc(ctx, f.Properties.Export_include_dirs) |
| 181 | } |
| 182 | } |
| 183 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 184 | func (f *flagExporter) exportIncludes(ctx ModuleContext, inc string) { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 185 | includeDirs := f.exportedIncludes(ctx) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 186 | for _, dir := range includeDirs.Strings() { |
| 187 | f.flags = append(f.flags, inc+dir) |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | func (f *flagExporter) reexportFlags(flags []string) { |
| 192 | f.flags = append(f.flags, flags...) |
| 193 | } |
| 194 | |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 195 | func (f *flagExporter) reexportDeps(deps android.Paths) { |
| 196 | f.flagsDeps = append(f.flagsDeps, deps...) |
| 197 | } |
| 198 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 199 | func (f *flagExporter) exportedFlags() []string { |
| 200 | return f.flags |
| 201 | } |
| 202 | |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 203 | func (f *flagExporter) exportedFlagsDeps() android.Paths { |
| 204 | return f.flagsDeps |
| 205 | } |
| 206 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 207 | type exportedFlagsProducer interface { |
| 208 | exportedFlags() []string |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 209 | exportedFlagsDeps() android.Paths |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | var _ exportedFlagsProducer = (*flagExporter)(nil) |
| 213 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 214 | // libraryDecorator wraps baseCompiler, baseLinker and baseInstaller to provide library-specific |
| 215 | // functionality: static vs. shared linkage, reusing object files for shared libraries |
| 216 | type libraryDecorator struct { |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 217 | Properties LibraryProperties |
| 218 | MutatedProperties LibraryMutatedProperties |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 219 | |
| 220 | // For reusing static library objects for shared library |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 221 | reuseObjects Objects |
| 222 | reuseExportedFlags []string |
Colin Cross | bbc9f4d | 2017-05-03 16:24:55 -0700 | [diff] [blame] | 223 | reuseExportedDeps android.Paths |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 224 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 225 | // table-of-contents file to optimize out relinking when possible |
| 226 | tocFile android.OptionalPath |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 227 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 228 | flagExporter |
| 229 | stripper |
| 230 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 231 | // If we're used as a whole_static_lib, our missing dependencies need |
| 232 | // to be given |
| 233 | wholeStaticMissingDeps []string |
| 234 | |
| 235 | // For whole_static_libs |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 236 | objects Objects |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 237 | |
| 238 | // Uses the module's name if empty, but can be overridden. Does not include |
| 239 | // shlib suffix. |
| 240 | libName string |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 241 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 242 | sabi *sabi |
| 243 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 244 | // Output archive of gcno coverage information files |
| 245 | coverageOutputFile android.OptionalPath |
| 246 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 247 | // linked Source Abi Dump |
| 248 | sAbiOutputFile android.OptionalPath |
| 249 | |
| 250 | // Source Abi Diff |
| 251 | sAbiDiff android.OptionalPath |
| 252 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 253 | // Location of the static library in the sysroot. Empty if the library is |
| 254 | // not included in the NDK. |
| 255 | ndkSysrootPath android.Path |
| 256 | |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 257 | // Location of the linked, unstripped library for shared libraries |
| 258 | unstrippedOutputFile android.Path |
| 259 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 260 | versionScriptPath android.ModuleGenPath |
| 261 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 262 | // Decorated interafaces |
| 263 | *baseCompiler |
| 264 | *baseLinker |
| 265 | *baseInstaller |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 268 | func (library *libraryDecorator) linkerProps() []interface{} { |
| 269 | var props []interface{} |
| 270 | props = append(props, library.baseLinker.linkerProps()...) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 271 | return append(props, |
| 272 | &library.Properties, |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 273 | &library.MutatedProperties, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 274 | &library.flagExporter.Properties, |
Colin Cross | 22f3795 | 2018-09-05 10:43:13 -0700 | [diff] [blame] | 275 | &library.stripper.StripProperties) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 278 | func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 279 | flags = library.baseLinker.linkerFlags(ctx, flags) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 280 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 281 | // MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because |
| 282 | // all code is position independent, and then those warnings get promoted to |
| 283 | // errors. |
Colin Cross | 3edeee1 | 2017-04-04 12:59:48 -0700 | [diff] [blame] | 284 | if !ctx.Windows() { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 285 | flags.CFlags = append(flags.CFlags, "-fPIC") |
| 286 | } |
| 287 | |
| 288 | if library.static() { |
| 289 | flags.CFlags = append(flags.CFlags, library.Properties.Static.Cflags...) |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 290 | } else if library.shared() { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 291 | flags.CFlags = append(flags.CFlags, library.Properties.Shared.Cflags...) |
| 292 | } |
| 293 | |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 294 | if library.shared() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 295 | libName := library.getLibName(ctx) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 296 | var f []string |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 297 | if ctx.toolchain().Bionic() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 298 | f = append(f, |
| 299 | "-nostdlib", |
| 300 | "-Wl,--gc-sections", |
| 301 | ) |
| 302 | } |
| 303 | |
| 304 | if ctx.Darwin() { |
| 305 | f = append(f, |
| 306 | "-dynamiclib", |
| 307 | "-single_module", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 308 | "-install_name @rpath/"+libName+flags.Toolchain.ShlibSuffix(), |
| 309 | ) |
Colin Cross | 7863cf5 | 2016-10-20 10:47:21 -0700 | [diff] [blame] | 310 | if ctx.Arch().ArchType == android.X86 { |
| 311 | f = append(f, |
| 312 | "-read_only_relocs suppress", |
| 313 | ) |
| 314 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 315 | } else { |
| 316 | f = append(f, |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 317 | "-shared", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 318 | "-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix()) |
| 319 | } |
| 320 | |
| 321 | flags.LdFlags = append(f, flags.LdFlags...) |
| 322 | } |
| 323 | |
| 324 | return flags |
| 325 | } |
| 326 | |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 327 | func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 328 | exportIncludeDirs := library.flagExporter.exportedIncludes(ctx) |
Dan Willemsen | 273af7f | 2016-11-03 15:53:42 -0700 | [diff] [blame] | 329 | if len(exportIncludeDirs) > 0 { |
Colin Cross | dad8c95 | 2017-04-26 14:55:27 -0700 | [diff] [blame] | 330 | f := includeDirsToFlags(exportIncludeDirs) |
| 331 | flags.GlobalFlags = append(flags.GlobalFlags, f) |
| 332 | flags.YasmFlags = append(flags.YasmFlags, f) |
Dan Willemsen | 273af7f | 2016-11-03 15:53:42 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 335 | flags = library.baseCompiler.compilerFlags(ctx, flags, deps) |
| 336 | if library.buildStubs() { |
| 337 | flags = addStubLibraryCompilerFlags(flags) |
| 338 | } |
| 339 | return flags |
Dan Willemsen | 273af7f | 2016-11-03 15:53:42 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 342 | func extractExportIncludesFromFlags(flags []string) []string { |
| 343 | // This method is used in the generation of rules which produce |
| 344 | // abi-dumps for source files. Exported headers are needed to infer the |
| 345 | // abi exported by a library and filter out the rest of the abi dumped |
| 346 | // from a source. We extract the include flags exported by a library. |
| 347 | // This includes the flags exported which are re-exported from static |
| 348 | // library dependencies, exported header library dependencies and |
Jayant Chowdhary | af6eb71 | 2017-08-23 16:08:29 -0700 | [diff] [blame] | 349 | // generated header dependencies. -isystem headers are not included |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 350 | // since for bionic libraries, abi-filtering is taken care of by version |
| 351 | // scripts. |
| 352 | var exportedIncludes []string |
| 353 | for _, flag := range flags { |
| 354 | if strings.HasPrefix(flag, "-I") { |
| 355 | exportedIncludes = append(exportedIncludes, flag) |
| 356 | } |
| 357 | } |
| 358 | return exportedIncludes |
| 359 | } |
| 360 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 361 | func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 362 | if library.buildStubs() { |
| 363 | objs, versionScript := compileStubLibrary(ctx, flags, String(library.Properties.Stubs.Symbol_file), library.MutatedProperties.StubsVersion, "") |
| 364 | library.versionScriptPath = versionScript |
| 365 | return objs |
| 366 | } |
| 367 | |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 368 | if !library.buildShared() && !library.buildStatic() { |
| 369 | if len(library.baseCompiler.Properties.Srcs) > 0 { |
| 370 | ctx.PropertyErrorf("srcs", "cc_library_headers must not have any srcs") |
| 371 | } |
| 372 | if len(library.Properties.Static.Srcs) > 0 { |
| 373 | ctx.PropertyErrorf("static.srcs", "cc_library_headers must not have any srcs") |
| 374 | } |
| 375 | if len(library.Properties.Shared.Srcs) > 0 { |
| 376 | ctx.PropertyErrorf("shared.srcs", "cc_library_headers must not have any srcs") |
| 377 | } |
| 378 | return Objects{} |
| 379 | } |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 380 | if ctx.shouldCreateVndkSourceAbiDump() || library.sabi.Properties.CreateSAbiDumps { |
Jayant Chowdhary | a4fce19 | 2017-09-06 13:10:03 -0700 | [diff] [blame] | 381 | exportIncludeDirs := library.flagExporter.exportedIncludes(ctx) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 382 | var SourceAbiFlags []string |
| 383 | for _, dir := range exportIncludeDirs.Strings() { |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 384 | SourceAbiFlags = append(SourceAbiFlags, "-I"+dir) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 385 | } |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 386 | for _, reexportedInclude := range extractExportIncludesFromFlags(library.sabi.Properties.ReexportedIncludeFlags) { |
| 387 | SourceAbiFlags = append(SourceAbiFlags, reexportedInclude) |
| 388 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 389 | flags.SAbiFlags = SourceAbiFlags |
| 390 | total_length := len(library.baseCompiler.Properties.Srcs) + len(deps.GeneratedSources) + len(library.Properties.Shared.Srcs) + |
| 391 | len(library.Properties.Static.Srcs) |
| 392 | if total_length > 0 { |
| 393 | flags.SAbiDump = true |
| 394 | } |
| 395 | } |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 396 | objs := library.baseCompiler.compile(ctx, flags, deps) |
| 397 | library.reuseObjects = objs |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 398 | buildFlags := flagsToBuilderFlags(flags) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 399 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 400 | if library.static() { |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 401 | srcs := android.PathsForModuleSrc(ctx, library.Properties.Static.Srcs) |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 402 | objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceStaticLibrary, |
Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 403 | srcs, library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps)) |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 404 | } else if library.shared() { |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 405 | srcs := android.PathsForModuleSrc(ctx, library.Properties.Shared.Srcs) |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 406 | objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceSharedLibrary, |
Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 407 | srcs, library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps)) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 410 | return objs |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | type libraryInterface interface { |
| 414 | getWholeStaticMissingDeps() []string |
| 415 | static() bool |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 416 | objs() Objects |
Colin Cross | bbc9f4d | 2017-05-03 16:24:55 -0700 | [diff] [blame] | 417 | reuseObjs() (Objects, []string, android.Paths) |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 418 | toc() android.OptionalPath |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 419 | |
| 420 | // Returns true if the build options for the module have selected a static or shared build |
| 421 | buildStatic() bool |
| 422 | buildShared() bool |
| 423 | |
| 424 | // Sets whether a specific variant is static or shared |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 425 | setStatic() |
| 426 | setShared() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | func (library *libraryDecorator) getLibName(ctx ModuleContext) string { |
| 430 | name := library.libName |
| 431 | if name == "" { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 432 | name = ctx.baseModuleName() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 435 | if ctx.isVndkExt() { |
| 436 | name = ctx.getVndkExtendsModuleName() |
| 437 | } |
| 438 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 439 | if ctx.Host() && Bool(library.Properties.Unique_host_soname) { |
| 440 | if !strings.HasSuffix(name, "-host") { |
| 441 | name = name + "-host" |
| 442 | } |
| 443 | } |
| 444 | |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 445 | return name + library.MutatedProperties.VariantName |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame^] | 448 | var versioningMacroNamesListMutex sync.Mutex |
| 449 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 450 | func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) { |
| 451 | location := InstallInSystem |
Dan Albert | 61f3212 | 2018-07-26 14:00:24 -0700 | [diff] [blame] | 452 | if library.baseLinker.sanitize.inSanitizerDir() { |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 453 | location = InstallInSanitizerDir |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 454 | } |
| 455 | library.baseInstaller.location = location |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 456 | library.baseLinker.linkerInit(ctx) |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 457 | // Let baseLinker know whether this variant is for stubs or not, so that |
| 458 | // it can omit things that are not required for linking stubs. |
| 459 | library.baseLinker.dynamicProperties.BuildStubs = library.buildStubs() |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame^] | 460 | |
| 461 | if library.buildStubs() { |
| 462 | macroNames := versioningMacroNamesList(ctx.Config()) |
| 463 | myName := versioningMacroName(ctx.ModuleName()) |
| 464 | versioningMacroNamesListMutex.Lock() |
| 465 | defer versioningMacroNamesListMutex.Unlock() |
| 466 | if (*macroNames)[myName] == "" { |
| 467 | (*macroNames)[myName] = ctx.ModuleName() |
| 468 | } else if (*macroNames)[myName] != ctx.ModuleName() { |
| 469 | ctx.ModuleErrorf("Macro name %q for versioning conflicts with macro name from module %q ", myName, (*macroNames)[myName]) |
| 470 | } |
| 471 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 474 | func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 475 | deps = library.baseLinker.linkerDeps(ctx, deps) |
| 476 | |
| 477 | if library.static() { |
| 478 | deps.WholeStaticLibs = append(deps.WholeStaticLibs, |
| 479 | library.Properties.Static.Whole_static_libs...) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 480 | deps.StaticLibs = append(deps.StaticLibs, library.Properties.Static.Static_libs...) |
| 481 | deps.SharedLibs = append(deps.SharedLibs, library.Properties.Static.Shared_libs...) |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 482 | } else if library.shared() { |
Dan Willemsen | 2e47b34 | 2016-11-17 01:02:25 -0800 | [diff] [blame] | 483 | if ctx.toolchain().Bionic() && !Bool(library.baseLinker.Properties.Nocrt) { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 484 | if !ctx.useSdk() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 485 | deps.CrtBegin = "crtbegin_so" |
| 486 | deps.CrtEnd = "crtend_so" |
| 487 | } else { |
Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 488 | // TODO(danalbert): Add generation of crt objects. |
| 489 | // For `sdk_version: "current"`, we don't actually have a |
| 490 | // freshly generated set of CRT objects. Use the last stable |
| 491 | // version. |
| 492 | version := ctx.sdkVersion() |
| 493 | if version == "current" { |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 494 | version = getCurrentNdkPrebuiltVersion(ctx) |
Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 495 | } |
| 496 | deps.CrtBegin = "ndk_crtbegin_so." + version |
| 497 | deps.CrtEnd = "ndk_crtend_so." + version |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.Properties.Shared.Whole_static_libs...) |
| 501 | deps.StaticLibs = append(deps.StaticLibs, library.Properties.Shared.Static_libs...) |
| 502 | deps.SharedLibs = append(deps.SharedLibs, library.Properties.Shared.Shared_libs...) |
| 503 | } |
Jiyong Park | 52d25bd | 2017-10-13 09:17:01 +0900 | [diff] [blame] | 504 | if ctx.useVndk() { |
| 505 | deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, library.baseLinker.Properties.Target.Vendor.Exclude_static_libs) |
| 506 | deps.SharedLibs = removeListFromList(deps.SharedLibs, library.baseLinker.Properties.Target.Vendor.Exclude_shared_libs) |
| 507 | deps.StaticLibs = removeListFromList(deps.StaticLibs, library.baseLinker.Properties.Target.Vendor.Exclude_static_libs) |
| 508 | } |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 509 | if ctx.inRecovery() { |
| 510 | deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, library.baseLinker.Properties.Target.Recovery.Exclude_static_libs) |
| 511 | deps.SharedLibs = removeListFromList(deps.SharedLibs, library.baseLinker.Properties.Target.Recovery.Exclude_shared_libs) |
| 512 | deps.StaticLibs = removeListFromList(deps.StaticLibs, library.baseLinker.Properties.Target.Recovery.Exclude_static_libs) |
| 513 | } |
Colin Cross | 2383f3b | 2018-02-06 14:40:13 -0800 | [diff] [blame] | 514 | |
Colin Cross | 2383f3b | 2018-02-06 14:40:13 -0800 | [diff] [blame] | 515 | android.ExtractSourceDeps(ctx, library.Properties.Unexported_symbols_list) |
| 516 | android.ExtractSourceDeps(ctx, library.Properties.Force_symbols_not_weak_list) |
| 517 | android.ExtractSourceDeps(ctx, library.Properties.Force_symbols_weak_list) |
Colin Cross | 2383f3b | 2018-02-06 14:40:13 -0800 | [diff] [blame] | 518 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 519 | return deps |
| 520 | } |
| 521 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 522 | func (library *libraryDecorator) linkStatic(ctx ModuleContext, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 523 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 524 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 525 | library.objects = deps.WholeStaticLibObjs.Copy() |
| 526 | library.objects = library.objects.Append(objs) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 527 | |
Colin Cross | 86803cf | 2018-02-15 14:12:26 -0800 | [diff] [blame] | 528 | fileName := ctx.ModuleName() + library.MutatedProperties.VariantName + staticLibraryExtension |
| 529 | outputFile := android.PathForModuleOut(ctx, fileName) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 530 | builderFlags := flagsToBuilderFlags(flags) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 531 | |
Colin Cross | 86803cf | 2018-02-15 14:12:26 -0800 | [diff] [blame] | 532 | if Bool(library.baseLinker.Properties.Use_version_lib) && ctx.Host() { |
| 533 | versionedOutputFile := outputFile |
| 534 | outputFile = android.PathForModuleOut(ctx, "unversioned", fileName) |
| 535 | library.injectVersionSymbol(ctx, outputFile, versionedOutputFile) |
| 536 | } |
| 537 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 538 | TransformObjToStaticLib(ctx, library.objects.objFiles, builderFlags, outputFile, objs.tidyFiles) |
| 539 | |
| 540 | library.coverageOutputFile = TransformCoverageFilesToLib(ctx, library.objects, builderFlags, |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 541 | ctx.ModuleName()+library.MutatedProperties.VariantName) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 542 | |
| 543 | library.wholeStaticMissingDeps = ctx.GetMissingDependencies() |
| 544 | |
| 545 | ctx.CheckbuildFile(outputFile) |
| 546 | |
| 547 | return outputFile |
| 548 | } |
| 549 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 550 | func (library *libraryDecorator) linkShared(ctx ModuleContext, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 551 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 552 | |
| 553 | var linkerDeps android.Paths |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 554 | linkerDeps = append(linkerDeps, flags.LdFlagsDeps...) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 555 | |
Colin Cross | 2383f3b | 2018-02-06 14:40:13 -0800 | [diff] [blame] | 556 | unexportedSymbols := ctx.ExpandOptionalSource(library.Properties.Unexported_symbols_list, "unexported_symbols_list") |
| 557 | forceNotWeakSymbols := ctx.ExpandOptionalSource(library.Properties.Force_symbols_not_weak_list, "force_symbols_not_weak_list") |
| 558 | forceWeakSymbols := ctx.ExpandOptionalSource(library.Properties.Force_symbols_weak_list, "force_symbols_weak_list") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 559 | if !ctx.Darwin() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 560 | if unexportedSymbols.Valid() { |
| 561 | ctx.PropertyErrorf("unexported_symbols_list", "Only supported on Darwin") |
| 562 | } |
| 563 | if forceNotWeakSymbols.Valid() { |
| 564 | ctx.PropertyErrorf("force_symbols_not_weak_list", "Only supported on Darwin") |
| 565 | } |
| 566 | if forceWeakSymbols.Valid() { |
| 567 | ctx.PropertyErrorf("force_symbols_weak_list", "Only supported on Darwin") |
| 568 | } |
| 569 | } else { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 570 | if unexportedSymbols.Valid() { |
| 571 | flags.LdFlags = append(flags.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String()) |
| 572 | linkerDeps = append(linkerDeps, unexportedSymbols.Path()) |
| 573 | } |
| 574 | if forceNotWeakSymbols.Valid() { |
| 575 | flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_not_weak_list,"+forceNotWeakSymbols.String()) |
| 576 | linkerDeps = append(linkerDeps, forceNotWeakSymbols.Path()) |
| 577 | } |
| 578 | if forceWeakSymbols.Valid() { |
| 579 | flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_weak_list,"+forceWeakSymbols.String()) |
| 580 | linkerDeps = append(linkerDeps, forceWeakSymbols.Path()) |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | fileName := library.getLibName(ctx) + flags.Toolchain.ShlibSuffix() |
| 585 | outputFile := android.PathForModuleOut(ctx, fileName) |
| 586 | ret := outputFile |
| 587 | |
| 588 | builderFlags := flagsToBuilderFlags(flags) |
| 589 | |
Colin Cross | b496cfd | 2018-09-10 16:50:05 -0700 | [diff] [blame] | 590 | // Optimize out relinking against shared libraries whose interface hasn't changed by |
| 591 | // depending on a table of contents file instead of the library itself. |
| 592 | tocPath := outputFile.RelPathString() |
| 593 | tocPath = pathtools.ReplaceExtension(tocPath, flags.Toolchain.ShlibSuffix()[1:]+".toc") |
| 594 | tocFile := android.PathForOutput(ctx, tocPath) |
| 595 | library.tocFile = android.OptionalPathForPath(tocFile) |
| 596 | TransformSharedObjectToToc(ctx, outputFile, tocFile, builderFlags) |
Colin Cross | 89562dc | 2016-10-03 17:47:19 -0700 | [diff] [blame] | 597 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 598 | if library.stripper.needsStrip(ctx) { |
Chih-Hung Hsieh | 30485c9 | 2018-06-04 10:37:43 -0700 | [diff] [blame] | 599 | // b/80093681, GNU strip/objcopy bug. |
| 600 | // Use llvm-{strip,objcopy} when clang lld is used. |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 601 | builderFlags.stripUseLlvmStrip = library.baseLinker.useClangLld(ctx) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 602 | strippedOutputFile := outputFile |
| 603 | outputFile = android.PathForModuleOut(ctx, "unstripped", fileName) |
| 604 | library.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags) |
| 605 | } |
| 606 | |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 607 | library.unstrippedOutputFile = outputFile |
| 608 | |
Colin Cross | 86803cf | 2018-02-15 14:12:26 -0800 | [diff] [blame] | 609 | if Bool(library.baseLinker.Properties.Use_version_lib) && ctx.Host() { |
| 610 | versionedOutputFile := outputFile |
| 611 | outputFile = android.PathForModuleOut(ctx, "unversioned", fileName) |
| 612 | library.injectVersionSymbol(ctx, outputFile, versionedOutputFile) |
| 613 | } |
| 614 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 615 | sharedLibs := deps.SharedLibs |
| 616 | sharedLibs = append(sharedLibs, deps.LateSharedLibs...) |
| 617 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 618 | linkerDeps = append(linkerDeps, deps.SharedLibsDeps...) |
| 619 | linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 620 | linkerDeps = append(linkerDeps, objs.tidyFiles...) |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 621 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 622 | TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 623 | deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs, |
| 624 | linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile) |
| 625 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 626 | objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...) |
| 627 | objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 628 | |
| 629 | objs.sAbiDumpFiles = append(objs.sAbiDumpFiles, deps.StaticLibObjs.sAbiDumpFiles...) |
| 630 | objs.sAbiDumpFiles = append(objs.sAbiDumpFiles, deps.WholeStaticLibObjs.sAbiDumpFiles...) |
| 631 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 632 | library.coverageOutputFile = TransformCoverageFilesToLib(ctx, objs, builderFlags, library.getLibName(ctx)) |
Jayant Chowdhary | 6ab3d84 | 2017-06-26 12:52:58 -0700 | [diff] [blame] | 633 | library.linkSAbiDumpFiles(ctx, objs, fileName, ret) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 634 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 635 | return ret |
| 636 | } |
| 637 | |
Logan Chien | 7eefdc4 | 2018-07-11 18:10:41 +0800 | [diff] [blame] | 638 | func getRefAbiDumpFile(ctx ModuleContext, vndkVersion, fileName string) android.Path { |
Logan Chien | f4b79c6 | 2018-08-02 02:27:02 +0800 | [diff] [blame] | 639 | isLlndk := inList(ctx.baseModuleName(), llndkLibraries) || inList(ctx.baseModuleName(), ndkMigratedLibs) |
Logan Chien | 7eefdc4 | 2018-07-11 18:10:41 +0800 | [diff] [blame] | 640 | |
| 641 | refAbiDumpTextFile := android.PathForVndkRefAbiDump(ctx, vndkVersion, fileName, isLlndk, false) |
| 642 | refAbiDumpGzipFile := android.PathForVndkRefAbiDump(ctx, vndkVersion, fileName, isLlndk, true) |
| 643 | |
| 644 | if refAbiDumpTextFile.Valid() { |
| 645 | if refAbiDumpGzipFile.Valid() { |
| 646 | ctx.ModuleErrorf( |
| 647 | "Two reference ABI dump files are found: %q and %q. Please delete the stale one.", |
| 648 | refAbiDumpTextFile, refAbiDumpGzipFile) |
| 649 | return nil |
| 650 | } |
| 651 | return refAbiDumpTextFile.Path() |
| 652 | } |
| 653 | if refAbiDumpGzipFile.Valid() { |
| 654 | return UnzipRefDump(ctx, refAbiDumpGzipFile.Path(), fileName) |
| 655 | } |
| 656 | return nil |
| 657 | } |
| 658 | |
Jayant Chowdhary | 6ab3d84 | 2017-06-26 12:52:58 -0700 | [diff] [blame] | 659 | func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objects, fileName string, soFile android.Path) { |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 660 | if len(objs.sAbiDumpFiles) > 0 && ctx.shouldCreateVndkSourceAbiDump() { |
Logan Chien | a8f5158 | 2018-03-21 11:53:48 +0800 | [diff] [blame] | 661 | vndkVersion := ctx.DeviceConfig().PlatformVndkVersion() |
| 662 | if ver := ctx.DeviceConfig().VndkVersion(); ver != "" && ver != "current" { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 663 | vndkVersion = ver |
| 664 | } |
| 665 | |
Jayant Chowdhary | a4fce19 | 2017-09-06 13:10:03 -0700 | [diff] [blame] | 666 | exportIncludeDirs := library.flagExporter.exportedIncludes(ctx) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 667 | var SourceAbiFlags []string |
| 668 | for _, dir := range exportIncludeDirs.Strings() { |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 669 | SourceAbiFlags = append(SourceAbiFlags, "-I"+dir) |
| 670 | } |
| 671 | for _, reexportedInclude := range extractExportIncludesFromFlags(library.sabi.Properties.ReexportedIncludeFlags) { |
| 672 | SourceAbiFlags = append(SourceAbiFlags, reexportedInclude) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 673 | } |
| 674 | exportedHeaderFlags := strings.Join(SourceAbiFlags, " ") |
Jayant Chowdhary | df344d5 | 2018-01-17 11:11:42 -0800 | [diff] [blame] | 675 | library.sAbiOutputFile = TransformDumpToLinkedDump(ctx, objs.sAbiDumpFiles, soFile, fileName, exportedHeaderFlags) |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 676 | |
Logan Chien | 7eefdc4 | 2018-07-11 18:10:41 +0800 | [diff] [blame] | 677 | refAbiDumpFile := getRefAbiDumpFile(ctx, vndkVersion, fileName) |
| 678 | if refAbiDumpFile != nil { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 679 | library.sAbiDiff = SourceAbiDiff(ctx, library.sAbiOutputFile.Path(), |
Logan Chien | 7eefdc4 | 2018-07-11 18:10:41 +0800 | [diff] [blame] | 680 | refAbiDumpFile, fileName, exportedHeaderFlags, ctx.isVndkExt()) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | } |
| 684 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 685 | func (library *libraryDecorator) link(ctx ModuleContext, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 686 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 687 | |
Colin Cross | ad59e75 | 2017-11-16 14:29:11 -0800 | [diff] [blame] | 688 | objs = deps.Objs.Copy().Append(objs) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 689 | var out android.Path |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 690 | if library.static() || library.header() { |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 691 | out = library.linkStatic(ctx, flags, deps, objs) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 692 | } else { |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 693 | out = library.linkShared(ctx, flags, deps, objs) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | library.exportIncludes(ctx, "-I") |
| 697 | library.reexportFlags(deps.ReexportedFlags) |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 698 | library.reexportDeps(deps.ReexportedFlagsDeps) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 699 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 700 | if Bool(library.Properties.Aidl.Export_aidl_headers) { |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 701 | if library.baseCompiler.hasSrcExt(".aidl") { |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 702 | flags := []string{ |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 703 | "-I" + android.PathForModuleGen(ctx, "aidl").String(), |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 704 | } |
| 705 | library.reexportFlags(flags) |
| 706 | library.reuseExportedFlags = append(library.reuseExportedFlags, flags...) |
Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 707 | library.reexportDeps(library.baseCompiler.pathDeps) // TODO: restrict to aidl deps |
| 708 | library.reuseExportedDeps = append(library.reuseExportedDeps, library.baseCompiler.pathDeps...) |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 712 | if Bool(library.Properties.Proto.Export_proto_headers) { |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 713 | if library.baseCompiler.hasSrcExt(".proto") { |
Dan Willemsen | ab9f426 | 2018-02-14 13:58:34 -0800 | [diff] [blame] | 714 | includes := []string{} |
| 715 | if flags.ProtoRoot { |
| 716 | includes = append(includes, "-I"+android.ProtoSubDir(ctx).String()) |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 717 | } |
Dan Willemsen | ab9f426 | 2018-02-14 13:58:34 -0800 | [diff] [blame] | 718 | includes = append(includes, "-I"+android.ProtoDir(ctx).String()) |
| 719 | library.reexportFlags(includes) |
| 720 | library.reuseExportedFlags = append(library.reuseExportedFlags, includes...) |
Pirama Arumuga Nainar | f231b19 | 2018-01-23 10:49:04 -0800 | [diff] [blame] | 721 | library.reexportDeps(library.baseCompiler.pathDeps) // TODO: restrict to proto deps |
| 722 | library.reuseExportedDeps = append(library.reuseExportedDeps, library.baseCompiler.pathDeps...) |
Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | |
Inseob Kim | 21f2690 | 2018-09-06 00:55:20 +0900 | [diff] [blame] | 726 | if library.baseCompiler.hasSrcExt(".sysprop") { |
| 727 | flags := []string{ |
| 728 | "-I" + android.PathForModuleGen(ctx, "sysprop", "include").String(), |
| 729 | } |
| 730 | library.reexportFlags(flags) |
| 731 | library.reuseExportedFlags = append(library.reuseExportedFlags, flags...) |
| 732 | } |
| 733 | |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame^] | 734 | if library.buildStubs() { |
| 735 | library.reexportFlags([]string{"-D" + versioningMacroName(ctx.ModuleName()) + "=" + library.stubsVersion()}) |
| 736 | } |
| 737 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 738 | return out |
| 739 | } |
| 740 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 741 | func (library *libraryDecorator) buildStatic() bool { |
Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 742 | return library.MutatedProperties.BuildStatic && BoolDefault(library.Properties.Static.Enabled, true) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 745 | func (library *libraryDecorator) buildShared() bool { |
Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 746 | return library.MutatedProperties.BuildShared && BoolDefault(library.Properties.Shared.Enabled, true) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 749 | func (library *libraryDecorator) getWholeStaticMissingDeps() []string { |
Colin Cross | d2343a3 | 2018-04-30 14:50:01 -0700 | [diff] [blame] | 750 | return append([]string(nil), library.wholeStaticMissingDeps...) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 753 | func (library *libraryDecorator) objs() Objects { |
| 754 | return library.objects |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 755 | } |
| 756 | |
Colin Cross | bbc9f4d | 2017-05-03 16:24:55 -0700 | [diff] [blame] | 757 | func (library *libraryDecorator) reuseObjs() (Objects, []string, android.Paths) { |
| 758 | return library.reuseObjects, library.reuseExportedFlags, library.reuseExportedDeps |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 761 | func (library *libraryDecorator) toc() android.OptionalPath { |
| 762 | return library.tocFile |
| 763 | } |
| 764 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 765 | func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) { |
Colin Cross | c43ae77 | 2017-04-14 15:42:53 -0700 | [diff] [blame] | 766 | if library.shared() { |
Justin Yun | 8fe1212 | 2017-12-07 17:18:15 +0900 | [diff] [blame] | 767 | if ctx.Device() && ctx.useVndk() { |
| 768 | if ctx.isVndkSp() { |
| 769 | library.baseInstaller.subDir = "vndk-sp" |
| 770 | } else if ctx.isVndk() { |
| 771 | library.baseInstaller.subDir = "vndk" |
| 772 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 773 | |
| 774 | // Append a version to vndk or vndk-sp directories on the system partition. |
| 775 | if ctx.isVndk() && !ctx.isVndkExt() { |
| 776 | vndkVersion := ctx.DeviceConfig().PlatformVndkVersion() |
| 777 | if vndkVersion != "current" && vndkVersion != "" { |
| 778 | library.baseInstaller.subDir += "-" + vndkVersion |
| 779 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 780 | } |
| 781 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 782 | library.baseInstaller.install(ctx, file) |
| 783 | } |
Dan Albert | f563d25 | 2017-10-13 00:29:00 -0700 | [diff] [blame] | 784 | |
Dan Albert | 281f22b | 2017-12-13 15:03:47 -0800 | [diff] [blame] | 785 | if Bool(library.Properties.Static_ndk_lib) && library.static() && |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 786 | !ctx.useVndk() && !ctx.inRecovery() && ctx.Device() && |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 787 | library.baseLinker.sanitize.isUnsanitizedVariant() && |
| 788 | !library.buildStubs() { |
Dan Albert | f563d25 | 2017-10-13 00:29:00 -0700 | [diff] [blame] | 789 | installPath := getNdkSysrootBase(ctx).Join( |
Dan Albert | ea4b7b9 | 2018-04-25 16:05:30 -0700 | [diff] [blame] | 790 | ctx, "usr/lib", config.NDKTriple(ctx.toolchain()), file.Base()) |
Dan Albert | f563d25 | 2017-10-13 00:29:00 -0700 | [diff] [blame] | 791 | |
| 792 | ctx.ModuleBuild(pctx, android.ModuleBuildParams{ |
| 793 | Rule: android.Cp, |
| 794 | Description: "install " + installPath.Base(), |
| 795 | Output: installPath, |
| 796 | Input: file, |
| 797 | }) |
| 798 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 799 | library.ndkSysrootPath = installPath |
Dan Albert | f563d25 | 2017-10-13 00:29:00 -0700 | [diff] [blame] | 800 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 803 | func (library *libraryDecorator) static() bool { |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 804 | return library.MutatedProperties.VariantIsStatic |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 807 | func (library *libraryDecorator) shared() bool { |
| 808 | return library.MutatedProperties.VariantIsShared |
| 809 | } |
| 810 | |
| 811 | func (library *libraryDecorator) header() bool { |
| 812 | return !library.static() && !library.shared() |
| 813 | } |
| 814 | |
| 815 | func (library *libraryDecorator) setStatic() { |
| 816 | library.MutatedProperties.VariantIsStatic = true |
| 817 | library.MutatedProperties.VariantIsShared = false |
| 818 | } |
| 819 | |
| 820 | func (library *libraryDecorator) setShared() { |
| 821 | library.MutatedProperties.VariantIsStatic = false |
| 822 | library.MutatedProperties.VariantIsShared = true |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 825 | func (library *libraryDecorator) BuildOnlyStatic() { |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 826 | library.MutatedProperties.BuildShared = false |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | func (library *libraryDecorator) BuildOnlyShared() { |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 830 | library.MutatedProperties.BuildStatic = false |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 831 | } |
| 832 | |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 833 | func (library *libraryDecorator) HeaderOnly() { |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 834 | library.MutatedProperties.BuildShared = false |
| 835 | library.MutatedProperties.BuildStatic = false |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 836 | } |
| 837 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 838 | func (library *libraryDecorator) buildStubs() bool { |
| 839 | return library.MutatedProperties.BuildStubs |
| 840 | } |
| 841 | |
| 842 | func (library *libraryDecorator) stubsVersion() string { |
| 843 | return library.MutatedProperties.StubsVersion |
| 844 | } |
| 845 | |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame^] | 846 | func versioningMacroNamesList(config android.Config) *map[string]string { |
| 847 | return config.Once("versioningMacroNamesList", func() interface{} { |
| 848 | m := make(map[string]string) |
| 849 | return &m |
| 850 | }).(*map[string]string) |
| 851 | } |
| 852 | |
| 853 | // alphanumeric and _ characters are preserved. |
| 854 | // other characters are all converted to _ |
| 855 | var charsNotForMacro = regexp.MustCompile("[^a-zA-Z0-9_]+") |
| 856 | |
| 857 | func versioningMacroName(moduleName string) string { |
| 858 | macroName := charsNotForMacro.ReplaceAllString(moduleName, "_") |
| 859 | macroName = strings.ToUpper(moduleName) |
| 860 | return "__" + macroName + "_API__" |
| 861 | } |
| 862 | |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 863 | func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 864 | module := newModule(hod, android.MultilibBoth) |
| 865 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 866 | library := &libraryDecorator{ |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 867 | MutatedProperties: LibraryMutatedProperties{ |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 868 | BuildShared: true, |
| 869 | BuildStatic: true, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 870 | }, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 871 | baseCompiler: NewBaseCompiler(), |
Dan Albert | 61f3212 | 2018-07-26 14:00:24 -0700 | [diff] [blame] | 872 | baseLinker: NewBaseLinker(module.sanitize), |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 873 | baseInstaller: NewBaseInstaller("lib", "lib64", InstallInSystem), |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 874 | sabi: module.sabi, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 877 | module.compiler = library |
| 878 | module.linker = library |
| 879 | module.installer = library |
| 880 | |
| 881 | return module, library |
| 882 | } |
| 883 | |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 884 | // connects a shared library to a static library in order to reuse its .o files to avoid |
| 885 | // compiling source files twice. |
| 886 | func reuseStaticLibrary(mctx android.BottomUpMutatorContext, static, shared *Module) { |
| 887 | if staticCompiler, ok := static.compiler.(*libraryDecorator); ok { |
| 888 | sharedCompiler := shared.compiler.(*libraryDecorator) |
| 889 | if len(staticCompiler.Properties.Static.Cflags) == 0 && |
| 890 | len(sharedCompiler.Properties.Shared.Cflags) == 0 { |
| 891 | |
| 892 | mctx.AddInterVariantDependency(reuseObjTag, shared, static) |
| 893 | sharedCompiler.baseCompiler.Properties.OriginalSrcs = |
| 894 | sharedCompiler.baseCompiler.Properties.Srcs |
| 895 | sharedCompiler.baseCompiler.Properties.Srcs = nil |
| 896 | sharedCompiler.baseCompiler.Properties.Generated_sources = nil |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 901 | func LinkageMutator(mctx android.BottomUpMutatorContext) { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 902 | if m, ok := mctx.Module().(*Module); ok && m.linker != nil { |
| 903 | if library, ok := m.linker.(libraryInterface); ok { |
| 904 | var modules []blueprint.Module |
| 905 | if library.buildStatic() && library.buildShared() { |
| 906 | modules = mctx.CreateLocalVariations("static", "shared") |
| 907 | static := modules[0].(*Module) |
| 908 | shared := modules[1].(*Module) |
| 909 | |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 910 | static.linker.(libraryInterface).setStatic() |
| 911 | shared.linker.(libraryInterface).setShared() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 912 | |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 913 | reuseStaticLibrary(mctx, static, shared) |
| 914 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 915 | } else if library.buildStatic() { |
| 916 | modules = mctx.CreateLocalVariations("static") |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 917 | modules[0].(*Module).linker.(libraryInterface).setStatic() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 918 | } else if library.buildShared() { |
| 919 | modules = mctx.CreateLocalVariations("shared") |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 920 | modules[0].(*Module).linker.(libraryInterface).setShared() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 924 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 925 | |
| 926 | // Version mutator splits a module into the mandatory non-stubs variant |
| 927 | // (which is named "impl") and zero or more stubs variants. |
| 928 | func versionMutator(mctx android.BottomUpMutatorContext) { |
| 929 | if mctx.Os() != android.Android { |
| 930 | return |
| 931 | } |
| 932 | |
| 933 | if m, ok := mctx.Module().(*Module); ok && !m.inRecovery() && m.linker != nil { |
| 934 | if library, ok := m.linker.(*libraryDecorator); ok && library.buildShared() { |
| 935 | versions := []string{""} |
| 936 | for _, v := range library.Properties.Stubs.Versions { |
| 937 | versions = append(versions, v) |
| 938 | } |
| 939 | modules := mctx.CreateVariations(versions...) |
| 940 | for i, m := range modules { |
| 941 | l := m.(*Module).linker.(*libraryDecorator) |
| 942 | if i == 0 { |
| 943 | l.MutatedProperties.BuildStubs = false |
| 944 | continue |
| 945 | } |
| 946 | // Mark that this variant is for stubs. |
| 947 | l.MutatedProperties.BuildStubs = true |
| 948 | l.MutatedProperties.StubsVersion = versions[i] |
| 949 | m.(*Module).Properties.HideFromMake = true |
| 950 | } |
| 951 | } else { |
| 952 | mctx.CreateVariations("") |
| 953 | } |
| 954 | return |
| 955 | } |
| 956 | if genrule, ok := mctx.Module().(*genrule.Module); ok { |
| 957 | if props, ok := genrule.Extra.(*GenruleExtraProperties); ok && !props.InRecovery { |
| 958 | mctx.CreateVariations("") |
| 959 | return |
| 960 | } |
| 961 | } |
| 962 | } |