Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 15 | // This file offers AndroidMkEntriesProvider, which individual modules implement to output |
| 16 | // Android.mk entries that contain information about the modules built through Soong. Kati reads |
| 17 | // and combines them with the legacy Make-based module definitions to produce the complete view of |
| 18 | // the source tree, which makes this a critical point of Make-Soong interoperability. |
| 19 | // |
| 20 | // Naturally, Soong-only builds do not rely on this mechanism. |
| 21 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 22 | package android |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 23 | |
| 24 | import ( |
| 25 | "bytes" |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 26 | "fmt" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 27 | "io" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 28 | "os" |
| 29 | "path/filepath" |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 30 | "reflect" |
Dan Willemsen | def7b5d | 2021-10-17 00:22:33 -0700 | [diff] [blame] | 31 | "runtime" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 32 | "sort" |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 33 | "strconv" |
Dan Willemsen | 0fda89f | 2016-06-01 15:25:32 -0700 | [diff] [blame] | 34 | "strings" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 35 | |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 36 | "github.com/google/blueprint" |
Colin Cross | 836e387 | 2021-11-09 12:30:59 -0800 | [diff] [blame] | 37 | "github.com/google/blueprint/pathtools" |
Jiyong Park | 3f627e6 | 2024-05-01 16:14:38 +0900 | [diff] [blame] | 38 | "github.com/google/blueprint/proptools" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 39 | ) |
| 40 | |
| 41 | func init() { |
Paul Duffin | 8c3fec4 | 2020-03-04 20:15:08 +0000 | [diff] [blame] | 42 | RegisterAndroidMkBuildComponents(InitRegistrationContext) |
| 43 | } |
| 44 | |
| 45 | func RegisterAndroidMkBuildComponents(ctx RegistrationContext) { |
LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 46 | ctx.RegisterParallelSingletonType("androidmk", AndroidMkSingleton) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Paul Duffin | 6c9da04 | 2021-03-07 15:44:41 +0000 | [diff] [blame] | 49 | // Enable androidmk support. |
| 50 | // * Register the singleton |
| 51 | // * Configure that we are inside make |
| 52 | var PrepareForTestWithAndroidMk = GroupFixturePreparers( |
| 53 | FixtureRegisterWithContext(RegisterAndroidMkBuildComponents), |
| 54 | FixtureModifyConfig(SetKatiEnabledForTests), |
| 55 | ) |
| 56 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 57 | // Deprecated: Use AndroidMkEntriesProvider instead, especially if you're not going to use the |
| 58 | // Custom function. It's easier to use and test. |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 59 | type AndroidMkDataProvider interface { |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 60 | AndroidMk() AndroidMkData |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 61 | BaseModuleName() string |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | type AndroidMkData struct { |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 65 | Class string |
| 66 | SubName string |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 67 | DistFiles TaggedDistFiles |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 68 | OutputFile OptionalPath |
| 69 | Disabled bool |
| 70 | Include string |
| 71 | Required []string |
| 72 | Host_required []string |
| 73 | Target_required []string |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 74 | |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 75 | Custom func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 76 | |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 77 | Extra []AndroidMkExtraFunc |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 78 | |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 79 | Entries AndroidMkEntries |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 82 | type AndroidMkExtraFunc func(w io.Writer, outputFile Path) |
| 83 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 84 | // Interface for modules to declare their Android.mk outputs. Note that every module needs to |
| 85 | // implement this in order to be included in the final Android-<product_name>.mk output, even if |
| 86 | // they only need to output the common set of entries without any customizations. |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 87 | type AndroidMkEntriesProvider interface { |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 88 | // Returns AndroidMkEntries objects that contain all basic info plus extra customization data |
| 89 | // if needed. This is the core func to implement. |
| 90 | // Note that one can return multiple objects. For example, java_library may return an additional |
| 91 | // AndroidMkEntries object for its hostdex sub-module. |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 92 | AndroidMkEntries() []AndroidMkEntries |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 93 | // Modules don't need to implement this as it's already implemented by ModuleBase. |
| 94 | // AndroidMkEntries uses BaseModuleName() instead of ModuleName() because certain modules |
| 95 | // e.g. Prebuilts, override the Name() func and return modified names. |
| 96 | // If a different name is preferred, use SubName or OverrideName in AndroidMkEntries. |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 97 | BaseModuleName() string |
| 98 | } |
| 99 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 100 | // The core data struct that modules use to provide their Android.mk data. |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 101 | type AndroidMkEntries struct { |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 102 | // Android.mk class string, e.g EXECUTABLES, JAVA_LIBRARIES, ETC |
| 103 | Class string |
| 104 | // Optional suffix to append to the module name. Useful when a module wants to return multiple |
| 105 | // AndroidMkEntries objects. For example, when a java_library returns an additional entry for |
| 106 | // its hostdex sub-module, this SubName field is set to "-hostdex" so that it can have a |
| 107 | // different name than the parent's. |
| 108 | SubName string |
| 109 | // If set, this value overrides the base module name. SubName is still appended. |
| 110 | OverrideName string |
| 111 | // Dist files to output |
| 112 | DistFiles TaggedDistFiles |
| 113 | // The output file for Kati to process and/or install. If absent, the module is skipped. |
| 114 | OutputFile OptionalPath |
| 115 | // If true, the module is skipped and does not appear on the final Android-<product name>.mk |
| 116 | // file. Useful when a module needs to be skipped conditionally. |
| 117 | Disabled bool |
Ivan Lozano | d06cc74 | 2021-11-12 13:27:58 -0500 | [diff] [blame] | 118 | // The postprocessing mk file to include, e.g. $(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 119 | // If not set, $(BUILD_SYSTEM)/prebuilt.mk is used. |
| 120 | Include string |
| 121 | // Required modules that need to be built and included in the final build output when building |
| 122 | // this module. |
| 123 | Required []string |
| 124 | // Required host modules that need to be built and included in the final build output when |
| 125 | // building this module. |
| 126 | Host_required []string |
| 127 | // Required device modules that need to be built and included in the final build output when |
| 128 | // building this module. |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 129 | Target_required []string |
| 130 | |
| 131 | header bytes.Buffer |
| 132 | footer bytes.Buffer |
| 133 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 134 | // Funcs to append additional Android.mk entries or modify the common ones. Multiple funcs are |
| 135 | // accepted so that common logic can be factored out as a shared func. |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 136 | ExtraEntries []AndroidMkExtraEntriesFunc |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 137 | // Funcs to add extra lines to the module's Android.mk output. Unlike AndroidMkExtraEntriesFunc, |
| 138 | // which simply sets Make variable values, this can be used for anything since it can write any |
| 139 | // Make statements directly to the final Android-*.mk file. |
| 140 | // Primarily used to call macros or declare/update Make targets. |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 141 | ExtraFooters []AndroidMkExtraFootersFunc |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 142 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 143 | // A map that holds the up-to-date Make variable values. Can be accessed from tests. |
| 144 | EntryMap map[string][]string |
| 145 | // A list of EntryMap keys in insertion order. This serves a few purposes: |
| 146 | // 1. Prevents churns. Golang map doesn't provide consistent iteration order, so without this, |
| 147 | // the outputted Android-*.mk file may change even though there have been no content changes. |
| 148 | // 2. Allows modules to refer to other variables, like LOCAL_BAR_VAR := $(LOCAL_FOO_VAR), |
| 149 | // without worrying about the variables being mixed up in the actual mk file. |
| 150 | // 3. Makes troubleshooting and spotting errors easier. |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 151 | entryOrder []string |
Trevor Radcliffe | 90727f4 | 2022-03-21 19:34:02 +0000 | [diff] [blame] | 152 | |
| 153 | // Provides data typically stored by Context objects that are commonly needed by |
| 154 | //AndroidMkEntries objects. |
| 155 | entryContext AndroidMkEntriesContext |
| 156 | } |
| 157 | |
| 158 | type AndroidMkEntriesContext interface { |
Yu Liu | ec81054 | 2024-08-26 18:09:15 +0000 | [diff] [blame] | 159 | OtherModuleProviderContext |
Trevor Radcliffe | 90727f4 | 2022-03-21 19:34:02 +0000 | [diff] [blame] | 160 | Config() Config |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 163 | type AndroidMkExtraEntriesContext interface { |
Colin Cross | 3c0a83d | 2023-12-12 14:13:26 -0800 | [diff] [blame] | 164 | Provider(provider blueprint.AnyProviderKey) (any, bool) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | type androidMkExtraEntriesContext struct { |
| 168 | ctx fillInEntriesContext |
| 169 | mod blueprint.Module |
| 170 | } |
| 171 | |
Colin Cross | 3c0a83d | 2023-12-12 14:13:26 -0800 | [diff] [blame] | 172 | func (a *androidMkExtraEntriesContext) Provider(provider blueprint.AnyProviderKey) (any, bool) { |
Yu Liu | 663e450 | 2024-08-12 18:23:59 +0000 | [diff] [blame] | 173 | return a.ctx.otherModuleProvider(a.mod, provider) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | type AndroidMkExtraEntriesFunc func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) |
Jaewoong Jung | 02b11a6 | 2020-12-07 10:23:54 -0800 | [diff] [blame] | 177 | type AndroidMkExtraFootersFunc func(w io.Writer, name, prefix, moduleDir string) |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 178 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 179 | // Utility funcs to manipulate Android.mk variable entries. |
| 180 | |
| 181 | // SetString sets a Make variable with the given name to the given value. |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 182 | func (a *AndroidMkEntries) SetString(name, value string) { |
| 183 | if _, ok := a.EntryMap[name]; !ok { |
| 184 | a.entryOrder = append(a.entryOrder, name) |
| 185 | } |
| 186 | a.EntryMap[name] = []string{value} |
| 187 | } |
| 188 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 189 | // SetPath sets a Make variable with the given name to the given path string. |
Jaewoong Jung | 9a1e8bd | 2019-09-04 20:17:54 -0700 | [diff] [blame] | 190 | func (a *AndroidMkEntries) SetPath(name string, path Path) { |
| 191 | if _, ok := a.EntryMap[name]; !ok { |
| 192 | a.entryOrder = append(a.entryOrder, name) |
| 193 | } |
| 194 | a.EntryMap[name] = []string{path.String()} |
| 195 | } |
| 196 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 197 | // SetOptionalPath sets a Make variable with the given name to the given path string if it is valid. |
| 198 | // It is a no-op if the given path is invalid. |
Colin Cross | c0efd1d | 2020-07-03 11:56:24 -0700 | [diff] [blame] | 199 | func (a *AndroidMkEntries) SetOptionalPath(name string, path OptionalPath) { |
| 200 | if path.Valid() { |
| 201 | a.SetPath(name, path.Path()) |
| 202 | } |
| 203 | } |
| 204 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 205 | // AddPath appends the given path string to a Make variable with the given name. |
Colin Cross | c0efd1d | 2020-07-03 11:56:24 -0700 | [diff] [blame] | 206 | func (a *AndroidMkEntries) AddPath(name string, path Path) { |
| 207 | if _, ok := a.EntryMap[name]; !ok { |
| 208 | a.entryOrder = append(a.entryOrder, name) |
| 209 | } |
| 210 | a.EntryMap[name] = append(a.EntryMap[name], path.String()) |
| 211 | } |
| 212 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 213 | // AddOptionalPath appends the given path string to a Make variable with the given name if it is |
| 214 | // valid. It is a no-op if the given path is invalid. |
Colin Cross | c0efd1d | 2020-07-03 11:56:24 -0700 | [diff] [blame] | 215 | func (a *AndroidMkEntries) AddOptionalPath(name string, path OptionalPath) { |
| 216 | if path.Valid() { |
| 217 | a.AddPath(name, path.Path()) |
| 218 | } |
| 219 | } |
| 220 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 221 | // SetPaths sets a Make variable with the given name to a slice of the given path strings. |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 222 | func (a *AndroidMkEntries) SetPaths(name string, paths Paths) { |
| 223 | if _, ok := a.EntryMap[name]; !ok { |
| 224 | a.entryOrder = append(a.entryOrder, name) |
| 225 | } |
| 226 | a.EntryMap[name] = paths.Strings() |
| 227 | } |
| 228 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 229 | // SetOptionalPaths sets a Make variable with the given name to a slice of the given path strings |
| 230 | // only if there are a non-zero amount of paths. |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 231 | func (a *AndroidMkEntries) SetOptionalPaths(name string, paths Paths) { |
| 232 | if len(paths) > 0 { |
| 233 | a.SetPaths(name, paths) |
| 234 | } |
| 235 | } |
| 236 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 237 | // AddPaths appends the given path strings to a Make variable with the given name. |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 238 | func (a *AndroidMkEntries) AddPaths(name string, paths Paths) { |
| 239 | if _, ok := a.EntryMap[name]; !ok { |
| 240 | a.entryOrder = append(a.entryOrder, name) |
| 241 | } |
| 242 | a.EntryMap[name] = append(a.EntryMap[name], paths.Strings()...) |
| 243 | } |
| 244 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 245 | // SetBoolIfTrue sets a Make variable with the given name to true if the given flag is true. |
| 246 | // It is a no-op if the given flag is false. |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 247 | func (a *AndroidMkEntries) SetBoolIfTrue(name string, flag bool) { |
| 248 | if flag { |
| 249 | if _, ok := a.EntryMap[name]; !ok { |
| 250 | a.entryOrder = append(a.entryOrder, name) |
| 251 | } |
| 252 | a.EntryMap[name] = []string{"true"} |
| 253 | } |
| 254 | } |
| 255 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 256 | // SetBool sets a Make variable with the given name to if the given bool flag value. |
Jaewoong Jung | 9a1e8bd | 2019-09-04 20:17:54 -0700 | [diff] [blame] | 257 | func (a *AndroidMkEntries) SetBool(name string, flag bool) { |
| 258 | if _, ok := a.EntryMap[name]; !ok { |
| 259 | a.entryOrder = append(a.entryOrder, name) |
| 260 | } |
| 261 | if flag { |
| 262 | a.EntryMap[name] = []string{"true"} |
| 263 | } else { |
| 264 | a.EntryMap[name] = []string{"false"} |
| 265 | } |
| 266 | } |
| 267 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 268 | // AddStrings appends the given strings to a Make variable with the given name. |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 269 | func (a *AndroidMkEntries) AddStrings(name string, value ...string) { |
| 270 | if len(value) == 0 { |
| 271 | return |
| 272 | } |
| 273 | if _, ok := a.EntryMap[name]; !ok { |
| 274 | a.entryOrder = append(a.entryOrder, name) |
| 275 | } |
| 276 | a.EntryMap[name] = append(a.EntryMap[name], value...) |
| 277 | } |
| 278 | |
Liz Kammer | 57f5b33 | 2020-11-24 12:42:58 -0800 | [diff] [blame] | 279 | // AddCompatibilityTestSuites adds the supplied test suites to the EntryMap, with special handling |
Tongbo Liu | c5f7b96 | 2024-01-04 09:03:35 +0000 | [diff] [blame] | 280 | // for partial MTS and MCTS test suites. |
Liz Kammer | 57f5b33 | 2020-11-24 12:42:58 -0800 | [diff] [blame] | 281 | func (a *AndroidMkEntries) AddCompatibilityTestSuites(suites ...string) { |
Tongbo Liu | c5f7b96 | 2024-01-04 09:03:35 +0000 | [diff] [blame] | 282 | // M(C)TS supports a full test suite and partial per-module MTS test suites, with naming mts-${MODULE}. |
| 283 | // To reduce repetition, if we find a partial M(C)TS test suite without an full M(C)TS test suite, |
Liz Kammer | 57f5b33 | 2020-11-24 12:42:58 -0800 | [diff] [blame] | 284 | // we add the full test suite to our list. |
| 285 | if PrefixInList(suites, "mts-") && !InList("mts", suites) { |
| 286 | suites = append(suites, "mts") |
| 287 | } |
Tongbo Liu | c5f7b96 | 2024-01-04 09:03:35 +0000 | [diff] [blame] | 288 | if PrefixInList(suites, "mcts-") && !InList("mcts", suites) { |
| 289 | suites = append(suites, "mcts") |
| 290 | } |
Liz Kammer | 57f5b33 | 2020-11-24 12:42:58 -0800 | [diff] [blame] | 291 | a.AddStrings("LOCAL_COMPATIBILITY_SUITE", suites...) |
| 292 | } |
| 293 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 294 | // The contributions to the dist. |
| 295 | type distContributions struct { |
Bob Badour | 5180438 | 2022-04-13 11:27:19 -0700 | [diff] [blame] | 296 | // Path to license metadata file. |
| 297 | licenseMetadataFile Path |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 298 | // List of goals and the dist copy instructions. |
| 299 | copiesForGoals []*copiesForGoals |
| 300 | } |
| 301 | |
| 302 | // getCopiesForGoals returns a copiesForGoals into which copy instructions that |
| 303 | // must be processed when building one or more of those goals can be added. |
| 304 | func (d *distContributions) getCopiesForGoals(goals string) *copiesForGoals { |
| 305 | copiesForGoals := &copiesForGoals{goals: goals} |
| 306 | d.copiesForGoals = append(d.copiesForGoals, copiesForGoals) |
| 307 | return copiesForGoals |
| 308 | } |
| 309 | |
| 310 | // Associates a list of dist copy instructions with a set of goals for which they |
| 311 | // should be run. |
| 312 | type copiesForGoals struct { |
| 313 | // goals are a space separated list of build targets that will trigger the |
| 314 | // copy instructions. |
| 315 | goals string |
| 316 | |
| 317 | // A list of instructions to copy a module's output files to somewhere in the |
| 318 | // dist directory. |
| 319 | copies []distCopy |
| 320 | } |
| 321 | |
| 322 | // Adds a copy instruction. |
| 323 | func (d *copiesForGoals) addCopyInstruction(from Path, dest string) { |
| 324 | d.copies = append(d.copies, distCopy{from, dest}) |
| 325 | } |
| 326 | |
| 327 | // Instruction on a path that must be copied into the dist. |
| 328 | type distCopy struct { |
| 329 | // The path to copy from. |
| 330 | from Path |
| 331 | |
| 332 | // The destination within the dist directory to copy to. |
| 333 | dest string |
| 334 | } |
| 335 | |
Jihoon Kang | 593171e | 2025-02-05 01:54:45 +0000 | [diff] [blame] | 336 | func (d *distCopy) String() string { |
| 337 | if len(d.dest) == 0 { |
| 338 | return d.from.String() |
| 339 | } |
| 340 | return fmt.Sprintf("%s:%s", d.from.String(), d.dest) |
| 341 | } |
| 342 | |
| 343 | type distCopies []distCopy |
| 344 | |
| 345 | func (d *distCopies) Strings() (ret []string) { |
| 346 | if d == nil { |
| 347 | return |
| 348 | } |
| 349 | for _, dist := range *d { |
| 350 | ret = append(ret, dist.String()) |
| 351 | } |
| 352 | return |
| 353 | } |
| 354 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 355 | // Compute the contributions that the module makes to the dist. |
| 356 | func (a *AndroidMkEntries) getDistContributions(mod blueprint.Module) *distContributions { |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 357 | amod := mod.(Module).base() |
| 358 | name := amod.BaseModuleName() |
| 359 | |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 360 | // Collate the set of associated tag/paths available for copying to the dist. |
| 361 | // Start with an empty (nil) set. |
Jingwen Chen | 7b27ca7 | 2020-07-24 09:13:49 +0000 | [diff] [blame] | 362 | var availableTaggedDists TaggedDistFiles |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 363 | |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 364 | // Then merge in any that are provided explicitly by the module. |
Jingwen Chen | 8481186 | 2020-07-21 11:32:19 +0000 | [diff] [blame] | 365 | if a.DistFiles != nil { |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 366 | // Merge the DistFiles into the set. |
| 367 | availableTaggedDists = availableTaggedDists.merge(a.DistFiles) |
| 368 | } |
| 369 | |
| 370 | // If no paths have been provided for the DefaultDistTag and the output file is |
| 371 | // valid then add that as the default dist path. |
| 372 | if _, ok := availableTaggedDists[DefaultDistTag]; !ok && a.OutputFile.Valid() { |
| 373 | availableTaggedDists = availableTaggedDists.addPathsForTag(DefaultDistTag, a.OutputFile.Path()) |
| 374 | } |
| 375 | |
Yu Liu | ec81054 | 2024-08-26 18:09:15 +0000 | [diff] [blame] | 376 | info := OtherModuleProviderOrDefault(a.entryContext, mod, InstallFilesProvider) |
Paul Duffin | af970a2 | 2020-11-23 23:32:56 +0000 | [diff] [blame] | 377 | // If the distFiles created by GenerateTaggedDistFiles contains paths for the |
| 378 | // DefaultDistTag then that takes priority so delete any existing paths. |
Yu Liu | ec81054 | 2024-08-26 18:09:15 +0000 | [diff] [blame] | 379 | if _, ok := info.DistFiles[DefaultDistTag]; ok { |
Paul Duffin | af970a2 | 2020-11-23 23:32:56 +0000 | [diff] [blame] | 380 | delete(availableTaggedDists, DefaultDistTag) |
| 381 | } |
| 382 | |
| 383 | // Finally, merge the distFiles created by GenerateTaggedDistFiles. |
Yu Liu | ec81054 | 2024-08-26 18:09:15 +0000 | [diff] [blame] | 384 | availableTaggedDists = availableTaggedDists.merge(info.DistFiles) |
Paul Duffin | af970a2 | 2020-11-23 23:32:56 +0000 | [diff] [blame] | 385 | |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 386 | if len(availableTaggedDists) == 0 { |
Jingwen Chen | 7b27ca7 | 2020-07-24 09:13:49 +0000 | [diff] [blame] | 387 | // Nothing dist-able for this module. |
| 388 | return nil |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 391 | // Collate the contributions this module makes to the dist. |
| 392 | distContributions := &distContributions{} |
| 393 | |
Bob Badour | 4660a98 | 2022-09-12 16:06:03 -0700 | [diff] [blame] | 394 | if !exemptFromRequiredApplicableLicensesProperty(mod.(Module)) { |
Yu Liu | ec81054 | 2024-08-26 18:09:15 +0000 | [diff] [blame] | 395 | distContributions.licenseMetadataFile = info.LicenseMetadataFile |
Bob Badour | 4660a98 | 2022-09-12 16:06:03 -0700 | [diff] [blame] | 396 | } |
Bob Badour | 5180438 | 2022-04-13 11:27:19 -0700 | [diff] [blame] | 397 | |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 398 | // Iterate over this module's dist structs, merged from the dist and dists properties. |
| 399 | for _, dist := range amod.Dists() { |
| 400 | // Get the list of goals this dist should be enabled for. e.g. sdk, droidcore |
| 401 | goals := strings.Join(dist.Targets, " ") |
| 402 | |
| 403 | // Get the tag representing the output files to be dist'd. e.g. ".jar", ".proguard_map" |
| 404 | var tag string |
| 405 | if dist.Tag == nil { |
| 406 | // If the dist struct does not specify a tag, use the default output files tag. |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 407 | tag = DefaultDistTag |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 408 | } else { |
| 409 | tag = *dist.Tag |
| 410 | } |
| 411 | |
| 412 | // Get the paths of the output files to be dist'd, represented by the tag. |
| 413 | // Can be an empty list. |
| 414 | tagPaths := availableTaggedDists[tag] |
| 415 | if len(tagPaths) == 0 { |
| 416 | // Nothing to dist for this tag, continue to the next dist. |
| 417 | continue |
| 418 | } |
| 419 | |
| 420 | if len(tagPaths) > 1 && (dist.Dest != nil || dist.Suffix != nil) { |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 421 | errorMessage := "%s: Cannot apply dest/suffix for more than one dist " + |
| 422 | "file for %q goals tag %q in module %s. The list of dist files, " + |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 423 | "which should have a single element, is:\n%s" |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 424 | panic(fmt.Errorf(errorMessage, mod, goals, tag, name, tagPaths)) |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 427 | copiesForGoals := distContributions.getCopiesForGoals(goals) |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 428 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 429 | // Iterate over each path adding a copy instruction to copiesForGoals |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 430 | for _, path := range tagPaths { |
| 431 | // It's possible that the Path is nil from errant modules. Be defensive here. |
| 432 | if path == nil { |
| 433 | tagName := "default" // for error message readability |
| 434 | if dist.Tag != nil { |
| 435 | tagName = *dist.Tag |
| 436 | } |
| 437 | panic(fmt.Errorf("Dist file should not be nil for the %s tag in %s", tagName, name)) |
| 438 | } |
| 439 | |
| 440 | dest := filepath.Base(path.String()) |
| 441 | |
| 442 | if dist.Dest != nil { |
| 443 | var err error |
| 444 | if dest, err = validateSafePath(*dist.Dest); err != nil { |
| 445 | // This was checked in ModuleBase.GenerateBuildActions |
| 446 | panic(err) |
| 447 | } |
| 448 | } |
| 449 | |
Trevor Radcliffe | 90727f4 | 2022-03-21 19:34:02 +0000 | [diff] [blame] | 450 | ext := filepath.Ext(dest) |
| 451 | suffix := "" |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 452 | if dist.Suffix != nil { |
Trevor Radcliffe | 90727f4 | 2022-03-21 19:34:02 +0000 | [diff] [blame] | 453 | suffix = *dist.Suffix |
| 454 | } |
| 455 | |
| 456 | productString := "" |
| 457 | if dist.Append_artifact_with_product != nil && *dist.Append_artifact_with_product { |
| 458 | productString = fmt.Sprintf("_%s", a.entryContext.Config().DeviceProduct()) |
| 459 | } |
| 460 | |
| 461 | if suffix != "" || productString != "" { |
| 462 | dest = strings.TrimSuffix(dest, ext) + suffix + productString + ext |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | if dist.Dir != nil { |
| 466 | var err error |
| 467 | if dest, err = validateSafePath(*dist.Dir, dest); err != nil { |
| 468 | // This was checked in ModuleBase.GenerateBuildActions |
| 469 | panic(err) |
| 470 | } |
| 471 | } |
| 472 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 473 | copiesForGoals.addCopyInstruction(path, dest) |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | return distContributions |
| 478 | } |
| 479 | |
| 480 | // generateDistContributionsForMake generates make rules that will generate the |
| 481 | // dist according to the instructions in the supplied distContribution. |
| 482 | func generateDistContributionsForMake(distContributions *distContributions) []string { |
| 483 | var ret []string |
| 484 | for _, d := range distContributions.copiesForGoals { |
Yu Liu | e70976d | 2024-10-15 20:45:35 +0000 | [diff] [blame] | 485 | ret = append(ret, fmt.Sprintf(".PHONY: %s", d.goals)) |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 486 | // Create dist-for-goals calls for each of the copy instructions. |
| 487 | for _, c := range d.copies { |
Bob Badour | 4660a98 | 2022-09-12 16:06:03 -0700 | [diff] [blame] | 488 | if distContributions.licenseMetadataFile != nil { |
| 489 | ret = append( |
| 490 | ret, |
Yu Liu | e70976d | 2024-10-15 20:45:35 +0000 | [diff] [blame] | 491 | fmt.Sprintf("$(if $(strip $(ALL_TARGETS.%s.META_LIC)),,$(eval ALL_TARGETS.%s.META_LIC := %s))", |
Bob Badour | 4660a98 | 2022-09-12 16:06:03 -0700 | [diff] [blame] | 492 | c.from.String(), c.from.String(), distContributions.licenseMetadataFile.String())) |
| 493 | } |
Bob Badour | 5180438 | 2022-04-13 11:27:19 -0700 | [diff] [blame] | 494 | ret = append( |
| 495 | ret, |
Yu Liu | e70976d | 2024-10-15 20:45:35 +0000 | [diff] [blame] | 496 | fmt.Sprintf("$(call dist-for-goals,%s,%s:%s)", d.goals, c.from.String(), c.dest)) |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
| 500 | return ret |
| 501 | } |
| 502 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 503 | // Compute the list of Make strings to declare phony goals and dist-for-goals |
| 504 | // calls from the module's dist and dists properties. |
| 505 | func (a *AndroidMkEntries) GetDistForGoals(mod blueprint.Module) []string { |
| 506 | distContributions := a.getDistContributions(mod) |
| 507 | if distContributions == nil { |
| 508 | return nil |
| 509 | } |
| 510 | |
| 511 | return generateDistContributionsForMake(distContributions) |
| 512 | } |
| 513 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 514 | // fillInEntries goes through the common variable processing and calls the extra data funcs to |
| 515 | // generate and fill in AndroidMkEntries's in-struct data, ready to be flushed to a file. |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 516 | type fillInEntriesContext interface { |
| 517 | ModuleDir(module blueprint.Module) string |
Cole Faust | 39aabe9 | 2023-02-23 16:57:43 -0800 | [diff] [blame] | 518 | ModuleSubDir(module blueprint.Module) string |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 519 | Config() Config |
Yu Liu | 663e450 | 2024-08-12 18:23:59 +0000 | [diff] [blame] | 520 | otherModuleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) |
Sasha Smundak | 5c4729d | 2022-12-01 10:49:23 -0800 | [diff] [blame] | 521 | ModuleType(module blueprint.Module) string |
Cole Faust | 43ddd08 | 2024-06-17 12:32:40 -0700 | [diff] [blame] | 522 | OtherModulePropertyErrorf(module Module, property string, fmt string, args ...interface{}) |
Cole Faust | 4e2bf9f | 2024-09-11 13:26:20 -0700 | [diff] [blame] | 523 | HasMutatorFinished(mutatorName string) bool |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint.Module) { |
Trevor Radcliffe | 90727f4 | 2022-03-21 19:34:02 +0000 | [diff] [blame] | 527 | a.entryContext = ctx |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 528 | a.EntryMap = make(map[string][]string) |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 529 | amod := mod.(Module) |
| 530 | base := amod.base() |
| 531 | name := base.BaseModuleName() |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 532 | if a.OverrideName != "" { |
| 533 | name = a.OverrideName |
| 534 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 535 | |
| 536 | if a.Include == "" { |
| 537 | a.Include = "$(BUILD_PREBUILT)" |
| 538 | } |
Cole Faust | 43ddd08 | 2024-06-17 12:32:40 -0700 | [diff] [blame] | 539 | a.Required = append(a.Required, amod.RequiredModuleNames(ctx)...) |
Kiyoung Kim | 04b64fc | 2024-08-19 11:25:30 +0900 | [diff] [blame] | 540 | a.Required = append(a.Required, amod.VintfFragmentModuleNames(ctx)...) |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 541 | a.Host_required = append(a.Host_required, amod.HostRequiredModuleNames()...) |
| 542 | a.Target_required = append(a.Target_required, amod.TargetRequiredModuleNames()...) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 543 | |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 544 | for _, distString := range a.GetDistForGoals(mod) { |
Yu Liu | e70976d | 2024-10-15 20:45:35 +0000 | [diff] [blame] | 545 | fmt.Fprintln(&a.header, distString) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Cole Faust | 39aabe9 | 2023-02-23 16:57:43 -0800 | [diff] [blame] | 548 | fmt.Fprintf(&a.header, "\ninclude $(CLEAR_VARS) # type: %s, name: %s, variant: %s\n", ctx.ModuleType(mod), base.BaseModuleName(), ctx.ModuleSubDir(mod)) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 549 | |
| 550 | // Collect make variable assignment entries. |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 551 | a.SetString("LOCAL_PATH", ctx.ModuleDir(mod)) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 552 | a.SetString("LOCAL_MODULE", name+a.SubName) |
| 553 | a.SetString("LOCAL_MODULE_CLASS", a.Class) |
| 554 | a.SetString("LOCAL_PREBUILT_MODULE_FILE", a.OutputFile.String()) |
| 555 | a.AddStrings("LOCAL_REQUIRED_MODULES", a.Required...) |
| 556 | a.AddStrings("LOCAL_HOST_REQUIRED_MODULES", a.Host_required...) |
| 557 | a.AddStrings("LOCAL_TARGET_REQUIRED_MODULES", a.Target_required...) |
Wei Li | 598f92d | 2023-01-04 17:12:24 -0800 | [diff] [blame] | 558 | a.AddStrings("LOCAL_SOONG_MODULE_TYPE", ctx.ModuleType(amod)) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 559 | |
Colin Cross | 6301c3c | 2021-09-28 17:40:21 -0700 | [diff] [blame] | 560 | // If the install rule was generated by Soong tell Make about it. |
Yu Liu | d46e5ae | 2024-08-15 18:46:17 +0000 | [diff] [blame] | 561 | info := OtherModuleProviderOrDefault(ctx, mod, InstallFilesProvider) |
| 562 | if len(info.KatiInstalls) > 0 { |
Colin Cross | 6301c3c | 2021-09-28 17:40:21 -0700 | [diff] [blame] | 563 | // Assume the primary install file is last since it probably needs to depend on any other |
| 564 | // installed files. If that is not the case we can add a method to specify the primary |
| 565 | // installed file. |
Yu Liu | d46e5ae | 2024-08-15 18:46:17 +0000 | [diff] [blame] | 566 | a.SetPath("LOCAL_SOONG_INSTALLED_MODULE", info.KatiInstalls[len(info.KatiInstalls)-1].to) |
| 567 | a.SetString("LOCAL_SOONG_INSTALL_PAIRS", info.KatiInstalls.BuiltInstalled()) |
| 568 | a.SetPaths("LOCAL_SOONG_INSTALL_SYMLINKS", info.KatiSymlinks.InstallPaths().Paths()) |
Jiyong Park | 3f627e6 | 2024-05-01 16:14:38 +0900 | [diff] [blame] | 569 | } else { |
| 570 | // Soong may not have generated the install rule also when `no_full_install: true`. |
| 571 | // Mark this module as uninstallable in order to prevent Make from creating an |
| 572 | // install rule there. |
| 573 | a.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", proptools.Bool(base.commonProperties.No_full_install)) |
Colin Cross | 6301c3c | 2021-09-28 17:40:21 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 576 | if info.UncheckedModule { |
| 577 | a.SetBool("LOCAL_DONT_CHECK_MODULE", true) |
| 578 | } else if info.CheckbuildTarget != nil { |
| 579 | a.SetPath("LOCAL_CHECKED_MODULE", info.CheckbuildTarget) |
| 580 | } else { |
| 581 | a.SetOptionalPath("LOCAL_CHECKED_MODULE", a.OutputFile) |
| 582 | } |
| 583 | |
Yu Liu | d46e5ae | 2024-08-15 18:46:17 +0000 | [diff] [blame] | 584 | if len(info.TestData) > 0 { |
| 585 | a.AddStrings("LOCAL_TEST_DATA", androidMkDataPaths(info.TestData)...) |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 586 | } |
| 587 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 588 | if am, ok := mod.(ApexModule); ok { |
| 589 | a.SetBoolIfTrue("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", am.NotAvailableForPlatform()) |
| 590 | } |
| 591 | |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 592 | archStr := base.Arch().ArchType.String() |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 593 | host := false |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 594 | switch base.Os().Class { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 595 | case Host: |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 596 | if base.Target().HostCross { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 597 | // Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common. |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 598 | if base.Arch().ArchType != Common { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 599 | a.SetString("LOCAL_MODULE_HOST_CROSS_ARCH", archStr) |
| 600 | } |
| 601 | } else { |
| 602 | // Make cannot identify LOCAL_MODULE_HOST_ARCH:= common. |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 603 | if base.Arch().ArchType != Common { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 604 | a.SetString("LOCAL_MODULE_HOST_ARCH", archStr) |
| 605 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 606 | } |
| 607 | host = true |
| 608 | case Device: |
| 609 | // Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common. |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 610 | if base.Arch().ArchType != Common { |
| 611 | if base.Target().NativeBridge { |
| 612 | hostArchStr := base.Target().NativeBridgeHostArchName |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 613 | if hostArchStr != "" { |
| 614 | a.SetString("LOCAL_MODULE_TARGET_ARCH", hostArchStr) |
| 615 | } |
| 616 | } else { |
| 617 | a.SetString("LOCAL_MODULE_TARGET_ARCH", archStr) |
| 618 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Kelvin Zhang | 4697725 | 2022-04-13 16:41:34 -0700 | [diff] [blame] | 621 | if !base.InVendorRamdisk() { |
Yu Liu | 82a6d14 | 2024-08-27 19:02:29 +0000 | [diff] [blame] | 622 | a.AddPaths("LOCAL_FULL_INIT_RC", info.InitRcPaths) |
Yifan Hong | 919dae1 | 2020-12-02 18:55:06 -0800 | [diff] [blame] | 623 | } |
Yu Liu | 82a6d14 | 2024-08-27 19:02:29 +0000 | [diff] [blame] | 624 | if len(info.VintfFragmentsPaths) > 0 { |
| 625 | a.AddPaths("LOCAL_FULL_VINTF_FRAGMENTS", info.VintfFragmentsPaths) |
Liz Kammer | 7b3dc8a | 2021-04-16 16:41:59 -0400 | [diff] [blame] | 626 | } |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 627 | a.SetBoolIfTrue("LOCAL_PROPRIETARY_MODULE", Bool(base.commonProperties.Proprietary)) |
| 628 | if Bool(base.commonProperties.Vendor) || Bool(base.commonProperties.Soc_specific) { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 629 | a.SetString("LOCAL_VENDOR_MODULE", "true") |
| 630 | } |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 631 | a.SetBoolIfTrue("LOCAL_ODM_MODULE", Bool(base.commonProperties.Device_specific)) |
| 632 | a.SetBoolIfTrue("LOCAL_PRODUCT_MODULE", Bool(base.commonProperties.Product_specific)) |
| 633 | a.SetBoolIfTrue("LOCAL_SYSTEM_EXT_MODULE", Bool(base.commonProperties.System_ext_specific)) |
| 634 | if base.commonProperties.Owner != nil { |
| 635 | a.SetString("LOCAL_MODULE_OWNER", *base.commonProperties.Owner) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 639 | if host { |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 640 | makeOs := base.Os().String() |
| 641 | if base.Os() == Linux || base.Os() == LinuxBionic || base.Os() == LinuxMusl { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 642 | makeOs = "linux" |
| 643 | } |
| 644 | a.SetString("LOCAL_MODULE_HOST_OS", makeOs) |
| 645 | a.SetString("LOCAL_IS_HOST_MODULE", "true") |
| 646 | } |
| 647 | |
| 648 | prefix := "" |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 649 | if base.ArchSpecific() { |
| 650 | switch base.Os().Class { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 651 | case Host: |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 652 | if base.Target().HostCross { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 653 | prefix = "HOST_CROSS_" |
| 654 | } else { |
| 655 | prefix = "HOST_" |
| 656 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 657 | case Device: |
| 658 | prefix = "TARGET_" |
| 659 | |
| 660 | } |
| 661 | |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 662 | if base.Arch().ArchType != ctx.Config().Targets[base.Os()][0].Arch.ArchType { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 663 | prefix = "2ND_" + prefix |
| 664 | } |
| 665 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 666 | |
Yu Liu | 663e450 | 2024-08-12 18:23:59 +0000 | [diff] [blame] | 667 | if licenseMetadata, ok := OtherModuleProvider(ctx, mod, LicenseMetadataProvider); ok { |
Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 668 | a.SetPath("LOCAL_SOONG_LICENSE_METADATA", licenseMetadata.LicenseMetadataPath) |
| 669 | } |
| 670 | |
Yu Liu | 663e450 | 2024-08-12 18:23:59 +0000 | [diff] [blame] | 671 | if _, ok := OtherModuleProvider(ctx, mod, ModuleInfoJSONProvider); ok { |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 672 | a.SetBool("LOCAL_SOONG_MODULE_INFO_JSON", true) |
| 673 | } |
| 674 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 675 | extraCtx := &androidMkExtraEntriesContext{ |
| 676 | ctx: ctx, |
| 677 | mod: mod, |
| 678 | } |
| 679 | |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 680 | for _, extra := range a.ExtraEntries { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 681 | extra(extraCtx, a) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | // Write to footer. |
| 685 | fmt.Fprintln(&a.footer, "include "+a.Include) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 686 | blueprintDir := ctx.ModuleDir(mod) |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 687 | for _, footerFunc := range a.ExtraFooters { |
Jaewoong Jung | 02b11a6 | 2020-12-07 10:23:54 -0800 | [diff] [blame] | 688 | footerFunc(&a.footer, name, prefix, blueprintDir) |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 689 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 692 | func (a *AndroidMkEntries) disabled() bool { |
| 693 | return a.Disabled || !a.OutputFile.Valid() |
| 694 | } |
| 695 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 696 | // write flushes the AndroidMkEntries's in-struct data populated by AndroidMkEntries into the |
| 697 | // given Writer object. |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 698 | func (a *AndroidMkEntries) write(w io.Writer) { |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 699 | if a.disabled() { |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 700 | return |
| 701 | } |
| 702 | |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 703 | w.Write(a.header.Bytes()) |
| 704 | for _, name := range a.entryOrder { |
Sasha Smundak | dcb6129 | 2022-12-08 10:41:33 -0800 | [diff] [blame] | 705 | AndroidMkEmitAssignList(w, name, a.EntryMap[name]) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 706 | } |
| 707 | w.Write(a.footer.Bytes()) |
| 708 | } |
| 709 | |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 710 | func (a *AndroidMkEntries) FooterLinesForTests() []string { |
| 711 | return strings.Split(string(a.footer.Bytes()), "\n") |
| 712 | } |
| 713 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 714 | // AndroidMkSingleton is a singleton to collect Android.mk data from all modules and dump them into |
| 715 | // the final Android-<product_name>.mk file output. |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 716 | func AndroidMkSingleton() Singleton { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 717 | return &androidMkSingleton{} |
| 718 | } |
| 719 | |
| 720 | type androidMkSingleton struct{} |
| 721 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 722 | func (c *androidMkSingleton) GenerateBuildActions(ctx SingletonContext) { |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 723 | var androidMkModulesList []blueprint.Module |
Colin Cross | 4f6e4e6 | 2016-01-11 12:55:55 -0800 | [diff] [blame] | 724 | |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 725 | ctx.VisitAllModulesBlueprint(func(module blueprint.Module) { |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 726 | androidMkModulesList = append(androidMkModulesList, module) |
Colin Cross | 4f6e4e6 | 2016-01-11 12:55:55 -0800 | [diff] [blame] | 727 | }) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 728 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 729 | // Sort the module list by the module names to eliminate random churns, which may erroneously |
| 730 | // invoke additional build processes. |
Colin Cross | 1ad8142 | 2019-01-14 12:47:35 -0800 | [diff] [blame] | 731 | sort.SliceStable(androidMkModulesList, func(i, j int) bool { |
| 732 | return ctx.ModuleName(androidMkModulesList[i]) < ctx.ModuleName(androidMkModulesList[j]) |
| 733 | }) |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 734 | |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 735 | // If running in soong-only mode, do a different, more limited version of this singleton |
| 736 | if !ctx.Config().KatiEnabled() { |
| 737 | c.soongOnlyBuildActions(ctx, androidMkModulesList) |
| 738 | return |
| 739 | } |
| 740 | |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 741 | transMk := PathForOutput(ctx, "Android"+String(ctx.Config().productVariables.Make_suffix)+".mk") |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 742 | if ctx.Failed() { |
| 743 | return |
| 744 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 745 | |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 746 | moduleInfoJSON := PathForOutput(ctx, "module-info"+String(ctx.Config().productVariables.Make_suffix)+".json") |
| 747 | |
| 748 | err := translateAndroidMk(ctx, absolutePath(transMk.String()), moduleInfoJSON, androidMkModulesList) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 749 | if err != nil { |
| 750 | ctx.Errorf(err.Error()) |
| 751 | } |
| 752 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 753 | ctx.Build(pctx, BuildParams{ |
| 754 | Rule: blueprint.Phony, |
| 755 | Output: transMk, |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 756 | }) |
| 757 | } |
| 758 | |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 759 | // In soong-only mode, we don't do most of the androidmk stuff. But disted files are still largely |
| 760 | // defined through the androidmk mechanisms, so this function is an alternate implementation of |
| 761 | // the androidmk singleton that just focuses on getting the dist contributions |
| 762 | func (c *androidMkSingleton) soongOnlyBuildActions(ctx SingletonContext, mods []blueprint.Module) { |
Cole Faust | f9a096c | 2025-01-21 16:55:43 -0800 | [diff] [blame] | 763 | allDistContributions, moduleInfoJSONs := getSoongOnlyDataFromMods(ctx, mods) |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 764 | |
Jihoon Kang | 1c6fcf5 | 2025-02-06 23:52:27 +0000 | [diff] [blame] | 765 | for _, provider := range makeVarsInitProviders { |
| 766 | mctx := &makeVarsContext{ |
| 767 | SingletonContext: ctx, |
| 768 | pctx: provider.pctx, |
| 769 | } |
| 770 | provider.call(mctx) |
Cole Faust | d62a489 | 2025-02-07 16:55:11 -0800 | [diff] [blame^] | 771 | if contribution := distsToDistContributions(mctx.dists); contribution != nil { |
Jihoon Kang | 1c6fcf5 | 2025-02-06 23:52:27 +0000 | [diff] [blame] | 772 | allDistContributions = append(allDistContributions, *contribution) |
| 773 | } |
| 774 | } |
| 775 | |
Cole Faust | f9a096c | 2025-01-21 16:55:43 -0800 | [diff] [blame] | 776 | // Build module-info.json. Only in builds with HasDeviceProduct(), as we need a named |
| 777 | // device to have a TARGET_OUT folder. |
| 778 | if ctx.Config().HasDeviceProduct() { |
Cole Faust | 601da06 | 2025-01-22 13:15:10 -0800 | [diff] [blame] | 779 | preMergePath := PathForOutput(ctx, "module_info_pre_merging.json") |
Cole Faust | f9a096c | 2025-01-21 16:55:43 -0800 | [diff] [blame] | 780 | moduleInfoJSONPath := pathForInstall(ctx, Android, X86_64, "", "module-info.json") |
Cole Faust | 601da06 | 2025-01-22 13:15:10 -0800 | [diff] [blame] | 781 | if err := writeModuleInfoJSON(ctx, moduleInfoJSONs, preMergePath); err != nil { |
Cole Faust | f9a096c | 2025-01-21 16:55:43 -0800 | [diff] [blame] | 782 | ctx.Errorf("%s", err) |
| 783 | } |
Cole Faust | 601da06 | 2025-01-22 13:15:10 -0800 | [diff] [blame] | 784 | builder := NewRuleBuilder(pctx, ctx) |
| 785 | builder.Command(). |
| 786 | BuiltTool("merge_module_info_json"). |
| 787 | FlagWithOutput("-o ", moduleInfoJSONPath). |
| 788 | Input(preMergePath) |
| 789 | builder.Build("merge_module_info_json", "merge module info json") |
Cole Faust | f9a096c | 2025-01-21 16:55:43 -0800 | [diff] [blame] | 790 | ctx.Phony("module-info", moduleInfoJSONPath) |
| 791 | ctx.Phony("droidcore-unbundled", moduleInfoJSONPath) |
| 792 | allDistContributions = append(allDistContributions, distContributions{ |
| 793 | copiesForGoals: []*copiesForGoals{{ |
| 794 | goals: "general-tests droidcore-unbundled", |
| 795 | copies: []distCopy{{ |
| 796 | from: moduleInfoJSONPath, |
| 797 | dest: "module-info.json", |
| 798 | }}, |
| 799 | }}, |
| 800 | }) |
| 801 | } |
| 802 | |
| 803 | // Build dist.mk for the packaging step to read and generate dist targets |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 804 | distMkFile := absolutePath(filepath.Join(ctx.Config().katiPackageMkDir(), "dist.mk")) |
| 805 | |
| 806 | var goalOutputPairs []string |
Cole Faust | 82611a1 | 2025-01-09 11:20:41 -0800 | [diff] [blame] | 807 | var srcDstPairs []string |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 808 | for _, contributions := range allDistContributions { |
| 809 | for _, copiesForGoal := range contributions.copiesForGoals { |
| 810 | goals := strings.Fields(copiesForGoal.goals) |
| 811 | for _, copy := range copiesForGoal.copies { |
| 812 | for _, goal := range goals { |
Cole Faust | 82611a1 | 2025-01-09 11:20:41 -0800 | [diff] [blame] | 813 | goalOutputPairs = append(goalOutputPairs, fmt.Sprintf(" %s:%s", goal, copy.dest)) |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 814 | } |
Cole Faust | 82611a1 | 2025-01-09 11:20:41 -0800 | [diff] [blame] | 815 | srcDstPairs = append(srcDstPairs, fmt.Sprintf(" %s:%s", copy.from.String(), copy.dest)) |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | } |
Cole Faust | 82611a1 | 2025-01-09 11:20:41 -0800 | [diff] [blame] | 819 | // There are duplicates in the lists that we need to remove |
| 820 | goalOutputPairs = SortedUniqueStrings(goalOutputPairs) |
| 821 | srcDstPairs = SortedUniqueStrings(srcDstPairs) |
| 822 | var buf strings.Builder |
| 823 | buf.WriteString("DIST_SRC_DST_PAIRS :=") |
| 824 | for _, srcDstPair := range srcDstPairs { |
| 825 | buf.WriteString(srcDstPair) |
| 826 | } |
| 827 | buf.WriteString("\nDIST_GOAL_OUTPUT_PAIRS :=") |
| 828 | for _, goalOutputPair := range goalOutputPairs { |
| 829 | buf.WriteString(goalOutputPair) |
| 830 | } |
| 831 | buf.WriteString("\n") |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 832 | |
| 833 | writeValueIfChanged(ctx, distMkFile, buf.String()) |
| 834 | } |
| 835 | |
| 836 | func writeValueIfChanged(ctx SingletonContext, path string, value string) { |
| 837 | if err := os.MkdirAll(filepath.Dir(path), 0777); err != nil { |
| 838 | ctx.Errorf("%s\n", err) |
| 839 | return |
| 840 | } |
| 841 | previousValue := "" |
| 842 | rawPreviousValue, err := os.ReadFile(path) |
| 843 | if err == nil { |
| 844 | previousValue = string(rawPreviousValue) |
| 845 | } |
| 846 | |
| 847 | if previousValue != value { |
| 848 | if err = os.WriteFile(path, []byte(value), 0666); err != nil { |
| 849 | ctx.Errorf("Failed to write: %v", err) |
| 850 | } |
| 851 | } |
| 852 | } |
| 853 | |
Cole Faust | d62a489 | 2025-02-07 16:55:11 -0800 | [diff] [blame^] | 854 | func distsToDistContributions(dists []dist) *distContributions { |
| 855 | if len(dists) == 0 { |
Jihoon Kang | 593171e | 2025-02-05 01:54:45 +0000 | [diff] [blame] | 856 | return nil |
| 857 | } |
| 858 | |
| 859 | copyGoals := []*copiesForGoals{} |
Cole Faust | d62a489 | 2025-02-07 16:55:11 -0800 | [diff] [blame^] | 860 | for _, dist := range dists { |
Jihoon Kang | 593171e | 2025-02-05 01:54:45 +0000 | [diff] [blame] | 861 | for _, goal := range dist.goals { |
Cole Faust | d62a489 | 2025-02-07 16:55:11 -0800 | [diff] [blame^] | 862 | copyGoals = append(copyGoals, &copiesForGoals{ |
| 863 | goals: goal, |
| 864 | copies: dist.paths, |
| 865 | }) |
Jihoon Kang | 593171e | 2025-02-05 01:54:45 +0000 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | |
Cole Faust | d62a489 | 2025-02-07 16:55:11 -0800 | [diff] [blame^] | 869 | return &distContributions{ |
| 870 | copiesForGoals: copyGoals, |
| 871 | } |
Jihoon Kang | 593171e | 2025-02-05 01:54:45 +0000 | [diff] [blame] | 872 | } |
| 873 | |
Cole Faust | f9a096c | 2025-01-21 16:55:43 -0800 | [diff] [blame] | 874 | // getSoongOnlyDataFromMods gathers data from the given modules needed in soong-only builds. |
| 875 | // Currently, this is the dist contributions, and the module-info.json contents. |
| 876 | func getSoongOnlyDataFromMods(ctx fillInEntriesContext, mods []blueprint.Module) ([]distContributions, []*ModuleInfoJSON) { |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 877 | var allDistContributions []distContributions |
Cole Faust | f9a096c | 2025-01-21 16:55:43 -0800 | [diff] [blame] | 878 | var moduleInfoJSONs []*ModuleInfoJSON |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 879 | for _, mod := range mods { |
Cole Faust | d62a489 | 2025-02-07 16:55:11 -0800 | [diff] [blame^] | 880 | if distInfo, ok := OtherModuleProvider(ctx, mod, DistProvider); ok { |
| 881 | if contribution := distsToDistContributions(distInfo.Dists); contribution != nil { |
| 882 | allDistContributions = append(allDistContributions, *contribution) |
| 883 | } |
| 884 | } |
| 885 | |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 886 | if amod, ok := mod.(Module); ok && shouldSkipAndroidMkProcessing(ctx, amod.base()) { |
| 887 | continue |
| 888 | } |
| 889 | if info, ok := OtherModuleProvider(ctx, mod, AndroidMkInfoProvider); ok { |
Cole Faust | 556f1f4 | 2025-01-09 10:49:42 -0800 | [diff] [blame] | 890 | // Deep copy the provider info since we need to modify the info later |
| 891 | info := deepCopyAndroidMkProviderInfo(info) |
| 892 | info.PrimaryInfo.fillInEntries(ctx, mod) |
| 893 | if info.PrimaryInfo.disabled() { |
| 894 | continue |
| 895 | } |
Cole Faust | f9a096c | 2025-01-21 16:55:43 -0800 | [diff] [blame] | 896 | if moduleInfoJSON, ok := OtherModuleProvider(ctx, mod, ModuleInfoJSONProvider); ok { |
Jihoon Kang | d406381 | 2025-01-24 00:25:30 +0000 | [diff] [blame] | 897 | moduleInfoJSONs = append(moduleInfoJSONs, moduleInfoJSON...) |
Cole Faust | f9a096c | 2025-01-21 16:55:43 -0800 | [diff] [blame] | 898 | } |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 899 | if contribution := info.PrimaryInfo.getDistContributions(ctx, mod); contribution != nil { |
| 900 | allDistContributions = append(allDistContributions, *contribution) |
| 901 | } |
| 902 | for _, ei := range info.ExtraInfo { |
Cole Faust | 556f1f4 | 2025-01-09 10:49:42 -0800 | [diff] [blame] | 903 | ei.fillInEntries(ctx, mod) |
| 904 | if ei.disabled() { |
| 905 | continue |
| 906 | } |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 907 | if contribution := ei.getDistContributions(ctx, mod); contribution != nil { |
| 908 | allDistContributions = append(allDistContributions, *contribution) |
| 909 | } |
| 910 | } |
| 911 | } else { |
Jihoon Kang | e6daf66 | 2025-02-06 01:38:16 +0000 | [diff] [blame] | 912 | if x, ok := mod.(AndroidMkDataProvider); ok { |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 913 | data := x.AndroidMk() |
| 914 | |
| 915 | if data.Include == "" { |
| 916 | data.Include = "$(BUILD_PREBUILT)" |
| 917 | } |
| 918 | |
| 919 | data.fillInData(ctx, mod) |
Cole Faust | 556f1f4 | 2025-01-09 10:49:42 -0800 | [diff] [blame] | 920 | if data.Entries.disabled() { |
| 921 | continue |
| 922 | } |
Cole Faust | f9a096c | 2025-01-21 16:55:43 -0800 | [diff] [blame] | 923 | if moduleInfoJSON, ok := OtherModuleProvider(ctx, mod, ModuleInfoJSONProvider); ok { |
Jihoon Kang | d406381 | 2025-01-24 00:25:30 +0000 | [diff] [blame] | 924 | moduleInfoJSONs = append(moduleInfoJSONs, moduleInfoJSON...) |
Cole Faust | f9a096c | 2025-01-21 16:55:43 -0800 | [diff] [blame] | 925 | } |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 926 | if contribution := data.Entries.getDistContributions(mod); contribution != nil { |
| 927 | allDistContributions = append(allDistContributions, *contribution) |
| 928 | } |
Jihoon Kang | e6daf66 | 2025-02-06 01:38:16 +0000 | [diff] [blame] | 929 | } |
| 930 | if x, ok := mod.(AndroidMkEntriesProvider); ok { |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 931 | entriesList := x.AndroidMkEntries() |
| 932 | for _, entries := range entriesList { |
| 933 | entries.fillInEntries(ctx, mod) |
Cole Faust | 556f1f4 | 2025-01-09 10:49:42 -0800 | [diff] [blame] | 934 | if entries.disabled() { |
| 935 | continue |
| 936 | } |
Cole Faust | f9a096c | 2025-01-21 16:55:43 -0800 | [diff] [blame] | 937 | if moduleInfoJSON, ok := OtherModuleProvider(ctx, mod, ModuleInfoJSONProvider); ok { |
Jihoon Kang | d406381 | 2025-01-24 00:25:30 +0000 | [diff] [blame] | 938 | moduleInfoJSONs = append(moduleInfoJSONs, moduleInfoJSON...) |
Cole Faust | f9a096c | 2025-01-21 16:55:43 -0800 | [diff] [blame] | 939 | } |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 940 | if contribution := entries.getDistContributions(mod); contribution != nil { |
| 941 | allDistContributions = append(allDistContributions, *contribution) |
| 942 | } |
| 943 | } |
Jihoon Kang | e6daf66 | 2025-02-06 01:38:16 +0000 | [diff] [blame] | 944 | } |
| 945 | if x, ok := mod.(ModuleMakeVarsProvider); ok { |
| 946 | mctx := &makeVarsContext{ |
| 947 | SingletonContext: ctx.(SingletonContext), |
| 948 | config: ctx.Config(), |
| 949 | pctx: pctx, |
| 950 | } |
Jihoon Kang | 593171e | 2025-02-05 01:54:45 +0000 | [diff] [blame] | 951 | if !x.Enabled(ctx) { |
| 952 | continue |
| 953 | } |
| 954 | x.MakeVars(mctx) |
Cole Faust | d62a489 | 2025-02-07 16:55:11 -0800 | [diff] [blame^] | 955 | if contribution := distsToDistContributions(mctx.dists); contribution != nil { |
Jihoon Kang | 593171e | 2025-02-05 01:54:45 +0000 | [diff] [blame] | 956 | allDistContributions = append(allDistContributions, *contribution) |
| 957 | } |
Jihoon Kang | e6daf66 | 2025-02-06 01:38:16 +0000 | [diff] [blame] | 958 | } |
| 959 | if x, ok := mod.(SingletonMakeVarsProvider); ok { |
| 960 | mctx := &makeVarsContext{ |
| 961 | SingletonContext: ctx.(SingletonContext), |
| 962 | config: ctx.Config(), |
| 963 | pctx: pctx, |
| 964 | } |
Jihoon Kang | 593171e | 2025-02-05 01:54:45 +0000 | [diff] [blame] | 965 | x.MakeVars(mctx) |
Cole Faust | d62a489 | 2025-02-07 16:55:11 -0800 | [diff] [blame^] | 966 | if contribution := distsToDistContributions(mctx.dists); contribution != nil { |
Jihoon Kang | 593171e | 2025-02-05 01:54:45 +0000 | [diff] [blame] | 967 | allDistContributions = append(allDistContributions, *contribution) |
| 968 | } |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 969 | } |
| 970 | } |
| 971 | } |
Cole Faust | f9a096c | 2025-01-21 16:55:43 -0800 | [diff] [blame] | 972 | return allDistContributions, moduleInfoJSONs |
Cole Faust | c5bfbdd | 2025-01-08 13:05:40 -0800 | [diff] [blame] | 973 | } |
| 974 | |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 975 | func translateAndroidMk(ctx SingletonContext, absMkFile string, moduleInfoJSONPath WritablePath, mods []blueprint.Module) error { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 976 | buf := &bytes.Buffer{} |
| 977 | |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 978 | var moduleInfoJSONs []*ModuleInfoJSON |
| 979 | |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 980 | fmt.Fprintln(buf, "LOCAL_MODULE_MAKEFILE := $(lastword $(MAKEFILE_LIST))") |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 981 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 982 | typeStats := make(map[string]int) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 983 | for _, mod := range mods { |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 984 | err := translateAndroidMkModule(ctx, buf, &moduleInfoJSONs, mod) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 985 | if err != nil { |
Colin Cross | 836e387 | 2021-11-09 12:30:59 -0800 | [diff] [blame] | 986 | os.Remove(absMkFile) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 987 | return err |
| 988 | } |
Dan Willemsen | 70e17fa | 2016-07-25 16:00:20 -0700 | [diff] [blame] | 989 | |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 990 | if amod, ok := mod.(Module); ok && ctx.PrimaryModule(amod) == amod { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 991 | typeStats[ctx.ModuleType(amod)] += 1 |
Dan Willemsen | 70e17fa | 2016-07-25 16:00:20 -0700 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | |
| 995 | keys := []string{} |
| 996 | fmt.Fprintln(buf, "\nSTATS.SOONG_MODULE_TYPE :=") |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 997 | for k := range typeStats { |
Dan Willemsen | 70e17fa | 2016-07-25 16:00:20 -0700 | [diff] [blame] | 998 | keys = append(keys, k) |
| 999 | } |
| 1000 | sort.Strings(keys) |
| 1001 | for _, mod_type := range keys { |
| 1002 | fmt.Fprintln(buf, "STATS.SOONG_MODULE_TYPE +=", mod_type) |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1003 | fmt.Fprintf(buf, "STATS.SOONG_MODULE_TYPE.%s := %d\n", mod_type, typeStats[mod_type]) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 1006 | err := pathtools.WriteFileIfChanged(absMkFile, buf.Bytes(), 0666) |
| 1007 | if err != nil { |
| 1008 | return err |
| 1009 | } |
| 1010 | |
| 1011 | return writeModuleInfoJSON(ctx, moduleInfoJSONs, moduleInfoJSONPath) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 1014 | func writeModuleInfoJSON(ctx SingletonContext, moduleInfoJSONs []*ModuleInfoJSON, moduleInfoJSONPath WritablePath) error { |
| 1015 | moduleInfoJSONBuf := &strings.Builder{} |
| 1016 | moduleInfoJSONBuf.WriteString("[") |
| 1017 | for i, moduleInfoJSON := range moduleInfoJSONs { |
| 1018 | if i != 0 { |
| 1019 | moduleInfoJSONBuf.WriteString(",\n") |
| 1020 | } |
| 1021 | moduleInfoJSONBuf.WriteString("{") |
| 1022 | moduleInfoJSONBuf.WriteString(strconv.Quote(moduleInfoJSON.core.RegisterName)) |
| 1023 | moduleInfoJSONBuf.WriteString(":") |
| 1024 | err := encodeModuleInfoJSON(moduleInfoJSONBuf, moduleInfoJSON) |
| 1025 | moduleInfoJSONBuf.WriteString("}") |
| 1026 | if err != nil { |
| 1027 | return err |
| 1028 | } |
| 1029 | } |
| 1030 | moduleInfoJSONBuf.WriteString("]") |
| 1031 | WriteFileRule(ctx, moduleInfoJSONPath, moduleInfoJSONBuf.String()) |
| 1032 | return nil |
| 1033 | } |
| 1034 | |
| 1035 | func translateAndroidMkModule(ctx SingletonContext, w io.Writer, moduleInfoJSONs *[]*ModuleInfoJSON, mod blueprint.Module) error { |
Colin Cross | 953d3a2 | 2018-09-05 16:23:54 -0700 | [diff] [blame] | 1036 | defer func() { |
| 1037 | if r := recover(); r != nil { |
| 1038 | panic(fmt.Errorf("%s in translateAndroidMkModule for module %s variant %s", |
| 1039 | r, ctx.ModuleName(mod), ctx.ModuleSubDir(mod))) |
| 1040 | } |
| 1041 | }() |
| 1042 | |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 1043 | // Additional cases here require review for correct license propagation to make. |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 1044 | var err error |
mrziwang | 1842097 | 2024-09-03 15:12:51 -0700 | [diff] [blame] | 1045 | |
Yu Liu | e70976d | 2024-10-15 20:45:35 +0000 | [diff] [blame] | 1046 | if info, ok := OtherModuleProvider(ctx, mod, AndroidMkInfoProvider); ok { |
| 1047 | err = translateAndroidMkEntriesInfoModule(ctx, w, moduleInfoJSONs, mod, info) |
mrziwang | 1842097 | 2024-09-03 15:12:51 -0700 | [diff] [blame] | 1048 | } else { |
| 1049 | switch x := mod.(type) { |
| 1050 | case AndroidMkDataProvider: |
| 1051 | err = translateAndroidModule(ctx, w, moduleInfoJSONs, mod, x) |
mrziwang | 1842097 | 2024-09-03 15:12:51 -0700 | [diff] [blame] | 1052 | case AndroidMkEntriesProvider: |
| 1053 | err = translateAndroidMkEntriesModule(ctx, w, moduleInfoJSONs, mod, x) |
| 1054 | default: |
| 1055 | // Not exported to make so no make variables to set. |
| 1056 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 1057 | } |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 1058 | |
| 1059 | if err != nil { |
| 1060 | return err |
| 1061 | } |
| 1062 | |
| 1063 | return err |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 1066 | func (data *AndroidMkData) fillInData(ctx fillInEntriesContext, mod blueprint.Module) { |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 1067 | // Get the preamble content through AndroidMkEntries logic. |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 1068 | data.Entries = AndroidMkEntries{ |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 1069 | Class: data.Class, |
| 1070 | SubName: data.SubName, |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 1071 | DistFiles: data.DistFiles, |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 1072 | OutputFile: data.OutputFile, |
| 1073 | Disabled: data.Disabled, |
| 1074 | Include: data.Include, |
| 1075 | Required: data.Required, |
| 1076 | Host_required: data.Host_required, |
| 1077 | Target_required: data.Target_required, |
| 1078 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 1079 | data.Entries.fillInEntries(ctx, mod) |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 1080 | |
| 1081 | // copy entries back to data since it is used in Custom |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 1082 | data.Required = data.Entries.Required |
| 1083 | data.Host_required = data.Entries.Host_required |
| 1084 | data.Target_required = data.Entries.Target_required |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 1085 | } |
| 1086 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 1087 | // A support func for the deprecated AndroidMkDataProvider interface. Use AndroidMkEntryProvider |
| 1088 | // instead. |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 1089 | func translateAndroidModule(ctx SingletonContext, w io.Writer, moduleInfoJSONs *[]*ModuleInfoJSON, |
| 1090 | mod blueprint.Module, provider AndroidMkDataProvider) error { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 1091 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1092 | amod := mod.(Module).base() |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 1093 | if shouldSkipAndroidMkProcessing(ctx, amod) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 1094 | return nil |
| 1095 | } |
| 1096 | |
Colin Cross | 91825d2 | 2017-08-10 16:59:47 -0700 | [diff] [blame] | 1097 | data := provider.AndroidMk() |
Yu Liu | ddc2833 | 2024-08-09 22:48:30 +0000 | [diff] [blame] | 1098 | |
Colin Cross | 5349941 | 2017-09-07 13:20:25 -0700 | [diff] [blame] | 1099 | if data.Include == "" { |
| 1100 | data.Include = "$(BUILD_PREBUILT)" |
| 1101 | } |
| 1102 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 1103 | data.fillInData(ctx, mod) |
LaMont Jones | b509938 | 2024-01-10 23:42:36 +0000 | [diff] [blame] | 1104 | aconfigUpdateAndroidMkData(ctx, mod.(Module), &data) |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 1105 | |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 1106 | prefix := "" |
| 1107 | if amod.ArchSpecific() { |
| 1108 | switch amod.Os().Class { |
| 1109 | case Host: |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1110 | if amod.Target().HostCross { |
| 1111 | prefix = "HOST_CROSS_" |
| 1112 | } else { |
| 1113 | prefix = "HOST_" |
| 1114 | } |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 1115 | case Device: |
| 1116 | prefix = "TARGET_" |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 1117 | |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1120 | if amod.Arch().ArchType != ctx.Config().Targets[amod.Os()][0].Arch.ArchType { |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 1121 | prefix = "2ND_" + prefix |
| 1122 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 1125 | name := provider.BaseModuleName() |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 1126 | blueprintDir := filepath.Dir(ctx.BlueprintFile(mod)) |
| 1127 | |
| 1128 | if data.Custom != nil { |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 1129 | // List of module types allowed to use .Custom(...) |
| 1130 | // Additions to the list require careful review for proper license handling. |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 1131 | switch reflect.TypeOf(mod).String() { // ctx.ModuleType(mod) doesn't work: aidl_interface creates phony without type |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 1132 | case "*aidl.aidlApi": // writes non-custom before adding .phony |
| 1133 | case "*aidl.aidlMapping": // writes non-custom before adding .phony |
| 1134 | case "*android.customModule": // appears in tests only |
Dan Willemsen | 9fe1410 | 2021-07-13 21:52:04 -0700 | [diff] [blame] | 1135 | case "*android_sdk.sdkRepoHost": // doesn't go through base_rules |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 1136 | case "*apex.apexBundle": // license properties written |
| 1137 | case "*bpf.bpf": // license properties written (both for module and objs) |
Neill Kapron | 41efab7 | 2024-07-31 22:17:36 +0000 | [diff] [blame] | 1138 | case "*libbpf_prog.libbpfProg": // license properties written (both for module and objs) |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 1139 | case "*genrule.Module": // writes non-custom before adding .phony |
| 1140 | case "*java.SystemModules": // doesn't go through base_rules |
| 1141 | case "*java.systemModulesImport": // doesn't go through base_rules |
| 1142 | case "*phony.phony": // license properties written |
Nelson Li | f3c7068 | 2023-12-20 02:37:52 +0000 | [diff] [blame] | 1143 | case "*phony.PhonyRule": // writes phony deps and acts like `.PHONY` |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 1144 | case "*selinux.selinuxContextsModule": // license properties written |
| 1145 | case "*sysprop.syspropLibrary": // license properties written |
Bill Yang | 3b3aac0 | 2024-09-05 09:22:09 +0000 | [diff] [blame] | 1146 | case "*vintf.vintfCompatibilityMatrixRule": // use case like phony |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 1147 | default: |
Bob Badour | 65ee90a | 2021-09-02 15:33:10 -0700 | [diff] [blame] | 1148 | if !ctx.Config().IsEnvFalse("ANDROID_REQUIRE_LICENSES") { |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 1149 | return fmt.Errorf("custom make rules not allowed for %q (%q) module %q", ctx.ModuleType(mod), reflect.TypeOf(mod), ctx.ModuleName(mod)) |
| 1150 | } |
| 1151 | } |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 1152 | data.Custom(w, name, prefix, blueprintDir, data) |
| 1153 | } else { |
| 1154 | WriteAndroidMkData(w, data) |
| 1155 | } |
| 1156 | |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 1157 | if !data.Entries.disabled() { |
Yu Liu | 663e450 | 2024-08-12 18:23:59 +0000 | [diff] [blame] | 1158 | if moduleInfoJSON, ok := OtherModuleProvider(ctx, mod, ModuleInfoJSONProvider); ok { |
Jihoon Kang | d406381 | 2025-01-24 00:25:30 +0000 | [diff] [blame] | 1159 | *moduleInfoJSONs = append(*moduleInfoJSONs, moduleInfoJSON...) |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 1163 | return nil |
| 1164 | } |
| 1165 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 1166 | // A support func for the deprecated AndroidMkDataProvider interface. Use AndroidMkEntryProvider |
| 1167 | // instead. |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 1168 | func WriteAndroidMkData(w io.Writer, data AndroidMkData) { |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 1169 | if data.Entries.disabled() { |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 1170 | return |
| 1171 | } |
| 1172 | |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 1173 | // write preamble via Entries |
| 1174 | data.Entries.footer = bytes.Buffer{} |
| 1175 | data.Entries.write(w) |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 1176 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1177 | for _, extra := range data.Extra { |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 1178 | extra(w, data.OutputFile.Path()) |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 1179 | } |
| 1180 | |
Colin Cross | 5349941 | 2017-09-07 13:20:25 -0700 | [diff] [blame] | 1181 | fmt.Fprintln(w, "include "+data.Include) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 1182 | } |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 1183 | |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 1184 | func translateAndroidMkEntriesModule(ctx SingletonContext, w io.Writer, moduleInfoJSONs *[]*ModuleInfoJSON, |
| 1185 | mod blueprint.Module, provider AndroidMkEntriesProvider) error { |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 1186 | if shouldSkipAndroidMkProcessing(ctx, mod.(Module).base()) { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 1187 | return nil |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 1188 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 1189 | |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 1190 | entriesList := provider.AndroidMkEntries() |
LaMont Jones | b509938 | 2024-01-10 23:42:36 +0000 | [diff] [blame] | 1191 | aconfigUpdateAndroidMkEntries(ctx, mod.(Module), &entriesList) |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 1192 | |
Jihoon Kang | d406381 | 2025-01-24 00:25:30 +0000 | [diff] [blame] | 1193 | moduleInfoJSON, providesModuleInfoJSON := OtherModuleProvider(ctx, mod, ModuleInfoJSONProvider) |
| 1194 | |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 1195 | // Any new or special cases here need review to verify correct propagation of license information. |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 1196 | for _, entries := range entriesList { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 1197 | entries.fillInEntries(ctx, mod) |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1198 | entries.write(w) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 1199 | |
Jihoon Kang | d406381 | 2025-01-24 00:25:30 +0000 | [diff] [blame] | 1200 | if providesModuleInfoJSON && !entries.disabled() { |
| 1201 | // append only the name matching moduleInfoJSON entry |
| 1202 | for _, m := range moduleInfoJSON { |
| 1203 | if m.RegisterNameOverride == entries.OverrideName && m.SubName == entries.SubName { |
| 1204 | *moduleInfoJSONs = append(*moduleInfoJSONs, m) |
| 1205 | } |
| 1206 | } |
Colin Cross | d6fd013 | 2023-11-06 13:54:06 -0800 | [diff] [blame] | 1207 | } |
| 1208 | } |
| 1209 | |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 1210 | return nil |
| 1211 | } |
| 1212 | |
Cole Faust | e8a8783 | 2024-09-11 11:35:46 -0700 | [diff] [blame] | 1213 | func ShouldSkipAndroidMkProcessing(ctx ConfigurableEvaluatorContext, module Module) bool { |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 1214 | return shouldSkipAndroidMkProcessing(ctx, module.base()) |
Chih-Hung Hsieh | 8078377 | 2021-10-11 16:46:56 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Cole Faust | e8a8783 | 2024-09-11 11:35:46 -0700 | [diff] [blame] | 1217 | func shouldSkipAndroidMkProcessing(ctx ConfigurableEvaluatorContext, module *ModuleBase) bool { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 1218 | if !module.commonProperties.NamespaceExportedToMake { |
| 1219 | // TODO(jeffrygaston) do we want to validate that there are no modules being |
| 1220 | // exported to Kati that depend on this module? |
| 1221 | return true |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 1222 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 1223 | |
Dan Willemsen | def7b5d | 2021-10-17 00:22:33 -0700 | [diff] [blame] | 1224 | // On Mac, only expose host darwin modules to Make, as that's all we claim to support. |
| 1225 | // In reality, some of them depend on device-built (Java) modules, so we can't disable all |
| 1226 | // device modules in Soong, but we can hide them from Make (and thus the build user interface) |
| 1227 | if runtime.GOOS == "darwin" && module.Os() != Darwin { |
| 1228 | return true |
| 1229 | } |
| 1230 | |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 1231 | // Only expose the primary Darwin target, as Make does not understand Darwin+Arm64 |
| 1232 | if module.Os() == Darwin && module.Target().HostCross { |
| 1233 | return true |
| 1234 | } |
| 1235 | |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 1236 | return !module.Enabled(ctx) || |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 1237 | module.commonProperties.HideFromMake || |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 1238 | // Make does not understand LinuxBionic |
Colin Cross | 9a027be | 2022-06-24 18:45:58 -0700 | [diff] [blame] | 1239 | module.Os() == LinuxBionic || |
| 1240 | // Make does not understand LinuxMusl, except when we are building with USE_HOST_MUSL=true |
| 1241 | // and all host binaries are LinuxMusl |
| 1242 | (module.Os() == LinuxMusl && module.Target().HostCross) |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 1243 | } |
Dan Shi | 3194912 | 2020-09-21 12:11:02 -0700 | [diff] [blame] | 1244 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 1245 | // A utility func to format LOCAL_TEST_DATA outputs. See the comments on DataPath to understand how |
| 1246 | // to use this func. |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 1247 | func androidMkDataPaths(data []DataPath) []string { |
Dan Shi | 3194912 | 2020-09-21 12:11:02 -0700 | [diff] [blame] | 1248 | var testFiles []string |
| 1249 | for _, d := range data { |
| 1250 | rel := d.SrcPath.Rel() |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 1251 | if d.WithoutRel { |
| 1252 | rel = d.SrcPath.Base() |
| 1253 | } |
Dan Shi | 3194912 | 2020-09-21 12:11:02 -0700 | [diff] [blame] | 1254 | path := d.SrcPath.String() |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 1255 | // LOCAL_TEST_DATA requires the rel portion of the path to be removed from the path. |
Dan Shi | 3194912 | 2020-09-21 12:11:02 -0700 | [diff] [blame] | 1256 | if !strings.HasSuffix(path, rel) { |
| 1257 | panic(fmt.Errorf("path %q does not end with %q", path, rel)) |
| 1258 | } |
| 1259 | path = strings.TrimSuffix(path, rel) |
| 1260 | testFileString := path + ":" + rel |
| 1261 | if len(d.RelativeInstallPath) > 0 { |
| 1262 | testFileString += ":" + d.RelativeInstallPath |
| 1263 | } |
| 1264 | testFiles = append(testFiles, testFileString) |
| 1265 | } |
| 1266 | return testFiles |
| 1267 | } |
Sasha Smundak | dcb6129 | 2022-12-08 10:41:33 -0800 | [diff] [blame] | 1268 | |
| 1269 | // AndroidMkEmitAssignList emits the line |
| 1270 | // |
| 1271 | // VAR := ITEM ... |
| 1272 | // |
| 1273 | // Items are the elements to the given set of lists |
| 1274 | // If all the passed lists are empty, no line will be emitted |
| 1275 | func AndroidMkEmitAssignList(w io.Writer, varName string, lists ...[]string) { |
| 1276 | doPrint := false |
| 1277 | for _, l := range lists { |
| 1278 | if doPrint = len(l) > 0; doPrint { |
| 1279 | break |
| 1280 | } |
| 1281 | } |
| 1282 | if !doPrint { |
| 1283 | return |
| 1284 | } |
| 1285 | fmt.Fprint(w, varName, " :=") |
| 1286 | for _, l := range lists { |
| 1287 | for _, item := range l { |
| 1288 | fmt.Fprint(w, " ", item) |
| 1289 | } |
| 1290 | } |
| 1291 | fmt.Fprintln(w) |
| 1292 | } |
mrziwang | 1842097 | 2024-09-03 15:12:51 -0700 | [diff] [blame] | 1293 | |
| 1294 | type AndroidMkProviderInfo struct { |
| 1295 | PrimaryInfo AndroidMkInfo |
| 1296 | ExtraInfo []AndroidMkInfo |
| 1297 | } |
| 1298 | |
| 1299 | type AndroidMkInfo struct { |
| 1300 | // Android.mk class string, e.g. EXECUTABLES, JAVA_LIBRARIES, ETC |
| 1301 | Class string |
| 1302 | // Optional suffix to append to the module name. Useful when a module wants to return multiple |
| 1303 | // AndroidMkEntries objects. For example, when a java_library returns an additional entry for |
| 1304 | // its hostdex sub-module, this SubName field is set to "-hostdex" so that it can have a |
| 1305 | // different name than the parent's. |
| 1306 | SubName string |
| 1307 | // If set, this value overrides the base module name. SubName is still appended. |
| 1308 | OverrideName string |
| 1309 | // Dist files to output |
| 1310 | DistFiles TaggedDistFiles |
| 1311 | // The output file for Kati to process and/or install. If absent, the module is skipped. |
| 1312 | OutputFile OptionalPath |
| 1313 | // If true, the module is skipped and does not appear on the final Android-<product name>.mk |
| 1314 | // file. Useful when a module needs to be skipped conditionally. |
| 1315 | Disabled bool |
| 1316 | // The postprocessing mk file to include, e.g. $(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk |
| 1317 | // If not set, $(BUILD_SYSTEM)/prebuilt.mk is used. |
| 1318 | Include string |
| 1319 | // Required modules that need to be built and included in the final build output when building |
| 1320 | // this module. |
| 1321 | Required []string |
| 1322 | // Required host modules that need to be built and included in the final build output when |
| 1323 | // building this module. |
| 1324 | Host_required []string |
| 1325 | // Required device modules that need to be built and included in the final build output when |
| 1326 | // building this module. |
| 1327 | Target_required []string |
| 1328 | |
| 1329 | HeaderStrings []string |
| 1330 | FooterStrings []string |
| 1331 | |
| 1332 | // A map that holds the up-to-date Make variable values. Can be accessed from tests. |
| 1333 | EntryMap map[string][]string |
| 1334 | // A list of EntryMap keys in insertion order. This serves a few purposes: |
| 1335 | // 1. Prevents churns. Golang map doesn't provide consistent iteration order, so without this, |
| 1336 | // the outputted Android-*.mk file may change even though there have been no content changes. |
| 1337 | // 2. Allows modules to refer to other variables, like LOCAL_BAR_VAR := $(LOCAL_FOO_VAR), |
| 1338 | // without worrying about the variables being mixed up in the actual mk file. |
| 1339 | // 3. Makes troubleshooting and spotting errors easier. |
| 1340 | EntryOrder []string |
| 1341 | } |
| 1342 | |
Yu Liu | e70976d | 2024-10-15 20:45:35 +0000 | [diff] [blame] | 1343 | type AndroidMkProviderInfoProducer interface { |
| 1344 | PrepareAndroidMKProviderInfo(config Config) *AndroidMkProviderInfo |
| 1345 | } |
| 1346 | |
mrziwang | 1842097 | 2024-09-03 15:12:51 -0700 | [diff] [blame] | 1347 | // TODO: rename it to AndroidMkEntriesProvider after AndroidMkEntriesProvider interface is gone. |
| 1348 | var AndroidMkInfoProvider = blueprint.NewProvider[*AndroidMkProviderInfo]() |
| 1349 | |
| 1350 | func translateAndroidMkEntriesInfoModule(ctx SingletonContext, w io.Writer, moduleInfoJSONs *[]*ModuleInfoJSON, |
| 1351 | mod blueprint.Module, providerInfo *AndroidMkProviderInfo) error { |
| 1352 | if shouldSkipAndroidMkProcessing(ctx, mod.(Module).base()) { |
| 1353 | return nil |
| 1354 | } |
| 1355 | |
| 1356 | // Deep copy the provider info since we need to modify the info later |
| 1357 | info := deepCopyAndroidMkProviderInfo(providerInfo) |
| 1358 | |
| 1359 | aconfigUpdateAndroidMkInfos(ctx, mod.(Module), &info) |
| 1360 | |
| 1361 | // Any new or special cases here need review to verify correct propagation of license information. |
| 1362 | info.PrimaryInfo.fillInEntries(ctx, mod) |
| 1363 | info.PrimaryInfo.write(w) |
| 1364 | if len(info.ExtraInfo) > 0 { |
| 1365 | for _, ei := range info.ExtraInfo { |
| 1366 | ei.fillInEntries(ctx, mod) |
| 1367 | ei.write(w) |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | if !info.PrimaryInfo.disabled() { |
| 1372 | if moduleInfoJSON, ok := OtherModuleProvider(ctx, mod, ModuleInfoJSONProvider); ok { |
Jihoon Kang | d406381 | 2025-01-24 00:25:30 +0000 | [diff] [blame] | 1373 | *moduleInfoJSONs = append(*moduleInfoJSONs, moduleInfoJSON...) |
mrziwang | 1842097 | 2024-09-03 15:12:51 -0700 | [diff] [blame] | 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | return nil |
| 1378 | } |
| 1379 | |
| 1380 | // Utility funcs to manipulate Android.mk variable entries. |
| 1381 | |
| 1382 | // SetString sets a Make variable with the given name to the given value. |
| 1383 | func (a *AndroidMkInfo) SetString(name, value string) { |
| 1384 | if _, ok := a.EntryMap[name]; !ok { |
| 1385 | a.EntryOrder = append(a.EntryOrder, name) |
| 1386 | } |
| 1387 | a.EntryMap[name] = []string{value} |
| 1388 | } |
| 1389 | |
| 1390 | // SetPath sets a Make variable with the given name to the given path string. |
| 1391 | func (a *AndroidMkInfo) SetPath(name string, path Path) { |
| 1392 | if _, ok := a.EntryMap[name]; !ok { |
| 1393 | a.EntryOrder = append(a.EntryOrder, name) |
| 1394 | } |
| 1395 | a.EntryMap[name] = []string{path.String()} |
| 1396 | } |
| 1397 | |
| 1398 | // SetOptionalPath sets a Make variable with the given name to the given path string if it is valid. |
| 1399 | // It is a no-op if the given path is invalid. |
| 1400 | func (a *AndroidMkInfo) SetOptionalPath(name string, path OptionalPath) { |
| 1401 | if path.Valid() { |
| 1402 | a.SetPath(name, path.Path()) |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | // AddPath appends the given path string to a Make variable with the given name. |
| 1407 | func (a *AndroidMkInfo) AddPath(name string, path Path) { |
| 1408 | if _, ok := a.EntryMap[name]; !ok { |
| 1409 | a.EntryOrder = append(a.EntryOrder, name) |
| 1410 | } |
| 1411 | a.EntryMap[name] = append(a.EntryMap[name], path.String()) |
| 1412 | } |
| 1413 | |
| 1414 | // AddOptionalPath appends the given path string to a Make variable with the given name if it is |
| 1415 | // valid. It is a no-op if the given path is invalid. |
| 1416 | func (a *AndroidMkInfo) AddOptionalPath(name string, path OptionalPath) { |
| 1417 | if path.Valid() { |
| 1418 | a.AddPath(name, path.Path()) |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | // SetPaths sets a Make variable with the given name to a slice of the given path strings. |
| 1423 | func (a *AndroidMkInfo) SetPaths(name string, paths Paths) { |
| 1424 | if _, ok := a.EntryMap[name]; !ok { |
| 1425 | a.EntryOrder = append(a.EntryOrder, name) |
| 1426 | } |
| 1427 | a.EntryMap[name] = paths.Strings() |
| 1428 | } |
| 1429 | |
| 1430 | // SetOptionalPaths sets a Make variable with the given name to a slice of the given path strings |
| 1431 | // only if there are a non-zero amount of paths. |
| 1432 | func (a *AndroidMkInfo) SetOptionalPaths(name string, paths Paths) { |
| 1433 | if len(paths) > 0 { |
| 1434 | a.SetPaths(name, paths) |
| 1435 | } |
| 1436 | } |
| 1437 | |
| 1438 | // AddPaths appends the given path strings to a Make variable with the given name. |
| 1439 | func (a *AndroidMkInfo) AddPaths(name string, paths Paths) { |
| 1440 | if _, ok := a.EntryMap[name]; !ok { |
| 1441 | a.EntryOrder = append(a.EntryOrder, name) |
| 1442 | } |
| 1443 | a.EntryMap[name] = append(a.EntryMap[name], paths.Strings()...) |
| 1444 | } |
| 1445 | |
| 1446 | // SetBoolIfTrue sets a Make variable with the given name to true if the given flag is true. |
| 1447 | // It is a no-op if the given flag is false. |
| 1448 | func (a *AndroidMkInfo) SetBoolIfTrue(name string, flag bool) { |
| 1449 | if flag { |
| 1450 | if _, ok := a.EntryMap[name]; !ok { |
| 1451 | a.EntryOrder = append(a.EntryOrder, name) |
| 1452 | } |
| 1453 | a.EntryMap[name] = []string{"true"} |
| 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | // SetBool sets a Make variable with the given name to if the given bool flag value. |
| 1458 | func (a *AndroidMkInfo) SetBool(name string, flag bool) { |
| 1459 | if _, ok := a.EntryMap[name]; !ok { |
| 1460 | a.EntryOrder = append(a.EntryOrder, name) |
| 1461 | } |
| 1462 | if flag { |
| 1463 | a.EntryMap[name] = []string{"true"} |
| 1464 | } else { |
| 1465 | a.EntryMap[name] = []string{"false"} |
| 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | // AddStrings appends the given strings to a Make variable with the given name. |
| 1470 | func (a *AndroidMkInfo) AddStrings(name string, value ...string) { |
| 1471 | if len(value) == 0 { |
| 1472 | return |
| 1473 | } |
| 1474 | if _, ok := a.EntryMap[name]; !ok { |
| 1475 | a.EntryOrder = append(a.EntryOrder, name) |
| 1476 | } |
| 1477 | a.EntryMap[name] = append(a.EntryMap[name], value...) |
| 1478 | } |
| 1479 | |
| 1480 | // AddCompatibilityTestSuites adds the supplied test suites to the EntryMap, with special handling |
| 1481 | // for partial MTS and MCTS test suites. |
| 1482 | func (a *AndroidMkInfo) AddCompatibilityTestSuites(suites ...string) { |
| 1483 | // M(C)TS supports a full test suite and partial per-module MTS test suites, with naming mts-${MODULE}. |
| 1484 | // To reduce repetition, if we find a partial M(C)TS test suite without an full M(C)TS test suite, |
| 1485 | // we add the full test suite to our list. |
| 1486 | if PrefixInList(suites, "mts-") && !InList("mts", suites) { |
| 1487 | suites = append(suites, "mts") |
| 1488 | } |
| 1489 | if PrefixInList(suites, "mcts-") && !InList("mcts", suites) { |
| 1490 | suites = append(suites, "mcts") |
| 1491 | } |
| 1492 | a.AddStrings("LOCAL_COMPATIBILITY_SUITE", suites...) |
| 1493 | } |
| 1494 | |
| 1495 | func (a *AndroidMkInfo) fillInEntries(ctx fillInEntriesContext, mod blueprint.Module) { |
| 1496 | helperInfo := AndroidMkInfo{ |
| 1497 | EntryMap: make(map[string][]string), |
| 1498 | } |
| 1499 | |
| 1500 | amod := mod.(Module) |
| 1501 | base := amod.base() |
| 1502 | name := base.BaseModuleName() |
| 1503 | if a.OverrideName != "" { |
| 1504 | name = a.OverrideName |
| 1505 | } |
| 1506 | |
| 1507 | if a.Include == "" { |
| 1508 | a.Include = "$(BUILD_PREBUILT)" |
| 1509 | } |
| 1510 | a.Required = append(a.Required, amod.RequiredModuleNames(ctx)...) |
| 1511 | a.Required = append(a.Required, amod.VintfFragmentModuleNames(ctx)...) |
| 1512 | a.Host_required = append(a.Host_required, amod.HostRequiredModuleNames()...) |
| 1513 | a.Target_required = append(a.Target_required, amod.TargetRequiredModuleNames()...) |
| 1514 | |
| 1515 | for _, distString := range a.GetDistForGoals(ctx, mod) { |
| 1516 | a.HeaderStrings = append(a.HeaderStrings, distString) |
| 1517 | } |
| 1518 | |
Yu Liu | e70976d | 2024-10-15 20:45:35 +0000 | [diff] [blame] | 1519 | a.HeaderStrings = append(a.HeaderStrings, fmt.Sprintf("\ninclude $(CLEAR_VARS) # type: %s, name: %s, variant: %s", ctx.ModuleType(mod), base.BaseModuleName(), ctx.ModuleSubDir(mod))) |
mrziwang | 1842097 | 2024-09-03 15:12:51 -0700 | [diff] [blame] | 1520 | |
| 1521 | // Collect make variable assignment entries. |
| 1522 | helperInfo.SetString("LOCAL_PATH", ctx.ModuleDir(mod)) |
| 1523 | helperInfo.SetString("LOCAL_MODULE", name+a.SubName) |
| 1524 | helperInfo.SetString("LOCAL_MODULE_CLASS", a.Class) |
| 1525 | helperInfo.SetString("LOCAL_PREBUILT_MODULE_FILE", a.OutputFile.String()) |
| 1526 | helperInfo.AddStrings("LOCAL_REQUIRED_MODULES", a.Required...) |
| 1527 | helperInfo.AddStrings("LOCAL_HOST_REQUIRED_MODULES", a.Host_required...) |
| 1528 | helperInfo.AddStrings("LOCAL_TARGET_REQUIRED_MODULES", a.Target_required...) |
| 1529 | helperInfo.AddStrings("LOCAL_SOONG_MODULE_TYPE", ctx.ModuleType(amod)) |
| 1530 | |
| 1531 | // If the install rule was generated by Soong tell Make about it. |
| 1532 | info := OtherModuleProviderOrDefault(ctx, mod, InstallFilesProvider) |
| 1533 | if len(info.KatiInstalls) > 0 { |
| 1534 | // Assume the primary install file is last since it probably needs to depend on any other |
| 1535 | // installed files. If that is not the case we can add a method to specify the primary |
| 1536 | // installed file. |
| 1537 | helperInfo.SetPath("LOCAL_SOONG_INSTALLED_MODULE", info.KatiInstalls[len(info.KatiInstalls)-1].to) |
| 1538 | helperInfo.SetString("LOCAL_SOONG_INSTALL_PAIRS", info.KatiInstalls.BuiltInstalled()) |
| 1539 | helperInfo.SetPaths("LOCAL_SOONG_INSTALL_SYMLINKS", info.KatiSymlinks.InstallPaths().Paths()) |
| 1540 | } else { |
| 1541 | // Soong may not have generated the install rule also when `no_full_install: true`. |
| 1542 | // Mark this module as uninstallable in order to prevent Make from creating an |
| 1543 | // install rule there. |
| 1544 | helperInfo.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", proptools.Bool(base.commonProperties.No_full_install)) |
| 1545 | } |
| 1546 | |
Yu Liu | e70976d | 2024-10-15 20:45:35 +0000 | [diff] [blame] | 1547 | if info.UncheckedModule { |
| 1548 | helperInfo.SetBool("LOCAL_DONT_CHECK_MODULE", true) |
| 1549 | } else if info.CheckbuildTarget != nil { |
| 1550 | helperInfo.SetPath("LOCAL_CHECKED_MODULE", info.CheckbuildTarget) |
| 1551 | } else { |
| 1552 | helperInfo.SetOptionalPath("LOCAL_CHECKED_MODULE", a.OutputFile) |
| 1553 | } |
| 1554 | |
mrziwang | 1842097 | 2024-09-03 15:12:51 -0700 | [diff] [blame] | 1555 | if len(info.TestData) > 0 { |
| 1556 | helperInfo.AddStrings("LOCAL_TEST_DATA", androidMkDataPaths(info.TestData)...) |
| 1557 | } |
| 1558 | |
| 1559 | if am, ok := mod.(ApexModule); ok { |
| 1560 | helperInfo.SetBoolIfTrue("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", am.NotAvailableForPlatform()) |
| 1561 | } |
| 1562 | |
| 1563 | archStr := base.Arch().ArchType.String() |
| 1564 | host := false |
| 1565 | switch base.Os().Class { |
| 1566 | case Host: |
| 1567 | if base.Target().HostCross { |
| 1568 | // Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common. |
| 1569 | if base.Arch().ArchType != Common { |
| 1570 | helperInfo.SetString("LOCAL_MODULE_HOST_CROSS_ARCH", archStr) |
| 1571 | } |
| 1572 | } else { |
| 1573 | // Make cannot identify LOCAL_MODULE_HOST_ARCH:= common. |
| 1574 | if base.Arch().ArchType != Common { |
| 1575 | helperInfo.SetString("LOCAL_MODULE_HOST_ARCH", archStr) |
| 1576 | } |
| 1577 | } |
| 1578 | host = true |
| 1579 | case Device: |
| 1580 | // Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common. |
| 1581 | if base.Arch().ArchType != Common { |
| 1582 | if base.Target().NativeBridge { |
| 1583 | hostArchStr := base.Target().NativeBridgeHostArchName |
| 1584 | if hostArchStr != "" { |
| 1585 | helperInfo.SetString("LOCAL_MODULE_TARGET_ARCH", hostArchStr) |
| 1586 | } |
| 1587 | } else { |
| 1588 | helperInfo.SetString("LOCAL_MODULE_TARGET_ARCH", archStr) |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | if !base.InVendorRamdisk() { |
| 1593 | helperInfo.AddPaths("LOCAL_FULL_INIT_RC", info.InitRcPaths) |
| 1594 | } |
| 1595 | if len(info.VintfFragmentsPaths) > 0 { |
| 1596 | helperInfo.AddPaths("LOCAL_FULL_VINTF_FRAGMENTS", info.VintfFragmentsPaths) |
| 1597 | } |
| 1598 | helperInfo.SetBoolIfTrue("LOCAL_PROPRIETARY_MODULE", Bool(base.commonProperties.Proprietary)) |
| 1599 | if Bool(base.commonProperties.Vendor) || Bool(base.commonProperties.Soc_specific) { |
| 1600 | helperInfo.SetString("LOCAL_VENDOR_MODULE", "true") |
| 1601 | } |
| 1602 | helperInfo.SetBoolIfTrue("LOCAL_ODM_MODULE", Bool(base.commonProperties.Device_specific)) |
| 1603 | helperInfo.SetBoolIfTrue("LOCAL_PRODUCT_MODULE", Bool(base.commonProperties.Product_specific)) |
| 1604 | helperInfo.SetBoolIfTrue("LOCAL_SYSTEM_EXT_MODULE", Bool(base.commonProperties.System_ext_specific)) |
| 1605 | if base.commonProperties.Owner != nil { |
| 1606 | helperInfo.SetString("LOCAL_MODULE_OWNER", *base.commonProperties.Owner) |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | if host { |
| 1611 | makeOs := base.Os().String() |
| 1612 | if base.Os() == Linux || base.Os() == LinuxBionic || base.Os() == LinuxMusl { |
| 1613 | makeOs = "linux" |
| 1614 | } |
| 1615 | helperInfo.SetString("LOCAL_MODULE_HOST_OS", makeOs) |
| 1616 | helperInfo.SetString("LOCAL_IS_HOST_MODULE", "true") |
| 1617 | } |
| 1618 | |
mrziwang | 1842097 | 2024-09-03 15:12:51 -0700 | [diff] [blame] | 1619 | if licenseMetadata, ok := OtherModuleProvider(ctx, mod, LicenseMetadataProvider); ok { |
| 1620 | helperInfo.SetPath("LOCAL_SOONG_LICENSE_METADATA", licenseMetadata.LicenseMetadataPath) |
| 1621 | } |
| 1622 | |
| 1623 | if _, ok := OtherModuleProvider(ctx, mod, ModuleInfoJSONProvider); ok { |
| 1624 | helperInfo.SetBool("LOCAL_SOONG_MODULE_INFO_JSON", true) |
| 1625 | } |
| 1626 | |
| 1627 | a.mergeEntries(&helperInfo) |
| 1628 | |
| 1629 | // Write to footer. |
| 1630 | a.FooterStrings = append([]string{"include " + a.Include}, a.FooterStrings...) |
| 1631 | } |
| 1632 | |
| 1633 | // This method merges the entries to helperInfo, then replaces a's EntryMap and |
| 1634 | // EntryOrder with helperInfo's |
| 1635 | func (a *AndroidMkInfo) mergeEntries(helperInfo *AndroidMkInfo) { |
| 1636 | for _, extraEntry := range a.EntryOrder { |
| 1637 | if v, ok := helperInfo.EntryMap[extraEntry]; ok { |
| 1638 | v = append(v, a.EntryMap[extraEntry]...) |
| 1639 | } else { |
| 1640 | helperInfo.EntryMap[extraEntry] = a.EntryMap[extraEntry] |
| 1641 | helperInfo.EntryOrder = append(helperInfo.EntryOrder, extraEntry) |
| 1642 | } |
| 1643 | } |
| 1644 | a.EntryOrder = helperInfo.EntryOrder |
| 1645 | a.EntryMap = helperInfo.EntryMap |
| 1646 | } |
| 1647 | |
| 1648 | func (a *AndroidMkInfo) disabled() bool { |
| 1649 | return a.Disabled || !a.OutputFile.Valid() |
| 1650 | } |
| 1651 | |
| 1652 | // write flushes the AndroidMkEntries's in-struct data populated by AndroidMkEntries into the |
| 1653 | // given Writer object. |
| 1654 | func (a *AndroidMkInfo) write(w io.Writer) { |
| 1655 | if a.disabled() { |
| 1656 | return |
| 1657 | } |
| 1658 | |
Yu Liu | e70976d | 2024-10-15 20:45:35 +0000 | [diff] [blame] | 1659 | combinedHeaderString := strings.Join(a.HeaderStrings, "\n") + "\n" |
| 1660 | combinedFooterString := strings.Join(a.FooterStrings, "\n") + "\n" |
mrziwang | 1842097 | 2024-09-03 15:12:51 -0700 | [diff] [blame] | 1661 | w.Write([]byte(combinedHeaderString)) |
| 1662 | for _, name := range a.EntryOrder { |
| 1663 | AndroidMkEmitAssignList(w, name, a.EntryMap[name]) |
| 1664 | } |
| 1665 | w.Write([]byte(combinedFooterString)) |
| 1666 | } |
| 1667 | |
| 1668 | // Compute the list of Make strings to declare phony goals and dist-for-goals |
| 1669 | // calls from the module's dist and dists properties. |
| 1670 | func (a *AndroidMkInfo) GetDistForGoals(ctx fillInEntriesContext, mod blueprint.Module) []string { |
| 1671 | distContributions := a.getDistContributions(ctx, mod) |
| 1672 | if distContributions == nil { |
| 1673 | return nil |
| 1674 | } |
| 1675 | |
| 1676 | return generateDistContributionsForMake(distContributions) |
| 1677 | } |
| 1678 | |
| 1679 | // Compute the contributions that the module makes to the dist. |
| 1680 | func (a *AndroidMkInfo) getDistContributions(ctx fillInEntriesContext, mod blueprint.Module) *distContributions { |
| 1681 | amod := mod.(Module).base() |
| 1682 | name := amod.BaseModuleName() |
| 1683 | |
| 1684 | // Collate the set of associated tag/paths available for copying to the dist. |
| 1685 | // Start with an empty (nil) set. |
| 1686 | var availableTaggedDists TaggedDistFiles |
| 1687 | |
| 1688 | // Then merge in any that are provided explicitly by the module. |
| 1689 | if a.DistFiles != nil { |
| 1690 | // Merge the DistFiles into the set. |
| 1691 | availableTaggedDists = availableTaggedDists.merge(a.DistFiles) |
| 1692 | } |
| 1693 | |
| 1694 | // If no paths have been provided for the DefaultDistTag and the output file is |
| 1695 | // valid then add that as the default dist path. |
| 1696 | if _, ok := availableTaggedDists[DefaultDistTag]; !ok && a.OutputFile.Valid() { |
| 1697 | availableTaggedDists = availableTaggedDists.addPathsForTag(DefaultDistTag, a.OutputFile.Path()) |
| 1698 | } |
| 1699 | |
| 1700 | info := OtherModuleProviderOrDefault(ctx, mod, InstallFilesProvider) |
| 1701 | // If the distFiles created by GenerateTaggedDistFiles contains paths for the |
| 1702 | // DefaultDistTag then that takes priority so delete any existing paths. |
| 1703 | if _, ok := info.DistFiles[DefaultDistTag]; ok { |
| 1704 | delete(availableTaggedDists, DefaultDistTag) |
| 1705 | } |
| 1706 | |
| 1707 | // Finally, merge the distFiles created by GenerateTaggedDistFiles. |
| 1708 | availableTaggedDists = availableTaggedDists.merge(info.DistFiles) |
| 1709 | |
| 1710 | if len(availableTaggedDists) == 0 { |
| 1711 | // Nothing dist-able for this module. |
| 1712 | return nil |
| 1713 | } |
| 1714 | |
| 1715 | // Collate the contributions this module makes to the dist. |
| 1716 | distContributions := &distContributions{} |
| 1717 | |
| 1718 | if !exemptFromRequiredApplicableLicensesProperty(mod.(Module)) { |
| 1719 | distContributions.licenseMetadataFile = info.LicenseMetadataFile |
| 1720 | } |
| 1721 | |
| 1722 | // Iterate over this module's dist structs, merged from the dist and dists properties. |
| 1723 | for _, dist := range amod.Dists() { |
| 1724 | // Get the list of goals this dist should be enabled for. e.g. sdk, droidcore |
| 1725 | goals := strings.Join(dist.Targets, " ") |
| 1726 | |
| 1727 | // Get the tag representing the output files to be dist'd. e.g. ".jar", ".proguard_map" |
| 1728 | var tag string |
| 1729 | if dist.Tag == nil { |
| 1730 | // If the dist struct does not specify a tag, use the default output files tag. |
| 1731 | tag = DefaultDistTag |
| 1732 | } else { |
| 1733 | tag = *dist.Tag |
| 1734 | } |
| 1735 | |
| 1736 | // Get the paths of the output files to be dist'd, represented by the tag. |
| 1737 | // Can be an empty list. |
| 1738 | tagPaths := availableTaggedDists[tag] |
| 1739 | if len(tagPaths) == 0 { |
| 1740 | // Nothing to dist for this tag, continue to the next dist. |
| 1741 | continue |
| 1742 | } |
| 1743 | |
| 1744 | if len(tagPaths) > 1 && (dist.Dest != nil || dist.Suffix != nil) { |
| 1745 | errorMessage := "%s: Cannot apply dest/suffix for more than one dist " + |
| 1746 | "file for %q goals tag %q in module %s. The list of dist files, " + |
| 1747 | "which should have a single element, is:\n%s" |
| 1748 | panic(fmt.Errorf(errorMessage, mod, goals, tag, name, tagPaths)) |
| 1749 | } |
| 1750 | |
| 1751 | copiesForGoals := distContributions.getCopiesForGoals(goals) |
| 1752 | |
| 1753 | // Iterate over each path adding a copy instruction to copiesForGoals |
| 1754 | for _, path := range tagPaths { |
| 1755 | // It's possible that the Path is nil from errant modules. Be defensive here. |
| 1756 | if path == nil { |
| 1757 | tagName := "default" // for error message readability |
| 1758 | if dist.Tag != nil { |
| 1759 | tagName = *dist.Tag |
| 1760 | } |
| 1761 | panic(fmt.Errorf("Dist file should not be nil for the %s tag in %s", tagName, name)) |
| 1762 | } |
| 1763 | |
| 1764 | dest := filepath.Base(path.String()) |
| 1765 | |
| 1766 | if dist.Dest != nil { |
| 1767 | var err error |
| 1768 | if dest, err = validateSafePath(*dist.Dest); err != nil { |
| 1769 | // This was checked in ModuleBase.GenerateBuildActions |
| 1770 | panic(err) |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | ext := filepath.Ext(dest) |
| 1775 | suffix := "" |
| 1776 | if dist.Suffix != nil { |
| 1777 | suffix = *dist.Suffix |
| 1778 | } |
| 1779 | |
| 1780 | productString := "" |
| 1781 | if dist.Append_artifact_with_product != nil && *dist.Append_artifact_with_product { |
| 1782 | productString = fmt.Sprintf("_%s", ctx.Config().DeviceProduct()) |
| 1783 | } |
| 1784 | |
| 1785 | if suffix != "" || productString != "" { |
| 1786 | dest = strings.TrimSuffix(dest, ext) + suffix + productString + ext |
| 1787 | } |
| 1788 | |
| 1789 | if dist.Dir != nil { |
| 1790 | var err error |
| 1791 | if dest, err = validateSafePath(*dist.Dir, dest); err != nil { |
| 1792 | // This was checked in ModuleBase.GenerateBuildActions |
| 1793 | panic(err) |
| 1794 | } |
| 1795 | } |
| 1796 | |
| 1797 | copiesForGoals.addCopyInstruction(path, dest) |
| 1798 | } |
| 1799 | } |
| 1800 | |
| 1801 | return distContributions |
| 1802 | } |
| 1803 | |
| 1804 | func deepCopyAndroidMkProviderInfo(providerInfo *AndroidMkProviderInfo) AndroidMkProviderInfo { |
| 1805 | info := AndroidMkProviderInfo{ |
| 1806 | PrimaryInfo: deepCopyAndroidMkInfo(&providerInfo.PrimaryInfo), |
| 1807 | } |
| 1808 | if len(providerInfo.ExtraInfo) > 0 { |
| 1809 | for _, i := range providerInfo.ExtraInfo { |
| 1810 | info.ExtraInfo = append(info.ExtraInfo, deepCopyAndroidMkInfo(&i)) |
| 1811 | } |
| 1812 | } |
| 1813 | return info |
| 1814 | } |
| 1815 | |
| 1816 | func deepCopyAndroidMkInfo(mkinfo *AndroidMkInfo) AndroidMkInfo { |
| 1817 | info := AndroidMkInfo{ |
| 1818 | Class: mkinfo.Class, |
| 1819 | SubName: mkinfo.SubName, |
| 1820 | OverrideName: mkinfo.OverrideName, |
| 1821 | // There is no modification on DistFiles or OutputFile, so no need to |
| 1822 | // make their deep copy. |
| 1823 | DistFiles: mkinfo.DistFiles, |
| 1824 | OutputFile: mkinfo.OutputFile, |
| 1825 | Disabled: mkinfo.Disabled, |
| 1826 | Include: mkinfo.Include, |
| 1827 | Required: deepCopyStringSlice(mkinfo.Required), |
| 1828 | Host_required: deepCopyStringSlice(mkinfo.Host_required), |
| 1829 | Target_required: deepCopyStringSlice(mkinfo.Target_required), |
| 1830 | HeaderStrings: deepCopyStringSlice(mkinfo.HeaderStrings), |
| 1831 | FooterStrings: deepCopyStringSlice(mkinfo.FooterStrings), |
| 1832 | EntryOrder: deepCopyStringSlice(mkinfo.EntryOrder), |
| 1833 | } |
| 1834 | info.EntryMap = make(map[string][]string) |
| 1835 | for k, v := range mkinfo.EntryMap { |
| 1836 | info.EntryMap[k] = deepCopyStringSlice(v) |
| 1837 | } |
| 1838 | |
| 1839 | return info |
| 1840 | } |
| 1841 | |
| 1842 | func deepCopyStringSlice(original []string) []string { |
| 1843 | result := make([]string, len(original)) |
| 1844 | copy(result, original) |
| 1845 | return result |
| 1846 | } |