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