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