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