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" |
| 28 | "io/ioutil" |
| 29 | "os" |
| 30 | "path/filepath" |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 31 | "reflect" |
Dan Willemsen | def7b5d | 2021-10-17 00:22:33 -0700 | [diff] [blame] | 32 | "runtime" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 33 | "sort" |
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 | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 37 | "github.com/google/blueprint/bootstrap" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 38 | ) |
| 39 | |
| 40 | func init() { |
Paul Duffin | 8c3fec4 | 2020-03-04 20:15:08 +0000 | [diff] [blame] | 41 | RegisterAndroidMkBuildComponents(InitRegistrationContext) |
| 42 | } |
| 43 | |
| 44 | func RegisterAndroidMkBuildComponents(ctx RegistrationContext) { |
| 45 | ctx.RegisterSingletonType("androidmk", AndroidMkSingleton) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Paul Duffin | 6c9da04 | 2021-03-07 15:44:41 +0000 | [diff] [blame] | 48 | // Enable androidmk support. |
| 49 | // * Register the singleton |
| 50 | // * Configure that we are inside make |
| 51 | var PrepareForTestWithAndroidMk = GroupFixturePreparers( |
| 52 | FixtureRegisterWithContext(RegisterAndroidMkBuildComponents), |
| 53 | FixtureModifyConfig(SetKatiEnabledForTests), |
| 54 | ) |
| 55 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 56 | // Deprecated: Use AndroidMkEntriesProvider instead, especially if you're not going to use the |
| 57 | // Custom function. It's easier to use and test. |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 58 | type AndroidMkDataProvider interface { |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 59 | AndroidMk() AndroidMkData |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 60 | BaseModuleName() string |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | type AndroidMkData struct { |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 64 | Class string |
| 65 | SubName string |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 66 | DistFiles TaggedDistFiles |
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 | |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 81 | type AndroidMkExtraFunc func(w io.Writer, outputFile Path) |
| 82 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 83 | // Interface for modules to declare their Android.mk outputs. Note that every module needs to |
| 84 | // implement this in order to be included in the final Android-<product_name>.mk output, even if |
| 85 | // 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] | 86 | type AndroidMkEntriesProvider interface { |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 87 | // Returns AndroidMkEntries objects that contain all basic info plus extra customization data |
| 88 | // if needed. This is the core func to implement. |
| 89 | // Note that one can return multiple objects. For example, java_library may return an additional |
| 90 | // AndroidMkEntries object for its hostdex sub-module. |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 91 | AndroidMkEntries() []AndroidMkEntries |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 92 | // Modules don't need to implement this as it's already implemented by ModuleBase. |
| 93 | // AndroidMkEntries uses BaseModuleName() instead of ModuleName() because certain modules |
| 94 | // e.g. Prebuilts, override the Name() func and return modified names. |
| 95 | // If a different name is preferred, use SubName or OverrideName in AndroidMkEntries. |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 96 | BaseModuleName() string |
| 97 | } |
| 98 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 99 | // 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] | 100 | type AndroidMkEntries struct { |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 101 | // Android.mk class string, e.g EXECUTABLES, JAVA_LIBRARIES, ETC |
| 102 | Class string |
| 103 | // Optional suffix to append to the module name. Useful when a module wants to return multiple |
| 104 | // AndroidMkEntries objects. For example, when a java_library returns an additional entry for |
| 105 | // its hostdex sub-module, this SubName field is set to "-hostdex" so that it can have a |
| 106 | // different name than the parent's. |
| 107 | SubName string |
| 108 | // If set, this value overrides the base module name. SubName is still appended. |
| 109 | OverrideName string |
| 110 | // Dist files to output |
| 111 | DistFiles TaggedDistFiles |
| 112 | // The output file for Kati to process and/or install. If absent, the module is skipped. |
| 113 | OutputFile OptionalPath |
| 114 | // If true, the module is skipped and does not appear on the final Android-<product name>.mk |
| 115 | // file. Useful when a module needs to be skipped conditionally. |
| 116 | Disabled bool |
| 117 | // The postprocessing mk file to include, e.g. $(BUILD_SYSTEM)/soong_cc_prebuilt.mk |
| 118 | // If not set, $(BUILD_SYSTEM)/prebuilt.mk is used. |
| 119 | Include string |
| 120 | // Required modules that need to be built and included in the final build output when building |
| 121 | // this module. |
| 122 | Required []string |
| 123 | // Required host modules that need to be built and included in the final build output when |
| 124 | // building this module. |
| 125 | Host_required []string |
| 126 | // Required device modules that need to be built and included in the final build output when |
| 127 | // building this module. |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 128 | Target_required []string |
| 129 | |
| 130 | header bytes.Buffer |
| 131 | footer bytes.Buffer |
| 132 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 133 | // Funcs to append additional Android.mk entries or modify the common ones. Multiple funcs are |
| 134 | // 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] | 135 | ExtraEntries []AndroidMkExtraEntriesFunc |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 136 | // Funcs to add extra lines to the module's Android.mk output. Unlike AndroidMkExtraEntriesFunc, |
| 137 | // which simply sets Make variable values, this can be used for anything since it can write any |
| 138 | // Make statements directly to the final Android-*.mk file. |
| 139 | // Primarily used to call macros or declare/update Make targets. |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 140 | ExtraFooters []AndroidMkExtraFootersFunc |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 141 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 142 | // A map that holds the up-to-date Make variable values. Can be accessed from tests. |
| 143 | EntryMap map[string][]string |
| 144 | // A list of EntryMap keys in insertion order. This serves a few purposes: |
| 145 | // 1. Prevents churns. Golang map doesn't provide consistent iteration order, so without this, |
| 146 | // the outputted Android-*.mk file may change even though there have been no content changes. |
| 147 | // 2. Allows modules to refer to other variables, like LOCAL_BAR_VAR := $(LOCAL_FOO_VAR), |
| 148 | // without worrying about the variables being mixed up in the actual mk file. |
| 149 | // 3. Makes troubleshooting and spotting errors easier. |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 150 | entryOrder []string |
| 151 | } |
| 152 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 153 | type AndroidMkExtraEntriesContext interface { |
| 154 | Provider(provider blueprint.ProviderKey) interface{} |
| 155 | } |
| 156 | |
| 157 | type androidMkExtraEntriesContext struct { |
| 158 | ctx fillInEntriesContext |
| 159 | mod blueprint.Module |
| 160 | } |
| 161 | |
| 162 | func (a *androidMkExtraEntriesContext) Provider(provider blueprint.ProviderKey) interface{} { |
| 163 | return a.ctx.ModuleProvider(a.mod, provider) |
| 164 | } |
| 165 | |
| 166 | type AndroidMkExtraEntriesFunc func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) |
Jaewoong Jung | 02b11a6 | 2020-12-07 10:23:54 -0800 | [diff] [blame] | 167 | type AndroidMkExtraFootersFunc func(w io.Writer, name, prefix, moduleDir string) |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 168 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 169 | // Utility funcs to manipulate Android.mk variable entries. |
| 170 | |
| 171 | // 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] | 172 | func (a *AndroidMkEntries) SetString(name, value string) { |
| 173 | if _, ok := a.EntryMap[name]; !ok { |
| 174 | a.entryOrder = append(a.entryOrder, name) |
| 175 | } |
| 176 | a.EntryMap[name] = []string{value} |
| 177 | } |
| 178 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 179 | // 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] | 180 | func (a *AndroidMkEntries) SetPath(name string, path Path) { |
| 181 | if _, ok := a.EntryMap[name]; !ok { |
| 182 | a.entryOrder = append(a.entryOrder, name) |
| 183 | } |
| 184 | a.EntryMap[name] = []string{path.String()} |
| 185 | } |
| 186 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 187 | // SetOptionalPath sets a Make variable with the given name to the given path string if it is valid. |
| 188 | // It is a no-op if the given path is invalid. |
Colin Cross | c0efd1d | 2020-07-03 11:56:24 -0700 | [diff] [blame] | 189 | func (a *AndroidMkEntries) SetOptionalPath(name string, path OptionalPath) { |
| 190 | if path.Valid() { |
| 191 | a.SetPath(name, path.Path()) |
| 192 | } |
| 193 | } |
| 194 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 195 | // 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] | 196 | func (a *AndroidMkEntries) AddPath(name string, path Path) { |
| 197 | if _, ok := a.EntryMap[name]; !ok { |
| 198 | a.entryOrder = append(a.entryOrder, name) |
| 199 | } |
| 200 | a.EntryMap[name] = append(a.EntryMap[name], path.String()) |
| 201 | } |
| 202 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 203 | // AddOptionalPath appends the given path string to a Make variable with the given name if it is |
| 204 | // valid. It is a no-op if the given path is invalid. |
Colin Cross | c0efd1d | 2020-07-03 11:56:24 -0700 | [diff] [blame] | 205 | func (a *AndroidMkEntries) AddOptionalPath(name string, path OptionalPath) { |
| 206 | if path.Valid() { |
| 207 | a.AddPath(name, path.Path()) |
| 208 | } |
| 209 | } |
| 210 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 211 | // 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] | 212 | func (a *AndroidMkEntries) SetPaths(name string, paths Paths) { |
| 213 | if _, ok := a.EntryMap[name]; !ok { |
| 214 | a.entryOrder = append(a.entryOrder, name) |
| 215 | } |
| 216 | a.EntryMap[name] = paths.Strings() |
| 217 | } |
| 218 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 219 | // SetOptionalPaths sets a Make variable with the given name to a slice of the given path strings |
| 220 | // only if there are a non-zero amount of paths. |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 221 | func (a *AndroidMkEntries) SetOptionalPaths(name string, paths Paths) { |
| 222 | if len(paths) > 0 { |
| 223 | a.SetPaths(name, paths) |
| 224 | } |
| 225 | } |
| 226 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 227 | // 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] | 228 | func (a *AndroidMkEntries) AddPaths(name string, paths Paths) { |
| 229 | if _, ok := a.EntryMap[name]; !ok { |
| 230 | a.entryOrder = append(a.entryOrder, name) |
| 231 | } |
| 232 | a.EntryMap[name] = append(a.EntryMap[name], paths.Strings()...) |
| 233 | } |
| 234 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 235 | // SetBoolIfTrue sets a Make variable with the given name to true if the given flag is true. |
| 236 | // It is a no-op if the given flag is false. |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 237 | func (a *AndroidMkEntries) SetBoolIfTrue(name string, flag bool) { |
| 238 | if flag { |
| 239 | if _, ok := a.EntryMap[name]; !ok { |
| 240 | a.entryOrder = append(a.entryOrder, name) |
| 241 | } |
| 242 | a.EntryMap[name] = []string{"true"} |
| 243 | } |
| 244 | } |
| 245 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 246 | // 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] | 247 | func (a *AndroidMkEntries) SetBool(name string, flag bool) { |
| 248 | if _, ok := a.EntryMap[name]; !ok { |
| 249 | a.entryOrder = append(a.entryOrder, name) |
| 250 | } |
| 251 | if flag { |
| 252 | a.EntryMap[name] = []string{"true"} |
| 253 | } else { |
| 254 | a.EntryMap[name] = []string{"false"} |
| 255 | } |
| 256 | } |
| 257 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 258 | // 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] | 259 | func (a *AndroidMkEntries) AddStrings(name string, value ...string) { |
| 260 | if len(value) == 0 { |
| 261 | return |
| 262 | } |
| 263 | if _, ok := a.EntryMap[name]; !ok { |
| 264 | a.entryOrder = append(a.entryOrder, name) |
| 265 | } |
| 266 | a.EntryMap[name] = append(a.EntryMap[name], value...) |
| 267 | } |
| 268 | |
Liz Kammer | 57f5b33 | 2020-11-24 12:42:58 -0800 | [diff] [blame] | 269 | // AddCompatibilityTestSuites adds the supplied test suites to the EntryMap, with special handling |
| 270 | // for partial MTS test suites. |
| 271 | func (a *AndroidMkEntries) AddCompatibilityTestSuites(suites ...string) { |
| 272 | // MTS supports a full test suite and partial per-module MTS test suites, with naming mts-${MODULE}. |
| 273 | // To reduce repetition, if we find a partial MTS test suite without an full MTS test suite, |
| 274 | // we add the full test suite to our list. |
| 275 | if PrefixInList(suites, "mts-") && !InList("mts", suites) { |
| 276 | suites = append(suites, "mts") |
| 277 | } |
| 278 | a.AddStrings("LOCAL_COMPATIBILITY_SUITE", suites...) |
| 279 | } |
| 280 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 281 | // The contributions to the dist. |
| 282 | type distContributions struct { |
| 283 | // List of goals and the dist copy instructions. |
| 284 | copiesForGoals []*copiesForGoals |
| 285 | } |
| 286 | |
| 287 | // getCopiesForGoals returns a copiesForGoals into which copy instructions that |
| 288 | // must be processed when building one or more of those goals can be added. |
| 289 | func (d *distContributions) getCopiesForGoals(goals string) *copiesForGoals { |
| 290 | copiesForGoals := &copiesForGoals{goals: goals} |
| 291 | d.copiesForGoals = append(d.copiesForGoals, copiesForGoals) |
| 292 | return copiesForGoals |
| 293 | } |
| 294 | |
| 295 | // Associates a list of dist copy instructions with a set of goals for which they |
| 296 | // should be run. |
| 297 | type copiesForGoals struct { |
| 298 | // goals are a space separated list of build targets that will trigger the |
| 299 | // copy instructions. |
| 300 | goals string |
| 301 | |
| 302 | // A list of instructions to copy a module's output files to somewhere in the |
| 303 | // dist directory. |
| 304 | copies []distCopy |
| 305 | } |
| 306 | |
| 307 | // Adds a copy instruction. |
| 308 | func (d *copiesForGoals) addCopyInstruction(from Path, dest string) { |
| 309 | d.copies = append(d.copies, distCopy{from, dest}) |
| 310 | } |
| 311 | |
| 312 | // Instruction on a path that must be copied into the dist. |
| 313 | type distCopy struct { |
| 314 | // The path to copy from. |
| 315 | from Path |
| 316 | |
| 317 | // The destination within the dist directory to copy to. |
| 318 | dest string |
| 319 | } |
| 320 | |
| 321 | // Compute the contributions that the module makes to the dist. |
| 322 | func (a *AndroidMkEntries) getDistContributions(mod blueprint.Module) *distContributions { |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 323 | amod := mod.(Module).base() |
| 324 | name := amod.BaseModuleName() |
| 325 | |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 326 | // Collate the set of associated tag/paths available for copying to the dist. |
| 327 | // Start with an empty (nil) set. |
Jingwen Chen | 7b27ca7 | 2020-07-24 09:13:49 +0000 | [diff] [blame] | 328 | var availableTaggedDists TaggedDistFiles |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 329 | |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 330 | // Then merge in any that are provided explicitly by the module. |
Jingwen Chen | 8481186 | 2020-07-21 11:32:19 +0000 | [diff] [blame] | 331 | if a.DistFiles != nil { |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 332 | // Merge the DistFiles into the set. |
| 333 | availableTaggedDists = availableTaggedDists.merge(a.DistFiles) |
| 334 | } |
| 335 | |
| 336 | // If no paths have been provided for the DefaultDistTag and the output file is |
| 337 | // valid then add that as the default dist path. |
| 338 | if _, ok := availableTaggedDists[DefaultDistTag]; !ok && a.OutputFile.Valid() { |
| 339 | availableTaggedDists = availableTaggedDists.addPathsForTag(DefaultDistTag, a.OutputFile.Path()) |
| 340 | } |
| 341 | |
Paul Duffin | af970a2 | 2020-11-23 23:32:56 +0000 | [diff] [blame] | 342 | // If the distFiles created by GenerateTaggedDistFiles contains paths for the |
| 343 | // DefaultDistTag then that takes priority so delete any existing paths. |
| 344 | if _, ok := amod.distFiles[DefaultDistTag]; ok { |
| 345 | delete(availableTaggedDists, DefaultDistTag) |
| 346 | } |
| 347 | |
| 348 | // Finally, merge the distFiles created by GenerateTaggedDistFiles. |
| 349 | availableTaggedDists = availableTaggedDists.merge(amod.distFiles) |
| 350 | |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 351 | if len(availableTaggedDists) == 0 { |
Jingwen Chen | 7b27ca7 | 2020-07-24 09:13:49 +0000 | [diff] [blame] | 352 | // Nothing dist-able for this module. |
| 353 | return nil |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 356 | // Collate the contributions this module makes to the dist. |
| 357 | distContributions := &distContributions{} |
| 358 | |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 359 | // Iterate over this module's dist structs, merged from the dist and dists properties. |
| 360 | for _, dist := range amod.Dists() { |
| 361 | // Get the list of goals this dist should be enabled for. e.g. sdk, droidcore |
| 362 | goals := strings.Join(dist.Targets, " ") |
| 363 | |
| 364 | // Get the tag representing the output files to be dist'd. e.g. ".jar", ".proguard_map" |
| 365 | var tag string |
| 366 | if dist.Tag == nil { |
| 367 | // 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] | 368 | tag = DefaultDistTag |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 369 | } else { |
| 370 | tag = *dist.Tag |
| 371 | } |
| 372 | |
| 373 | // Get the paths of the output files to be dist'd, represented by the tag. |
| 374 | // Can be an empty list. |
| 375 | tagPaths := availableTaggedDists[tag] |
| 376 | if len(tagPaths) == 0 { |
| 377 | // Nothing to dist for this tag, continue to the next dist. |
| 378 | continue |
| 379 | } |
| 380 | |
| 381 | if len(tagPaths) > 1 && (dist.Dest != nil || dist.Suffix != nil) { |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 382 | errorMessage := "%s: Cannot apply dest/suffix for more than one dist " + |
| 383 | "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] | 384 | "which should have a single element, is:\n%s" |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 385 | panic(fmt.Errorf(errorMessage, mod, goals, tag, name, tagPaths)) |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 388 | copiesForGoals := distContributions.getCopiesForGoals(goals) |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 389 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 390 | // Iterate over each path adding a copy instruction to copiesForGoals |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 391 | for _, path := range tagPaths { |
| 392 | // It's possible that the Path is nil from errant modules. Be defensive here. |
| 393 | if path == nil { |
| 394 | tagName := "default" // for error message readability |
| 395 | if dist.Tag != nil { |
| 396 | tagName = *dist.Tag |
| 397 | } |
| 398 | panic(fmt.Errorf("Dist file should not be nil for the %s tag in %s", tagName, name)) |
| 399 | } |
| 400 | |
| 401 | dest := filepath.Base(path.String()) |
| 402 | |
| 403 | if dist.Dest != nil { |
| 404 | var err error |
| 405 | if dest, err = validateSafePath(*dist.Dest); err != nil { |
| 406 | // This was checked in ModuleBase.GenerateBuildActions |
| 407 | panic(err) |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | if dist.Suffix != nil { |
| 412 | ext := filepath.Ext(dest) |
| 413 | suffix := *dist.Suffix |
| 414 | dest = strings.TrimSuffix(dest, ext) + suffix + ext |
| 415 | } |
| 416 | |
| 417 | if dist.Dir != nil { |
| 418 | var err error |
| 419 | if dest, err = validateSafePath(*dist.Dir, dest); err != nil { |
| 420 | // This was checked in ModuleBase.GenerateBuildActions |
| 421 | panic(err) |
| 422 | } |
| 423 | } |
| 424 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 425 | copiesForGoals.addCopyInstruction(path, dest) |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | return distContributions |
| 430 | } |
| 431 | |
| 432 | // generateDistContributionsForMake generates make rules that will generate the |
| 433 | // dist according to the instructions in the supplied distContribution. |
| 434 | func generateDistContributionsForMake(distContributions *distContributions) []string { |
| 435 | var ret []string |
| 436 | for _, d := range distContributions.copiesForGoals { |
| 437 | ret = append(ret, fmt.Sprintf(".PHONY: %s\n", d.goals)) |
| 438 | // Create dist-for-goals calls for each of the copy instructions. |
| 439 | for _, c := range d.copies { |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 440 | ret = append( |
| 441 | ret, |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 442 | fmt.Sprintf("$(call dist-for-goals,%s,%s:%s)\n", d.goals, c.from.String(), c.dest)) |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
| 446 | return ret |
| 447 | } |
| 448 | |
Paul Duffin | 8b0349c | 2020-11-26 14:33:21 +0000 | [diff] [blame] | 449 | // Compute the list of Make strings to declare phony goals and dist-for-goals |
| 450 | // calls from the module's dist and dists properties. |
| 451 | func (a *AndroidMkEntries) GetDistForGoals(mod blueprint.Module) []string { |
| 452 | distContributions := a.getDistContributions(mod) |
| 453 | if distContributions == nil { |
| 454 | return nil |
| 455 | } |
| 456 | |
| 457 | return generateDistContributionsForMake(distContributions) |
| 458 | } |
| 459 | |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 460 | // Write the license variables to Make for AndroidMkData.Custom(..) methods that do not call WriteAndroidMkData(..) |
| 461 | // It's required to propagate the license metadata even for module types that have non-standard interfaces to Make. |
| 462 | func (a *AndroidMkEntries) WriteLicenseVariables(w io.Writer) { |
| 463 | fmt.Fprintln(w, "LOCAL_LICENSE_KINDS :=", strings.Join(a.EntryMap["LOCAL_LICENSE_KINDS"], " ")) |
| 464 | fmt.Fprintln(w, "LOCAL_LICENSE_CONDITIONS :=", strings.Join(a.EntryMap["LOCAL_LICENSE_CONDITIONS"], " ")) |
| 465 | fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", strings.Join(a.EntryMap["LOCAL_NOTICE_FILE"], " ")) |
| 466 | if pn, ok := a.EntryMap["LOCAL_LICENSE_PACKAGE_NAME"]; ok { |
| 467 | fmt.Fprintln(w, "LOCAL_LICENSE_PACKAGE_NAME :=", strings.Join(pn, " ")) |
| 468 | } |
| 469 | } |
| 470 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 471 | // fillInEntries goes through the common variable processing and calls the extra data funcs to |
| 472 | // 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] | 473 | type fillInEntriesContext interface { |
| 474 | ModuleDir(module blueprint.Module) string |
| 475 | Config() Config |
| 476 | ModuleProvider(module blueprint.Module, provider blueprint.ProviderKey) interface{} |
| 477 | } |
| 478 | |
| 479 | func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint.Module) { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 480 | a.EntryMap = make(map[string][]string) |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 481 | amod := mod.(Module) |
| 482 | base := amod.base() |
| 483 | name := base.BaseModuleName() |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 484 | if a.OverrideName != "" { |
| 485 | name = a.OverrideName |
| 486 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 487 | |
| 488 | if a.Include == "" { |
| 489 | a.Include = "$(BUILD_PREBUILT)" |
| 490 | } |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 491 | a.Required = append(a.Required, amod.RequiredModuleNames()...) |
| 492 | a.Host_required = append(a.Host_required, amod.HostRequiredModuleNames()...) |
| 493 | a.Target_required = append(a.Target_required, amod.TargetRequiredModuleNames()...) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 494 | |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 495 | for _, distString := range a.GetDistForGoals(mod) { |
| 496 | fmt.Fprintf(&a.header, distString) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | fmt.Fprintln(&a.header, "\ninclude $(CLEAR_VARS)") |
| 500 | |
| 501 | // Collect make variable assignment entries. |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 502 | a.SetString("LOCAL_PATH", ctx.ModuleDir(mod)) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 503 | a.SetString("LOCAL_MODULE", name+a.SubName) |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 504 | a.AddStrings("LOCAL_LICENSE_KINDS", base.commonProperties.Effective_license_kinds...) |
| 505 | a.AddStrings("LOCAL_LICENSE_CONDITIONS", base.commonProperties.Effective_license_conditions...) |
| 506 | a.AddStrings("LOCAL_NOTICE_FILE", base.commonProperties.Effective_license_text.Strings()...) |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 507 | // TODO(b/151177513): Does this code need to set LOCAL_MODULE_IS_CONTAINER ? |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 508 | if base.commonProperties.Effective_package_name != nil { |
| 509 | a.SetString("LOCAL_LICENSE_PACKAGE_NAME", *base.commonProperties.Effective_package_name) |
| 510 | } else if len(base.commonProperties.Effective_licenses) > 0 { |
| 511 | a.SetString("LOCAL_LICENSE_PACKAGE_NAME", strings.Join(base.commonProperties.Effective_licenses, " ")) |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 512 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 513 | a.SetString("LOCAL_MODULE_CLASS", a.Class) |
| 514 | a.SetString("LOCAL_PREBUILT_MODULE_FILE", a.OutputFile.String()) |
| 515 | a.AddStrings("LOCAL_REQUIRED_MODULES", a.Required...) |
| 516 | a.AddStrings("LOCAL_HOST_REQUIRED_MODULES", a.Host_required...) |
| 517 | a.AddStrings("LOCAL_TARGET_REQUIRED_MODULES", a.Target_required...) |
| 518 | |
Colin Cross | 6301c3c | 2021-09-28 17:40:21 -0700 | [diff] [blame^] | 519 | // If the install rule was generated by Soong tell Make about it. |
| 520 | if amod.InstallBypassMake() && len(base.katiInstalls) > 0 { |
| 521 | // Assume the primary install file is last since it probably needs to depend on any other |
| 522 | // installed files. If that is not the case we can add a method to specify the primary |
| 523 | // installed file. |
| 524 | a.SetPath("LOCAL_SOONG_INSTALLED_MODULE", base.katiInstalls[len(base.katiInstalls)-1].to) |
| 525 | a.SetString("LOCAL_SOONG_INSTALL_PAIRS", base.katiInstalls.BuiltInstalled()) |
| 526 | a.SetPaths("LOCAL_SOONG_INSTALL_SYMLINKS", base.katiSymlinks.InstallPaths().Paths()) |
| 527 | } |
| 528 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 529 | if am, ok := mod.(ApexModule); ok { |
| 530 | a.SetBoolIfTrue("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", am.NotAvailableForPlatform()) |
| 531 | } |
| 532 | |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 533 | archStr := base.Arch().ArchType.String() |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 534 | host := false |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 535 | switch base.Os().Class { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 536 | case Host: |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 537 | if base.Target().HostCross { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 538 | // Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common. |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 539 | if base.Arch().ArchType != Common { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 540 | a.SetString("LOCAL_MODULE_HOST_CROSS_ARCH", archStr) |
| 541 | } |
| 542 | } else { |
| 543 | // Make cannot identify LOCAL_MODULE_HOST_ARCH:= common. |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 544 | if base.Arch().ArchType != Common { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 545 | a.SetString("LOCAL_MODULE_HOST_ARCH", archStr) |
| 546 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 547 | } |
| 548 | host = true |
| 549 | case Device: |
| 550 | // Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common. |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 551 | if base.Arch().ArchType != Common { |
| 552 | if base.Target().NativeBridge { |
| 553 | hostArchStr := base.Target().NativeBridgeHostArchName |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 554 | if hostArchStr != "" { |
| 555 | a.SetString("LOCAL_MODULE_TARGET_ARCH", hostArchStr) |
| 556 | } |
| 557 | } else { |
| 558 | a.SetString("LOCAL_MODULE_TARGET_ARCH", archStr) |
| 559 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 562 | if !base.InRamdisk() && !base.InVendorRamdisk() { |
| 563 | a.AddPaths("LOCAL_FULL_INIT_RC", base.initRcPaths) |
Yifan Hong | 919dae1 | 2020-12-02 18:55:06 -0800 | [diff] [blame] | 564 | } |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 565 | if len(base.vintfFragmentsPaths) > 0 { |
| 566 | a.AddPaths("LOCAL_FULL_VINTF_FRAGMENTS", base.vintfFragmentsPaths) |
Liz Kammer | 7b3dc8a | 2021-04-16 16:41:59 -0400 | [diff] [blame] | 567 | } |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 568 | a.SetBoolIfTrue("LOCAL_PROPRIETARY_MODULE", Bool(base.commonProperties.Proprietary)) |
| 569 | if Bool(base.commonProperties.Vendor) || Bool(base.commonProperties.Soc_specific) { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 570 | a.SetString("LOCAL_VENDOR_MODULE", "true") |
| 571 | } |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 572 | a.SetBoolIfTrue("LOCAL_ODM_MODULE", Bool(base.commonProperties.Device_specific)) |
| 573 | a.SetBoolIfTrue("LOCAL_PRODUCT_MODULE", Bool(base.commonProperties.Product_specific)) |
| 574 | a.SetBoolIfTrue("LOCAL_SYSTEM_EXT_MODULE", Bool(base.commonProperties.System_ext_specific)) |
| 575 | if base.commonProperties.Owner != nil { |
| 576 | a.SetString("LOCAL_MODULE_OWNER", *base.commonProperties.Owner) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 580 | if len(base.noticeFiles) > 0 { |
| 581 | a.SetString("LOCAL_NOTICE_FILE", strings.Join(base.noticeFiles.Strings(), " ")) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | if host { |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 585 | makeOs := base.Os().String() |
| 586 | if base.Os() == Linux || base.Os() == LinuxBionic || base.Os() == LinuxMusl { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 587 | makeOs = "linux" |
| 588 | } |
| 589 | a.SetString("LOCAL_MODULE_HOST_OS", makeOs) |
| 590 | a.SetString("LOCAL_IS_HOST_MODULE", "true") |
| 591 | } |
| 592 | |
| 593 | prefix := "" |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 594 | if base.ArchSpecific() { |
| 595 | switch base.Os().Class { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 596 | case Host: |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 597 | if base.Target().HostCross { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 598 | prefix = "HOST_CROSS_" |
| 599 | } else { |
| 600 | prefix = "HOST_" |
| 601 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 602 | case Device: |
| 603 | prefix = "TARGET_" |
| 604 | |
| 605 | } |
| 606 | |
Colin Cross | f1f763a | 2021-10-21 16:14:19 -0700 | [diff] [blame] | 607 | if base.Arch().ArchType != ctx.Config().Targets[base.Os()][0].Arch.ArchType { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 608 | prefix = "2ND_" + prefix |
| 609 | } |
| 610 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 611 | |
| 612 | extraCtx := &androidMkExtraEntriesContext{ |
| 613 | ctx: ctx, |
| 614 | mod: mod, |
| 615 | } |
| 616 | |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 617 | for _, extra := range a.ExtraEntries { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 618 | extra(extraCtx, a) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | // Write to footer. |
| 622 | fmt.Fprintln(&a.footer, "include "+a.Include) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 623 | blueprintDir := ctx.ModuleDir(mod) |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 624 | for _, footerFunc := range a.ExtraFooters { |
Jaewoong Jung | 02b11a6 | 2020-12-07 10:23:54 -0800 | [diff] [blame] | 625 | footerFunc(&a.footer, name, prefix, blueprintDir) |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 626 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 629 | // write flushes the AndroidMkEntries's in-struct data populated by AndroidMkEntries into the |
| 630 | // given Writer object. |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 631 | func (a *AndroidMkEntries) write(w io.Writer) { |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 632 | if a.Disabled { |
| 633 | return |
| 634 | } |
| 635 | |
| 636 | if !a.OutputFile.Valid() { |
| 637 | return |
| 638 | } |
| 639 | |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 640 | w.Write(a.header.Bytes()) |
| 641 | for _, name := range a.entryOrder { |
| 642 | fmt.Fprintln(w, name+" := "+strings.Join(a.EntryMap[name], " ")) |
| 643 | } |
| 644 | w.Write(a.footer.Bytes()) |
| 645 | } |
| 646 | |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 647 | func (a *AndroidMkEntries) FooterLinesForTests() []string { |
| 648 | return strings.Split(string(a.footer.Bytes()), "\n") |
| 649 | } |
| 650 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 651 | // AndroidMkSingleton is a singleton to collect Android.mk data from all modules and dump them into |
| 652 | // the final Android-<product_name>.mk file output. |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 653 | func AndroidMkSingleton() Singleton { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 654 | return &androidMkSingleton{} |
| 655 | } |
| 656 | |
| 657 | type androidMkSingleton struct{} |
| 658 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 659 | func (c *androidMkSingleton) GenerateBuildActions(ctx SingletonContext) { |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 660 | // Skip if Soong wasn't invoked from Make. |
Jingwen Chen | cda22c9 | 2020-11-23 00:22:30 -0500 | [diff] [blame] | 661 | if !ctx.Config().KatiEnabled() { |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 662 | return |
| 663 | } |
| 664 | |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 665 | var androidMkModulesList []blueprint.Module |
Colin Cross | 4f6e4e6 | 2016-01-11 12:55:55 -0800 | [diff] [blame] | 666 | |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 667 | ctx.VisitAllModulesBlueprint(func(module blueprint.Module) { |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 668 | androidMkModulesList = append(androidMkModulesList, module) |
Colin Cross | 4f6e4e6 | 2016-01-11 12:55:55 -0800 | [diff] [blame] | 669 | }) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 670 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 671 | // Sort the module list by the module names to eliminate random churns, which may erroneously |
| 672 | // invoke additional build processes. |
Colin Cross | 1ad8142 | 2019-01-14 12:47:35 -0800 | [diff] [blame] | 673 | sort.SliceStable(androidMkModulesList, func(i, j int) bool { |
| 674 | return ctx.ModuleName(androidMkModulesList[i]) < ctx.ModuleName(androidMkModulesList[j]) |
| 675 | }) |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 676 | |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 677 | transMk := PathForOutput(ctx, "Android"+String(ctx.Config().productVariables.Make_suffix)+".mk") |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 678 | if ctx.Failed() { |
| 679 | return |
| 680 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 681 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 682 | err := translateAndroidMk(ctx, absolutePath(transMk.String()), androidMkModulesList) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 683 | if err != nil { |
| 684 | ctx.Errorf(err.Error()) |
| 685 | } |
| 686 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 687 | ctx.Build(pctx, BuildParams{ |
| 688 | Rule: blueprint.Phony, |
| 689 | Output: transMk, |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 690 | }) |
| 691 | } |
| 692 | |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 693 | func translateAndroidMk(ctx SingletonContext, mkFile string, mods []blueprint.Module) error { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 694 | buf := &bytes.Buffer{} |
| 695 | |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 696 | fmt.Fprintln(buf, "LOCAL_MODULE_MAKEFILE := $(lastword $(MAKEFILE_LIST))") |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 697 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 698 | typeStats := make(map[string]int) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 699 | for _, mod := range mods { |
| 700 | err := translateAndroidMkModule(ctx, buf, mod) |
| 701 | if err != nil { |
| 702 | os.Remove(mkFile) |
| 703 | return err |
| 704 | } |
Dan Willemsen | 70e17fa | 2016-07-25 16:00:20 -0700 | [diff] [blame] | 705 | |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 706 | if amod, ok := mod.(Module); ok && ctx.PrimaryModule(amod) == amod { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 707 | typeStats[ctx.ModuleType(amod)] += 1 |
Dan Willemsen | 70e17fa | 2016-07-25 16:00:20 -0700 | [diff] [blame] | 708 | } |
| 709 | } |
| 710 | |
| 711 | keys := []string{} |
| 712 | fmt.Fprintln(buf, "\nSTATS.SOONG_MODULE_TYPE :=") |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 713 | for k := range typeStats { |
Dan Willemsen | 70e17fa | 2016-07-25 16:00:20 -0700 | [diff] [blame] | 714 | keys = append(keys, k) |
| 715 | } |
| 716 | sort.Strings(keys) |
| 717 | for _, mod_type := range keys { |
| 718 | fmt.Fprintln(buf, "STATS.SOONG_MODULE_TYPE +=", mod_type) |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 719 | 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] | 720 | } |
| 721 | |
| 722 | // Don't write to the file if it hasn't changed |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 723 | if _, err := os.Stat(absolutePath(mkFile)); !os.IsNotExist(err) { |
| 724 | if data, err := ioutil.ReadFile(absolutePath(mkFile)); err == nil { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 725 | matches := buf.Len() == len(data) |
| 726 | |
| 727 | if matches { |
| 728 | for i, value := range buf.Bytes() { |
| 729 | if value != data[i] { |
| 730 | matches = false |
| 731 | break |
| 732 | } |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | if matches { |
| 737 | return nil |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | |
Colin Cross | 988414c | 2020-01-11 01:11:46 +0000 | [diff] [blame] | 742 | return ioutil.WriteFile(absolutePath(mkFile), buf.Bytes(), 0666) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 745 | func translateAndroidMkModule(ctx SingletonContext, w io.Writer, mod blueprint.Module) error { |
Colin Cross | 953d3a2 | 2018-09-05 16:23:54 -0700 | [diff] [blame] | 746 | defer func() { |
| 747 | if r := recover(); r != nil { |
| 748 | panic(fmt.Errorf("%s in translateAndroidMkModule for module %s variant %s", |
| 749 | r, ctx.ModuleName(mod), ctx.ModuleSubDir(mod))) |
| 750 | } |
| 751 | }() |
| 752 | |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 753 | // Additional cases here require review for correct license propagation to make. |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 754 | switch x := mod.(type) { |
| 755 | case AndroidMkDataProvider: |
| 756 | return translateAndroidModule(ctx, w, mod, x) |
| 757 | case bootstrap.GoBinaryTool: |
| 758 | return translateGoBinaryModule(ctx, w, mod, x) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 759 | case AndroidMkEntriesProvider: |
| 760 | return translateAndroidMkEntriesModule(ctx, w, mod, x) |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 761 | default: |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 762 | // Not exported to make so no make variables to set. |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 763 | return nil |
| 764 | } |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 767 | // A simple, special Android.mk entry output func to make it possible to build blueprint tools using |
| 768 | // m by making them phony targets. |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 769 | func translateGoBinaryModule(ctx SingletonContext, w io.Writer, mod blueprint.Module, |
| 770 | goBinary bootstrap.GoBinaryTool) error { |
| 771 | |
| 772 | name := ctx.ModuleName(mod) |
| 773 | fmt.Fprintln(w, ".PHONY:", name) |
| 774 | fmt.Fprintln(w, name+":", goBinary.InstallPath()) |
| 775 | fmt.Fprintln(w, "") |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 776 | // Assuming no rules in make include go binaries in distributables. |
| 777 | // If the assumption is wrong, make will fail to build without the necessary .meta_lic and .meta_module files. |
| 778 | // In that case, add the targets and rules here to build a .meta_lic file for `name` and a .meta_module for |
| 779 | // `goBinary.InstallPath()` pointing to the `name`.meta_lic file. |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 780 | |
| 781 | return nil |
| 782 | } |
| 783 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 784 | func (data *AndroidMkData) fillInData(ctx fillInEntriesContext, mod blueprint.Module) { |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 785 | // Get the preamble content through AndroidMkEntries logic. |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 786 | data.Entries = AndroidMkEntries{ |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 787 | Class: data.Class, |
| 788 | SubName: data.SubName, |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 789 | DistFiles: data.DistFiles, |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 790 | OutputFile: data.OutputFile, |
| 791 | Disabled: data.Disabled, |
| 792 | Include: data.Include, |
| 793 | Required: data.Required, |
| 794 | Host_required: data.Host_required, |
| 795 | Target_required: data.Target_required, |
| 796 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 797 | data.Entries.fillInEntries(ctx, mod) |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 798 | |
| 799 | // copy entries back to data since it is used in Custom |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 800 | data.Required = data.Entries.Required |
| 801 | data.Host_required = data.Entries.Host_required |
| 802 | data.Target_required = data.Entries.Target_required |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 803 | } |
| 804 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 805 | // A support func for the deprecated AndroidMkDataProvider interface. Use AndroidMkEntryProvider |
| 806 | // instead. |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 807 | func translateAndroidModule(ctx SingletonContext, w io.Writer, mod blueprint.Module, |
| 808 | provider AndroidMkDataProvider) error { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 809 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 810 | amod := mod.(Module).base() |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 811 | if shouldSkipAndroidMkProcessing(amod) { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 812 | return nil |
| 813 | } |
| 814 | |
Colin Cross | 91825d2 | 2017-08-10 16:59:47 -0700 | [diff] [blame] | 815 | data := provider.AndroidMk() |
Colin Cross | 5349941 | 2017-09-07 13:20:25 -0700 | [diff] [blame] | 816 | if data.Include == "" { |
| 817 | data.Include = "$(BUILD_PREBUILT)" |
| 818 | } |
| 819 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 820 | data.fillInData(ctx, mod) |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 821 | |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 822 | prefix := "" |
| 823 | if amod.ArchSpecific() { |
| 824 | switch amod.Os().Class { |
| 825 | case Host: |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 826 | if amod.Target().HostCross { |
| 827 | prefix = "HOST_CROSS_" |
| 828 | } else { |
| 829 | prefix = "HOST_" |
| 830 | } |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 831 | case Device: |
| 832 | prefix = "TARGET_" |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 833 | |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 834 | } |
| 835 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 836 | if amod.Arch().ArchType != ctx.Config().Targets[amod.Os()][0].Arch.ArchType { |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 837 | prefix = "2ND_" + prefix |
| 838 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 841 | name := provider.BaseModuleName() |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 842 | blueprintDir := filepath.Dir(ctx.BlueprintFile(mod)) |
| 843 | |
| 844 | if data.Custom != nil { |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 845 | // List of module types allowed to use .Custom(...) |
| 846 | // Additions to the list require careful review for proper license handling. |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 847 | 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] | 848 | case "*aidl.aidlApi": // writes non-custom before adding .phony |
| 849 | case "*aidl.aidlMapping": // writes non-custom before adding .phony |
| 850 | case "*android.customModule": // appears in tests only |
Dan Willemsen | 9fe1410 | 2021-07-13 21:52:04 -0700 | [diff] [blame] | 851 | case "*android_sdk.sdkRepoHost": // doesn't go through base_rules |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 852 | case "*apex.apexBundle": // license properties written |
| 853 | case "*bpf.bpf": // license properties written (both for module and objs) |
| 854 | case "*genrule.Module": // writes non-custom before adding .phony |
| 855 | case "*java.SystemModules": // doesn't go through base_rules |
| 856 | case "*java.systemModulesImport": // doesn't go through base_rules |
| 857 | case "*phony.phony": // license properties written |
| 858 | case "*selinux.selinuxContextsModule": // license properties written |
| 859 | case "*sysprop.syspropLibrary": // license properties written |
| 860 | default: |
Bob Badour | 65ee90a | 2021-09-02 15:33:10 -0700 | [diff] [blame] | 861 | if !ctx.Config().IsEnvFalse("ANDROID_REQUIRE_LICENSES") { |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 862 | return fmt.Errorf("custom make rules not allowed for %q (%q) module %q", ctx.ModuleType(mod), reflect.TypeOf(mod), ctx.ModuleName(mod)) |
| 863 | } |
| 864 | } |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 865 | data.Custom(w, name, prefix, blueprintDir, data) |
| 866 | } else { |
| 867 | WriteAndroidMkData(w, data) |
| 868 | } |
| 869 | |
| 870 | return nil |
| 871 | } |
| 872 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 873 | // A support func for the deprecated AndroidMkDataProvider interface. Use AndroidMkEntryProvider |
| 874 | // instead. |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 875 | func WriteAndroidMkData(w io.Writer, data AndroidMkData) { |
| 876 | if data.Disabled { |
| 877 | return |
| 878 | } |
| 879 | |
| 880 | if !data.OutputFile.Valid() { |
| 881 | return |
| 882 | } |
| 883 | |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 884 | // write preamble via Entries |
| 885 | data.Entries.footer = bytes.Buffer{} |
| 886 | data.Entries.write(w) |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 887 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 888 | for _, extra := range data.Extra { |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 889 | extra(w, data.OutputFile.Path()) |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 890 | } |
| 891 | |
Colin Cross | 5349941 | 2017-09-07 13:20:25 -0700 | [diff] [blame] | 892 | fmt.Fprintln(w, "include "+data.Include) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 893 | } |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 894 | |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 895 | func translateAndroidMkEntriesModule(ctx SingletonContext, w io.Writer, mod blueprint.Module, |
| 896 | provider AndroidMkEntriesProvider) error { |
| 897 | if shouldSkipAndroidMkProcessing(mod.(Module).base()) { |
| 898 | return nil |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 899 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 900 | |
Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 901 | // Any new or special cases here need review to verify correct propagation of license information. |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 902 | for _, entries := range provider.AndroidMkEntries() { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 903 | entries.fillInEntries(ctx, mod) |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 904 | entries.write(w) |
| 905 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 906 | |
| 907 | return nil |
| 908 | } |
| 909 | |
| 910 | func shouldSkipAndroidMkProcessing(module *ModuleBase) bool { |
| 911 | if !module.commonProperties.NamespaceExportedToMake { |
| 912 | // TODO(jeffrygaston) do we want to validate that there are no modules being |
| 913 | // exported to Kati that depend on this module? |
| 914 | return true |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 915 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 916 | |
Dan Willemsen | def7b5d | 2021-10-17 00:22:33 -0700 | [diff] [blame] | 917 | // On Mac, only expose host darwin modules to Make, as that's all we claim to support. |
| 918 | // In reality, some of them depend on device-built (Java) modules, so we can't disable all |
| 919 | // device modules in Soong, but we can hide them from Make (and thus the build user interface) |
| 920 | if runtime.GOOS == "darwin" && module.Os() != Darwin { |
| 921 | return true |
| 922 | } |
| 923 | |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 924 | return !module.Enabled() || |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 925 | module.commonProperties.HideFromMake || |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 926 | // Make does not understand LinuxBionic |
| 927 | module.Os() == LinuxBionic |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 928 | } |
Dan Shi | 3194912 | 2020-09-21 12:11:02 -0700 | [diff] [blame] | 929 | |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 930 | // A utility func to format LOCAL_TEST_DATA outputs. See the comments on DataPath to understand how |
| 931 | // to use this func. |
Dan Shi | 3194912 | 2020-09-21 12:11:02 -0700 | [diff] [blame] | 932 | func AndroidMkDataPaths(data []DataPath) []string { |
| 933 | var testFiles []string |
| 934 | for _, d := range data { |
| 935 | rel := d.SrcPath.Rel() |
| 936 | path := d.SrcPath.String() |
Jaewoong Jung | 7ef4a90 | 2020-11-16 12:50:29 -0800 | [diff] [blame] | 937 | // 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] | 938 | if !strings.HasSuffix(path, rel) { |
| 939 | panic(fmt.Errorf("path %q does not end with %q", path, rel)) |
| 940 | } |
| 941 | path = strings.TrimSuffix(path, rel) |
| 942 | testFileString := path + ":" + rel |
| 943 | if len(d.RelativeInstallPath) > 0 { |
| 944 | testFileString += ":" + d.RelativeInstallPath |
| 945 | } |
| 946 | testFiles = append(testFiles, testFileString) |
| 947 | } |
| 948 | return testFiles |
| 949 | } |