blob: 71a9df656412a1f44bda7c3e2e6e78824a68dc2c [file] [log] [blame]
Colin Cross4d9c2d12016-07-29 12:48:20 -07001// 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
15package cc
16
17import (
Jiyong Parkda732bd2018-11-02 18:23:15 +090018 "regexp"
Jiyong Park25fc6a92018-11-18 18:02:45 +090019 "sort"
20 "strconv"
Colin Cross4d9c2d12016-07-29 12:48:20 -070021 "strings"
Jiyong Parkda732bd2018-11-02 18:23:15 +090022 "sync"
Colin Cross4d9c2d12016-07-29 12:48:20 -070023
24 "github.com/google/blueprint"
Colin Cross26c34ed2016-09-30 17:10:16 -070025 "github.com/google/blueprint/pathtools"
Colin Cross4d9c2d12016-07-29 12:48:20 -070026
Colin Cross4d9c2d12016-07-29 12:48:20 -070027 "android/soong/android"
Dan Albertea4b7b92018-04-25 16:05:30 -070028 "android/soong/cc/config"
Jiyong Park7ed9de32018-10-15 22:25:07 +090029 "android/soong/genrule"
Colin Cross4d9c2d12016-07-29 12:48:20 -070030)
31
Colin Crosseefe9a32019-01-22 14:41:08 -080032type StaticSharedLibraryProperties struct {
Colin Cross27b922f2019-03-04 22:35:41 -080033 Srcs []string `android:"path,arch_variant"`
34 Cflags []string `android:"path,arch_variant"`
Colin Crosseefe9a32019-01-22 14:41:08 -080035
36 Enabled *bool `android:"arch_variant"`
37 Whole_static_libs []string `android:"arch_variant"`
38 Static_libs []string `android:"arch_variant"`
39 Shared_libs []string `android:"arch_variant"`
40 System_shared_libs []string `android:"arch_variant"`
41
42 Export_shared_lib_headers []string `android:"arch_variant"`
43 Export_static_lib_headers []string `android:"arch_variant"`
44}
45
Colin Crossb916a382016-07-29 17:28:03 -070046type LibraryProperties struct {
Colin Crosseefe9a32019-01-22 14:41:08 -080047 Static StaticSharedLibraryProperties `android:"arch_variant"`
48 Shared StaticSharedLibraryProperties `android:"arch_variant"`
Colin Cross4d9c2d12016-07-29 12:48:20 -070049
Colin Cross4d9c2d12016-07-29 12:48:20 -070050 // local file name to pass to the linker as -unexported_symbols_list
Colin Cross27b922f2019-03-04 22:35:41 -080051 Unexported_symbols_list *string `android:"path,arch_variant"`
Colin Cross4d9c2d12016-07-29 12:48:20 -070052 // local file name to pass to the linker as -force_symbols_not_weak_list
Colin Cross27b922f2019-03-04 22:35:41 -080053 Force_symbols_not_weak_list *string `android:"path,arch_variant"`
Colin Cross4d9c2d12016-07-29 12:48:20 -070054 // local file name to pass to the linker as -force_symbols_weak_list
Colin Cross27b922f2019-03-04 22:35:41 -080055 Force_symbols_weak_list *string `android:"path,arch_variant"`
Colin Cross4d9c2d12016-07-29 12:48:20 -070056
57 // rename host libraries to prevent overlap with system installed libraries
58 Unique_host_soname *bool
59
Dan Willemsene1240db2016-11-03 14:28:51 -070060 Aidl struct {
61 // export headers generated from .aidl sources
Nan Zhang0007d812017-11-07 10:57:05 -080062 Export_aidl_headers *bool
Dan Willemsene1240db2016-11-03 14:28:51 -070063 }
64
Colin Cross0c461f12016-10-20 16:11:43 -070065 Proto struct {
66 // export headers generated from .proto sources
Nan Zhang0007d812017-11-07 10:57:05 -080067 Export_proto_headers *bool
Colin Cross0c461f12016-10-20 16:11:43 -070068 }
Dan Albertf563d252017-10-13 00:29:00 -070069
Inseob Kimc0907f12019-02-08 21:00:45 +090070 Sysprop struct {
71 // Whether platform owns this sysprop library.
72 Platform *bool
Inseob Kimb3f22ca2019-03-05 12:40:24 +090073 } `blueprint:"mutated"`
Inseob Kimc0907f12019-02-08 21:00:45 +090074
Nan Zhang0007d812017-11-07 10:57:05 -080075 Static_ndk_lib *bool
Jiyong Park7ed9de32018-10-15 22:25:07 +090076
77 Stubs struct {
78 // Relative path to the symbol map. The symbol map provides the list of
79 // symbols that are exported for stubs variant of this library.
Colin Cross27b922f2019-03-04 22:35:41 -080080 Symbol_file *string `android:"path"`
Jiyong Park7ed9de32018-10-15 22:25:07 +090081
82 // List versions to generate stubs libs for.
83 Versions []string
84 }
dimitryd95964a2018-11-07 13:43:34 +010085
86 // set the name of the output
87 Stem *string `android:"arch_variant"`
88
89 // Names of modules to be overridden. Listed modules can only be other shared libraries
90 // (in Make or Soong).
91 // This does not completely prevent installation of the overridden libraries, but if both
92 // binaries would be installed by default (in PRODUCT_PACKAGES) the other library will be removed
93 // from PRODUCT_PACKAGES.
94 Overrides []string
Logan Chiene3d7a0d2019-01-17 00:18:02 +080095
96 // Properties for ABI compatibility checker
97 Header_abi_checker struct {
98 // Path to a symbol file that specifies the symbols to be included in the generated
99 // ABI dump file
Colin Cross27b922f2019-03-04 22:35:41 -0800100 Symbol_file *string `android:"path"`
Logan Chiene3d7a0d2019-01-17 00:18:02 +0800101
102 // Symbol versions that should be ignored from the symbol file
103 Exclude_symbol_versions []string
104
105 // Symbol tags that should be ignored from the symbol file
106 Exclude_symbol_tags []string
107 }
Colin Crossa48ab5b2017-02-14 15:28:44 -0800108}
Colin Cross0c461f12016-10-20 16:11:43 -0700109
Colin Crossa48ab5b2017-02-14 15:28:44 -0800110type LibraryMutatedProperties struct {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700111 VariantName string `blueprint:"mutated"`
Colin Crossb916a382016-07-29 17:28:03 -0700112
113 // Build a static variant
114 BuildStatic bool `blueprint:"mutated"`
115 // Build a shared variant
116 BuildShared bool `blueprint:"mutated"`
117 // This variant is shared
118 VariantIsShared bool `blueprint:"mutated"`
119 // This variant is static
120 VariantIsStatic bool `blueprint:"mutated"`
Jiyong Park7ed9de32018-10-15 22:25:07 +0900121
122 // This variant is a stubs lib
123 BuildStubs bool `blueprint:"mutated"`
124 // Version of the stubs lib
125 StubsVersion string `blueprint:"mutated"`
Colin Crossb916a382016-07-29 17:28:03 -0700126}
127
128type FlagExporterProperties struct {
129 // list of directories relative to the Blueprints file that will
Dan Willemsen273af7f2016-11-03 15:53:42 -0700130 // be added to the include path (using -I) for this module and any module that links
Colin Cross5d195602017-10-17 16:15:50 -0700131 // against this module. Directories listed in export_include_dirs do not need to be
132 // listed in local_include_dirs.
Colin Crossb916a382016-07-29 17:28:03 -0700133 Export_include_dirs []string `android:"arch_variant"`
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700134
135 Target struct {
136 Vendor struct {
137 // list of exported include directories, like
138 // export_include_dirs, that will be applied to the
139 // vendor variant of this library. This will overwrite
140 // any other declarations.
Steven Morelandb21df8f2018-01-05 14:42:54 -0800141 Override_export_include_dirs []string
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700142 }
143 }
Colin Cross4d9c2d12016-07-29 12:48:20 -0700144}
145
146func init() {
Steven Morelandf9e62162017-11-02 17:00:50 -0700147 android.RegisterModuleType("cc_library_static", LibraryStaticFactory)
148 android.RegisterModuleType("cc_library_shared", LibrarySharedFactory)
149 android.RegisterModuleType("cc_library", LibraryFactory)
150 android.RegisterModuleType("cc_library_host_static", LibraryHostStaticFactory)
151 android.RegisterModuleType("cc_library_host_shared", LibraryHostSharedFactory)
152 android.RegisterModuleType("cc_library_headers", LibraryHeaderFactory)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700153}
154
155// Module factory for combined static + shared libraries, device by default but with possible host
156// support
Steven Morelandf9e62162017-11-02 17:00:50 -0700157func LibraryFactory() android.Module {
Colin Crossab3b7322016-12-09 14:46:15 -0800158 module, _ := NewLibrary(android.HostAndDeviceSupported)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700159 return module.Init()
160}
161
162// Module factory for static libraries
Steven Morelandf9e62162017-11-02 17:00:50 -0700163func LibraryStaticFactory() android.Module {
Colin Crossab3b7322016-12-09 14:46:15 -0800164 module, library := NewLibrary(android.HostAndDeviceSupported)
165 library.BuildOnlyStatic()
Colin Cross4d9c2d12016-07-29 12:48:20 -0700166 return module.Init()
167}
168
169// Module factory for shared libraries
Steven Morelandf9e62162017-11-02 17:00:50 -0700170func LibrarySharedFactory() android.Module {
Colin Crossab3b7322016-12-09 14:46:15 -0800171 module, library := NewLibrary(android.HostAndDeviceSupported)
172 library.BuildOnlyShared()
Colin Cross4d9c2d12016-07-29 12:48:20 -0700173 return module.Init()
174}
175
176// Module factory for host static libraries
Steven Morelandf9e62162017-11-02 17:00:50 -0700177func LibraryHostStaticFactory() android.Module {
Colin Crossab3b7322016-12-09 14:46:15 -0800178 module, library := NewLibrary(android.HostSupported)
179 library.BuildOnlyStatic()
Colin Cross4d9c2d12016-07-29 12:48:20 -0700180 return module.Init()
181}
182
183// Module factory for host shared libraries
Steven Morelandf9e62162017-11-02 17:00:50 -0700184func LibraryHostSharedFactory() android.Module {
Colin Crossab3b7322016-12-09 14:46:15 -0800185 module, library := NewLibrary(android.HostSupported)
186 library.BuildOnlyShared()
Colin Cross4d9c2d12016-07-29 12:48:20 -0700187 return module.Init()
188}
189
Colin Cross5950f382016-12-13 12:50:57 -0800190// Module factory for header-only libraries
Steven Morelandf9e62162017-11-02 17:00:50 -0700191func LibraryHeaderFactory() android.Module {
Colin Cross5950f382016-12-13 12:50:57 -0800192 module, library := NewLibrary(android.HostAndDeviceSupported)
193 library.HeaderOnly()
194 return module.Init()
195}
196
Colin Cross4d9c2d12016-07-29 12:48:20 -0700197type flagExporter struct {
198 Properties FlagExporterProperties
199
Dan Willemsen847dcc72016-09-29 12:13:36 -0700200 flags []string
201 flagsDeps android.Paths
Colin Cross4d9c2d12016-07-29 12:48:20 -0700202}
203
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700204func (f *flagExporter) exportedIncludes(ctx ModuleContext) android.Paths {
Steven Morelandb21df8f2018-01-05 14:42:54 -0800205 if ctx.useVndk() && f.Properties.Target.Vendor.Override_export_include_dirs != nil {
206 return android.PathsForModuleSrc(ctx, f.Properties.Target.Vendor.Override_export_include_dirs)
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700207 } else {
208 return android.PathsForModuleSrc(ctx, f.Properties.Export_include_dirs)
209 }
210}
211
Colin Cross4d9c2d12016-07-29 12:48:20 -0700212func (f *flagExporter) exportIncludes(ctx ModuleContext, inc string) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700213 includeDirs := f.exportedIncludes(ctx)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700214 for _, dir := range includeDirs.Strings() {
215 f.flags = append(f.flags, inc+dir)
216 }
217}
218
219func (f *flagExporter) reexportFlags(flags []string) {
220 f.flags = append(f.flags, flags...)
221}
222
Dan Willemsen847dcc72016-09-29 12:13:36 -0700223func (f *flagExporter) reexportDeps(deps android.Paths) {
224 f.flagsDeps = append(f.flagsDeps, deps...)
225}
226
Colin Cross4d9c2d12016-07-29 12:48:20 -0700227func (f *flagExporter) exportedFlags() []string {
228 return f.flags
229}
230
Dan Willemsen847dcc72016-09-29 12:13:36 -0700231func (f *flagExporter) exportedFlagsDeps() android.Paths {
232 return f.flagsDeps
233}
234
Colin Cross4d9c2d12016-07-29 12:48:20 -0700235type exportedFlagsProducer interface {
236 exportedFlags() []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700237 exportedFlagsDeps() android.Paths
Colin Cross4d9c2d12016-07-29 12:48:20 -0700238}
239
240var _ exportedFlagsProducer = (*flagExporter)(nil)
241
Colin Crossb916a382016-07-29 17:28:03 -0700242// libraryDecorator wraps baseCompiler, baseLinker and baseInstaller to provide library-specific
243// functionality: static vs. shared linkage, reusing object files for shared libraries
244type libraryDecorator struct {
Colin Crossa48ab5b2017-02-14 15:28:44 -0800245 Properties LibraryProperties
246 MutatedProperties LibraryMutatedProperties
Colin Cross4d9c2d12016-07-29 12:48:20 -0700247
248 // For reusing static library objects for shared library
Colin Cross10d22312017-05-03 11:01:58 -0700249 reuseObjects Objects
250 reuseExportedFlags []string
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700251 reuseExportedDeps android.Paths
Colin Cross10d22312017-05-03 11:01:58 -0700252
Colin Cross26c34ed2016-09-30 17:10:16 -0700253 // table-of-contents file to optimize out relinking when possible
254 tocFile android.OptionalPath
Colin Cross4d9c2d12016-07-29 12:48:20 -0700255
Colin Cross4d9c2d12016-07-29 12:48:20 -0700256 flagExporter
257 stripper
258
Colin Cross4d9c2d12016-07-29 12:48:20 -0700259 // If we're used as a whole_static_lib, our missing dependencies need
260 // to be given
261 wholeStaticMissingDeps []string
262
263 // For whole_static_libs
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700264 objects Objects
Colin Cross4d9c2d12016-07-29 12:48:20 -0700265
266 // Uses the module's name if empty, but can be overridden. Does not include
267 // shlib suffix.
268 libName string
Colin Crossb916a382016-07-29 17:28:03 -0700269
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800270 sabi *sabi
271
Dan Willemsen581341d2017-02-09 16:16:31 -0800272 // Output archive of gcno coverage information files
273 coverageOutputFile android.OptionalPath
274
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800275 // linked Source Abi Dump
276 sAbiOutputFile android.OptionalPath
277
278 // Source Abi Diff
279 sAbiDiff android.OptionalPath
280
Colin Cross0875c522017-11-28 17:34:01 -0800281 // Location of the static library in the sysroot. Empty if the library is
282 // not included in the NDK.
283 ndkSysrootPath android.Path
284
Colin Crossb60190a2018-09-04 16:28:17 -0700285 // Location of the linked, unstripped library for shared libraries
286 unstrippedOutputFile android.Path
287
Dan Willemsen569edc52018-11-19 09:33:29 -0800288 // Location of the file that should be copied to dist dir when requested
289 distFile android.OptionalPath
290
Jiyong Park7ed9de32018-10-15 22:25:07 +0900291 versionScriptPath android.ModuleGenPath
292
Colin Crossb916a382016-07-29 17:28:03 -0700293 // Decorated interafaces
294 *baseCompiler
295 *baseLinker
296 *baseInstaller
Colin Cross4d9c2d12016-07-29 12:48:20 -0700297}
298
Colin Crossb916a382016-07-29 17:28:03 -0700299func (library *libraryDecorator) linkerProps() []interface{} {
300 var props []interface{}
301 props = append(props, library.baseLinker.linkerProps()...)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700302 return append(props,
303 &library.Properties,
Colin Crossa48ab5b2017-02-14 15:28:44 -0800304 &library.MutatedProperties,
Colin Cross4d9c2d12016-07-29 12:48:20 -0700305 &library.flagExporter.Properties,
Colin Cross22f37952018-09-05 10:43:13 -0700306 &library.stripper.StripProperties)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700307}
308
Colin Crossb916a382016-07-29 17:28:03 -0700309func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Colin Cross42742b82016-08-01 13:20:05 -0700310 flags = library.baseLinker.linkerFlags(ctx, flags)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700311
Colin Crossb916a382016-07-29 17:28:03 -0700312 // MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
313 // all code is position independent, and then those warnings get promoted to
314 // errors.
Colin Cross3edeee12017-04-04 12:59:48 -0700315 if !ctx.Windows() {
Colin Crossb916a382016-07-29 17:28:03 -0700316 flags.CFlags = append(flags.CFlags, "-fPIC")
317 }
318
319 if library.static() {
320 flags.CFlags = append(flags.CFlags, library.Properties.Static.Cflags...)
Colin Crossa48ab5b2017-02-14 15:28:44 -0800321 } else if library.shared() {
Colin Crossb916a382016-07-29 17:28:03 -0700322 flags.CFlags = append(flags.CFlags, library.Properties.Shared.Cflags...)
323 }
324
Colin Crossa48ab5b2017-02-14 15:28:44 -0800325 if library.shared() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700326 libName := library.getLibName(ctx)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700327 var f []string
Dan Willemsen01a405a2016-06-13 17:19:03 -0700328 if ctx.toolchain().Bionic() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700329 f = append(f,
330 "-nostdlib",
331 "-Wl,--gc-sections",
332 )
333 }
334
335 if ctx.Darwin() {
336 f = append(f,
337 "-dynamiclib",
338 "-single_module",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700339 "-install_name @rpath/"+libName+flags.Toolchain.ShlibSuffix(),
340 )
Colin Cross7863cf52016-10-20 10:47:21 -0700341 if ctx.Arch().ArchType == android.X86 {
342 f = append(f,
343 "-read_only_relocs suppress",
344 )
345 }
Colin Cross4d9c2d12016-07-29 12:48:20 -0700346 } else {
347 f = append(f,
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700348 "-shared",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700349 "-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix())
350 }
351
352 flags.LdFlags = append(f, flags.LdFlags...)
353 }
354
355 return flags
356}
357
Colin Crossf18e1102017-11-16 14:33:08 -0800358func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700359 exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
Dan Willemsen273af7f2016-11-03 15:53:42 -0700360 if len(exportIncludeDirs) > 0 {
Colin Crossdad8c952017-04-26 14:55:27 -0700361 f := includeDirsToFlags(exportIncludeDirs)
362 flags.GlobalFlags = append(flags.GlobalFlags, f)
363 flags.YasmFlags = append(flags.YasmFlags, f)
Dan Willemsen273af7f2016-11-03 15:53:42 -0700364 }
365
Jiyong Park7ed9de32018-10-15 22:25:07 +0900366 flags = library.baseCompiler.compilerFlags(ctx, flags, deps)
367 if library.buildStubs() {
Jiyong Park64379952018-12-13 18:37:29 +0900368 // Remove -include <file> when compiling stubs. Otherwise, the force included
369 // headers might cause conflicting types error with the symbols in the
370 // generated stubs source code. e.g.
371 // double acos(double); // in header
372 // void acos() {} // in the generated source code
373 removeInclude := func(flags []string) []string {
374 ret := flags[:0]
375 for _, f := range flags {
376 if strings.HasPrefix(f, "-include ") {
377 continue
378 }
379 ret = append(ret, f)
380 }
381 return ret
382 }
383 flags.GlobalFlags = removeInclude(flags.GlobalFlags)
384 flags.CFlags = removeInclude(flags.CFlags)
385
Jiyong Park7ed9de32018-10-15 22:25:07 +0900386 flags = addStubLibraryCompilerFlags(flags)
387 }
388 return flags
Dan Willemsen273af7f2016-11-03 15:53:42 -0700389}
390
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700391func extractExportIncludesFromFlags(flags []string) []string {
392 // This method is used in the generation of rules which produce
393 // abi-dumps for source files. Exported headers are needed to infer the
394 // abi exported by a library and filter out the rest of the abi dumped
395 // from a source. We extract the include flags exported by a library.
396 // This includes the flags exported which are re-exported from static
397 // library dependencies, exported header library dependencies and
Jayant Chowdharyaf6eb712017-08-23 16:08:29 -0700398 // generated header dependencies. -isystem headers are not included
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700399 // since for bionic libraries, abi-filtering is taken care of by version
400 // scripts.
401 var exportedIncludes []string
402 for _, flag := range flags {
403 if strings.HasPrefix(flag, "-I") {
404 exportedIncludes = append(exportedIncludes, flag)
405 }
406 }
407 return exportedIncludes
408}
409
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700410func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
Jiyong Park7ed9de32018-10-15 22:25:07 +0900411 if library.buildStubs() {
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900412 objs, versionScript := compileStubLibrary(ctx, flags, String(library.Properties.Stubs.Symbol_file), library.MutatedProperties.StubsVersion, "--apex")
Jiyong Park7ed9de32018-10-15 22:25:07 +0900413 library.versionScriptPath = versionScript
414 return objs
415 }
416
Colin Cross5950f382016-12-13 12:50:57 -0800417 if !library.buildShared() && !library.buildStatic() {
418 if len(library.baseCompiler.Properties.Srcs) > 0 {
419 ctx.PropertyErrorf("srcs", "cc_library_headers must not have any srcs")
420 }
421 if len(library.Properties.Static.Srcs) > 0 {
422 ctx.PropertyErrorf("static.srcs", "cc_library_headers must not have any srcs")
423 }
424 if len(library.Properties.Shared.Srcs) > 0 {
425 ctx.PropertyErrorf("shared.srcs", "cc_library_headers must not have any srcs")
426 }
427 return Objects{}
428 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800429 if ctx.shouldCreateVndkSourceAbiDump() || library.sabi.Properties.CreateSAbiDumps {
Jayant Chowdharya4fce192017-09-06 13:10:03 -0700430 exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800431 var SourceAbiFlags []string
432 for _, dir := range exportIncludeDirs.Strings() {
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700433 SourceAbiFlags = append(SourceAbiFlags, "-I"+dir)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800434 }
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700435 for _, reexportedInclude := range extractExportIncludesFromFlags(library.sabi.Properties.ReexportedIncludeFlags) {
436 SourceAbiFlags = append(SourceAbiFlags, reexportedInclude)
437 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800438 flags.SAbiFlags = SourceAbiFlags
439 total_length := len(library.baseCompiler.Properties.Srcs) + len(deps.GeneratedSources) + len(library.Properties.Shared.Srcs) +
440 len(library.Properties.Static.Srcs)
441 if total_length > 0 {
442 flags.SAbiDump = true
443 }
444 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700445 objs := library.baseCompiler.compile(ctx, flags, deps)
446 library.reuseObjects = objs
Colin Cross2f336352016-10-26 10:03:47 -0700447 buildFlags := flagsToBuilderFlags(flags)
Colin Crossb916a382016-07-29 17:28:03 -0700448
Colin Cross4d9c2d12016-07-29 12:48:20 -0700449 if library.static() {
dimitry0345ad82018-12-05 16:28:14 +0100450 srcs := ctx.ExpandSources(library.Properties.Static.Srcs, nil)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700451 objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceStaticLibrary,
Pirama Arumuga Nainarf231b192018-01-23 10:49:04 -0800452 srcs, library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps))
Colin Crossa48ab5b2017-02-14 15:28:44 -0800453 } else if library.shared() {
dimitry0345ad82018-12-05 16:28:14 +0100454 srcs := ctx.ExpandSources(library.Properties.Shared.Srcs, nil)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700455 objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceSharedLibrary,
Pirama Arumuga Nainarf231b192018-01-23 10:49:04 -0800456 srcs, library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps))
Colin Crossb916a382016-07-29 17:28:03 -0700457 }
458
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700459 return objs
Colin Crossb916a382016-07-29 17:28:03 -0700460}
461
462type libraryInterface interface {
463 getWholeStaticMissingDeps() []string
464 static() bool
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700465 objs() Objects
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700466 reuseObjs() (Objects, []string, android.Paths)
Colin Cross26c34ed2016-09-30 17:10:16 -0700467 toc() android.OptionalPath
Colin Crossb916a382016-07-29 17:28:03 -0700468
469 // Returns true if the build options for the module have selected a static or shared build
470 buildStatic() bool
471 buildShared() bool
472
473 // Sets whether a specific variant is static or shared
Colin Crossa48ab5b2017-02-14 15:28:44 -0800474 setStatic()
475 setShared()
Colin Crossb916a382016-07-29 17:28:03 -0700476}
477
478func (library *libraryDecorator) getLibName(ctx ModuleContext) string {
479 name := library.libName
480 if name == "" {
dimitryd95964a2018-11-07 13:43:34 +0100481 name = String(library.Properties.Stem)
482 if name == "" {
483 name = ctx.baseModuleName()
484 }
Colin Crossb916a382016-07-29 17:28:03 -0700485 }
486
Logan Chienf3511742017-10-31 18:04:35 +0800487 if ctx.isVndkExt() {
488 name = ctx.getVndkExtendsModuleName()
489 }
490
Colin Crossb916a382016-07-29 17:28:03 -0700491 if ctx.Host() && Bool(library.Properties.Unique_host_soname) {
492 if !strings.HasSuffix(name, "-host") {
493 name = name + "-host"
494 }
495 }
496
Colin Crossa48ab5b2017-02-14 15:28:44 -0800497 return name + library.MutatedProperties.VariantName
Colin Crossb916a382016-07-29 17:28:03 -0700498}
499
Jiyong Parkda732bd2018-11-02 18:23:15 +0900500var versioningMacroNamesListMutex sync.Mutex
501
Colin Crossb916a382016-07-29 17:28:03 -0700502func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) {
503 location := InstallInSystem
Dan Albert61f32122018-07-26 14:00:24 -0700504 if library.baseLinker.sanitize.inSanitizerDir() {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700505 location = InstallInSanitizerDir
Colin Crossb916a382016-07-29 17:28:03 -0700506 }
507 library.baseInstaller.location = location
Colin Crossb916a382016-07-29 17:28:03 -0700508 library.baseLinker.linkerInit(ctx)
Jiyong Park7ed9de32018-10-15 22:25:07 +0900509 // Let baseLinker know whether this variant is for stubs or not, so that
510 // it can omit things that are not required for linking stubs.
511 library.baseLinker.dynamicProperties.BuildStubs = library.buildStubs()
Jiyong Parkda732bd2018-11-02 18:23:15 +0900512
513 if library.buildStubs() {
514 macroNames := versioningMacroNamesList(ctx.Config())
515 myName := versioningMacroName(ctx.ModuleName())
516 versioningMacroNamesListMutex.Lock()
517 defer versioningMacroNamesListMutex.Unlock()
518 if (*macroNames)[myName] == "" {
519 (*macroNames)[myName] = ctx.ModuleName()
520 } else if (*macroNames)[myName] != ctx.ModuleName() {
521 ctx.ModuleErrorf("Macro name %q for versioning conflicts with macro name from module %q ", myName, (*macroNames)[myName])
522 }
523 }
Colin Crossb916a382016-07-29 17:28:03 -0700524}
525
dimitry0345ad82018-12-05 16:28:14 +0100526func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
527 deps = library.baseCompiler.compilerDeps(ctx, deps)
528
dimitry0345ad82018-12-05 16:28:14 +0100529 return deps
530}
531
Colin Cross37047f12016-12-13 17:06:13 -0800532func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
Dan Willemsen3a26eef2018-12-03 15:25:46 -0800533 if library.static() {
534 if library.Properties.Static.System_shared_libs != nil {
535 library.baseLinker.Properties.System_shared_libs = library.Properties.Static.System_shared_libs
536 }
537 } else if library.shared() {
538 if library.Properties.Shared.System_shared_libs != nil {
539 library.baseLinker.Properties.System_shared_libs = library.Properties.Shared.System_shared_libs
540 }
541 }
542
Colin Crossb916a382016-07-29 17:28:03 -0700543 deps = library.baseLinker.linkerDeps(ctx, deps)
544
545 if library.static() {
546 deps.WholeStaticLibs = append(deps.WholeStaticLibs,
547 library.Properties.Static.Whole_static_libs...)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700548 deps.StaticLibs = append(deps.StaticLibs, library.Properties.Static.Static_libs...)
549 deps.SharedLibs = append(deps.SharedLibs, library.Properties.Static.Shared_libs...)
Colin Crosseefe9a32019-01-22 14:41:08 -0800550
551 deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, library.Properties.Static.Export_shared_lib_headers...)
552 deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.Properties.Static.Export_static_lib_headers...)
Colin Crossa48ab5b2017-02-14 15:28:44 -0800553 } else if library.shared() {
Dan Willemsen2e47b342016-11-17 01:02:25 -0800554 if ctx.toolchain().Bionic() && !Bool(library.baseLinker.Properties.Nocrt) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700555 if !ctx.useSdk() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700556 deps.CrtBegin = "crtbegin_so"
557 deps.CrtEnd = "crtend_so"
558 } else {
Dan Albertebedf672016-11-08 15:06:22 -0800559 // TODO(danalbert): Add generation of crt objects.
560 // For `sdk_version: "current"`, we don't actually have a
561 // freshly generated set of CRT objects. Use the last stable
562 // version.
563 version := ctx.sdkVersion()
564 if version == "current" {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -0700565 version = getCurrentNdkPrebuiltVersion(ctx)
Dan Albertebedf672016-11-08 15:06:22 -0800566 }
567 deps.CrtBegin = "ndk_crtbegin_so." + version
568 deps.CrtEnd = "ndk_crtend_so." + version
Colin Cross4d9c2d12016-07-29 12:48:20 -0700569 }
570 }
571 deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.Properties.Shared.Whole_static_libs...)
572 deps.StaticLibs = append(deps.StaticLibs, library.Properties.Shared.Static_libs...)
573 deps.SharedLibs = append(deps.SharedLibs, library.Properties.Shared.Shared_libs...)
Colin Crosseefe9a32019-01-22 14:41:08 -0800574
575 deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, library.Properties.Shared.Export_shared_lib_headers...)
576 deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.Properties.Shared.Export_static_lib_headers...)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700577 }
Jiyong Park52d25bd2017-10-13 09:17:01 +0900578 if ctx.useVndk() {
579 deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, library.baseLinker.Properties.Target.Vendor.Exclude_static_libs)
580 deps.SharedLibs = removeListFromList(deps.SharedLibs, library.baseLinker.Properties.Target.Vendor.Exclude_shared_libs)
581 deps.StaticLibs = removeListFromList(deps.StaticLibs, library.baseLinker.Properties.Target.Vendor.Exclude_static_libs)
Victor Chang51271c12019-01-30 16:02:22 +0000582 deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, library.baseLinker.Properties.Target.Vendor.Exclude_shared_libs)
583 deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, library.baseLinker.Properties.Target.Vendor.Exclude_static_libs)
Jiyong Park52d25bd2017-10-13 09:17:01 +0900584 }
Jiyong Parkf9332f12018-02-01 00:54:12 +0900585 if ctx.inRecovery() {
586 deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, library.baseLinker.Properties.Target.Recovery.Exclude_static_libs)
587 deps.SharedLibs = removeListFromList(deps.SharedLibs, library.baseLinker.Properties.Target.Recovery.Exclude_shared_libs)
588 deps.StaticLibs = removeListFromList(deps.StaticLibs, library.baseLinker.Properties.Target.Recovery.Exclude_static_libs)
Victor Chang51271c12019-01-30 16:02:22 +0000589 deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, library.baseLinker.Properties.Target.Recovery.Exclude_shared_libs)
590 deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, library.baseLinker.Properties.Target.Recovery.Exclude_static_libs)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900591 }
Colin Cross2383f3b2018-02-06 14:40:13 -0800592
Colin Cross4d9c2d12016-07-29 12:48:20 -0700593 return deps
594}
595
Colin Crossb916a382016-07-29 17:28:03 -0700596func (library *libraryDecorator) linkStatic(ctx ModuleContext,
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700597 flags Flags, deps PathDeps, objs Objects) android.Path {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700598
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700599 library.objects = deps.WholeStaticLibObjs.Copy()
600 library.objects = library.objects.Append(objs)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700601
Colin Cross86803cf2018-02-15 14:12:26 -0800602 fileName := ctx.ModuleName() + library.MutatedProperties.VariantName + staticLibraryExtension
603 outputFile := android.PathForModuleOut(ctx, fileName)
Dan Willemsen581341d2017-02-09 16:16:31 -0800604 builderFlags := flagsToBuilderFlags(flags)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700605
Dan Willemsen569edc52018-11-19 09:33:29 -0800606 if Bool(library.baseLinker.Properties.Use_version_lib) {
607 if ctx.Host() {
608 versionedOutputFile := outputFile
609 outputFile = android.PathForModuleOut(ctx, "unversioned", fileName)
610 library.injectVersionSymbol(ctx, outputFile, versionedOutputFile)
611 } else {
612 versionedOutputFile := android.PathForModuleOut(ctx, "versioned", fileName)
613 library.distFile = android.OptionalPathForPath(versionedOutputFile)
614 library.injectVersionSymbol(ctx, outputFile, versionedOutputFile)
615 }
Colin Cross86803cf2018-02-15 14:12:26 -0800616 }
617
Dan Willemsen581341d2017-02-09 16:16:31 -0800618 TransformObjToStaticLib(ctx, library.objects.objFiles, builderFlags, outputFile, objs.tidyFiles)
619
620 library.coverageOutputFile = TransformCoverageFilesToLib(ctx, library.objects, builderFlags,
Colin Crossa48ab5b2017-02-14 15:28:44 -0800621 ctx.ModuleName()+library.MutatedProperties.VariantName)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700622
623 library.wholeStaticMissingDeps = ctx.GetMissingDependencies()
624
625 ctx.CheckbuildFile(outputFile)
626
627 return outputFile
628}
629
Colin Crossb916a382016-07-29 17:28:03 -0700630func (library *libraryDecorator) linkShared(ctx ModuleContext,
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700631 flags Flags, deps PathDeps, objs Objects) android.Path {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700632
633 var linkerDeps android.Paths
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700634 linkerDeps = append(linkerDeps, flags.LdFlagsDeps...)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700635
Colin Cross2383f3b2018-02-06 14:40:13 -0800636 unexportedSymbols := ctx.ExpandOptionalSource(library.Properties.Unexported_symbols_list, "unexported_symbols_list")
637 forceNotWeakSymbols := ctx.ExpandOptionalSource(library.Properties.Force_symbols_not_weak_list, "force_symbols_not_weak_list")
638 forceWeakSymbols := ctx.ExpandOptionalSource(library.Properties.Force_symbols_weak_list, "force_symbols_weak_list")
Colin Cross4d9c2d12016-07-29 12:48:20 -0700639 if !ctx.Darwin() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700640 if unexportedSymbols.Valid() {
641 ctx.PropertyErrorf("unexported_symbols_list", "Only supported on Darwin")
642 }
643 if forceNotWeakSymbols.Valid() {
644 ctx.PropertyErrorf("force_symbols_not_weak_list", "Only supported on Darwin")
645 }
646 if forceWeakSymbols.Valid() {
647 ctx.PropertyErrorf("force_symbols_weak_list", "Only supported on Darwin")
648 }
649 } else {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700650 if unexportedSymbols.Valid() {
651 flags.LdFlags = append(flags.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String())
652 linkerDeps = append(linkerDeps, unexportedSymbols.Path())
653 }
654 if forceNotWeakSymbols.Valid() {
655 flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_not_weak_list,"+forceNotWeakSymbols.String())
656 linkerDeps = append(linkerDeps, forceNotWeakSymbols.Path())
657 }
658 if forceWeakSymbols.Valid() {
659 flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_weak_list,"+forceWeakSymbols.String())
660 linkerDeps = append(linkerDeps, forceWeakSymbols.Path())
661 }
662 }
Jiyong Parkc1e7f482019-01-12 13:39:10 +0900663 if library.buildStubs() {
664 linkerScriptFlags := "-Wl,--version-script," + library.versionScriptPath.String()
665 flags.LdFlags = append(flags.LdFlags, linkerScriptFlags)
666 linkerDeps = append(linkerDeps, library.versionScriptPath)
667 }
Colin Cross4d9c2d12016-07-29 12:48:20 -0700668
669 fileName := library.getLibName(ctx) + flags.Toolchain.ShlibSuffix()
670 outputFile := android.PathForModuleOut(ctx, fileName)
671 ret := outputFile
672
673 builderFlags := flagsToBuilderFlags(flags)
674
Colin Crossb496cfd2018-09-10 16:50:05 -0700675 // Optimize out relinking against shared libraries whose interface hasn't changed by
676 // depending on a table of contents file instead of the library itself.
677 tocPath := outputFile.RelPathString()
678 tocPath = pathtools.ReplaceExtension(tocPath, flags.Toolchain.ShlibSuffix()[1:]+".toc")
679 tocFile := android.PathForOutput(ctx, tocPath)
680 library.tocFile = android.OptionalPathForPath(tocFile)
681 TransformSharedObjectToToc(ctx, outputFile, tocFile, builderFlags)
Colin Cross89562dc2016-10-03 17:47:19 -0700682
Colin Cross4d9c2d12016-07-29 12:48:20 -0700683 if library.stripper.needsStrip(ctx) {
Yi Kongb5c34d72018-11-07 16:28:49 -0800684 if ctx.Darwin() {
685 builderFlags.stripUseGnuStrip = true
686 }
Colin Cross4d9c2d12016-07-29 12:48:20 -0700687 strippedOutputFile := outputFile
688 outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
689 library.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
690 }
691
Colin Crossb60190a2018-09-04 16:28:17 -0700692 library.unstrippedOutputFile = outputFile
693
Dan Willemsen569edc52018-11-19 09:33:29 -0800694 if Bool(library.baseLinker.Properties.Use_version_lib) {
695 if ctx.Host() {
696 versionedOutputFile := outputFile
697 outputFile = android.PathForModuleOut(ctx, "unversioned", fileName)
698 library.injectVersionSymbol(ctx, outputFile, versionedOutputFile)
699 } else {
700 versionedOutputFile := android.PathForModuleOut(ctx, "versioned", fileName)
701 library.distFile = android.OptionalPathForPath(versionedOutputFile)
702
703 if library.stripper.needsStrip(ctx) {
704 out := android.PathForModuleOut(ctx, "versioned-stripped", fileName)
705 library.distFile = android.OptionalPathForPath(out)
706 library.stripper.strip(ctx, versionedOutputFile, out, builderFlags)
707 }
708
709 library.injectVersionSymbol(ctx, outputFile, versionedOutputFile)
710 }
Colin Cross86803cf2018-02-15 14:12:26 -0800711 }
712
Jiyong Park64a44f22019-01-18 14:37:08 +0900713 sharedLibs := deps.EarlySharedLibs
714 sharedLibs = append(sharedLibs, deps.SharedLibs...)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700715 sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
716
Jiyong Park64a44f22019-01-18 14:37:08 +0900717 linkerDeps = append(linkerDeps, deps.EarlySharedLibsDeps...)
Colin Cross26c34ed2016-09-30 17:10:16 -0700718 linkerDeps = append(linkerDeps, deps.SharedLibsDeps...)
719 linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700720 linkerDeps = append(linkerDeps, objs.tidyFiles...)
Colin Cross26c34ed2016-09-30 17:10:16 -0700721
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700722 TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs,
Colin Cross4d9c2d12016-07-29 12:48:20 -0700723 deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
724 linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile)
725
Dan Willemsen581341d2017-02-09 16:16:31 -0800726 objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...)
727 objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800728
729 objs.sAbiDumpFiles = append(objs.sAbiDumpFiles, deps.StaticLibObjs.sAbiDumpFiles...)
730 objs.sAbiDumpFiles = append(objs.sAbiDumpFiles, deps.WholeStaticLibObjs.sAbiDumpFiles...)
731
Dan Willemsen581341d2017-02-09 16:16:31 -0800732 library.coverageOutputFile = TransformCoverageFilesToLib(ctx, objs, builderFlags, library.getLibName(ctx))
Jayant Chowdhary6ab3d842017-06-26 12:52:58 -0700733 library.linkSAbiDumpFiles(ctx, objs, fileName, ret)
Dan Willemsen581341d2017-02-09 16:16:31 -0800734
Colin Cross4d9c2d12016-07-29 12:48:20 -0700735 return ret
736}
737
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900738func (library *libraryDecorator) unstrippedOutputFilePath() android.Path {
739 return library.unstrippedOutputFile
740}
741
Logan Chien7eefdc42018-07-11 18:10:41 +0800742func getRefAbiDumpFile(ctx ModuleContext, vndkVersion, fileName string) android.Path {
Logan Chienf4b79c62018-08-02 02:27:02 +0800743 isLlndk := inList(ctx.baseModuleName(), llndkLibraries) || inList(ctx.baseModuleName(), ndkMigratedLibs)
Logan Chien7eefdc42018-07-11 18:10:41 +0800744
745 refAbiDumpTextFile := android.PathForVndkRefAbiDump(ctx, vndkVersion, fileName, isLlndk, false)
746 refAbiDumpGzipFile := android.PathForVndkRefAbiDump(ctx, vndkVersion, fileName, isLlndk, true)
747
748 if refAbiDumpTextFile.Valid() {
749 if refAbiDumpGzipFile.Valid() {
750 ctx.ModuleErrorf(
751 "Two reference ABI dump files are found: %q and %q. Please delete the stale one.",
752 refAbiDumpTextFile, refAbiDumpGzipFile)
753 return nil
754 }
755 return refAbiDumpTextFile.Path()
756 }
757 if refAbiDumpGzipFile.Valid() {
758 return UnzipRefDump(ctx, refAbiDumpGzipFile.Path(), fileName)
759 }
760 return nil
761}
762
Jayant Chowdhary6ab3d842017-06-26 12:52:58 -0700763func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objects, fileName string, soFile android.Path) {
Logan Chien2f2b8902018-07-10 15:01:19 +0800764 if len(objs.sAbiDumpFiles) > 0 && ctx.shouldCreateVndkSourceAbiDump() {
Logan Chiena8f51582018-03-21 11:53:48 +0800765 vndkVersion := ctx.DeviceConfig().PlatformVndkVersion()
766 if ver := ctx.DeviceConfig().VndkVersion(); ver != "" && ver != "current" {
Logan Chienf3511742017-10-31 18:04:35 +0800767 vndkVersion = ver
768 }
769
Jayant Chowdharya4fce192017-09-06 13:10:03 -0700770 exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800771 var SourceAbiFlags []string
772 for _, dir := range exportIncludeDirs.Strings() {
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700773 SourceAbiFlags = append(SourceAbiFlags, "-I"+dir)
774 }
775 for _, reexportedInclude := range extractExportIncludesFromFlags(library.sabi.Properties.ReexportedIncludeFlags) {
776 SourceAbiFlags = append(SourceAbiFlags, reexportedInclude)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800777 }
778 exportedHeaderFlags := strings.Join(SourceAbiFlags, " ")
Logan Chiene3d7a0d2019-01-17 00:18:02 +0800779 library.sAbiOutputFile = TransformDumpToLinkedDump(ctx, objs.sAbiDumpFiles, soFile, fileName, exportedHeaderFlags,
780 android.OptionalPathForModuleSrc(ctx, library.Properties.Header_abi_checker.Symbol_file),
781 library.Properties.Header_abi_checker.Exclude_symbol_versions,
782 library.Properties.Header_abi_checker.Exclude_symbol_tags)
Logan Chien2f2b8902018-07-10 15:01:19 +0800783
Logan Chien7eefdc42018-07-11 18:10:41 +0800784 refAbiDumpFile := getRefAbiDumpFile(ctx, vndkVersion, fileName)
785 if refAbiDumpFile != nil {
Logan Chienf3511742017-10-31 18:04:35 +0800786 library.sAbiDiff = SourceAbiDiff(ctx, library.sAbiOutputFile.Path(),
Logan Chien6227fed2019-02-18 13:12:21 +0800787 refAbiDumpFile, fileName, exportedHeaderFlags, ctx.isLlndk(), ctx.isVndkExt())
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800788 }
789 }
790}
791
Colin Crossb916a382016-07-29 17:28:03 -0700792func (library *libraryDecorator) link(ctx ModuleContext,
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700793 flags Flags, deps PathDeps, objs Objects) android.Path {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700794
Colin Crossad59e752017-11-16 14:29:11 -0800795 objs = deps.Objs.Copy().Append(objs)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700796 var out android.Path
Colin Crossa48ab5b2017-02-14 15:28:44 -0800797 if library.static() || library.header() {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700798 out = library.linkStatic(ctx, flags, deps, objs)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700799 } else {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700800 out = library.linkShared(ctx, flags, deps, objs)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700801 }
802
803 library.exportIncludes(ctx, "-I")
804 library.reexportFlags(deps.ReexportedFlags)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700805 library.reexportDeps(deps.ReexportedFlagsDeps)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700806
Nan Zhang0007d812017-11-07 10:57:05 -0800807 if Bool(library.Properties.Aidl.Export_aidl_headers) {
Dan Willemsene1240db2016-11-03 14:28:51 -0700808 if library.baseCompiler.hasSrcExt(".aidl") {
Colin Cross10d22312017-05-03 11:01:58 -0700809 flags := []string{
Dan Willemsene1240db2016-11-03 14:28:51 -0700810 "-I" + android.PathForModuleGen(ctx, "aidl").String(),
Colin Cross10d22312017-05-03 11:01:58 -0700811 }
812 library.reexportFlags(flags)
813 library.reuseExportedFlags = append(library.reuseExportedFlags, flags...)
Pirama Arumuga Nainarf231b192018-01-23 10:49:04 -0800814 library.reexportDeps(library.baseCompiler.pathDeps) // TODO: restrict to aidl deps
815 library.reuseExportedDeps = append(library.reuseExportedDeps, library.baseCompiler.pathDeps...)
Dan Willemsene1240db2016-11-03 14:28:51 -0700816 }
817 }
818
Nan Zhang0007d812017-11-07 10:57:05 -0800819 if Bool(library.Properties.Proto.Export_proto_headers) {
Dan Willemsene1240db2016-11-03 14:28:51 -0700820 if library.baseCompiler.hasSrcExt(".proto") {
Dan Willemsenab9f4262018-02-14 13:58:34 -0800821 includes := []string{}
822 if flags.ProtoRoot {
823 includes = append(includes, "-I"+android.ProtoSubDir(ctx).String())
Colin Cross10d22312017-05-03 11:01:58 -0700824 }
Dan Willemsenab9f4262018-02-14 13:58:34 -0800825 includes = append(includes, "-I"+android.ProtoDir(ctx).String())
826 library.reexportFlags(includes)
827 library.reuseExportedFlags = append(library.reuseExportedFlags, includes...)
Pirama Arumuga Nainarf231b192018-01-23 10:49:04 -0800828 library.reexportDeps(library.baseCompiler.pathDeps) // TODO: restrict to proto deps
829 library.reuseExportedDeps = append(library.reuseExportedDeps, library.baseCompiler.pathDeps...)
Colin Cross0c461f12016-10-20 16:11:43 -0700830 }
831 }
832
Inseob Kim21f26902018-09-06 00:55:20 +0900833 if library.baseCompiler.hasSrcExt(".sysprop") {
Inseob Kimc0907f12019-02-08 21:00:45 +0900834 internalFlags := []string{
Inseob Kim21f26902018-09-06 00:55:20 +0900835 "-I" + android.PathForModuleGen(ctx, "sysprop", "include").String(),
836 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900837 systemFlags := []string{
838 "-I" + android.PathForModuleGen(ctx, "sysprop/system", "include").String(),
839 }
840
841 flags := internalFlags
842
843 if library.Properties.Sysprop.Platform != nil {
844 isProduct := ctx.ProductSpecific() && !ctx.useVndk()
845 isVendor := ctx.useVndk()
846 isOwnerPlatform := Bool(library.Properties.Sysprop.Platform)
847
848 useSystem := isProduct || (isOwnerPlatform == isVendor)
849
850 if useSystem {
851 flags = systemFlags
852 }
853 }
854
Inseob Kim21f26902018-09-06 00:55:20 +0900855 library.reexportFlags(flags)
Sundong Ahn5b73f312018-12-19 14:39:29 +0900856 library.reexportDeps(library.baseCompiler.pathDeps)
Inseob Kim21f26902018-09-06 00:55:20 +0900857 library.reuseExportedFlags = append(library.reuseExportedFlags, flags...)
858 }
859
Jiyong Parkda732bd2018-11-02 18:23:15 +0900860 if library.buildStubs() {
861 library.reexportFlags([]string{"-D" + versioningMacroName(ctx.ModuleName()) + "=" + library.stubsVersion()})
862 }
863
Colin Cross4d9c2d12016-07-29 12:48:20 -0700864 return out
865}
866
Colin Crossb916a382016-07-29 17:28:03 -0700867func (library *libraryDecorator) buildStatic() bool {
Colin Cross38b40df2018-04-10 16:14:46 -0700868 return library.MutatedProperties.BuildStatic && BoolDefault(library.Properties.Static.Enabled, true)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700869}
870
Colin Crossb916a382016-07-29 17:28:03 -0700871func (library *libraryDecorator) buildShared() bool {
Colin Cross38b40df2018-04-10 16:14:46 -0700872 return library.MutatedProperties.BuildShared && BoolDefault(library.Properties.Shared.Enabled, true)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700873}
874
Colin Crossb916a382016-07-29 17:28:03 -0700875func (library *libraryDecorator) getWholeStaticMissingDeps() []string {
Colin Crossd2343a32018-04-30 14:50:01 -0700876 return append([]string(nil), library.wholeStaticMissingDeps...)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700877}
878
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700879func (library *libraryDecorator) objs() Objects {
880 return library.objects
Colin Cross4d9c2d12016-07-29 12:48:20 -0700881}
882
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700883func (library *libraryDecorator) reuseObjs() (Objects, []string, android.Paths) {
884 return library.reuseObjects, library.reuseExportedFlags, library.reuseExportedDeps
Colin Cross4d9c2d12016-07-29 12:48:20 -0700885}
886
Colin Cross26c34ed2016-09-30 17:10:16 -0700887func (library *libraryDecorator) toc() android.OptionalPath {
888 return library.tocFile
889}
890
Colin Crossb916a382016-07-29 17:28:03 -0700891func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) {
Colin Crossc43ae772017-04-14 15:42:53 -0700892 if library.shared() {
Justin Yun8fe12122017-12-07 17:18:15 +0900893 if ctx.Device() && ctx.useVndk() {
894 if ctx.isVndkSp() {
895 library.baseInstaller.subDir = "vndk-sp"
896 } else if ctx.isVndk() {
897 library.baseInstaller.subDir = "vndk"
898 }
Logan Chienf3511742017-10-31 18:04:35 +0800899
900 // Append a version to vndk or vndk-sp directories on the system partition.
901 if ctx.isVndk() && !ctx.isVndkExt() {
902 vndkVersion := ctx.DeviceConfig().PlatformVndkVersion()
903 if vndkVersion != "current" && vndkVersion != "" {
904 library.baseInstaller.subDir += "-" + vndkVersion
905 }
Justin Yun8effde42017-06-23 19:24:43 +0900906 }
Jiyong Park429660f2019-01-16 22:31:11 +0900907 } else if len(library.Properties.Stubs.Versions) > 0 && android.DirectlyInAnyApex(ctx, ctx.ModuleName()) {
908 // If a library in an APEX has stable versioned APIs, we basically don't need
909 // to have the platform variant of the library in /system partition because
910 // platform components can just use the lib from the APEX without fearing about
911 // compatibility. However, if the library is required for some early processes
912 // before the APEX is activated, the platform variant may also be required.
913 // In that case, it is installed to the subdirectory 'bootstrap' in order to
914 // be distinguished/isolated from other non-bootstrap libraries in /system/lib
915 // so that the bootstrap libraries are used only when the APEX isn't ready.
916 if !library.buildStubs() && ctx.Arch().Native {
917 library.baseInstaller.subDir = "bootstrap"
918 }
Justin Yun8effde42017-06-23 19:24:43 +0900919 }
Colin Cross4d9c2d12016-07-29 12:48:20 -0700920 library.baseInstaller.install(ctx, file)
921 }
Dan Albertf563d252017-10-13 00:29:00 -0700922
Dan Albert281f22b2017-12-13 15:03:47 -0800923 if Bool(library.Properties.Static_ndk_lib) && library.static() &&
Jiyong Parkf9332f12018-02-01 00:54:12 +0900924 !ctx.useVndk() && !ctx.inRecovery() && ctx.Device() &&
Jiyong Park7ed9de32018-10-15 22:25:07 +0900925 library.baseLinker.sanitize.isUnsanitizedVariant() &&
926 !library.buildStubs() {
Dan Albertf563d252017-10-13 00:29:00 -0700927 installPath := getNdkSysrootBase(ctx).Join(
Dan Albertea4b7b92018-04-25 16:05:30 -0700928 ctx, "usr/lib", config.NDKTriple(ctx.toolchain()), file.Base())
Dan Albertf563d252017-10-13 00:29:00 -0700929
930 ctx.ModuleBuild(pctx, android.ModuleBuildParams{
931 Rule: android.Cp,
932 Description: "install " + installPath.Base(),
933 Output: installPath,
934 Input: file,
935 })
936
Colin Cross0875c522017-11-28 17:34:01 -0800937 library.ndkSysrootPath = installPath
Dan Albertf563d252017-10-13 00:29:00 -0700938 }
Colin Cross4d9c2d12016-07-29 12:48:20 -0700939}
940
Colin Crossb916a382016-07-29 17:28:03 -0700941func (library *libraryDecorator) static() bool {
Colin Crossa48ab5b2017-02-14 15:28:44 -0800942 return library.MutatedProperties.VariantIsStatic
Colin Cross4d9c2d12016-07-29 12:48:20 -0700943}
944
Colin Crossa48ab5b2017-02-14 15:28:44 -0800945func (library *libraryDecorator) shared() bool {
946 return library.MutatedProperties.VariantIsShared
947}
948
949func (library *libraryDecorator) header() bool {
950 return !library.static() && !library.shared()
951}
952
953func (library *libraryDecorator) setStatic() {
954 library.MutatedProperties.VariantIsStatic = true
955 library.MutatedProperties.VariantIsShared = false
956}
957
958func (library *libraryDecorator) setShared() {
959 library.MutatedProperties.VariantIsStatic = false
960 library.MutatedProperties.VariantIsShared = true
Colin Crossb916a382016-07-29 17:28:03 -0700961}
962
Colin Crossab3b7322016-12-09 14:46:15 -0800963func (library *libraryDecorator) BuildOnlyStatic() {
Colin Crossa48ab5b2017-02-14 15:28:44 -0800964 library.MutatedProperties.BuildShared = false
Colin Crossab3b7322016-12-09 14:46:15 -0800965}
966
967func (library *libraryDecorator) BuildOnlyShared() {
Colin Crossa48ab5b2017-02-14 15:28:44 -0800968 library.MutatedProperties.BuildStatic = false
Colin Crossab3b7322016-12-09 14:46:15 -0800969}
970
Colin Cross5950f382016-12-13 12:50:57 -0800971func (library *libraryDecorator) HeaderOnly() {
Colin Crossa48ab5b2017-02-14 15:28:44 -0800972 library.MutatedProperties.BuildShared = false
973 library.MutatedProperties.BuildStatic = false
Colin Cross5950f382016-12-13 12:50:57 -0800974}
975
Jiyong Park7ed9de32018-10-15 22:25:07 +0900976func (library *libraryDecorator) buildStubs() bool {
977 return library.MutatedProperties.BuildStubs
978}
979
980func (library *libraryDecorator) stubsVersion() string {
981 return library.MutatedProperties.StubsVersion
982}
983
Colin Cross571cccf2019-02-04 11:22:08 -0800984var versioningMacroNamesListKey = android.NewOnceKey("versioningMacroNamesList")
985
Jiyong Parkda732bd2018-11-02 18:23:15 +0900986func versioningMacroNamesList(config android.Config) *map[string]string {
Colin Cross571cccf2019-02-04 11:22:08 -0800987 return config.Once(versioningMacroNamesListKey, func() interface{} {
Jiyong Parkda732bd2018-11-02 18:23:15 +0900988 m := make(map[string]string)
989 return &m
990 }).(*map[string]string)
991}
992
993// alphanumeric and _ characters are preserved.
994// other characters are all converted to _
995var charsNotForMacro = regexp.MustCompile("[^a-zA-Z0-9_]+")
996
997func versioningMacroName(moduleName string) string {
998 macroName := charsNotForMacro.ReplaceAllString(moduleName, "_")
999 macroName = strings.ToUpper(moduleName)
1000 return "__" + macroName + "_API__"
1001}
1002
Colin Crossab3b7322016-12-09 14:46:15 -08001003func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
Colin Cross4d9c2d12016-07-29 12:48:20 -07001004 module := newModule(hod, android.MultilibBoth)
1005
Colin Crossb916a382016-07-29 17:28:03 -07001006 library := &libraryDecorator{
Colin Crossa48ab5b2017-02-14 15:28:44 -08001007 MutatedProperties: LibraryMutatedProperties{
Colin Crossab3b7322016-12-09 14:46:15 -08001008 BuildShared: true,
1009 BuildStatic: true,
Colin Cross4d9c2d12016-07-29 12:48:20 -07001010 },
Colin Crossb916a382016-07-29 17:28:03 -07001011 baseCompiler: NewBaseCompiler(),
Dan Albert61f32122018-07-26 14:00:24 -07001012 baseLinker: NewBaseLinker(module.sanitize),
Colin Crossb916a382016-07-29 17:28:03 -07001013 baseInstaller: NewBaseInstaller("lib", "lib64", InstallInSystem),
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001014 sabi: module.sabi,
Colin Cross4d9c2d12016-07-29 12:48:20 -07001015 }
1016
Colin Crossb916a382016-07-29 17:28:03 -07001017 module.compiler = library
1018 module.linker = library
1019 module.installer = library
1020
1021 return module, library
1022}
1023
Colin Cross10d22312017-05-03 11:01:58 -07001024// connects a shared library to a static library in order to reuse its .o files to avoid
1025// compiling source files twice.
1026func reuseStaticLibrary(mctx android.BottomUpMutatorContext, static, shared *Module) {
1027 if staticCompiler, ok := static.compiler.(*libraryDecorator); ok {
1028 sharedCompiler := shared.compiler.(*libraryDecorator)
Dan Willemsen3a26eef2018-12-03 15:25:46 -08001029
1030 // Check libraries in addition to cflags, since libraries may be exporting different
1031 // include directories.
Colin Cross10d22312017-05-03 11:01:58 -07001032 if len(staticCompiler.Properties.Static.Cflags) == 0 &&
Dan Willemsen3a26eef2018-12-03 15:25:46 -08001033 len(sharedCompiler.Properties.Shared.Cflags) == 0 &&
1034 len(staticCompiler.Properties.Static.Whole_static_libs) == 0 &&
1035 len(sharedCompiler.Properties.Shared.Whole_static_libs) == 0 &&
1036 len(staticCompiler.Properties.Static.Static_libs) == 0 &&
1037 len(sharedCompiler.Properties.Shared.Static_libs) == 0 &&
1038 len(staticCompiler.Properties.Static.Shared_libs) == 0 &&
1039 len(sharedCompiler.Properties.Shared.Shared_libs) == 0 &&
1040 staticCompiler.Properties.Static.System_shared_libs == nil &&
1041 sharedCompiler.Properties.Shared.System_shared_libs == nil {
Colin Cross10d22312017-05-03 11:01:58 -07001042
1043 mctx.AddInterVariantDependency(reuseObjTag, shared, static)
1044 sharedCompiler.baseCompiler.Properties.OriginalSrcs =
1045 sharedCompiler.baseCompiler.Properties.Srcs
1046 sharedCompiler.baseCompiler.Properties.Srcs = nil
1047 sharedCompiler.baseCompiler.Properties.Generated_sources = nil
Jiyong Parke4bb9862019-02-01 00:31:10 +09001048 } else {
1049 // This dep is just to reference static variant from shared variant
1050 mctx.AddInterVariantDependency(staticVariantTag, shared, static)
Colin Cross10d22312017-05-03 11:01:58 -07001051 }
1052 }
1053}
1054
Colin Crosse40b4ea2018-10-02 22:25:58 -07001055func LinkageMutator(mctx android.BottomUpMutatorContext) {
Colin Crossb916a382016-07-29 17:28:03 -07001056 if m, ok := mctx.Module().(*Module); ok && m.linker != nil {
1057 if library, ok := m.linker.(libraryInterface); ok {
1058 var modules []blueprint.Module
1059 if library.buildStatic() && library.buildShared() {
1060 modules = mctx.CreateLocalVariations("static", "shared")
1061 static := modules[0].(*Module)
1062 shared := modules[1].(*Module)
1063
Colin Crossa48ab5b2017-02-14 15:28:44 -08001064 static.linker.(libraryInterface).setStatic()
1065 shared.linker.(libraryInterface).setShared()
Colin Crossb916a382016-07-29 17:28:03 -07001066
Colin Cross10d22312017-05-03 11:01:58 -07001067 reuseStaticLibrary(mctx, static, shared)
1068
Colin Crossb916a382016-07-29 17:28:03 -07001069 } else if library.buildStatic() {
1070 modules = mctx.CreateLocalVariations("static")
Colin Crossa48ab5b2017-02-14 15:28:44 -08001071 modules[0].(*Module).linker.(libraryInterface).setStatic()
Colin Crossb916a382016-07-29 17:28:03 -07001072 } else if library.buildShared() {
1073 modules = mctx.CreateLocalVariations("shared")
Colin Crossa48ab5b2017-02-14 15:28:44 -08001074 modules[0].(*Module).linker.(libraryInterface).setShared()
Colin Crossb916a382016-07-29 17:28:03 -07001075 }
1076 }
1077 }
Colin Cross4d9c2d12016-07-29 12:48:20 -07001078}
Jiyong Park7ed9de32018-10-15 22:25:07 +09001079
Colin Cross571cccf2019-02-04 11:22:08 -08001080var stubVersionsKey = android.NewOnceKey("stubVersions")
1081
Jiyong Park25fc6a92018-11-18 18:02:45 +09001082// maps a module name to the list of stubs versions available for the module
1083func stubsVersionsFor(config android.Config) map[string][]string {
Colin Cross571cccf2019-02-04 11:22:08 -08001084 return config.Once(stubVersionsKey, func() interface{} {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001085 return make(map[string][]string)
1086 }).(map[string][]string)
1087}
1088
1089var stubsVersionsLock sync.Mutex
1090
1091func latestStubsVersionFor(config android.Config, name string) string {
1092 versions, ok := stubsVersionsFor(config)[name]
1093 if ok && len(versions) > 0 {
1094 // the versions are alreay sorted in ascending order
1095 return versions[len(versions)-1]
1096 }
1097 return ""
1098}
1099
Jiyong Park7ed9de32018-10-15 22:25:07 +09001100// Version mutator splits a module into the mandatory non-stubs variant
Jiyong Park25fc6a92018-11-18 18:02:45 +09001101// (which is unnamed) and zero or more stubs variants.
1102func VersionMutator(mctx android.BottomUpMutatorContext) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001103 if m, ok := mctx.Module().(*Module); ok && !m.inRecovery() && m.linker != nil {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001104 if library, ok := m.linker.(*libraryDecorator); ok && library.buildShared() &&
1105 len(library.Properties.Stubs.Versions) > 0 {
1106 versions := []string{}
Jiyong Park7ed9de32018-10-15 22:25:07 +09001107 for _, v := range library.Properties.Stubs.Versions {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001108 if _, err := strconv.Atoi(v); err != nil {
1109 mctx.PropertyErrorf("versions", "%q is not a number", v)
1110 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001111 versions = append(versions, v)
1112 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001113 sort.Slice(versions, func(i, j int) bool {
1114 left, _ := strconv.Atoi(versions[i])
1115 right, _ := strconv.Atoi(versions[j])
1116 return left < right
1117 })
1118
1119 // save the list of versions for later use
1120 copiedVersions := make([]string, len(versions))
1121 copy(copiedVersions, versions)
1122 stubsVersionsLock.Lock()
1123 defer stubsVersionsLock.Unlock()
1124 stubsVersionsFor(mctx.Config())[mctx.ModuleName()] = copiedVersions
1125
1126 // "" is for the non-stubs variant
Jiyong Park67883b32019-01-03 21:35:58 +09001127 versions = append([]string{""}, versions...)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001128
Jiyong Park7ed9de32018-10-15 22:25:07 +09001129 modules := mctx.CreateVariations(versions...)
1130 for i, m := range modules {
1131 l := m.(*Module).linker.(*libraryDecorator)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001132 if versions[i] != "" {
1133 l.MutatedProperties.BuildStubs = true
1134 l.MutatedProperties.StubsVersion = versions[i]
1135 m.(*Module).Properties.HideFromMake = true
Jiyong Park090d9df2018-12-11 02:47:16 +09001136 m.(*Module).sanitize = nil
1137 m.(*Module).stl = nil
Jiyong Park127d5652018-12-12 10:26:20 +09001138 m.(*Module).Properties.PreventInstall = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001139 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001140 }
1141 } else {
1142 mctx.CreateVariations("")
1143 }
1144 return
1145 }
1146 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1147 if props, ok := genrule.Extra.(*GenruleExtraProperties); ok && !props.InRecovery {
1148 mctx.CreateVariations("")
1149 return
1150 }
1151 }
1152}