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