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