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