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 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 15 | package android |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 16 | |
| 17 | import ( |
| 18 | "bytes" |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 19 | "fmt" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 20 | "io" |
| 21 | "io/ioutil" |
| 22 | "os" |
| 23 | "path/filepath" |
| 24 | "sort" |
Dan Willemsen | 0fda89f | 2016-06-01 15:25:32 -0700 | [diff] [blame] | 25 | "strings" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 26 | |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 27 | "github.com/google/blueprint" |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 28 | "github.com/google/blueprint/bootstrap" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 29 | ) |
| 30 | |
| 31 | func init() { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 32 | RegisterSingletonType("androidmk", AndroidMkSingleton) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | type AndroidMkDataProvider interface { |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 36 | AndroidMk() AndroidMkData |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 37 | BaseModuleName() string |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | type AndroidMkData struct { |
| 41 | Class string |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 42 | SubName string |
Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 43 | DistFile OptionalPath |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 44 | OutputFile OptionalPath |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 45 | Disabled bool |
Colin Cross | 5349941 | 2017-09-07 13:20:25 -0700 | [diff] [blame] | 46 | Include string |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 47 | Required []string |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 48 | |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 49 | Custom func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 50 | |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 51 | Extra []AndroidMkExtraFunc |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 52 | |
| 53 | preamble bytes.Buffer |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 56 | type AndroidMkExtraFunc func(w io.Writer, outputFile Path) |
| 57 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 58 | func AndroidMkSingleton() Singleton { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 59 | return &androidMkSingleton{} |
| 60 | } |
| 61 | |
| 62 | type androidMkSingleton struct{} |
| 63 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 64 | func (c *androidMkSingleton) GenerateBuildActions(ctx SingletonContext) { |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 65 | if !ctx.Config().EmbeddedInMake() { |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 66 | return |
| 67 | } |
| 68 | |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 69 | var androidMkModulesList []blueprint.Module |
Colin Cross | 4f6e4e6 | 2016-01-11 12:55:55 -0800 | [diff] [blame] | 70 | |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 71 | ctx.VisitAllModulesBlueprint(func(module blueprint.Module) { |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 72 | androidMkModulesList = append(androidMkModulesList, module) |
Colin Cross | 4f6e4e6 | 2016-01-11 12:55:55 -0800 | [diff] [blame] | 73 | }) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 74 | |
Colin Cross | 1ad8142 | 2019-01-14 12:47:35 -0800 | [diff] [blame] | 75 | sort.SliceStable(androidMkModulesList, func(i, j int) bool { |
| 76 | return ctx.ModuleName(androidMkModulesList[i]) < ctx.ModuleName(androidMkModulesList[j]) |
| 77 | }) |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 78 | |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 79 | transMk := PathForOutput(ctx, "Android"+String(ctx.Config().productVariables.Make_suffix)+".mk") |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 80 | if ctx.Failed() { |
| 81 | return |
| 82 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 83 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 84 | err := translateAndroidMk(ctx, transMk.String(), androidMkModulesList) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 85 | if err != nil { |
| 86 | ctx.Errorf(err.Error()) |
| 87 | } |
| 88 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 89 | ctx.Build(pctx, BuildParams{ |
| 90 | Rule: blueprint.Phony, |
| 91 | Output: transMk, |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 92 | }) |
| 93 | } |
| 94 | |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 95 | func translateAndroidMk(ctx SingletonContext, mkFile string, mods []blueprint.Module) error { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 96 | buf := &bytes.Buffer{} |
| 97 | |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 98 | fmt.Fprintln(buf, "LOCAL_MODULE_MAKEFILE := $(lastword $(MAKEFILE_LIST))") |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 99 | |
Dan Willemsen | 70e17fa | 2016-07-25 16:00:20 -0700 | [diff] [blame] | 100 | type_stats := make(map[string]int) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 101 | for _, mod := range mods { |
| 102 | err := translateAndroidMkModule(ctx, buf, mod) |
| 103 | if err != nil { |
| 104 | os.Remove(mkFile) |
| 105 | return err |
| 106 | } |
Dan Willemsen | 70e17fa | 2016-07-25 16:00:20 -0700 | [diff] [blame] | 107 | |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 108 | if amod, ok := mod.(Module); ok && ctx.PrimaryModule(amod) == amod { |
| 109 | type_stats[ctx.ModuleType(amod)] += 1 |
Dan Willemsen | 70e17fa | 2016-07-25 16:00:20 -0700 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | |
| 113 | keys := []string{} |
| 114 | fmt.Fprintln(buf, "\nSTATS.SOONG_MODULE_TYPE :=") |
| 115 | for k := range type_stats { |
| 116 | keys = append(keys, k) |
| 117 | } |
| 118 | sort.Strings(keys) |
| 119 | for _, mod_type := range keys { |
| 120 | fmt.Fprintln(buf, "STATS.SOONG_MODULE_TYPE +=", mod_type) |
| 121 | fmt.Fprintf(buf, "STATS.SOONG_MODULE_TYPE.%s := %d\n", mod_type, type_stats[mod_type]) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | // Don't write to the file if it hasn't changed |
| 125 | if _, err := os.Stat(mkFile); !os.IsNotExist(err) { |
| 126 | if data, err := ioutil.ReadFile(mkFile); err == nil { |
| 127 | matches := buf.Len() == len(data) |
| 128 | |
| 129 | if matches { |
| 130 | for i, value := range buf.Bytes() { |
| 131 | if value != data[i] { |
| 132 | matches = false |
| 133 | break |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | if matches { |
| 139 | return nil |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | return ioutil.WriteFile(mkFile, buf.Bytes(), 0666) |
| 145 | } |
| 146 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 147 | func translateAndroidMkModule(ctx SingletonContext, w io.Writer, mod blueprint.Module) error { |
Colin Cross | 953d3a2 | 2018-09-05 16:23:54 -0700 | [diff] [blame] | 148 | defer func() { |
| 149 | if r := recover(); r != nil { |
| 150 | panic(fmt.Errorf("%s in translateAndroidMkModule for module %s variant %s", |
| 151 | r, ctx.ModuleName(mod), ctx.ModuleSubDir(mod))) |
| 152 | } |
| 153 | }() |
| 154 | |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 155 | switch x := mod.(type) { |
| 156 | case AndroidMkDataProvider: |
| 157 | return translateAndroidModule(ctx, w, mod, x) |
| 158 | case bootstrap.GoBinaryTool: |
| 159 | return translateGoBinaryModule(ctx, w, mod, x) |
| 160 | default: |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 161 | return nil |
| 162 | } |
Colin Cross | 2465c3d | 2018-09-28 10:19:18 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | func translateGoBinaryModule(ctx SingletonContext, w io.Writer, mod blueprint.Module, |
| 166 | goBinary bootstrap.GoBinaryTool) error { |
| 167 | |
| 168 | name := ctx.ModuleName(mod) |
| 169 | fmt.Fprintln(w, ".PHONY:", name) |
| 170 | fmt.Fprintln(w, name+":", goBinary.InstallPath()) |
| 171 | fmt.Fprintln(w, "") |
| 172 | |
| 173 | return nil |
| 174 | } |
| 175 | |
| 176 | func translateAndroidModule(ctx SingletonContext, w io.Writer, mod blueprint.Module, |
| 177 | provider AndroidMkDataProvider) error { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 178 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 179 | name := provider.BaseModuleName() |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 180 | amod := mod.(Module).base() |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 181 | |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 182 | if !amod.Enabled() { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 183 | return nil |
| 184 | } |
| 185 | |
| 186 | if amod.commonProperties.SkipInstall { |
| 187 | return nil |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 190 | if !amod.commonProperties.NamespaceExportedToMake { |
| 191 | // TODO(jeffrygaston) do we want to validate that there are no modules being |
| 192 | // exported to Kati that depend on this module? |
| 193 | return nil |
| 194 | } |
| 195 | |
Colin Cross | 91825d2 | 2017-08-10 16:59:47 -0700 | [diff] [blame] | 196 | data := provider.AndroidMk() |
Colin Cross | cc4f3e3 | 2016-11-23 15:41:09 -0800 | [diff] [blame] | 197 | |
Colin Cross | 5349941 | 2017-09-07 13:20:25 -0700 | [diff] [blame] | 198 | if data.Include == "" { |
| 199 | data.Include = "$(BUILD_PREBUILT)" |
| 200 | } |
| 201 | |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 202 | data.Required = append(data.Required, amod.commonProperties.Required...) |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 203 | |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 204 | // Make does not understand LinuxBionic |
| 205 | if amod.Os() == LinuxBionic { |
| 206 | return nil |
| 207 | } |
| 208 | |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 209 | prefix := "" |
| 210 | if amod.ArchSpecific() { |
| 211 | switch amod.Os().Class { |
| 212 | case Host: |
| 213 | prefix = "HOST_" |
| 214 | case HostCross: |
| 215 | prefix = "HOST_CROSS_" |
| 216 | case Device: |
| 217 | prefix = "TARGET_" |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 218 | |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 221 | if amod.Arch().ArchType != ctx.Config().Targets[amod.Os()][0].Arch.ArchType { |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 222 | prefix = "2ND_" + prefix |
| 223 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 226 | if len(amod.commonProperties.Dist.Targets) > 0 { |
| 227 | distFile := data.DistFile |
| 228 | if !distFile.Valid() { |
| 229 | distFile = data.OutputFile |
| 230 | } |
| 231 | if distFile.Valid() { |
| 232 | dest := filepath.Base(distFile.String()) |
| 233 | |
| 234 | if amod.commonProperties.Dist.Dest != nil { |
| 235 | var err error |
| 236 | dest, err = validateSafePath(*amod.commonProperties.Dist.Dest) |
| 237 | if err != nil { |
| 238 | // This was checked in ModuleBase.GenerateBuildActions |
| 239 | panic(err) |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | if amod.commonProperties.Dist.Suffix != nil { |
| 244 | ext := filepath.Ext(dest) |
| 245 | suffix := *amod.commonProperties.Dist.Suffix |
| 246 | dest = strings.TrimSuffix(dest, ext) + suffix + ext |
| 247 | } |
| 248 | |
| 249 | if amod.commonProperties.Dist.Dir != nil { |
| 250 | var err error |
| 251 | dest, err = validateSafePath(*amod.commonProperties.Dist.Dir, dest) |
| 252 | if err != nil { |
| 253 | // This was checked in ModuleBase.GenerateBuildActions |
| 254 | panic(err) |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | goals := strings.Join(amod.commonProperties.Dist.Targets, " ") |
| 259 | fmt.Fprintln(&data.preamble, ".PHONY:", goals) |
| 260 | fmt.Fprintf(&data.preamble, "$(call dist-for-goals,%s,%s:%s)\n", |
| 261 | goals, distFile.String(), dest) |
| 262 | } |
| 263 | } |
| 264 | |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 265 | fmt.Fprintln(&data.preamble, "\ninclude $(CLEAR_VARS)") |
| 266 | fmt.Fprintln(&data.preamble, "LOCAL_PATH :=", filepath.Dir(ctx.BlueprintFile(mod))) |
| 267 | fmt.Fprintln(&data.preamble, "LOCAL_MODULE :=", name+data.SubName) |
| 268 | fmt.Fprintln(&data.preamble, "LOCAL_MODULE_CLASS :=", data.Class) |
| 269 | fmt.Fprintln(&data.preamble, "LOCAL_PREBUILT_MODULE_FILE :=", data.OutputFile.String()) |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 270 | |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 271 | if len(data.Required) > 0 { |
| 272 | fmt.Fprintln(&data.preamble, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " ")) |
Chris Wolfe | 998306e | 2016-08-15 14:47:23 -0400 | [diff] [blame] | 273 | } |
| 274 | |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 275 | archStr := amod.Arch().ArchType.String() |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 276 | host := false |
| 277 | switch amod.Os().Class { |
| 278 | case Host: |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 279 | // Make cannot identify LOCAL_MODULE_HOST_ARCH:= common. |
| 280 | if archStr != "common" { |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 281 | fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_ARCH :=", archStr) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 282 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 283 | host = true |
| 284 | case HostCross: |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 285 | // Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common. |
| 286 | if archStr != "common" { |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 287 | fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 288 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 289 | host = true |
| 290 | case Device: |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 291 | // Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common. |
| 292 | if archStr != "common" { |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 293 | fmt.Fprintln(&data.preamble, "LOCAL_MODULE_TARGET_ARCH :=", archStr) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 294 | } |
Dan Willemsen | 0fda89f | 2016-06-01 15:25:32 -0700 | [diff] [blame] | 295 | |
Dan Willemsen | 2277bcb | 2016-07-25 20:27:39 -0700 | [diff] [blame] | 296 | if len(amod.commonProperties.Init_rc) > 0 { |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 297 | fmt.Fprintln(&data.preamble, "LOCAL_INIT_RC := ", strings.Join(amod.commonProperties.Init_rc, " ")) |
Dan Willemsen | 2277bcb | 2016-07-25 20:27:39 -0700 | [diff] [blame] | 298 | } |
Steven Moreland | 57a23d2 | 2018-04-04 15:42:19 -0700 | [diff] [blame] | 299 | if len(amod.commonProperties.Vintf_fragments) > 0 { |
| 300 | fmt.Fprintln(&data.preamble, "LOCAL_VINTF_FRAGMENTS := ", strings.Join(amod.commonProperties.Vintf_fragments, " ")) |
| 301 | } |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 302 | if Bool(amod.commonProperties.Proprietary) { |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 303 | fmt.Fprintln(&data.preamble, "LOCAL_PROPRIETARY_MODULE := true") |
Dan Willemsen | 7ed1ae3 | 2016-12-05 16:47:50 -0800 | [diff] [blame] | 304 | } |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 305 | if Bool(amod.commonProperties.Vendor) || Bool(amod.commonProperties.Soc_specific) { |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 306 | fmt.Fprintln(&data.preamble, "LOCAL_VENDOR_MODULE := true") |
Dan Willemsen | aa118f9 | 2017-04-06 12:49:58 -0700 | [diff] [blame] | 307 | } |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 308 | if Bool(amod.commonProperties.Device_specific) { |
| 309 | fmt.Fprintln(&data.preamble, "LOCAL_ODM_MODULE := true") |
| 310 | } |
| 311 | if Bool(amod.commonProperties.Product_specific) { |
Jaekyun Seok | 5cfbfbb | 2018-01-10 19:00:15 +0900 | [diff] [blame] | 312 | fmt.Fprintln(&data.preamble, "LOCAL_PRODUCT_MODULE := true") |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 313 | } |
Dario Freni | 95cf767 | 2018-08-17 00:57:57 +0100 | [diff] [blame] | 314 | if Bool(amod.commonProperties.Product_services_specific) { |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 315 | fmt.Fprintln(&data.preamble, "LOCAL_PRODUCT_SERVICES_MODULE := true") |
| 316 | } |
Dan Willemsen | efac4a8 | 2017-07-18 19:42:09 -0700 | [diff] [blame] | 317 | if amod.commonProperties.Owner != nil { |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 318 | fmt.Fprintln(&data.preamble, "LOCAL_MODULE_OWNER :=", *amod.commonProperties.Owner) |
Colin Cross | 55708f3 | 2017-03-20 13:23:34 -0700 | [diff] [blame] | 319 | } |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame^] | 322 | if amod.noticeFile.Valid() { |
Jaewoong Jung | 62707f7 | 2018-11-16 13:26:43 -0800 | [diff] [blame] | 323 | fmt.Fprintln(&data.preamble, "LOCAL_NOTICE_FILE :=", amod.noticeFile.String()) |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 326 | if host { |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 327 | makeOs := amod.Os().String() |
| 328 | if amod.Os() == Linux || amod.Os() == LinuxBionic { |
| 329 | makeOs = "linux" |
| 330 | } |
| 331 | fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_OS :=", makeOs) |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 332 | fmt.Fprintln(&data.preamble, "LOCAL_IS_HOST_MODULE := true") |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 335 | blueprintDir := filepath.Dir(ctx.BlueprintFile(mod)) |
| 336 | |
| 337 | if data.Custom != nil { |
| 338 | data.Custom(w, name, prefix, blueprintDir, data) |
| 339 | } else { |
| 340 | WriteAndroidMkData(w, data) |
| 341 | } |
| 342 | |
| 343 | return nil |
| 344 | } |
| 345 | |
| 346 | func WriteAndroidMkData(w io.Writer, data AndroidMkData) { |
| 347 | if data.Disabled { |
| 348 | return |
| 349 | } |
| 350 | |
| 351 | if !data.OutputFile.Valid() { |
| 352 | return |
| 353 | } |
| 354 | |
| 355 | w.Write(data.preamble.Bytes()) |
| 356 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 357 | for _, extra := range data.Extra { |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 358 | extra(w, data.OutputFile.Path()) |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 359 | } |
| 360 | |
Colin Cross | 5349941 | 2017-09-07 13:20:25 -0700 | [diff] [blame] | 361 | fmt.Fprintln(w, "include "+data.Include) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 362 | } |