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