Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved. |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 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 | // This file contains the module types for compiling C/C++ for Android, and converts the properties |
| 18 | // into the flags and filenames necessary to pass to the compiler. The final creation of the rules |
| 19 | // is handled in builder.go |
| 20 | |
| 21 | import ( |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 22 | "fmt" |
Logan Chien | 41eabe6 | 2019-04-10 13:33:58 +0800 | [diff] [blame] | 23 | "io" |
Dan Albert | 9e10cd4 | 2016-08-03 14:12:14 -0700 | [diff] [blame] | 24 | "strconv" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 25 | "strings" |
| 26 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 27 | "github.com/google/blueprint" |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 28 | "github.com/google/blueprint/proptools" |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 29 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 30 | "android/soong/android" |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 31 | "android/soong/cc/config" |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 32 | "android/soong/genrule" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 33 | ) |
| 34 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 35 | func init() { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 36 | android.RegisterModuleType("cc_defaults", defaultsFactory) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 37 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 38 | android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 39 | ctx.BottomUp("image", ImageMutator).Parallel() |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 40 | ctx.BottomUp("link", LinkageMutator).Parallel() |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 41 | ctx.BottomUp("vndk", VndkMutator).Parallel() |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 42 | ctx.BottomUp("ndk_api", ndkApiMutator).Parallel() |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 43 | ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 44 | ctx.BottomUp("version", VersionMutator).Parallel() |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 45 | ctx.BottomUp("begin", BeginMutator).Parallel() |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 46 | ctx.BottomUp("sysprop", SyspropMutator).Parallel() |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 47 | }) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 48 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 49 | android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 50 | ctx.TopDown("asan_deps", sanitizerDepsMutator(asan)) |
| 51 | ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel() |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 52 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 53 | ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan)) |
| 54 | ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel() |
| 55 | |
Mitch Phillips | bfeade6 | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 56 | ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer)) |
| 57 | ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel() |
| 58 | |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame^] | 59 | // cfi mutator shouldn't run before sanitizers that return true for |
| 60 | // incompatibleWithCfi() |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 61 | ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi)) |
| 62 | ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel() |
| 63 | |
Peter Collingbourne | 8c7e6e2 | 2018-11-19 16:03:58 -0800 | [diff] [blame] | 64 | ctx.TopDown("scs_deps", sanitizerDepsMutator(scs)) |
| 65 | ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel() |
| 66 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 67 | ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan)) |
| 68 | ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel() |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 69 | |
Colin Cross | 0b90833 | 2019-06-19 23:00:20 -0700 | [diff] [blame] | 70 | ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel() |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 71 | ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel() |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 72 | |
Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 73 | ctx.BottomUp("coverage", coverageMutator).Parallel() |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 74 | ctx.TopDown("vndk_deps", sabiDepsMutator) |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 75 | |
| 76 | ctx.TopDown("lto_deps", ltoDepsMutator) |
| 77 | ctx.BottomUp("lto", ltoMutator).Parallel() |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 78 | |
| 79 | ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel() |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 80 | }) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 81 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 82 | android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 83 | pctx.Import("android/soong/cc/config") |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 86 | type Deps struct { |
| 87 | SharedLibs, LateSharedLibs []string |
| 88 | StaticLibs, LateStaticLibs, WholeStaticLibs []string |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 89 | HeaderLibs []string |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 90 | RuntimeLibs []string |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 91 | |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 92 | ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 93 | |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 94 | ObjFiles []string |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 95 | |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 96 | GeneratedSources []string |
| 97 | GeneratedHeaders []string |
| 98 | |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 99 | ReexportGeneratedHeaders []string |
| 100 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 101 | CrtBegin, CrtEnd string |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 102 | |
| 103 | // Used for host bionic |
| 104 | LinkerFlagsFile string |
| 105 | DynamicLinker string |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 108 | type PathDeps struct { |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 109 | // Paths to .so files |
Jiyong Park | 64a44f2 | 2019-01-18 14:37:08 +0900 | [diff] [blame] | 110 | SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 111 | // Paths to the dependencies to use for .so files (.so.toc files) |
Jiyong Park | 64a44f2 | 2019-01-18 14:37:08 +0900 | [diff] [blame] | 112 | SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 113 | // Paths to .a files |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 114 | StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 115 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 116 | // Paths to .o files |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 117 | Objs Objects |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 118 | StaticLibObjs Objects |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 119 | WholeStaticLibObjs Objects |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 120 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 121 | // Paths to generated source files |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 122 | GeneratedSources android.Paths |
| 123 | GeneratedHeaders android.Paths |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 124 | |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 125 | Flags []string |
| 126 | IncludeDirs []string |
| 127 | SystemIncludeDirs []string |
| 128 | ReexportedDirs []string |
| 129 | ReexportedSystemDirs []string |
| 130 | ReexportedFlags []string |
| 131 | ReexportedDeps android.Paths |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 132 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 133 | // Paths to crt*.o files |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 134 | CrtBegin, CrtEnd android.OptionalPath |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 135 | |
| 136 | // Path to the file container flags to use with the linker |
| 137 | LinkerFlagsFile android.OptionalPath |
| 138 | |
| 139 | // Path to the dynamic linker binary |
| 140 | DynamicLinker android.OptionalPath |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 143 | type Flags struct { |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 144 | GlobalFlags []string // Flags that apply to C, C++, and assembly source files |
| 145 | ArFlags []string // Flags that apply to ar |
| 146 | AsFlags []string // Flags that apply to assembly source files |
| 147 | CFlags []string // Flags that apply to C and C++ source files |
| 148 | ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools |
| 149 | ConlyFlags []string // Flags that apply to C source files |
| 150 | CppFlags []string // Flags that apply to C++ source files |
| 151 | ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 152 | aidlFlags []string // Flags that apply to aidl source files |
| 153 | rsFlags []string // Flags that apply to renderscript source files |
| 154 | LdFlags []string // Flags that apply to linker command lines |
| 155 | libFlags []string // Flags to add libraries early to the link order |
| 156 | TidyFlags []string // Flags that apply to clang-tidy |
| 157 | SAbiFlags []string // Flags that apply to header-abi-dumper |
| 158 | YasmFlags []string // Flags that apply to yasm assembly source files |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 159 | |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 160 | // Global include flags that apply to C, C++, and assembly source files |
| 161 | // These must be after any module include flags, which will be in GlobalFlags. |
| 162 | SystemIncludeFlags []string |
| 163 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 164 | Toolchain config.Toolchain |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 165 | Tidy bool |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 166 | Coverage bool |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 167 | SAbiDump bool |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 168 | EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 169 | |
| 170 | RequiredInstructionSet string |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 171 | DynamicLinker string |
| 172 | |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 173 | CFlagsDeps android.Paths // Files depended on by compiler flags |
| 174 | LdFlagsDeps android.Paths // Files depended on by linker flags |
Colin Cross | 18c0c5a | 2016-12-01 14:45:23 -0800 | [diff] [blame] | 175 | |
| 176 | GroupStaticLibs bool |
Dan Willemsen | 60e62f0 | 2018-11-16 21:05:32 -0800 | [diff] [blame] | 177 | |
Colin Cross | 19878da | 2019-03-28 14:45:07 -0700 | [diff] [blame] | 178 | proto android.ProtoFlags |
Colin Cross | 19878da | 2019-03-28 14:45:07 -0700 | [diff] [blame] | 179 | protoC bool // Whether to use C instead of C++ |
| 180 | protoOptionsFile bool // Whether to look for a .options file next to the .proto |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 181 | |
| 182 | Yacc *YaccProperties |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 185 | type ObjectLinkerProperties struct { |
Paul Duffin | a37832a | 2019-07-18 12:31:26 +0100 | [diff] [blame] | 186 | // list of modules that should only provide headers for this module. |
| 187 | Header_libs []string `android:"arch_variant,variant_prepend"` |
| 188 | |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 189 | // names of other cc_object modules to link into this module using partial linking |
| 190 | Objs []string `android:"arch_variant"` |
Dan Willemsen | efb1dd9 | 2017-09-18 22:47:20 -0700 | [diff] [blame] | 191 | |
| 192 | // if set, add an extra objcopy --prefix-symbols= step |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 193 | Prefix_symbols *string |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 196 | // Properties used to compile all C or C++ modules |
| 197 | type BaseProperties struct { |
Dan Willemsen | 742a545 | 2018-07-23 17:19:36 -0700 | [diff] [blame] | 198 | // Deprecated. true is the default, false is invalid. |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 199 | Clang *bool `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 200 | |
| 201 | // Minimum sdk version supported when compiling against the ndk |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 202 | Sdk_version *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 203 | |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 204 | AndroidMkSharedLibs []string `blueprint:"mutated"` |
| 205 | AndroidMkStaticLibs []string `blueprint:"mutated"` |
| 206 | AndroidMkRuntimeLibs []string `blueprint:"mutated"` |
| 207 | AndroidMkWholeStaticLibs []string `blueprint:"mutated"` |
| 208 | HideFromMake bool `blueprint:"mutated"` |
| 209 | PreventInstall bool `blueprint:"mutated"` |
| 210 | ApexesProvidingSharedLibs []string `blueprint:"mutated"` |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 211 | |
| 212 | UseVndk bool `blueprint:"mutated"` |
Colin Cross | 5beccee | 2017-12-07 15:28:59 -0800 | [diff] [blame] | 213 | |
| 214 | // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags |
| 215 | // file |
| 216 | Logtags []string |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 217 | |
| 218 | // Make this module available when building for recovery |
| 219 | Recovery_available *bool |
| 220 | |
| 221 | InRecovery bool `blueprint:"mutated"` |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 222 | |
| 223 | // Allows this module to use non-APEX version of libraries. Useful |
| 224 | // for building binaries that are started before APEXes are activated. |
| 225 | Bootstrap *bool |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | type VendorProperties struct { |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 229 | // whether this module should be allowed to be directly depended by other |
| 230 | // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`. |
| 231 | // If set to true, two variants will be built separately, one like |
| 232 | // normal, and the other limited to the set of libraries and headers |
| 233 | // that are exposed to /vendor modules. |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 234 | // |
| 235 | // The vendor variant may be used with a different (newer) /system, |
| 236 | // so it shouldn't have any unversioned runtime dependencies, or |
| 237 | // make assumptions about the system that may not be true in the |
| 238 | // future. |
| 239 | // |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 240 | // If set to false, this module becomes inaccessible from /vendor modules. |
| 241 | // |
| 242 | // Default value is true when vndk: {enabled: true} or vendor: true. |
| 243 | // |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 244 | // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk |
| 245 | Vendor_available *bool |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 246 | |
| 247 | // whether this module is capable of being loaded with other instance |
| 248 | // (possibly an older version) of the same module in the same process. |
| 249 | // Currently, a shared library that is a member of VNDK (vndk: {enabled: true}) |
| 250 | // can be double loaded in a vendor process if the library is also a |
| 251 | // (direct and indirect) dependency of an LLNDK library. Such libraries must be |
| 252 | // explicitly marked as `double_loadable: true` by the owner, or the dependency |
| 253 | // from the LLNDK lib should be cut if the lib is not designed to be double loaded. |
| 254 | Double_loadable *bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 257 | type ModuleContextIntf interface { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 258 | static() bool |
| 259 | staticBinary() bool |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame^] | 260 | header() bool |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 261 | toolchain() config.Toolchain |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 262 | useSdk() bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 263 | sdkVersion() string |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 264 | useVndk() bool |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 265 | isNdk() bool |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 266 | isLlndk(config android.Config) bool |
| 267 | isLlndkPublic(config android.Config) bool |
| 268 | isVndkPrivate(config android.Config) bool |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 269 | isVndk() bool |
| 270 | isVndkSp() bool |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 271 | isVndkExt() bool |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 272 | inRecovery() bool |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 273 | shouldCreateVndkSourceAbiDump(config android.Config) bool |
Dan Willemsen | 8146b2f | 2016-03-30 21:00:30 -0700 | [diff] [blame] | 274 | selectedStl() string |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 275 | baseModuleName() string |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 276 | getVndkExtendsModuleName() string |
Yi Kong | 7e53c57 | 2018-02-14 18:16:12 +0800 | [diff] [blame] | 277 | isPgoCompile() bool |
Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 278 | isNDKStubLibrary() bool |
Ivan Lozano | bd72126 | 2018-11-27 14:33:03 -0800 | [diff] [blame] | 279 | useClangLld(actx ModuleContext) bool |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 280 | apexName() string |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 281 | hasStubsVariants() bool |
| 282 | isStubs() bool |
Jiyong Park | a4b9dd0 | 2019-01-16 22:53:13 +0900 | [diff] [blame] | 283 | bootstrap() bool |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 284 | mustUseVendorVariant() bool |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 285 | nativeCoverage() bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | type ModuleContext interface { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 289 | android.ModuleContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 290 | ModuleContextIntf |
| 291 | } |
| 292 | |
| 293 | type BaseModuleContext interface { |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 294 | android.BaseModuleContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 295 | ModuleContextIntf |
| 296 | } |
| 297 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 298 | type DepsContext interface { |
| 299 | android.BottomUpMutatorContext |
| 300 | ModuleContextIntf |
| 301 | } |
| 302 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 303 | type feature interface { |
| 304 | begin(ctx BaseModuleContext) |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 305 | deps(ctx DepsContext, deps Deps) Deps |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 306 | flags(ctx ModuleContext, flags Flags) Flags |
| 307 | props() []interface{} |
| 308 | } |
| 309 | |
| 310 | type compiler interface { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 311 | compilerInit(ctx BaseModuleContext) |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 312 | compilerDeps(ctx DepsContext, deps Deps) Deps |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 313 | compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 314 | compilerProps() []interface{} |
| 315 | |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame] | 316 | appendCflags([]string) |
| 317 | appendAsflags([]string) |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 318 | compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | type linker interface { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 322 | linkerInit(ctx BaseModuleContext) |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 323 | linkerDeps(ctx DepsContext, deps Deps) Deps |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 324 | linkerFlags(ctx ModuleContext, flags Flags) Flags |
| 325 | linkerProps() []interface{} |
Ivan Lozano | bd72126 | 2018-11-27 14:33:03 -0800 | [diff] [blame] | 326 | useClangLld(actx ModuleContext) bool |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 327 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 328 | link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame] | 329 | appendLdflags([]string) |
Jiyong Park | af6d895 | 2019-01-31 12:21:23 +0900 | [diff] [blame] | 330 | unstrippedOutputFilePath() android.Path |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 331 | |
| 332 | nativeCoverage() bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | type installer interface { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 336 | installerProps() []interface{} |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 337 | install(ctx ModuleContext, path android.Path) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 338 | inData() bool |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 339 | inSanitizerDir() bool |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 340 | hostToolPath() android.OptionalPath |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 341 | relativeInstallPath() string |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 342 | } |
| 343 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 344 | type dependencyTag struct { |
| 345 | blueprint.BaseDependencyTag |
| 346 | name string |
| 347 | library bool |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 348 | shared bool |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 349 | |
| 350 | reexportFlags bool |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 351 | |
| 352 | explicitlyVersioned bool |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 355 | type xref interface { |
| 356 | XrefCcFiles() android.Paths |
| 357 | } |
| 358 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 359 | var ( |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 360 | sharedDepTag = dependencyTag{name: "shared", library: true, shared: true} |
| 361 | sharedExportDepTag = dependencyTag{name: "shared", library: true, shared: true, reexportFlags: true} |
| 362 | earlySharedDepTag = dependencyTag{name: "early_shared", library: true, shared: true} |
| 363 | lateSharedDepTag = dependencyTag{name: "late shared", library: true, shared: true} |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 364 | staticDepTag = dependencyTag{name: "static", library: true} |
| 365 | staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true} |
| 366 | lateStaticDepTag = dependencyTag{name: "late static", library: true} |
| 367 | wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true} |
Colin Cross | 32ec36c | 2016-12-15 07:39:51 -0800 | [diff] [blame] | 368 | headerDepTag = dependencyTag{name: "header", library: true} |
| 369 | headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true} |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 370 | genSourceDepTag = dependencyTag{name: "gen source"} |
| 371 | genHeaderDepTag = dependencyTag{name: "gen header"} |
| 372 | genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true} |
| 373 | objDepTag = dependencyTag{name: "obj"} |
| 374 | crtBeginDepTag = dependencyTag{name: "crtbegin"} |
| 375 | crtEndDepTag = dependencyTag{name: "crtend"} |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 376 | linkerFlagsDepTag = dependencyTag{name: "linker flags file"} |
| 377 | dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"} |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 378 | reuseObjTag = dependencyTag{name: "reuse objects"} |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 379 | staticVariantTag = dependencyTag{name: "static variant"} |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 380 | ndkStubDepTag = dependencyTag{name: "ndk stub", library: true} |
| 381 | ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true} |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 382 | vndkExtDepTag = dependencyTag{name: "vndk extends", library: true} |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 383 | runtimeDepTag = dependencyTag{name: "runtime lib"} |
Pirama Arumuga Nainar | 82fe59b | 2019-07-02 14:55:35 -0700 | [diff] [blame] | 384 | coverageDepTag = dependencyTag{name: "coverage"} |
Roland Levillain | f2fad97 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 385 | testPerSrcDepTag = dependencyTag{name: "test_per_src"} |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 386 | ) |
| 387 | |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 388 | func IsSharedDepTag(depTag blueprint.DependencyTag) bool { |
| 389 | ccDepTag, ok := depTag.(dependencyTag) |
| 390 | return ok && ccDepTag.shared |
| 391 | } |
| 392 | |
| 393 | func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool { |
| 394 | ccDepTag, ok := depTag.(dependencyTag) |
| 395 | return ok && ccDepTag == runtimeDepTag |
| 396 | } |
| 397 | |
| 398 | func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool { |
| 399 | ccDepTag, ok := depTag.(dependencyTag) |
| 400 | return ok && ccDepTag == testPerSrcDepTag |
| 401 | } |
| 402 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 403 | // Module contains the properties and members used by all C/C++ module types, and implements |
| 404 | // the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces |
| 405 | // to construct the output file. Behavior can be customized with a Customizer interface |
| 406 | type Module struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 407 | android.ModuleBase |
Colin Cross | 1f44a3a | 2017-07-07 14:33:33 -0700 | [diff] [blame] | 408 | android.DefaultableModuleBase |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 409 | android.ApexModuleBase |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 410 | |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 411 | Properties BaseProperties |
| 412 | VendorProperties VendorProperties |
Colin Cross | fa13879 | 2015-04-24 17:31:52 -0700 | [diff] [blame] | 413 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 414 | // initialize before calling Init |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 415 | hod android.HostOrDeviceSupported |
| 416 | multilib android.Multilib |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 417 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 418 | // delegates, initialize before calling Init |
Colin Cross | b4ce0ec | 2016-09-13 13:41:39 -0700 | [diff] [blame] | 419 | features []feature |
| 420 | compiler compiler |
| 421 | linker linker |
| 422 | installer installer |
| 423 | stl *stl |
| 424 | sanitize *sanitize |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 425 | coverage *coverage |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 426 | sabi *sabi |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 427 | vndkdep *vndkdep |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 428 | lto *lto |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 429 | pgo *pgo |
Ivan Lozano | 074ec48 | 2018-11-21 08:59:37 -0800 | [diff] [blame] | 430 | xom *xom |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 431 | |
| 432 | androidMkSharedLibDeps []string |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 433 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 434 | outputFile android.OptionalPath |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 435 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 436 | cachedToolchain config.Toolchain |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 437 | |
| 438 | subAndroidMkOnce map[subAndroidMkProvider]bool |
Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 439 | |
| 440 | // Flags used to compile this module |
| 441 | flags Flags |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 442 | |
| 443 | // When calling a linker, if module A depends on module B, then A must precede B in its command |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 444 | // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 445 | // deps of this module |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 446 | depsInLinkOrder android.Paths |
| 447 | |
| 448 | // only non-nil when this is a shared library that reuses the objects of a static library |
| 449 | staticVariant *Module |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 450 | |
| 451 | makeLinkType string |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 452 | // Kythe (source file indexer) paths for this compilation module |
| 453 | kytheFiles android.Paths |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Jiyong Park | c20eee3 | 2018-09-05 22:36:17 +0900 | [diff] [blame] | 456 | func (c *Module) OutputFile() android.OptionalPath { |
| 457 | return c.outputFile |
| 458 | } |
| 459 | |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 460 | func (c *Module) UnstrippedOutputFile() android.Path { |
Jiyong Park | af6d895 | 2019-01-31 12:21:23 +0900 | [diff] [blame] | 461 | if c.linker != nil { |
| 462 | return c.linker.unstrippedOutputFilePath() |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 463 | } |
| 464 | return nil |
| 465 | } |
| 466 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 467 | func (c *Module) RelativeInstallPath() string { |
| 468 | if c.installer != nil { |
| 469 | return c.installer.relativeInstallPath() |
| 470 | } |
| 471 | return "" |
| 472 | } |
| 473 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 474 | func (c *Module) Init() android.Module { |
Dan Willemsen | f923f2b | 2018-05-09 13:45:03 -0700 | [diff] [blame] | 475 | c.AddProperties(&c.Properties, &c.VendorProperties) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 476 | if c.compiler != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 477 | c.AddProperties(c.compiler.compilerProps()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 478 | } |
| 479 | if c.linker != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 480 | c.AddProperties(c.linker.linkerProps()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 481 | } |
| 482 | if c.installer != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 483 | c.AddProperties(c.installer.installerProps()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 484 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 485 | if c.stl != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 486 | c.AddProperties(c.stl.props()...) |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 487 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 488 | if c.sanitize != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 489 | c.AddProperties(c.sanitize.props()...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 490 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 491 | if c.coverage != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 492 | c.AddProperties(c.coverage.props()...) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 493 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 494 | if c.sabi != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 495 | c.AddProperties(c.sabi.props()...) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 496 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 497 | if c.vndkdep != nil { |
| 498 | c.AddProperties(c.vndkdep.props()...) |
| 499 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 500 | if c.lto != nil { |
| 501 | c.AddProperties(c.lto.props()...) |
| 502 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 503 | if c.pgo != nil { |
| 504 | c.AddProperties(c.pgo.props()...) |
| 505 | } |
Ivan Lozano | 074ec48 | 2018-11-21 08:59:37 -0800 | [diff] [blame] | 506 | if c.xom != nil { |
| 507 | c.AddProperties(c.xom.props()...) |
| 508 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 509 | for _, feature := range c.features { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 510 | c.AddProperties(feature.props()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 511 | } |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 512 | |
Colin Cross | a9d8bee | 2018-10-02 13:59:46 -0700 | [diff] [blame] | 513 | c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool { |
| 514 | switch class { |
| 515 | case android.Device: |
| 516 | return ctx.Config().DevicePrefer32BitExecutables() |
| 517 | case android.HostCross: |
| 518 | // Windows builds always prefer 32-bit |
| 519 | return true |
| 520 | default: |
| 521 | return false |
| 522 | } |
| 523 | }) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 524 | android.InitAndroidArchModule(c, c.hod, c.multilib) |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 525 | |
Colin Cross | 1f44a3a | 2017-07-07 14:33:33 -0700 | [diff] [blame] | 526 | android.InitDefaultableModule(c) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 527 | |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 528 | android.InitApexModule(c) |
| 529 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 530 | return c |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 533 | // Returns true for dependency roots (binaries) |
| 534 | // TODO(ccross): also handle dlopenable libraries |
| 535 | func (c *Module) isDependencyRoot() bool { |
| 536 | if root, ok := c.linker.(interface { |
| 537 | isDependencyRoot() bool |
| 538 | }); ok { |
| 539 | return root.isDependencyRoot() |
| 540 | } |
| 541 | return false |
| 542 | } |
| 543 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 544 | func (c *Module) useVndk() bool { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 545 | return c.Properties.UseVndk |
| 546 | } |
| 547 | |
Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 548 | func (c *Module) isCoverageVariant() bool { |
| 549 | return c.coverage.Properties.IsCoverageVariant |
| 550 | } |
| 551 | |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 552 | func (c *Module) isNdk() bool { |
| 553 | return inList(c.Name(), ndkMigratedLibs) |
| 554 | } |
| 555 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 556 | func (c *Module) isLlndk(config android.Config) bool { |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 557 | // Returns true for both LLNDK (public) and LLNDK-private libs. |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 558 | return inList(c.Name(), *llndkLibraries(config)) |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 559 | } |
| 560 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 561 | func (c *Module) isLlndkPublic(config android.Config) bool { |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 562 | // Returns true only for LLNDK (public) libs. |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 563 | return c.isLlndk(config) && !c.isVndkPrivate(config) |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 564 | } |
| 565 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 566 | func (c *Module) isVndkPrivate(config android.Config) bool { |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 567 | // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private. |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 568 | return inList(c.Name(), *vndkPrivateLibraries(config)) |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 569 | } |
| 570 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 571 | func (c *Module) isVndk() bool { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 572 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 573 | return vndkdep.isVndk() |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 574 | } |
| 575 | return false |
| 576 | } |
| 577 | |
Jooyung Han | 76106d9 | 2019-05-20 18:49:10 +0900 | [diff] [blame] | 578 | func (c *Module) vndkVersion() string { |
| 579 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 580 | return vndkdep.Properties.Vndk.Version |
| 581 | } |
| 582 | return "" |
| 583 | } |
| 584 | |
Yi Kong | 7e53c57 | 2018-02-14 18:16:12 +0800 | [diff] [blame] | 585 | func (c *Module) isPgoCompile() bool { |
| 586 | if pgo := c.pgo; pgo != nil { |
| 587 | return pgo.Properties.PgoCompile |
| 588 | } |
| 589 | return false |
| 590 | } |
| 591 | |
Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 592 | func (c *Module) isNDKStubLibrary() bool { |
| 593 | if _, ok := c.compiler.(*stubDecorator); ok { |
| 594 | return true |
| 595 | } |
| 596 | return false |
| 597 | } |
| 598 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 599 | func (c *Module) isVndkSp() bool { |
| 600 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 601 | return vndkdep.isVndkSp() |
| 602 | } |
| 603 | return false |
| 604 | } |
| 605 | |
| 606 | func (c *Module) isVndkExt() bool { |
| 607 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 608 | return vndkdep.isVndkExt() |
| 609 | } |
| 610 | return false |
| 611 | } |
| 612 | |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 613 | func (c *Module) mustUseVendorVariant() bool { |
| 614 | return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList) |
| 615 | } |
| 616 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 617 | func (c *Module) getVndkExtendsModuleName() string { |
| 618 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 619 | return vndkdep.getVndkExtendsModuleName() |
| 620 | } |
| 621 | return "" |
| 622 | } |
| 623 | |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 624 | // Returns true only when this module is configured to have core and vendor |
| 625 | // variants. |
| 626 | func (c *Module) hasVendorVariant() bool { |
| 627 | return c.isVndk() || Bool(c.VendorProperties.Vendor_available) |
| 628 | } |
| 629 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 630 | func (c *Module) inRecovery() bool { |
| 631 | return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery() |
| 632 | } |
| 633 | |
| 634 | func (c *Module) onlyInRecovery() bool { |
| 635 | return c.ModuleBase.InstallInRecovery() |
| 636 | } |
| 637 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 638 | func (c *Module) IsStubs() bool { |
| 639 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 640 | return library.buildStubs() |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 641 | } else if _, ok := c.linker.(*llndkStubDecorator); ok { |
| 642 | return true |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 643 | } |
| 644 | return false |
| 645 | } |
| 646 | |
| 647 | func (c *Module) HasStubsVariants() bool { |
| 648 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 649 | return len(library.Properties.Stubs.Versions) > 0 |
| 650 | } |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 651 | if library, ok := c.linker.(*prebuiltLibraryLinker); ok { |
| 652 | return len(library.Properties.Stubs.Versions) > 0 |
| 653 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 654 | return false |
| 655 | } |
| 656 | |
Jiyong Park | a4b9dd0 | 2019-01-16 22:53:13 +0900 | [diff] [blame] | 657 | func (c *Module) bootstrap() bool { |
| 658 | return Bool(c.Properties.Bootstrap) |
| 659 | } |
| 660 | |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 661 | func (c *Module) nativeCoverage() bool { |
| 662 | return c.linker != nil && c.linker.nativeCoverage() |
| 663 | } |
| 664 | |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 665 | func isBionic(name string) bool { |
| 666 | switch name { |
| 667 | case "libc", "libm", "libdl", "linker": |
| 668 | return true |
| 669 | } |
| 670 | return false |
| 671 | } |
| 672 | |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 673 | func installToBootstrap(name string, config android.Config) bool { |
| 674 | if name == "libclang_rt.hwasan-aarch64-android" { |
| 675 | return inList("hwaddress", config.SanitizeDevice()) |
| 676 | } |
| 677 | return isBionic(name) |
| 678 | } |
| 679 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 680 | func (c *Module) XrefCcFiles() android.Paths { |
| 681 | return c.kytheFiles |
| 682 | } |
| 683 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 684 | type baseModuleContext struct { |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 685 | android.BaseModuleContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 686 | moduleContextImpl |
| 687 | } |
| 688 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 689 | type depsContext struct { |
| 690 | android.BottomUpMutatorContext |
| 691 | moduleContextImpl |
| 692 | } |
| 693 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 694 | type moduleContext struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 695 | android.ModuleContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 696 | moduleContextImpl |
| 697 | } |
| 698 | |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 699 | func (ctx *moduleContext) SocSpecific() bool { |
| 700 | return ctx.ModuleContext.SocSpecific() || |
| 701 | (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk()) |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 704 | type moduleContextImpl struct { |
| 705 | mod *Module |
| 706 | ctx BaseModuleContext |
| 707 | } |
| 708 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 709 | func (ctx *moduleContextImpl) toolchain() config.Toolchain { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 710 | return ctx.mod.toolchain(ctx.ctx) |
| 711 | } |
| 712 | |
| 713 | func (ctx *moduleContextImpl) static() bool { |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 714 | return ctx.mod.static() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | func (ctx *moduleContextImpl) staticBinary() bool { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 718 | return ctx.mod.staticBinary() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 719 | } |
| 720 | |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame^] | 721 | func (ctx *moduleContextImpl) header() bool { |
| 722 | return ctx.mod.header() |
| 723 | } |
| 724 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 725 | func (ctx *moduleContextImpl) useSdk() bool { |
Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 726 | if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 727 | return String(ctx.mod.Properties.Sdk_version) != "" |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 728 | } |
| 729 | return false |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | func (ctx *moduleContextImpl) sdkVersion() string { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 733 | if ctx.ctx.Device() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 734 | if ctx.useVndk() { |
Justin Yun | 732aa6a | 2018-03-23 17:43:47 +0900 | [diff] [blame] | 735 | vndk_ver := ctx.ctx.DeviceConfig().VndkVersion() |
Ryan Prichard | 0520611 | 2018-03-26 21:25:27 -0700 | [diff] [blame] | 736 | if vndk_ver == "current" { |
Justin Yun | 732aa6a | 2018-03-23 17:43:47 +0900 | [diff] [blame] | 737 | platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion() |
| 738 | if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) { |
| 739 | return "current" |
| 740 | } |
| 741 | return platform_vndk_ver |
| 742 | } |
| 743 | return vndk_ver |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 744 | } |
Justin Yun | 732aa6a | 2018-03-23 17:43:47 +0900 | [diff] [blame] | 745 | return String(ctx.mod.Properties.Sdk_version) |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 746 | } |
| 747 | return "" |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 750 | func (ctx *moduleContextImpl) useVndk() bool { |
| 751 | return ctx.mod.useVndk() |
| 752 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 753 | |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 754 | func (ctx *moduleContextImpl) isNdk() bool { |
| 755 | return ctx.mod.isNdk() |
| 756 | } |
| 757 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 758 | func (ctx *moduleContextImpl) isLlndk(config android.Config) bool { |
| 759 | return ctx.mod.isLlndk(config) |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 760 | } |
| 761 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 762 | func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool { |
| 763 | return ctx.mod.isLlndkPublic(config) |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 764 | } |
| 765 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 766 | func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool { |
| 767 | return ctx.mod.isVndkPrivate(config) |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 768 | } |
| 769 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 770 | func (ctx *moduleContextImpl) isVndk() bool { |
| 771 | return ctx.mod.isVndk() |
| 772 | } |
| 773 | |
Yi Kong | 7e53c57 | 2018-02-14 18:16:12 +0800 | [diff] [blame] | 774 | func (ctx *moduleContextImpl) isPgoCompile() bool { |
| 775 | return ctx.mod.isPgoCompile() |
| 776 | } |
| 777 | |
Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 778 | func (ctx *moduleContextImpl) isNDKStubLibrary() bool { |
| 779 | return ctx.mod.isNDKStubLibrary() |
| 780 | } |
| 781 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 782 | func (ctx *moduleContextImpl) isVndkSp() bool { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 783 | return ctx.mod.isVndkSp() |
| 784 | } |
| 785 | |
| 786 | func (ctx *moduleContextImpl) isVndkExt() bool { |
| 787 | return ctx.mod.isVndkExt() |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 788 | } |
| 789 | |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 790 | func (ctx *moduleContextImpl) mustUseVendorVariant() bool { |
| 791 | return ctx.mod.mustUseVendorVariant() |
| 792 | } |
| 793 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 794 | func (ctx *moduleContextImpl) inRecovery() bool { |
| 795 | return ctx.mod.inRecovery() |
| 796 | } |
| 797 | |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 798 | // Check whether ABI dumps should be created for this module. |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 799 | func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump(config android.Config) bool { |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 800 | if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") { |
| 801 | return false |
Jayant Chowdhary | ea0a2e1 | 2018-03-01 19:12:16 -0800 | [diff] [blame] | 802 | } |
Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 803 | |
| 804 | if ctx.ctx.Fuchsia() { |
| 805 | return false |
| 806 | } |
| 807 | |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 808 | if sanitize := ctx.mod.sanitize; sanitize != nil { |
| 809 | if !sanitize.isVariantOnProductionDevice() { |
| 810 | return false |
| 811 | } |
| 812 | } |
| 813 | if !ctx.ctx.Device() { |
| 814 | // Host modules do not need ABI dumps. |
| 815 | return false |
| 816 | } |
Logan Chien | fa478c0 | 2018-12-28 16:25:39 +0800 | [diff] [blame] | 817 | if !ctx.mod.IsForPlatform() { |
| 818 | // APEX variants do not need ABI dumps. |
| 819 | return false |
| 820 | } |
Hsin-Yi Chen | f6a9546 | 2019-06-25 14:46:52 +0800 | [diff] [blame] | 821 | if ctx.isStubs() { |
| 822 | // Stubs do not need ABI dumps. |
| 823 | return false |
| 824 | } |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 825 | if ctx.isNdk() { |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 826 | return true |
| 827 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 828 | if ctx.isLlndkPublic(config) { |
Logan Chien | f4b79c6 | 2018-08-02 02:27:02 +0800 | [diff] [blame] | 829 | return true |
| 830 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 831 | if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate(config) { |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 832 | // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not |
| 833 | // VNDK-private. |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 834 | return true |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 835 | } |
| 836 | return false |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 837 | } |
| 838 | |
Dan Willemsen | 8146b2f | 2016-03-30 21:00:30 -0700 | [diff] [blame] | 839 | func (ctx *moduleContextImpl) selectedStl() string { |
| 840 | if stl := ctx.mod.stl; stl != nil { |
| 841 | return stl.Properties.SelectedStl |
| 842 | } |
| 843 | return "" |
| 844 | } |
| 845 | |
Ivan Lozano | bd72126 | 2018-11-27 14:33:03 -0800 | [diff] [blame] | 846 | func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool { |
| 847 | return ctx.mod.linker.useClangLld(actx) |
| 848 | } |
| 849 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 850 | func (ctx *moduleContextImpl) baseModuleName() string { |
| 851 | return ctx.mod.ModuleBase.BaseModuleName() |
| 852 | } |
| 853 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 854 | func (ctx *moduleContextImpl) getVndkExtendsModuleName() string { |
| 855 | return ctx.mod.getVndkExtendsModuleName() |
| 856 | } |
| 857 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 858 | func (ctx *moduleContextImpl) apexName() string { |
| 859 | return ctx.mod.ApexName() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 860 | } |
| 861 | |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 862 | func (ctx *moduleContextImpl) hasStubsVariants() bool { |
| 863 | return ctx.mod.HasStubsVariants() |
| 864 | } |
| 865 | |
| 866 | func (ctx *moduleContextImpl) isStubs() bool { |
| 867 | return ctx.mod.IsStubs() |
| 868 | } |
| 869 | |
Jiyong Park | a4b9dd0 | 2019-01-16 22:53:13 +0900 | [diff] [blame] | 870 | func (ctx *moduleContextImpl) bootstrap() bool { |
| 871 | return ctx.mod.bootstrap() |
| 872 | } |
| 873 | |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 874 | func (ctx *moduleContextImpl) nativeCoverage() bool { |
| 875 | return ctx.mod.nativeCoverage() |
| 876 | } |
| 877 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 878 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 879 | return &Module{ |
| 880 | hod: hod, |
| 881 | multilib: multilib, |
| 882 | } |
| 883 | } |
| 884 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 885 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 886 | module := newBaseModule(hod, multilib) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 887 | module.features = []feature{ |
| 888 | &tidyFeature{}, |
| 889 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 890 | module.stl = &stl{} |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 891 | module.sanitize = &sanitize{} |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 892 | module.coverage = &coverage{} |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 893 | module.sabi = &sabi{} |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 894 | module.vndkdep = &vndkdep{} |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 895 | module.lto = <o{} |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 896 | module.pgo = &pgo{} |
Ivan Lozano | 074ec48 | 2018-11-21 08:59:37 -0800 | [diff] [blame] | 897 | module.xom = &xom{} |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 898 | return module |
| 899 | } |
| 900 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 901 | func (c *Module) Prebuilt() *android.Prebuilt { |
| 902 | if p, ok := c.linker.(prebuiltLinkerInterface); ok { |
| 903 | return p.prebuilt() |
| 904 | } |
| 905 | return nil |
| 906 | } |
| 907 | |
| 908 | func (c *Module) Name() string { |
| 909 | name := c.ModuleBase.Name() |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 910 | if p, ok := c.linker.(interface { |
| 911 | Name(string) string |
| 912 | }); ok { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 913 | name = p.Name(name) |
| 914 | } |
| 915 | return name |
| 916 | } |
| 917 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 918 | func (c *Module) Symlinks() []string { |
| 919 | if p, ok := c.installer.(interface { |
| 920 | symlinkList() []string |
| 921 | }); ok { |
| 922 | return p.symlinkList() |
| 923 | } |
| 924 | return nil |
| 925 | } |
| 926 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 927 | // orderDeps reorders dependencies into a list such that if module A depends on B, then |
| 928 | // A will precede B in the resultant list. |
| 929 | // This is convenient for passing into a linker. |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 930 | // Note that directSharedDeps should be the analogous static library for each shared lib dep |
| 931 | func orderDeps(directStaticDeps []android.Path, directSharedDeps []android.Path, allTransitiveDeps map[android.Path][]android.Path) (orderedAllDeps []android.Path, orderedDeclaredDeps []android.Path) { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 932 | // If A depends on B, then |
| 933 | // Every list containing A will also contain B later in the list |
| 934 | // So, after concatenating all lists, the final instance of B will have come from the same |
| 935 | // original list as the final instance of A |
| 936 | // So, the final instance of B will be later in the concatenation than the final A |
| 937 | // So, keeping only the final instance of A and of B ensures that A is earlier in the output |
| 938 | // list than B |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 939 | for _, dep := range directStaticDeps { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 940 | orderedAllDeps = append(orderedAllDeps, dep) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 941 | orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...) |
| 942 | } |
| 943 | for _, dep := range directSharedDeps { |
| 944 | orderedAllDeps = append(orderedAllDeps, dep) |
| 945 | orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 946 | } |
| 947 | |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 948 | orderedAllDeps = android.LastUniquePaths(orderedAllDeps) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 949 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 950 | // We don't want to add any new dependencies into directStaticDeps (to allow the caller to |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 951 | // intentionally exclude or replace any unwanted transitive dependencies), so we limit the |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 952 | // resultant list to only what the caller has chosen to include in directStaticDeps |
| 953 | _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 954 | |
| 955 | return orderedAllDeps, orderedDeclaredDeps |
| 956 | } |
| 957 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 958 | func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) { |
| 959 | // convert Module to Path |
| 960 | allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps)) |
| 961 | staticDepFiles := []android.Path{} |
| 962 | for _, dep := range staticDeps { |
| 963 | allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder |
| 964 | staticDepFiles = append(staticDepFiles, dep.outputFile.Path()) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 965 | } |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 966 | sharedDepFiles := []android.Path{} |
| 967 | for _, sharedDep := range sharedDeps { |
| 968 | staticAnalogue := sharedDep.staticVariant |
| 969 | if staticAnalogue != nil { |
| 970 | allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder |
| 971 | sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path()) |
| 972 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | // reorder the dependencies based on transitive dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 976 | module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 977 | |
| 978 | return results |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 981 | func (c *Module) IsTestPerSrcAllTestsVariation() bool { |
| 982 | test, ok := c.linker.(testPerSrc) |
| 983 | return ok && test.isAllTestsVariation() |
| 984 | } |
| 985 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 986 | func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
Roland Levillain | f2fad97 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 987 | // Handle the case of a test module split by `test_per_src` mutator. |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 988 | // |
| 989 | // The `test_per_src` mutator adds an extra variation named "", depending on all the other |
| 990 | // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this |
| 991 | // module and return early, as this module does not produce an output file per se. |
| 992 | if c.IsTestPerSrcAllTestsVariation() { |
| 993 | c.outputFile = android.OptionalPath{} |
| 994 | return |
Roland Levillain | f2fad97 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 995 | } |
| 996 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 997 | c.makeLinkType = c.getMakeLinkType(actx) |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 998 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 999 | ctx := &moduleContext{ |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1000 | ModuleContext: actx, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1001 | moduleContextImpl: moduleContextImpl{ |
| 1002 | mod: c, |
| 1003 | }, |
| 1004 | } |
| 1005 | ctx.ctx = ctx |
| 1006 | |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 1007 | deps := c.depsToPaths(ctx) |
| 1008 | if ctx.Failed() { |
| 1009 | return |
| 1010 | } |
| 1011 | |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 1012 | if c.Properties.Clang != nil && *c.Properties.Clang == false { |
| 1013 | ctx.PropertyErrorf("clang", "false (GCC) is no longer supported") |
| 1014 | } |
| 1015 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1016 | flags := Flags{ |
| 1017 | Toolchain: c.toolchain(ctx), |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 1018 | EmitXrefs: ctx.Config().EmitXrefRules(), |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1019 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1020 | if c.compiler != nil { |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 1021 | flags = c.compiler.compilerFlags(ctx, flags, deps) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1022 | } |
| 1023 | if c.linker != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 1024 | flags = c.linker.linkerFlags(ctx, flags) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1025 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 1026 | if c.stl != nil { |
| 1027 | flags = c.stl.flags(ctx, flags) |
| 1028 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1029 | if c.sanitize != nil { |
| 1030 | flags = c.sanitize.flags(ctx, flags) |
| 1031 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1032 | if c.coverage != nil { |
Pirama Arumuga Nainar | 82fe59b | 2019-07-02 14:55:35 -0700 | [diff] [blame] | 1033 | flags, deps = c.coverage.flags(ctx, flags, deps) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1034 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 1035 | if c.lto != nil { |
| 1036 | flags = c.lto.flags(ctx, flags) |
| 1037 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 1038 | if c.pgo != nil { |
| 1039 | flags = c.pgo.flags(ctx, flags) |
| 1040 | } |
Ivan Lozano | 074ec48 | 2018-11-21 08:59:37 -0800 | [diff] [blame] | 1041 | if c.xom != nil { |
| 1042 | flags = c.xom.flags(ctx, flags) |
| 1043 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1044 | for _, feature := range c.features { |
| 1045 | flags = feature.flags(ctx, flags) |
| 1046 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1047 | if ctx.Failed() { |
| 1048 | return |
| 1049 | } |
| 1050 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 1051 | flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags) |
| 1052 | flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags) |
| 1053 | flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1054 | |
Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 1055 | flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1056 | |
| 1057 | for _, dir := range deps.IncludeDirs { |
| 1058 | flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir) |
| 1059 | } |
| 1060 | for _, dir := range deps.SystemIncludeDirs { |
| 1061 | flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir) |
| 1062 | } |
| 1063 | |
Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 1064 | c.flags = flags |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 1065 | // We need access to all the flags seen by a source file. |
| 1066 | if c.sabi != nil { |
| 1067 | flags = c.sabi.flags(ctx, flags) |
| 1068 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1069 | // Optimization to reduce size of build.ninja |
| 1070 | // Replace the long list of flags for each file with a module-local variable |
| 1071 | ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " ")) |
| 1072 | ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " ")) |
| 1073 | ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " ")) |
| 1074 | flags.CFlags = []string{"$cflags"} |
| 1075 | flags.CppFlags = []string{"$cppflags"} |
| 1076 | flags.AsFlags = []string{"$asflags"} |
| 1077 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1078 | var objs Objects |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1079 | if c.compiler != nil { |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1080 | objs = c.compiler.compile(ctx, flags, deps) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1081 | if ctx.Failed() { |
| 1082 | return |
| 1083 | } |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 1084 | c.kytheFiles = objs.kytheFiles |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1085 | } |
| 1086 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1087 | if c.linker != nil { |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1088 | outputFile := c.linker.link(ctx, flags, deps, objs) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1089 | if ctx.Failed() { |
| 1090 | return |
| 1091 | } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1092 | c.outputFile = android.OptionalPathForPath(outputFile) |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1093 | |
| 1094 | // If a lib is directly included in any of the APEXes, unhide the stubs |
| 1095 | // variant having the latest version gets visible to make. In addition, |
| 1096 | // the non-stubs variant is renamed to <libname>.bootstrap. This is to |
| 1097 | // force anything in the make world to link against the stubs library. |
| 1098 | // (unless it is explicitly referenced via .bootstrap suffix or the |
| 1099 | // module is marked with 'bootstrap: true'). |
Nicolas Geoffray | c22c1bf | 2019-01-15 19:53:23 +0000 | [diff] [blame] | 1100 | if c.HasStubsVariants() && |
| 1101 | android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && |
Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 1102 | !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() && |
| 1103 | c.IsStubs() { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1104 | c.Properties.HideFromMake = false // unhide |
| 1105 | // Note: this is still non-installable |
| 1106 | } |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1107 | } |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 1108 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 1109 | if c.installable() { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1110 | c.installer.install(ctx, c.outputFile.Path()) |
| 1111 | if ctx.Failed() { |
| 1112 | return |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1113 | } |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1114 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1115 | } |
| 1116 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 1117 | func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1118 | if c.cachedToolchain == nil { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 1119 | c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1120 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1121 | return c.cachedToolchain |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1122 | } |
| 1123 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1124 | func (c *Module) begin(ctx BaseModuleContext) { |
| 1125 | if c.compiler != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 1126 | c.compiler.compilerInit(ctx) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1127 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1128 | if c.linker != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 1129 | c.linker.linkerInit(ctx) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1130 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 1131 | if c.stl != nil { |
| 1132 | c.stl.begin(ctx) |
| 1133 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1134 | if c.sanitize != nil { |
| 1135 | c.sanitize.begin(ctx) |
| 1136 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1137 | if c.coverage != nil { |
| 1138 | c.coverage.begin(ctx) |
| 1139 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1140 | if c.sabi != nil { |
| 1141 | c.sabi.begin(ctx) |
| 1142 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1143 | if c.vndkdep != nil { |
| 1144 | c.vndkdep.begin(ctx) |
| 1145 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 1146 | if c.lto != nil { |
| 1147 | c.lto.begin(ctx) |
| 1148 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 1149 | if c.pgo != nil { |
| 1150 | c.pgo.begin(ctx) |
| 1151 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1152 | for _, feature := range c.features { |
| 1153 | feature.begin(ctx) |
| 1154 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1155 | if ctx.useSdk() { |
Dan Albert | f5415d7 | 2017-08-17 16:19:59 -0700 | [diff] [blame] | 1156 | version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch()) |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 1157 | if err != nil { |
| 1158 | ctx.PropertyErrorf("sdk_version", err.Error()) |
| 1159 | } |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 1160 | c.Properties.Sdk_version = StringPtr(version) |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 1161 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1162 | } |
| 1163 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 1164 | func (c *Module) deps(ctx DepsContext) Deps { |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1165 | deps := Deps{} |
| 1166 | |
| 1167 | if c.compiler != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 1168 | deps = c.compiler.compilerDeps(ctx, deps) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1169 | } |
Pirama Arumuga Nainar | 0b882f0 | 2018-04-23 22:44:39 +0000 | [diff] [blame] | 1170 | // Add the PGO dependency (the clang_rt.profile runtime library), which |
| 1171 | // sometimes depends on symbols from libgcc, before libgcc gets added |
| 1172 | // in linkerDeps(). |
Pirama Arumuga Nainar | 49b53d5 | 2017-10-04 16:47:29 -0700 | [diff] [blame] | 1173 | if c.pgo != nil { |
| 1174 | deps = c.pgo.deps(ctx, deps) |
| 1175 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1176 | if c.linker != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 1177 | deps = c.linker.linkerDeps(ctx, deps) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1178 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 1179 | if c.stl != nil { |
| 1180 | deps = c.stl.deps(ctx, deps) |
| 1181 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1182 | if c.sanitize != nil { |
| 1183 | deps = c.sanitize.deps(ctx, deps) |
| 1184 | } |
Pirama Arumuga Nainar | 0b882f0 | 2018-04-23 22:44:39 +0000 | [diff] [blame] | 1185 | if c.coverage != nil { |
| 1186 | deps = c.coverage.deps(ctx, deps) |
| 1187 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1188 | if c.sabi != nil { |
| 1189 | deps = c.sabi.deps(ctx, deps) |
| 1190 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1191 | if c.vndkdep != nil { |
| 1192 | deps = c.vndkdep.deps(ctx, deps) |
| 1193 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 1194 | if c.lto != nil { |
| 1195 | deps = c.lto.deps(ctx, deps) |
| 1196 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1197 | for _, feature := range c.features { |
| 1198 | deps = feature.deps(ctx, deps) |
| 1199 | } |
| 1200 | |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 1201 | deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs) |
| 1202 | deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) |
| 1203 | deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs) |
| 1204 | deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) |
| 1205 | deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs) |
| 1206 | deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1207 | deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1208 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1209 | for _, lib := range deps.ReexportSharedLibHeaders { |
| 1210 | if !inList(lib, deps.SharedLibs) { |
| 1211 | ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib) |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | for _, lib := range deps.ReexportStaticLibHeaders { |
| 1216 | if !inList(lib, deps.StaticLibs) { |
| 1217 | ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib) |
| 1218 | } |
| 1219 | } |
| 1220 | |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 1221 | for _, lib := range deps.ReexportHeaderLibHeaders { |
| 1222 | if !inList(lib, deps.HeaderLibs) { |
| 1223 | ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib) |
| 1224 | } |
| 1225 | } |
| 1226 | |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1227 | for _, gen := range deps.ReexportGeneratedHeaders { |
| 1228 | if !inList(gen, deps.GeneratedHeaders) { |
| 1229 | ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen) |
| 1230 | } |
| 1231 | } |
| 1232 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1233 | return deps |
| 1234 | } |
| 1235 | |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1236 | func (c *Module) beginMutator(actx android.BottomUpMutatorContext) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1237 | ctx := &baseModuleContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 1238 | BaseModuleContext: actx, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1239 | moduleContextImpl: moduleContextImpl{ |
| 1240 | mod: c, |
| 1241 | }, |
| 1242 | } |
| 1243 | ctx.ctx = ctx |
| 1244 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1245 | c.begin(ctx) |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1248 | // Split name#version into name and version |
| 1249 | func stubsLibNameAndVersion(name string) (string, string) { |
| 1250 | if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 { |
| 1251 | version := name[sharp+1:] |
| 1252 | libname := name[:sharp] |
| 1253 | return libname, version |
| 1254 | } |
| 1255 | return name, "" |
| 1256 | } |
| 1257 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 1258 | func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 1259 | ctx := &depsContext{ |
| 1260 | BottomUpMutatorContext: actx, |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1261 | moduleContextImpl: moduleContextImpl{ |
| 1262 | mod: c, |
| 1263 | }, |
| 1264 | } |
| 1265 | ctx.ctx = ctx |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1266 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1267 | deps := c.deps(ctx) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1268 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1269 | variantNdkLibs := []string{} |
| 1270 | variantLateNdkLibs := []string{} |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 1271 | if ctx.Os() == android.Android { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1272 | version := ctx.sdkVersion() |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 1273 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1274 | // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types |
| 1275 | // of names: |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1276 | // |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1277 | // 1. Name of an NDK library that refers to a prebuilt module. |
| 1278 | // For each of these, it adds the name of the prebuilt module (which will be in |
| 1279 | // prebuilts/ndk) to the list of nonvariant libs. |
| 1280 | // 2. Name of an NDK library that refers to an ndk_library module. |
| 1281 | // For each of these, it adds the name of the ndk_library module to the list of |
| 1282 | // variant libs. |
| 1283 | // 3. Anything else (so anything that isn't an NDK library). |
| 1284 | // It adds these to the nonvariantLibs list. |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1285 | // |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1286 | // The caller can then know to add the variantLibs dependencies differently from the |
| 1287 | // nonvariantLibs |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1288 | |
| 1289 | llndkLibraries := llndkLibraries(actx.Config()) |
| 1290 | vendorPublicLibraries := vendorPublicLibraries(actx.Config()) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1291 | rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) { |
| 1292 | variantLibs = []string{} |
| 1293 | nonvariantLibs = []string{} |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1294 | for _, entry := range list { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1295 | // strip #version suffix out |
| 1296 | name, _ := stubsLibNameAndVersion(entry) |
| 1297 | if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) { |
| 1298 | if !inList(name, ndkMigratedLibs) { |
| 1299 | nonvariantLibs = append(nonvariantLibs, name+".ndk."+version) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1300 | } else { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1301 | variantLibs = append(variantLibs, name+ndkLibrarySuffix) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1302 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1303 | } else if ctx.useVndk() && inList(name, *llndkLibraries) { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1304 | nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix) |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1305 | } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1306 | vendorPublicLib := name + vendorPublicLibrarySuffix |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1307 | if actx.OtherModuleExists(vendorPublicLib) { |
| 1308 | nonvariantLibs = append(nonvariantLibs, vendorPublicLib) |
| 1309 | } else { |
| 1310 | // This can happen if vendor_public_library module is defined in a |
| 1311 | // namespace that isn't visible to the current module. In that case, |
| 1312 | // link to the original library. |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1313 | nonvariantLibs = append(nonvariantLibs, name) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1314 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1315 | } else { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1316 | // put name#version back |
Dan Willemsen | 7cbf5f8 | 2017-03-28 00:08:30 -0700 | [diff] [blame] | 1317 | nonvariantLibs = append(nonvariantLibs, entry) |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 1318 | } |
| 1319 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1320 | return nonvariantLibs, variantLibs |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1323 | deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs) |
| 1324 | deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs) |
Jiyong Park | 4c35af0 | 2017-07-05 13:41:55 +0900 | [diff] [blame] | 1325 | deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders) |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 1326 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1327 | |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1328 | buildStubs := false |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1329 | if c.linker != nil { |
| 1330 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 1331 | if library.buildStubs() { |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1332 | buildStubs = true |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1333 | } |
| 1334 | } |
| 1335 | } |
| 1336 | |
Colin Cross | 32ec36c | 2016-12-15 07:39:51 -0800 | [diff] [blame] | 1337 | for _, lib := range deps.HeaderLibs { |
| 1338 | depTag := headerDepTag |
| 1339 | if inList(lib, deps.ReexportHeaderLibHeaders) { |
| 1340 | depTag = headerExportDepTag |
| 1341 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1342 | if buildStubs { |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1343 | actx.AddFarVariationDependencies([]blueprint.Variation{ |
| 1344 | {Mutator: "arch", Variation: ctx.Target().String()}, |
Jiyong Park | 3b1746a | 2019-01-29 11:15:04 +0900 | [diff] [blame] | 1345 | {Mutator: "image", Variation: c.imageVariation()}, |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1346 | }, depTag, lib) |
| 1347 | } else { |
| 1348 | actx.AddVariationDependencies(nil, depTag, lib) |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | if buildStubs { |
| 1353 | // Stubs lib does not have dependency to other static/shared libraries. |
| 1354 | // Don't proceed. |
| 1355 | return |
Colin Cross | 32ec36c | 2016-12-15 07:39:51 -0800 | [diff] [blame] | 1356 | } |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 1357 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1358 | syspropImplLibraries := syspropImplLibraries(actx.Config()) |
| 1359 | |
Jiyong Park | 5d1598f | 2019-02-25 22:14:17 +0900 | [diff] [blame] | 1360 | for _, lib := range deps.WholeStaticLibs { |
| 1361 | depTag := wholeStaticDepTag |
| 1362 | if impl, ok := syspropImplLibraries[lib]; ok { |
| 1363 | lib = impl |
| 1364 | } |
| 1365 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1366 | {Mutator: "link", Variation: "static"}, |
| 1367 | }, depTag, lib) |
| 1368 | } |
| 1369 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1370 | for _, lib := range deps.StaticLibs { |
| 1371 | depTag := staticDepTag |
| 1372 | if inList(lib, deps.ReexportStaticLibHeaders) { |
| 1373 | depTag = staticExportDepTag |
| 1374 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1375 | |
| 1376 | if impl, ok := syspropImplLibraries[lib]; ok { |
| 1377 | lib = impl |
| 1378 | } |
| 1379 | |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1380 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1381 | {Mutator: "link", Variation: "static"}, |
| 1382 | }, depTag, lib) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1383 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1384 | |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1385 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1386 | {Mutator: "link", Variation: "static"}, |
| 1387 | }, lateStaticDepTag, deps.LateStaticLibs...) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1388 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1389 | addSharedLibDependencies := func(depTag dependencyTag, name string, version string) { |
| 1390 | var variations []blueprint.Variation |
| 1391 | variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"}) |
Jiyong Park | 0fefdea | 2018-12-13 12:01:31 +0900 | [diff] [blame] | 1392 | versionVariantAvail := !ctx.useVndk() && !c.inRecovery() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1393 | if version != "" && versionVariantAvail { |
| 1394 | // Version is explicitly specified. i.e. libFoo#30 |
| 1395 | variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version}) |
| 1396 | depTag.explicitlyVersioned = true |
| 1397 | } |
| 1398 | actx.AddVariationDependencies(variations, depTag, name) |
| 1399 | |
| 1400 | // If the version is not specified, add dependency to the latest stubs library. |
| 1401 | // The stubs library will be used when the depending module is built for APEX and |
| 1402 | // the dependent module is not in the same APEX. |
| 1403 | latestVersion := latestStubsVersionFor(actx.Config(), name) |
| 1404 | if version == "" && latestVersion != "" && versionVariantAvail { |
| 1405 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1406 | {Mutator: "link", Variation: "shared"}, |
| 1407 | {Mutator: "version", Variation: latestVersion}, |
| 1408 | }, depTag, name) |
| 1409 | // Note that depTag.explicitlyVersioned is false in this case. |
| 1410 | } |
| 1411 | } |
| 1412 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1413 | // shared lib names without the #version suffix |
| 1414 | var sharedLibNames []string |
| 1415 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1416 | for _, lib := range deps.SharedLibs { |
| 1417 | depTag := sharedDepTag |
| 1418 | if inList(lib, deps.ReexportSharedLibHeaders) { |
| 1419 | depTag = sharedExportDepTag |
| 1420 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1421 | |
| 1422 | if impl, ok := syspropImplLibraries[lib]; ok { |
| 1423 | lib = impl |
| 1424 | } |
| 1425 | |
| 1426 | name, version := stubsLibNameAndVersion(lib) |
| 1427 | sharedLibNames = append(sharedLibNames, name) |
| 1428 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1429 | addSharedLibDependencies(depTag, name, version) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1430 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1431 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1432 | for _, lib := range deps.LateSharedLibs { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1433 | if inList(lib, sharedLibNames) { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1434 | // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...) |
| 1435 | // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be |
| 1436 | // linking against both the stubs lib and the non-stubs lib at the same time. |
| 1437 | continue |
| 1438 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1439 | addSharedLibDependencies(lateSharedDepTag, lib, "") |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1440 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1441 | |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1442 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1443 | {Mutator: "link", Variation: "shared"}, |
| 1444 | }, runtimeDepTag, deps.RuntimeLibs...) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1445 | |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 1446 | actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...) |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1447 | |
| 1448 | for _, gen := range deps.GeneratedHeaders { |
| 1449 | depTag := genHeaderDepTag |
| 1450 | if inList(gen, deps.ReexportGeneratedHeaders) { |
| 1451 | depTag = genHeaderExportDepTag |
| 1452 | } |
| 1453 | actx.AddDependency(c, depTag, gen) |
| 1454 | } |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1455 | |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 1456 | actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1457 | |
| 1458 | if deps.CrtBegin != "" { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 1459 | actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1460 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1461 | if deps.CrtEnd != "" { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 1462 | actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1463 | } |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1464 | if deps.LinkerFlagsFile != "" { |
| 1465 | actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile) |
| 1466 | } |
| 1467 | if deps.DynamicLinker != "" { |
| 1468 | actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker) |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 1469 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1470 | |
| 1471 | version := ctx.sdkVersion() |
| 1472 | actx.AddVariationDependencies([]blueprint.Variation{ |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1473 | {Mutator: "ndk_api", Variation: version}, |
| 1474 | {Mutator: "link", Variation: "shared"}, |
| 1475 | }, ndkStubDepTag, variantNdkLibs...) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1476 | actx.AddVariationDependencies([]blueprint.Variation{ |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1477 | {Mutator: "ndk_api", Variation: version}, |
| 1478 | {Mutator: "link", Variation: "shared"}, |
| 1479 | }, ndkLateStubDepTag, variantLateNdkLibs...) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1480 | |
| 1481 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 1482 | if vndkdep.isVndkExt() { |
| 1483 | baseModuleMode := vendorMode |
| 1484 | if actx.DeviceConfig().VndkVersion() == "" { |
| 1485 | baseModuleMode = coreMode |
| 1486 | } |
| 1487 | actx.AddVariationDependencies([]blueprint.Variation{ |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1488 | {Mutator: "image", Variation: baseModuleMode}, |
| 1489 | {Mutator: "link", Variation: "shared"}, |
| 1490 | }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName()) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1491 | } |
| 1492 | } |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 1493 | } |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1494 | |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 1495 | func BeginMutator(ctx android.BottomUpMutatorContext) { |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1496 | if c, ok := ctx.Module().(*Module); ok && c.Enabled() { |
| 1497 | c.beginMutator(ctx) |
| 1498 | } |
| 1499 | } |
| 1500 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1501 | // Whether a module can link to another module, taking into |
| 1502 | // account NDK linking. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1503 | func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1504 | if from.Target().Os != android.Android { |
| 1505 | // Host code is not restricted |
| 1506 | return |
| 1507 | } |
| 1508 | if from.Properties.UseVndk { |
| 1509 | // Though vendor code is limited by the vendor mutator, |
| 1510 | // each vendor-available module needs to check |
| 1511 | // link-type for VNDK. |
| 1512 | if from.vndkdep != nil { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1513 | from.vndkdep.vndkCheckLinkType(ctx, to, tag) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1514 | } |
| 1515 | return |
| 1516 | } |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 1517 | if String(from.Properties.Sdk_version) == "" { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1518 | // Platform code can link to anything |
| 1519 | return |
| 1520 | } |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1521 | if from.inRecovery() { |
| 1522 | // Recovery code is not NDK |
| 1523 | return |
| 1524 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1525 | if _, ok := to.linker.(*toolchainLibraryDecorator); ok { |
| 1526 | // These are always allowed |
| 1527 | return |
| 1528 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1529 | if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok { |
| 1530 | // These are allowed, but they don't set sdk_version |
| 1531 | return |
| 1532 | } |
| 1533 | if _, ok := to.linker.(*stubDecorator); ok { |
| 1534 | // These aren't real libraries, but are the stub shared libraries that are included in |
| 1535 | // the NDK. |
| 1536 | return |
| 1537 | } |
Logan Chien | 834b9a6 | 2019-01-14 15:39:03 +0800 | [diff] [blame] | 1538 | |
| 1539 | if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" { |
| 1540 | // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version) |
| 1541 | // to link to libc++ (non-NDK and without sdk_version). |
| 1542 | return |
| 1543 | } |
| 1544 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 1545 | if String(to.Properties.Sdk_version) == "" { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1546 | // NDK code linking to platform code is never okay. |
| 1547 | ctx.ModuleErrorf("depends on non-NDK-built library %q", |
| 1548 | ctx.OtherModuleName(to)) |
Dan Willemsen | 155d17c | 2019-02-06 18:30:02 -0800 | [diff] [blame] | 1549 | return |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | // At this point we know we have two NDK libraries, but we need to |
| 1553 | // check that we're not linking against anything built against a higher |
| 1554 | // API level, as it is only valid to link against older or equivalent |
| 1555 | // APIs. |
| 1556 | |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 1557 | // Current can link against anything. |
| 1558 | if String(from.Properties.Sdk_version) != "current" { |
| 1559 | // Otherwise we need to check. |
| 1560 | if String(to.Properties.Sdk_version) == "current" { |
| 1561 | // Current can't be linked against by anything else. |
| 1562 | ctx.ModuleErrorf("links %q built against newer API version %q", |
| 1563 | ctx.OtherModuleName(to), "current") |
| 1564 | } else { |
| 1565 | fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version)) |
| 1566 | if err != nil { |
| 1567 | ctx.PropertyErrorf("sdk_version", |
Inseob Kim | 34b2283 | 2018-04-11 10:13:16 +0900 | [diff] [blame] | 1568 | "Invalid sdk_version value (must be int or current): %q", |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 1569 | String(from.Properties.Sdk_version)) |
| 1570 | } |
| 1571 | toApi, err := strconv.Atoi(String(to.Properties.Sdk_version)) |
| 1572 | if err != nil { |
| 1573 | ctx.PropertyErrorf("sdk_version", |
Inseob Kim | 34b2283 | 2018-04-11 10:13:16 +0900 | [diff] [blame] | 1574 | "Invalid sdk_version value (must be int or current): %q", |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 1575 | String(to.Properties.Sdk_version)) |
| 1576 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1577 | |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 1578 | if toApi > fromApi { |
| 1579 | ctx.ModuleErrorf("links %q built against newer API version %q", |
| 1580 | ctx.OtherModuleName(to), String(to.Properties.Sdk_version)) |
| 1581 | } |
| 1582 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1583 | } |
Dan Albert | 202fe49 | 2017-12-15 13:56:59 -0800 | [diff] [blame] | 1584 | |
| 1585 | // Also check that the two STL choices are compatible. |
| 1586 | fromStl := from.stl.Properties.SelectedStl |
| 1587 | toStl := to.stl.Properties.SelectedStl |
| 1588 | if fromStl == "" || toStl == "" { |
| 1589 | // Libraries that don't use the STL are unrestricted. |
Inseob Kim | da2171a | 2018-04-11 15:41:38 +0900 | [diff] [blame] | 1590 | } else if fromStl == "ndk_system" || toStl == "ndk_system" { |
Dan Albert | 202fe49 | 2017-12-15 13:56:59 -0800 | [diff] [blame] | 1591 | // We can be permissive with the system "STL" since it is only the C++ |
| 1592 | // ABI layer, but in the future we should make sure that everyone is |
| 1593 | // using either libc++ or nothing. |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 1594 | } else if getNdkStlFamily(from) != getNdkStlFamily(to) { |
Dan Albert | 202fe49 | 2017-12-15 13:56:59 -0800 | [diff] [blame] | 1595 | ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q", |
| 1596 | from.stl.Properties.SelectedStl, ctx.OtherModuleName(to), |
| 1597 | to.stl.Properties.SelectedStl) |
| 1598 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 1601 | // Tests whether the dependent library is okay to be double loaded inside a single process. |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1602 | // If a library has a vendor variant and is a (transitive) dependency of an LLNDK library, |
| 1603 | // it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 1604 | // or as vndk-sp (vndk: { enabled: true, support_system_process: true}). |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1605 | func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) { |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1606 | llndkLibraries := llndkLibraries(ctx.Config()) |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1607 | check := func(child, parent android.Module) bool { |
| 1608 | to, ok := child.(*Module) |
| 1609 | if !ok { |
| 1610 | // follow thru cc.Defaults, etc. |
| 1611 | return true |
| 1612 | } |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 1613 | |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1614 | if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() { |
| 1615 | return false |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 1616 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1617 | |
| 1618 | // if target lib has no vendor variant, keep checking dependency graph |
| 1619 | if !to.hasVendorVariant() { |
| 1620 | return true |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 1621 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1622 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1623 | if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) { |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1624 | return false |
| 1625 | } |
| 1626 | |
| 1627 | var stringPath []string |
| 1628 | for _, m := range ctx.GetWalkPath() { |
| 1629 | stringPath = append(stringPath, m.Name()) |
| 1630 | } |
| 1631 | ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+ |
| 1632 | "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+ |
| 1633 | "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> ")) |
| 1634 | return false |
| 1635 | } |
| 1636 | if module, ok := ctx.Module().(*Module); ok { |
| 1637 | if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() { |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1638 | if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) { |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1639 | ctx.WalkDeps(check) |
| 1640 | } |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 1641 | } |
| 1642 | } |
| 1643 | } |
| 1644 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1645 | // Convert dependencies to paths. Returns a PathDeps containing paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1646 | func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1647 | var depPaths PathDeps |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1648 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1649 | directStaticDeps := []*Module{} |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1650 | directSharedDeps := []*Module{} |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1651 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1652 | llndkLibraries := llndkLibraries(ctx.Config()) |
| 1653 | vendorPublicLibraries := vendorPublicLibraries(ctx.Config()) |
| 1654 | |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1655 | reexportExporter := func(exporter exportedFlagsProducer) { |
| 1656 | depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...) |
| 1657 | depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...) |
| 1658 | depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...) |
| 1659 | depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...) |
| 1660 | } |
| 1661 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 1662 | ctx.VisitDirectDeps(func(dep android.Module) { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1663 | depName := ctx.OtherModuleName(dep) |
| 1664 | depTag := ctx.OtherModuleDependencyTag(dep) |
Dan Albert | 9e10cd4 | 2016-08-03 14:12:14 -0700 | [diff] [blame] | 1665 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1666 | ccDep, _ := dep.(*Module) |
| 1667 | if ccDep == nil { |
| 1668 | // handling for a few module types that aren't cc Module but that are also supported |
| 1669 | switch depTag { |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1670 | case genSourceDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1671 | if genRule, ok := dep.(genrule.SourceFileGenerator); ok { |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1672 | depPaths.GeneratedSources = append(depPaths.GeneratedSources, |
| 1673 | genRule.GeneratedSourceFiles()...) |
| 1674 | } else { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1675 | ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName) |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1676 | } |
Colin Cross | e90bfd1 | 2017-04-26 16:59:26 -0700 | [diff] [blame] | 1677 | // Support exported headers from a generated_sources dependency |
| 1678 | fallthrough |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1679 | case genHeaderDepTag, genHeaderExportDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1680 | if genRule, ok := dep.(genrule.SourceFileGenerator); ok { |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1681 | depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, |
Dan Willemsen | 9da9d49 | 2018-02-21 18:28:18 -0800 | [diff] [blame] | 1682 | genRule.GeneratedDeps()...) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1683 | dirs := genRule.GeneratedHeaderDirs().Strings() |
| 1684 | depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1685 | if depTag == genHeaderExportDepTag { |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1686 | depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...) |
| 1687 | depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...) |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 1688 | // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library. |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1689 | c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs...) |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 1690 | |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1691 | } |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1692 | } else { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1693 | ctx.ModuleErrorf("module %q is not a genrule", depName) |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1694 | } |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1695 | case linkerFlagsDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1696 | if genRule, ok := dep.(genrule.SourceFileGenerator); ok { |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 1697 | files := genRule.GeneratedSourceFiles() |
| 1698 | if len(files) == 1 { |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1699 | depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0]) |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 1700 | } else if len(files) > 1 { |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1701 | ctx.ModuleErrorf("module %q can only generate a single file if used for a linker flag file", depName) |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 1702 | } |
| 1703 | } else { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1704 | ctx.ModuleErrorf("module %q is not a genrule", depName) |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 1705 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1706 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1707 | return |
| 1708 | } |
| 1709 | |
Colin Cross | fe17f6f | 2019-03-28 19:30:56 -0700 | [diff] [blame] | 1710 | if depTag == android.ProtoPluginDepTag { |
| 1711 | return |
| 1712 | } |
| 1713 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 1714 | if dep.Target().Os != ctx.Os() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1715 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) |
| 1716 | return |
| 1717 | } |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 1718 | if dep.Target().Arch.ArchType != ctx.Arch().ArchType { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1719 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1720 | return |
| 1721 | } |
| 1722 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1723 | // re-exporting flags |
| 1724 | if depTag == reuseObjTag { |
| 1725 | if l, ok := ccDep.compiler.(libraryInterface); ok { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1726 | c.staticVariant = ccDep |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1727 | objs, exporter := l.reuseObjs() |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 1728 | depPaths.Objs = depPaths.Objs.Append(objs) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1729 | reexportExporter(exporter) |
Colin Cross | bba9904 | 2016-11-23 15:45:05 -0800 | [diff] [blame] | 1730 | return |
| 1731 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1732 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1733 | |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 1734 | if depTag == staticVariantTag { |
| 1735 | if _, ok := ccDep.compiler.(libraryInterface); ok { |
| 1736 | c.staticVariant = ccDep |
| 1737 | return |
| 1738 | } |
| 1739 | } |
| 1740 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1741 | // Extract explicitlyVersioned field from the depTag and reset it inside the struct. |
| 1742 | // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true |
| 1743 | // won't be matched to sharedDepTag and lateSharedDepTag. |
| 1744 | explicitlyVersioned := false |
| 1745 | if t, ok := depTag.(dependencyTag); ok { |
| 1746 | explicitlyVersioned = t.explicitlyVersioned |
| 1747 | t.explicitlyVersioned = false |
| 1748 | depTag = t |
| 1749 | } |
| 1750 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1751 | if t, ok := depTag.(dependencyTag); ok && t.library { |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1752 | depIsStatic := false |
| 1753 | switch depTag { |
| 1754 | case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag: |
| 1755 | depIsStatic = true |
| 1756 | } |
| 1757 | if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1758 | depIsStubs := dependentLibrary.buildStubs() |
| 1759 | depHasStubs := ccDep.HasStubsVariants() |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1760 | depInSameApex := android.DirectlyInApex(c.ApexName(), depName) |
Nicolas Geoffray | c22c1bf | 2019-01-15 19:53:23 +0000 | [diff] [blame] | 1761 | depInPlatform := !android.DirectlyInAnyApex(ctx, depName) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1762 | |
| 1763 | var useThisDep bool |
| 1764 | if depIsStubs && explicitlyVersioned { |
| 1765 | // Always respect dependency to the versioned stubs (i.e. libX#10) |
| 1766 | useThisDep = true |
| 1767 | } else if !depHasStubs { |
| 1768 | // Use non-stub variant if that is the only choice |
| 1769 | // (i.e. depending on a lib without stubs.version property) |
| 1770 | useThisDep = true |
| 1771 | } else if c.IsForPlatform() { |
| 1772 | // If not building for APEX, use stubs only when it is from |
| 1773 | // an APEX (and not from platform) |
| 1774 | useThisDep = (depInPlatform != depIsStubs) |
Jiyong Park | a4b9dd0 | 2019-01-16 22:53:13 +0900 | [diff] [blame] | 1775 | if c.inRecovery() || c.bootstrap() { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1776 | // However, for recovery or bootstrap modules, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1777 | // always link to non-stub variant |
| 1778 | useThisDep = !depIsStubs |
| 1779 | } |
| 1780 | } else { |
| 1781 | // If building for APEX, use stubs only when it is not from |
| 1782 | // the same APEX |
| 1783 | useThisDep = (depInSameApex != depIsStubs) |
| 1784 | } |
| 1785 | |
| 1786 | if !useThisDep { |
| 1787 | return // stop processing this dep |
| 1788 | } |
| 1789 | } |
| 1790 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1791 | if i, ok := ccDep.linker.(exportedFlagsProducer); ok { |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1792 | depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...) |
| 1793 | depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...) |
| 1794 | depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...) |
| 1795 | depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1796 | |
| 1797 | if t.reexportFlags { |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1798 | reexportExporter(i) |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 1799 | // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library. |
Jayant Chowdhary | af6eb71 | 2017-08-23 16:08:29 -0700 | [diff] [blame] | 1800 | // Re-exported shared library headers must be included as well since they can help us with type information |
| 1801 | // about template instantiations (instantiated from their headers). |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1802 | // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version |
| 1803 | // scripts. |
| 1804 | c.sabi.Properties.ReexportedIncludes = append( |
| 1805 | c.sabi.Properties.ReexportedIncludes, i.exportedDirs()...) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1806 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1807 | } |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1808 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1809 | checkLinkType(ctx, c, ccDep, t) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1812 | var ptr *android.Paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1813 | var depPtr *android.Paths |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1814 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1815 | linkFile := ccDep.outputFile |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1816 | depFile := android.OptionalPath{} |
| 1817 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1818 | switch depTag { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1819 | case ndkStubDepTag, sharedDepTag, sharedExportDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1820 | ptr = &depPaths.SharedLibs |
| 1821 | depPtr = &depPaths.SharedLibsDeps |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1822 | depFile = ccDep.linker.(libraryInterface).toc() |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1823 | directSharedDeps = append(directSharedDeps, ccDep) |
Jiyong Park | 64a44f2 | 2019-01-18 14:37:08 +0900 | [diff] [blame] | 1824 | case earlySharedDepTag: |
| 1825 | ptr = &depPaths.EarlySharedLibs |
| 1826 | depPtr = &depPaths.EarlySharedLibsDeps |
| 1827 | depFile = ccDep.linker.(libraryInterface).toc() |
| 1828 | directSharedDeps = append(directSharedDeps, ccDep) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1829 | case lateSharedDepTag, ndkLateStubDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1830 | ptr = &depPaths.LateSharedLibs |
| 1831 | depPtr = &depPaths.LateSharedLibsDeps |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1832 | depFile = ccDep.linker.(libraryInterface).toc() |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1833 | case staticDepTag, staticExportDepTag: |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1834 | ptr = nil |
| 1835 | directStaticDeps = append(directStaticDeps, ccDep) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1836 | case lateStaticDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1837 | ptr = &depPaths.LateStaticLibs |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1838 | case wholeStaticDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1839 | ptr = &depPaths.WholeStaticLibs |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1840 | staticLib, ok := ccDep.linker.(libraryInterface) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 1841 | if !ok || !staticLib.static() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1842 | ctx.ModuleErrorf("module %q not a static library", depName) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1843 | return |
| 1844 | } |
| 1845 | |
| 1846 | if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1847 | postfix := " (required by " + ctx.OtherModuleName(dep) + ")" |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1848 | for i := range missingDeps { |
| 1849 | missingDeps[i] += postfix |
| 1850 | } |
| 1851 | ctx.AddMissingDependencies(missingDeps) |
| 1852 | } |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1853 | depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs()) |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 1854 | case headerDepTag: |
| 1855 | // Nothing |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1856 | case objDepTag: |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1857 | depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path()) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1858 | case crtBeginDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1859 | depPaths.CrtBegin = linkFile |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1860 | case crtEndDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1861 | depPaths.CrtEnd = linkFile |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1862 | case dynamicLinkerDepTag: |
| 1863 | depPaths.DynamicLinker = linkFile |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1864 | } |
| 1865 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1866 | switch depTag { |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1867 | case staticDepTag, staticExportDepTag, lateStaticDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1868 | staticLib, ok := ccDep.linker.(libraryInterface) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1869 | if !ok || !staticLib.static() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1870 | ctx.ModuleErrorf("module %q not a static library", depName) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1871 | return |
| 1872 | } |
| 1873 | |
| 1874 | // When combining coverage files for shared libraries and executables, coverage files |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1875 | // in static libraries act as if they were whole static libraries. The same goes for |
| 1876 | // source based Abi dump files. |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1877 | depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles, |
| 1878 | staticLib.objs().coverageFiles...) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1879 | depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles, |
| 1880 | staticLib.objs().sAbiDumpFiles...) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1881 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1882 | } |
| 1883 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1884 | if ptr != nil { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1885 | if !linkFile.Valid() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1886 | ctx.ModuleErrorf("module %q missing output file", depName) |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1887 | return |
| 1888 | } |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1889 | *ptr = append(*ptr, linkFile.Path()) |
| 1890 | } |
| 1891 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1892 | if depPtr != nil { |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1893 | dep := depFile |
| 1894 | if !dep.Valid() { |
| 1895 | dep = linkFile |
| 1896 | } |
| 1897 | *depPtr = append(*depPtr, dep.Path()) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1898 | } |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1899 | |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1900 | makeLibName := func(depName string) string { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1901 | libName := strings.TrimSuffix(depName, llndkLibrarySuffix) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1902 | libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix) |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1903 | libName = strings.TrimPrefix(libName, "prebuilt_") |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1904 | isLLndk := inList(libName, *llndkLibraries) |
| 1905 | isVendorPublicLib := inList(libName, *vendorPublicLibraries) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1906 | bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 1907 | |
| 1908 | if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() { |
| 1909 | // The vendor module is a no-vendor-variant VNDK library. Depend on the |
| 1910 | // core module instead. |
| 1911 | return libName |
| 1912 | } else if c.useVndk() && bothVendorAndCoreVariantsExist { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1913 | // The vendor module in Make will have been renamed to not conflict with the core |
| 1914 | // module, so update the dependency name here accordingly. |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1915 | return libName + vendorSuffix |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1916 | } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1917 | return libName + vendorPublicLibrarySuffix |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1918 | } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() { |
| 1919 | return libName + recoverySuffix |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1920 | } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled { |
dimitry | 4320449 | 2019-05-23 13:24:38 +0200 | [diff] [blame] | 1921 | return libName + nativeBridgeSuffix |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1922 | } else { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1923 | return libName |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1924 | } |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | // Export the shared libs to Make. |
| 1928 | switch depTag { |
Jiyong Park | 64a44f2 | 2019-01-18 14:37:08 +0900 | [diff] [blame] | 1929 | case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag: |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 1930 | if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1931 | if dependentLibrary.buildStubs() && android.InAnyApex(depName) { |
Logan Chien | 09106e1 | 2019-01-18 14:57:48 +0800 | [diff] [blame] | 1932 | // Add the dependency to the APEX(es) providing the library so that |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 1933 | // m <module> can trigger building the APEXes as well. |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1934 | for _, an := range android.GetApexesForModule(depName) { |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 1935 | c.Properties.ApexesProvidingSharedLibs = append( |
| 1936 | c.Properties.ApexesProvidingSharedLibs, an) |
| 1937 | } |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 1938 | } |
| 1939 | } |
| 1940 | |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1941 | // Note: the order of libs in this list is not important because |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1942 | // they merely serve as Make dependencies and do not affect this lib itself. |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1943 | c.Properties.AndroidMkSharedLibs = append( |
| 1944 | c.Properties.AndroidMkSharedLibs, makeLibName(depName)) |
Logan Chien | c7f797e | 2019-01-14 15:35:08 +0800 | [diff] [blame] | 1945 | case ndkStubDepTag, ndkLateStubDepTag: |
| 1946 | ndkStub := ccDep.linker.(*stubDecorator) |
| 1947 | c.Properties.AndroidMkSharedLibs = append( |
| 1948 | c.Properties.AndroidMkSharedLibs, |
| 1949 | depName+"."+ndkStub.properties.ApiLevel) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 1950 | case staticDepTag, staticExportDepTag, lateStaticDepTag: |
| 1951 | c.Properties.AndroidMkStaticLibs = append( |
| 1952 | c.Properties.AndroidMkStaticLibs, makeLibName(depName)) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1953 | case runtimeDepTag: |
| 1954 | c.Properties.AndroidMkRuntimeLibs = append( |
| 1955 | c.Properties.AndroidMkRuntimeLibs, makeLibName(depName)) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 1956 | case wholeStaticDepTag: |
| 1957 | c.Properties.AndroidMkWholeStaticLibs = append( |
| 1958 | c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName)) |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1959 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1960 | }) |
| 1961 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1962 | // use the ordered dependencies as this module's dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1963 | depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1964 | |
Colin Cross | dd84e05 | 2017-05-17 13:44:16 -0700 | [diff] [blame] | 1965 | // Dedup exported flags from dependencies |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 1966 | depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1967 | depPaths.IncludeDirs = android.FirstUniqueStrings(depPaths.IncludeDirs) |
| 1968 | depPaths.SystemIncludeDirs = android.FirstUniqueStrings(depPaths.SystemIncludeDirs) |
Dan Willemsen | fe92c96 | 2017-08-29 12:28:37 -0700 | [diff] [blame] | 1969 | depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1970 | depPaths.ReexportedDirs = android.FirstUniqueStrings(depPaths.ReexportedDirs) |
| 1971 | depPaths.ReexportedSystemDirs = android.FirstUniqueStrings(depPaths.ReexportedSystemDirs) |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 1972 | depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1973 | depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps) |
Dan Willemsen | fe92c96 | 2017-08-29 12:28:37 -0700 | [diff] [blame] | 1974 | |
| 1975 | if c.sabi != nil { |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1976 | c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes) |
Dan Willemsen | fe92c96 | 2017-08-29 12:28:37 -0700 | [diff] [blame] | 1977 | } |
Colin Cross | dd84e05 | 2017-05-17 13:44:16 -0700 | [diff] [blame] | 1978 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1979 | return depPaths |
| 1980 | } |
| 1981 | |
| 1982 | func (c *Module) InstallInData() bool { |
| 1983 | if c.installer == nil { |
| 1984 | return false |
| 1985 | } |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 1986 | return c.installer.inData() |
| 1987 | } |
| 1988 | |
| 1989 | func (c *Module) InstallInSanitizerDir() bool { |
| 1990 | if c.installer == nil { |
| 1991 | return false |
| 1992 | } |
| 1993 | if c.sanitize != nil && c.sanitize.inSanitizerDir() { |
Colin Cross | 9461040 | 2016-08-29 13:41:32 -0700 | [diff] [blame] | 1994 | return true |
| 1995 | } |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 1996 | return c.installer.inSanitizerDir() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1997 | } |
| 1998 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1999 | func (c *Module) InstallInRecovery() bool { |
| 2000 | return c.inRecovery() |
| 2001 | } |
| 2002 | |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 2003 | func (c *Module) HostToolPath() android.OptionalPath { |
| 2004 | if c.installer == nil { |
| 2005 | return android.OptionalPath{} |
| 2006 | } |
| 2007 | return c.installer.hostToolPath() |
| 2008 | } |
| 2009 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 2010 | func (c *Module) IntermPathForModuleOut() android.OptionalPath { |
| 2011 | return c.outputFile |
| 2012 | } |
| 2013 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 2014 | func (c *Module) OutputFiles(tag string) (android.Paths, error) { |
| 2015 | switch tag { |
| 2016 | case "": |
| 2017 | if c.outputFile.Valid() { |
| 2018 | return android.Paths{c.outputFile.Path()}, nil |
| 2019 | } |
| 2020 | return android.Paths{}, nil |
| 2021 | default: |
| 2022 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 2023 | } |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 2026 | func (c *Module) static() bool { |
| 2027 | if static, ok := c.linker.(interface { |
| 2028 | static() bool |
| 2029 | }); ok { |
| 2030 | return static.static() |
| 2031 | } |
| 2032 | return false |
| 2033 | } |
| 2034 | |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 2035 | func (c *Module) staticBinary() bool { |
| 2036 | if static, ok := c.linker.(interface { |
| 2037 | staticBinary() bool |
| 2038 | }); ok { |
| 2039 | return static.staticBinary() |
| 2040 | } |
| 2041 | return false |
| 2042 | } |
| 2043 | |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame^] | 2044 | func (c *Module) header() bool { |
| 2045 | if h, ok := c.linker.(interface { |
| 2046 | header() bool |
| 2047 | }); ok { |
| 2048 | return h.header() |
| 2049 | } |
| 2050 | return false |
| 2051 | } |
| 2052 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2053 | func (c *Module) getMakeLinkType(actx android.ModuleContext) string { |
| 2054 | name := actx.ModuleName() |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 2055 | if c.useVndk() { |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2056 | if lib, ok := c.linker.(*llndkStubDecorator); ok { |
| 2057 | if Bool(lib.Properties.Vendor_available) { |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 2058 | return "native:vndk" |
| 2059 | } |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2060 | return "native:vndk_private" |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 2061 | } |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2062 | if c.isVndk() && !c.isVndkExt() { |
| 2063 | if Bool(c.VendorProperties.Vendor_available) { |
| 2064 | return "native:vndk" |
| 2065 | } |
| 2066 | return "native:vndk_private" |
| 2067 | } |
| 2068 | return "native:vendor" |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 2069 | } else if c.inRecovery() { |
| 2070 | return "native:recovery" |
| 2071 | } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" { |
| 2072 | return "native:ndk:none:none" |
| 2073 | // TODO(b/114741097): use the correct ndk stl once build errors have been fixed |
| 2074 | //family, link := getNdkStlFamilyAndLinkType(c) |
| 2075 | //return fmt.Sprintf("native:ndk:%s:%s", family, link) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2076 | } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) { |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 2077 | return "native:platform_vndk" |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 2078 | } else { |
| 2079 | return "native:platform" |
| 2080 | } |
| 2081 | } |
| 2082 | |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 2083 | // Overrides ApexModule.IsInstallabeToApex() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 2084 | // Only shared/runtime libraries and "test_per_src" tests are installable to APEX. |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 2085 | func (c *Module) IsInstallableToApex() bool { |
| 2086 | if shared, ok := c.linker.(interface { |
| 2087 | shared() bool |
| 2088 | }); ok { |
| 2089 | return shared.shared() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 2090 | } else if _, ok := c.linker.(testPerSrc); ok { |
| 2091 | return true |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 2092 | } |
| 2093 | return false |
| 2094 | } |
| 2095 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 2096 | func (c *Module) installable() bool { |
| 2097 | return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() |
| 2098 | } |
| 2099 | |
Jiyong Park | 3b1746a | 2019-01-29 11:15:04 +0900 | [diff] [blame] | 2100 | func (c *Module) imageVariation() string { |
| 2101 | variation := "core" |
| 2102 | if c.useVndk() { |
| 2103 | variation = "vendor" |
| 2104 | } else if c.inRecovery() { |
| 2105 | variation = "recovery" |
| 2106 | } |
| 2107 | return variation |
| 2108 | } |
| 2109 | |
bralee | 3f49f4d | 2019-03-04 06:58:15 +0800 | [diff] [blame] | 2110 | func (c *Module) IDEInfo(dpInfo *android.IdeInfo) { |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 2111 | outputFiles, err := c.OutputFiles("") |
| 2112 | if err != nil { |
| 2113 | panic(err) |
| 2114 | } |
| 2115 | dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...) |
bralee | 3f49f4d | 2019-03-04 06:58:15 +0800 | [diff] [blame] | 2116 | } |
| 2117 | |
Logan Chien | 41eabe6 | 2019-04-10 13:33:58 +0800 | [diff] [blame] | 2118 | func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) { |
| 2119 | if c.linker != nil { |
| 2120 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 2121 | library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w) |
| 2122 | } |
| 2123 | } |
| 2124 | } |
| 2125 | |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 2126 | // |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2127 | // Defaults |
| 2128 | // |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2129 | type Defaults struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2130 | android.ModuleBase |
Colin Cross | 1f44a3a | 2017-07-07 14:33:33 -0700 | [diff] [blame] | 2131 | android.DefaultsModuleBase |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 2132 | android.ApexModuleBase |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2133 | } |
| 2134 | |
Patrice Arruda | c249c71 | 2019-03-19 17:00:29 -0700 | [diff] [blame] | 2135 | // cc_defaults provides a set of properties that can be inherited by other cc |
| 2136 | // modules. A module can use the properties from a cc_defaults using |
| 2137 | // `defaults: ["<:default_module_name>"]`. Properties of both modules are |
| 2138 | // merged (when possible) by prepending the default module's values to the |
| 2139 | // depending module's values. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2140 | func defaultsFactory() android.Module { |
Colin Cross | e1d764e | 2016-08-18 14:18:32 -0700 | [diff] [blame] | 2141 | return DefaultsFactory() |
| 2142 | } |
| 2143 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2144 | func DefaultsFactory(props ...interface{}) android.Module { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2145 | module := &Defaults{} |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2146 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2147 | module.AddProperties(props...) |
| 2148 | module.AddProperties( |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2149 | &BaseProperties{}, |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 2150 | &VendorProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2151 | &BaseCompilerProperties{}, |
| 2152 | &BaseLinkerProperties{}, |
Paul Duffin | a37832a | 2019-07-18 12:31:26 +0100 | [diff] [blame] | 2153 | &ObjectLinkerProperties{}, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 2154 | &LibraryProperties{}, |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 2155 | &FlagExporterProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2156 | &BinaryLinkerProperties{}, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 2157 | &TestProperties{}, |
| 2158 | &TestBinaryProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2159 | &StlProperties{}, |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 2160 | &SanitizeProperties{}, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2161 | &StripProperties{}, |
Dan Willemsen | 7424d61 | 2016-09-01 13:45:39 -0700 | [diff] [blame] | 2162 | &InstallerProperties{}, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 2163 | &TidyProperties{}, |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 2164 | &CoverageProperties{}, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 2165 | &SAbiProperties{}, |
Justin Yun | 4b2382f | 2017-07-26 14:22:10 +0900 | [diff] [blame] | 2166 | &VndkProperties{}, |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 2167 | <OProperties{}, |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 2168 | &PgoProperties{}, |
Ivan Lozano | 074ec48 | 2018-11-21 08:59:37 -0800 | [diff] [blame] | 2169 | &XomProperties{}, |
Dan Willemsen | 6424d17 | 2018-03-08 13:27:59 -0800 | [diff] [blame] | 2170 | &android.ProtoProperties{}, |
Colin Cross | e1d764e | 2016-08-18 14:18:32 -0700 | [diff] [blame] | 2171 | ) |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2172 | |
Colin Cross | 1f44a3a | 2017-07-07 14:33:33 -0700 | [diff] [blame] | 2173 | android.InitDefaultsModule(module) |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 2174 | android.InitApexModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2175 | |
| 2176 | return module |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2177 | } |
| 2178 | |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2179 | const ( |
| 2180 | // coreMode is the variant used for framework-private libraries, or |
| 2181 | // SDK libraries. (which framework-private libraries can use) |
| 2182 | coreMode = "core" |
| 2183 | |
| 2184 | // vendorMode is the variant used for /vendor code that compiles |
| 2185 | // against the VNDK. |
| 2186 | vendorMode = "vendor" |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2187 | |
| 2188 | recoveryMode = "recovery" |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2189 | ) |
| 2190 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 2191 | func squashVendorSrcs(m *Module) { |
| 2192 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 2193 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 2194 | lib.baseCompiler.Properties.Target.Vendor.Srcs...) |
| 2195 | |
| 2196 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 2197 | lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...) |
| 2198 | } |
| 2199 | } |
| 2200 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2201 | func squashRecoverySrcs(m *Module) { |
| 2202 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 2203 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 2204 | lib.baseCompiler.Properties.Target.Recovery.Srcs...) |
| 2205 | |
| 2206 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 2207 | lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...) |
| 2208 | } |
| 2209 | } |
| 2210 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2211 | func ImageMutator(mctx android.BottomUpMutatorContext) { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2212 | if mctx.Os() != android.Android { |
| 2213 | return |
| 2214 | } |
| 2215 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2216 | if g, ok := mctx.Module().(*genrule.Module); ok { |
| 2217 | if props, ok := g.Extra.(*GenruleExtraProperties); ok { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 2218 | var coreVariantNeeded bool = false |
| 2219 | var vendorVariantNeeded bool = false |
| 2220 | var recoveryVariantNeeded bool = false |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 2221 | if mctx.DeviceConfig().VndkVersion() == "" { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 2222 | coreVariantNeeded = true |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 2223 | } else if Bool(props.Vendor_available) { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 2224 | coreVariantNeeded = true |
| 2225 | vendorVariantNeeded = true |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 2226 | } else if mctx.SocSpecific() || mctx.DeviceSpecific() { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 2227 | vendorVariantNeeded = true |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 2228 | } else { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 2229 | coreVariantNeeded = true |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 2230 | } |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 2231 | if Bool(props.Recovery_available) { |
| 2232 | recoveryVariantNeeded = true |
| 2233 | } |
| 2234 | |
Jiyong Park | 413cc74 | 2018-06-19 01:46:06 +0900 | [diff] [blame] | 2235 | if recoveryVariantNeeded { |
Jiyong Park | 8d52f86 | 2018-07-07 18:02:07 +0900 | [diff] [blame] | 2236 | primaryArch := mctx.Config().DevicePrimaryArchType() |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2237 | moduleArch := g.Target().Arch.ArchType |
Jiyong Park | 8d52f86 | 2018-07-07 18:02:07 +0900 | [diff] [blame] | 2238 | if moduleArch != primaryArch { |
Jiyong Park | 413cc74 | 2018-06-19 01:46:06 +0900 | [diff] [blame] | 2239 | recoveryVariantNeeded = false |
| 2240 | } |
| 2241 | } |
| 2242 | |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 2243 | var variants []string |
| 2244 | if coreVariantNeeded { |
| 2245 | variants = append(variants, coreMode) |
| 2246 | } |
| 2247 | if vendorVariantNeeded { |
| 2248 | variants = append(variants, vendorMode) |
| 2249 | } |
| 2250 | if recoveryVariantNeeded { |
| 2251 | variants = append(variants, recoveryMode) |
| 2252 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2253 | mod := mctx.CreateVariations(variants...) |
| 2254 | for i, v := range variants { |
| 2255 | if v == recoveryMode { |
| 2256 | m := mod[i].(*genrule.Module) |
| 2257 | m.Extra.(*GenruleExtraProperties).InRecovery = true |
| 2258 | } |
| 2259 | } |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 2260 | } |
| 2261 | } |
| 2262 | |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2263 | m, ok := mctx.Module().(*Module) |
| 2264 | if !ok { |
| 2265 | return |
| 2266 | } |
| 2267 | |
| 2268 | // Sanity check |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2269 | vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() |
Justin Yun | 9357f4a | 2018-11-28 15:14:47 +0900 | [diff] [blame] | 2270 | productSpecific := mctx.ProductSpecific() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2271 | |
| 2272 | if m.VendorProperties.Vendor_available != nil && vendorSpecific { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2273 | mctx.PropertyErrorf("vendor_available", |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 2274 | "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`") |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2275 | return |
| 2276 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2277 | |
| 2278 | if vndkdep := m.vndkdep; vndkdep != nil { |
| 2279 | if vndkdep.isVndk() { |
Justin Yun | 9357f4a | 2018-11-28 15:14:47 +0900 | [diff] [blame] | 2280 | if productSpecific { |
| 2281 | mctx.PropertyErrorf("product_specific", |
| 2282 | "product_specific must not be true when `vndk: {enabled: true}`") |
| 2283 | return |
| 2284 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2285 | if vendorSpecific { |
| 2286 | if !vndkdep.isVndkExt() { |
| 2287 | mctx.PropertyErrorf("vndk", |
| 2288 | "must set `extends: \"...\"` to vndk extension") |
| 2289 | return |
| 2290 | } |
| 2291 | } else { |
| 2292 | if vndkdep.isVndkExt() { |
| 2293 | mctx.PropertyErrorf("vndk", |
| 2294 | "must set `vendor: true` to set `extends: %q`", |
| 2295 | m.getVndkExtendsModuleName()) |
| 2296 | return |
| 2297 | } |
| 2298 | if m.VendorProperties.Vendor_available == nil { |
| 2299 | mctx.PropertyErrorf("vndk", |
| 2300 | "vendor_available must be set to either true or false when `vndk: {enabled: true}`") |
| 2301 | return |
| 2302 | } |
| 2303 | } |
| 2304 | } else { |
| 2305 | if vndkdep.isVndkSp() { |
| 2306 | mctx.PropertyErrorf("vndk", |
| 2307 | "must set `enabled: true` to set `support_system_process: true`") |
| 2308 | return |
| 2309 | } |
| 2310 | if vndkdep.isVndkExt() { |
| 2311 | mctx.PropertyErrorf("vndk", |
| 2312 | "must set `enabled: true` to set `extends: %q`", |
| 2313 | m.getVndkExtendsModuleName()) |
| 2314 | return |
| 2315 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 2316 | } |
| 2317 | } |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2318 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2319 | var coreVariantNeeded bool = false |
| 2320 | var vendorVariantNeeded bool = false |
| 2321 | var recoveryVariantNeeded bool = false |
| 2322 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 2323 | if mctx.DeviceConfig().VndkVersion() == "" { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2324 | // If the device isn't compiling against the VNDK, we always |
| 2325 | // use the core mode. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2326 | coreVariantNeeded = true |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2327 | } else if _, ok := m.linker.(*llndkStubDecorator); ok { |
| 2328 | // LL-NDK stubs only exist in the vendor variant, since the |
| 2329 | // real libraries will be used in the core variant. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2330 | vendorVariantNeeded = true |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 2331 | } else if _, ok := m.linker.(*llndkHeadersDecorator); ok { |
| 2332 | // ... and LL-NDK headers as well |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2333 | vendorVariantNeeded = true |
Justin Yun | 312ccb9 | 2018-01-23 12:07:46 +0900 | [diff] [blame] | 2334 | } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok { |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 2335 | // Make vendor variants only for the versions in BOARD_VNDK_VERSION and |
| 2336 | // PRODUCT_EXTRA_VNDK_VERSIONS. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2337 | vendorVariantNeeded = true |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2338 | } else if m.hasVendorVariant() && !vendorSpecific { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2339 | // This will be available in both /system and /vendor |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 2340 | // or a /system directory that is available to vendor. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2341 | coreVariantNeeded = true |
| 2342 | vendorVariantNeeded = true |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2343 | } else if vendorSpecific && String(m.Properties.Sdk_version) == "" { |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 2344 | // This will be available in /vendor (or /odm) only |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2345 | vendorVariantNeeded = true |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2346 | } else { |
| 2347 | // This is either in /system (or similar: /data), or is a |
| 2348 | // modules built with the NDK. Modules built with the NDK |
| 2349 | // will be restricted using the existing link type checks. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2350 | coreVariantNeeded = true |
| 2351 | } |
| 2352 | |
| 2353 | if Bool(m.Properties.Recovery_available) { |
| 2354 | recoveryVariantNeeded = true |
| 2355 | } |
| 2356 | |
| 2357 | if m.ModuleBase.InstallInRecovery() { |
| 2358 | recoveryVariantNeeded = true |
| 2359 | coreVariantNeeded = false |
| 2360 | } |
| 2361 | |
Jiyong Park | 413cc74 | 2018-06-19 01:46:06 +0900 | [diff] [blame] | 2362 | if recoveryVariantNeeded { |
Jiyong Park | 8d52f86 | 2018-07-07 18:02:07 +0900 | [diff] [blame] | 2363 | primaryArch := mctx.Config().DevicePrimaryArchType() |
| 2364 | moduleArch := m.Target().Arch.ArchType |
| 2365 | if moduleArch != primaryArch { |
Jiyong Park | 413cc74 | 2018-06-19 01:46:06 +0900 | [diff] [blame] | 2366 | recoveryVariantNeeded = false |
| 2367 | } |
| 2368 | } |
| 2369 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2370 | var variants []string |
| 2371 | if coreVariantNeeded { |
| 2372 | variants = append(variants, coreMode) |
| 2373 | } |
| 2374 | if vendorVariantNeeded { |
| 2375 | variants = append(variants, vendorMode) |
| 2376 | } |
| 2377 | if recoveryVariantNeeded { |
| 2378 | variants = append(variants, recoveryMode) |
| 2379 | } |
| 2380 | mod := mctx.CreateVariations(variants...) |
| 2381 | for i, v := range variants { |
| 2382 | if v == vendorMode { |
| 2383 | m := mod[i].(*Module) |
| 2384 | m.Properties.UseVndk = true |
| 2385 | squashVendorSrcs(m) |
| 2386 | } else if v == recoveryMode { |
| 2387 | m := mod[i].(*Module) |
| 2388 | m.Properties.InRecovery = true |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 2389 | m.MakeAsPlatform() |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2390 | squashRecoverySrcs(m) |
| 2391 | } |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2392 | } |
| 2393 | } |
| 2394 | |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 2395 | func getCurrentNdkPrebuiltVersion(ctx DepsContext) string { |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 2396 | if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt { |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 2397 | return strconv.Itoa(config.NdkMaxPrebuiltVersionInt) |
| 2398 | } |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 2399 | return ctx.Config().PlatformSdkVersion() |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 2400 | } |
| 2401 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 2402 | func kytheExtractAllFactory() android.Singleton { |
| 2403 | return &kytheExtractAllSingleton{} |
| 2404 | } |
| 2405 | |
| 2406 | type kytheExtractAllSingleton struct { |
| 2407 | } |
| 2408 | |
| 2409 | func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 2410 | var xrefTargets android.Paths |
| 2411 | ctx.VisitAllModules(func(module android.Module) { |
| 2412 | if ccModule, ok := module.(xref); ok { |
| 2413 | xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...) |
| 2414 | } |
| 2415 | }) |
| 2416 | // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets |
| 2417 | if len(xrefTargets) > 0 { |
| 2418 | ctx.Build(pctx, android.BuildParams{ |
| 2419 | Rule: blueprint.Phony, |
| 2420 | Output: android.PathForPhony(ctx, "xref_cxx"), |
| 2421 | Inputs: xrefTargets, |
| 2422 | //Default: true, |
| 2423 | }) |
| 2424 | } |
| 2425 | } |
| 2426 | |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 2427 | var Bool = proptools.Bool |
Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 2428 | var BoolDefault = proptools.BoolDefault |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 2429 | var BoolPtr = proptools.BoolPtr |
| 2430 | var String = proptools.String |
| 2431 | var StringPtr = proptools.StringPtr |