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