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