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