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