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