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