blob: 9071347763249e440efa472ee5fc0936bf582373 [file] [log] [blame]
Dan Willemsen218f6562015-07-08 18:13:11 -07001// 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 Cross635c3b02016-05-18 15:37:25 -070015package android
Dan Willemsen218f6562015-07-08 18:13:11 -070016
17import (
18 "bytes"
Dan Willemsen97750522016-02-09 17:43:51 -080019 "fmt"
Dan Willemsen218f6562015-07-08 18:13:11 -070020 "io"
21 "io/ioutil"
22 "os"
23 "path/filepath"
24 "sort"
Dan Willemsen0fda89f2016-06-01 15:25:32 -070025 "strings"
Dan Willemsen218f6562015-07-08 18:13:11 -070026
Dan Willemsen218f6562015-07-08 18:13:11 -070027 "github.com/google/blueprint"
Colin Cross2465c3d2018-09-28 10:19:18 -070028 "github.com/google/blueprint/bootstrap"
Dan Willemsen218f6562015-07-08 18:13:11 -070029)
30
31func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070032 RegisterSingletonType("androidmk", AndroidMkSingleton)
Dan Willemsen218f6562015-07-08 18:13:11 -070033}
34
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -070035// Deprecated: consider using AndroidMkEntriesProvider instead, especially if you're not going to
36// use the Custom function.
Dan Willemsen218f6562015-07-08 18:13:11 -070037type AndroidMkDataProvider interface {
Colin Crossa18e9cf2017-08-10 17:00:19 -070038 AndroidMk() AndroidMkData
Colin Crossce75d2c2016-10-06 16:12:58 -070039 BaseModuleName() string
Dan Willemsen218f6562015-07-08 18:13:11 -070040}
41
42type AndroidMkData struct {
Sasha Smundakb6d23052019-04-01 18:37:36 -070043 Class string
44 SubName string
45 DistFile OptionalPath
46 OutputFile OptionalPath
47 Disabled bool
48 Include string
49 Required []string
50 Host_required []string
51 Target_required []string
Dan Willemsen218f6562015-07-08 18:13:11 -070052
Colin Cross0f86d182017-08-10 17:07:28 -070053 Custom func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData)
Dan Willemsen218f6562015-07-08 18:13:11 -070054
Colin Cross27a4b052017-08-10 16:32:23 -070055 Extra []AndroidMkExtraFunc
Colin Cross0f86d182017-08-10 17:07:28 -070056
57 preamble bytes.Buffer
Dan Willemsen218f6562015-07-08 18:13:11 -070058}
59
Colin Cross27a4b052017-08-10 16:32:23 -070060type AndroidMkExtraFunc func(w io.Writer, outputFile Path)
61
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -070062// Allows modules to customize their Android*.mk output.
63type AndroidMkEntriesProvider interface {
64 AndroidMkEntries() AndroidMkEntries
65 BaseModuleName() string
66}
67
68type AndroidMkEntries struct {
69 Class string
70 SubName string
71 DistFile OptionalPath
72 OutputFile OptionalPath
73 Disabled bool
74 Include string
75 Required []string
76 Host_required []string
77 Target_required []string
78
79 header bytes.Buffer
80 footer bytes.Buffer
81
Jaewoong Junge0dc8df2019-08-27 17:33:16 -070082 ExtraEntries []AndroidMkExtraEntriesFunc
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070083 ExtraFooters []AndroidMkExtraFootersFunc
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -070084
85 EntryMap map[string][]string
86 entryOrder []string
87}
88
Jaewoong Junge0dc8df2019-08-27 17:33:16 -070089type AndroidMkExtraEntriesFunc func(entries *AndroidMkEntries)
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070090type AndroidMkExtraFootersFunc func(w io.Writer, name, prefix, moduleDir string, entries *AndroidMkEntries)
Jaewoong Junge0dc8df2019-08-27 17:33:16 -070091
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -070092func (a *AndroidMkEntries) SetString(name, value string) {
93 if _, ok := a.EntryMap[name]; !ok {
94 a.entryOrder = append(a.entryOrder, name)
95 }
96 a.EntryMap[name] = []string{value}
97}
98
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -070099func (a *AndroidMkEntries) SetPath(name string, path Path) {
100 if _, ok := a.EntryMap[name]; !ok {
101 a.entryOrder = append(a.entryOrder, name)
102 }
103 a.EntryMap[name] = []string{path.String()}
104}
105
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700106func (a *AndroidMkEntries) SetBoolIfTrue(name string, flag bool) {
107 if flag {
108 if _, ok := a.EntryMap[name]; !ok {
109 a.entryOrder = append(a.entryOrder, name)
110 }
111 a.EntryMap[name] = []string{"true"}
112 }
113}
114
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700115func (a *AndroidMkEntries) SetBool(name string, flag bool) {
116 if _, ok := a.EntryMap[name]; !ok {
117 a.entryOrder = append(a.entryOrder, name)
118 }
119 if flag {
120 a.EntryMap[name] = []string{"true"}
121 } else {
122 a.EntryMap[name] = []string{"false"}
123 }
124}
125
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700126func (a *AndroidMkEntries) AddStrings(name string, value ...string) {
127 if len(value) == 0 {
128 return
129 }
130 if _, ok := a.EntryMap[name]; !ok {
131 a.entryOrder = append(a.entryOrder, name)
132 }
133 a.EntryMap[name] = append(a.EntryMap[name], value...)
134}
135
136func (a *AndroidMkEntries) fillInEntries(config Config, bpPath string, mod blueprint.Module) {
137 a.EntryMap = make(map[string][]string)
138 amod := mod.(Module).base()
139 name := amod.BaseModuleName()
140
141 if a.Include == "" {
142 a.Include = "$(BUILD_PREBUILT)"
143 }
144 a.Required = append(a.Required, amod.commonProperties.Required...)
145 a.Host_required = append(a.Host_required, amod.commonProperties.Host_required...)
146 a.Target_required = append(a.Target_required, amod.commonProperties.Target_required...)
147
148 // Fill in the header part.
149 if len(amod.commonProperties.Dist.Targets) > 0 {
150 distFile := a.DistFile
151 if !distFile.Valid() {
152 distFile = a.OutputFile
153 }
154 if distFile.Valid() {
155 dest := filepath.Base(distFile.String())
156
157 if amod.commonProperties.Dist.Dest != nil {
158 var err error
159 if dest, err = validateSafePath(*amod.commonProperties.Dist.Dest); err != nil {
160 // This was checked in ModuleBase.GenerateBuildActions
161 panic(err)
162 }
163 }
164
165 if amod.commonProperties.Dist.Suffix != nil {
166 ext := filepath.Ext(dest)
167 suffix := *amod.commonProperties.Dist.Suffix
168 dest = strings.TrimSuffix(dest, ext) + suffix + ext
169 }
170
171 if amod.commonProperties.Dist.Dir != nil {
172 var err error
173 if dest, err = validateSafePath(*amod.commonProperties.Dist.Dir, dest); err != nil {
174 // This was checked in ModuleBase.GenerateBuildActions
175 panic(err)
176 }
177 }
178
179 goals := strings.Join(amod.commonProperties.Dist.Targets, " ")
180 fmt.Fprintln(&a.header, ".PHONY:", goals)
181 fmt.Fprintf(&a.header, "$(call dist-for-goals,%s,%s:%s)\n",
182 goals, distFile.String(), dest)
183 }
184 }
185
186 fmt.Fprintln(&a.header, "\ninclude $(CLEAR_VARS)")
187
188 // Collect make variable assignment entries.
189 a.SetString("LOCAL_PATH", filepath.Dir(bpPath))
190 a.SetString("LOCAL_MODULE", name+a.SubName)
191 a.SetString("LOCAL_MODULE_CLASS", a.Class)
192 a.SetString("LOCAL_PREBUILT_MODULE_FILE", a.OutputFile.String())
193 a.AddStrings("LOCAL_REQUIRED_MODULES", a.Required...)
194 a.AddStrings("LOCAL_HOST_REQUIRED_MODULES", a.Host_required...)
195 a.AddStrings("LOCAL_TARGET_REQUIRED_MODULES", a.Target_required...)
196
197 archStr := amod.Arch().ArchType.String()
198 host := false
199 switch amod.Os().Class {
200 case Host:
201 // Make cannot identify LOCAL_MODULE_HOST_ARCH:= common.
202 if archStr != "common" {
203 a.SetString("LOCAL_MODULE_HOST_ARCH", archStr)
204 }
205 host = true
206 case HostCross:
207 // Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common.
208 if archStr != "common" {
209 a.SetString("LOCAL_MODULE_HOST_CROSS_ARCH", archStr)
210 }
211 host = true
212 case Device:
213 // Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common.
214 if archStr != "common" {
dimitry1f33e402019-03-26 12:39:31 +0100215 if amod.Target().NativeBridge {
dimitry8d6dde82019-07-11 10:23:53 +0200216 hostArchStr := amod.Target().NativeBridgeHostArchName
dimitry1f33e402019-03-26 12:39:31 +0100217 if hostArchStr != "" {
218 a.SetString("LOCAL_MODULE_TARGET_ARCH", hostArchStr)
219 }
220 } else {
221 a.SetString("LOCAL_MODULE_TARGET_ARCH", archStr)
222 }
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700223 }
224
225 a.AddStrings("LOCAL_INIT_RC", amod.commonProperties.Init_rc...)
226 a.AddStrings("LOCAL_VINTF_FRAGMENTS", amod.commonProperties.Vintf_fragments...)
227 a.SetBoolIfTrue("LOCAL_PROPRIETARY_MODULE", Bool(amod.commonProperties.Proprietary))
228 if Bool(amod.commonProperties.Vendor) || Bool(amod.commonProperties.Soc_specific) {
229 a.SetString("LOCAL_VENDOR_MODULE", "true")
230 }
231 a.SetBoolIfTrue("LOCAL_ODM_MODULE", Bool(amod.commonProperties.Device_specific))
232 a.SetBoolIfTrue("LOCAL_PRODUCT_MODULE", Bool(amod.commonProperties.Product_specific))
Justin Yund5f6c822019-06-25 16:47:17 +0900233 // TODO(b/135957588) product_services_specific is matched to LOCAL_PRODUCT_MODULE
234 // as a workaround. Remove this after clearing all Android.bp
235 a.SetBoolIfTrue("LOCAL_PRODUCT_MODULE", Bool(amod.commonProperties.Product_services_specific))
236 a.SetBoolIfTrue("LOCAL_SYSTEM_EXT_MODULE", Bool(amod.commonProperties.System_ext_specific))
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700237 if amod.commonProperties.Owner != nil {
238 a.SetString("LOCAL_MODULE_OWNER", *amod.commonProperties.Owner)
239 }
240 }
241
242 if amod.noticeFile.Valid() {
243 a.SetString("LOCAL_NOTICE_FILE", amod.noticeFile.String())
244 }
245
246 if host {
247 makeOs := amod.Os().String()
248 if amod.Os() == Linux || amod.Os() == LinuxBionic {
249 makeOs = "linux"
250 }
251 a.SetString("LOCAL_MODULE_HOST_OS", makeOs)
252 a.SetString("LOCAL_IS_HOST_MODULE", "true")
253 }
254
255 prefix := ""
256 if amod.ArchSpecific() {
257 switch amod.Os().Class {
258 case Host:
259 prefix = "HOST_"
260 case HostCross:
261 prefix = "HOST_CROSS_"
262 case Device:
263 prefix = "TARGET_"
264
265 }
266
267 if amod.Arch().ArchType != config.Targets[amod.Os()][0].Arch.ArchType {
268 prefix = "2ND_" + prefix
269 }
270 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700271 for _, extra := range a.ExtraEntries {
272 extra(a)
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700273 }
274
275 // Write to footer.
276 fmt.Fprintln(&a.footer, "include "+a.Include)
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700277 blueprintDir := filepath.Dir(bpPath)
278 for _, footerFunc := range a.ExtraFooters {
279 footerFunc(&a.footer, name, prefix, blueprintDir, a)
280 }
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700281}
282
283func (a *AndroidMkEntries) write(w io.Writer) {
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700284 if a.Disabled {
285 return
286 }
287
288 if !a.OutputFile.Valid() {
289 return
290 }
291
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700292 w.Write(a.header.Bytes())
293 for _, name := range a.entryOrder {
294 fmt.Fprintln(w, name+" := "+strings.Join(a.EntryMap[name], " "))
295 }
296 w.Write(a.footer.Bytes())
297}
298
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700299func (a *AndroidMkEntries) FooterLinesForTests() []string {
300 return strings.Split(string(a.footer.Bytes()), "\n")
301}
302
Colin Cross0875c522017-11-28 17:34:01 -0800303func AndroidMkSingleton() Singleton {
Dan Willemsen218f6562015-07-08 18:13:11 -0700304 return &androidMkSingleton{}
305}
306
307type androidMkSingleton struct{}
308
Colin Cross0875c522017-11-28 17:34:01 -0800309func (c *androidMkSingleton) GenerateBuildActions(ctx SingletonContext) {
Colin Crossaabf6792017-11-29 00:27:14 -0800310 if !ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800311 return
312 }
313
Colin Cross2465c3d2018-09-28 10:19:18 -0700314 var androidMkModulesList []blueprint.Module
Colin Cross4f6e4e62016-01-11 12:55:55 -0800315
Colin Cross2465c3d2018-09-28 10:19:18 -0700316 ctx.VisitAllModulesBlueprint(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -0800317 androidMkModulesList = append(androidMkModulesList, module)
Colin Cross4f6e4e62016-01-11 12:55:55 -0800318 })
Dan Willemsen218f6562015-07-08 18:13:11 -0700319
Colin Cross1ad81422019-01-14 12:47:35 -0800320 sort.SliceStable(androidMkModulesList, func(i, j int) bool {
321 return ctx.ModuleName(androidMkModulesList[i]) < ctx.ModuleName(androidMkModulesList[j])
322 })
Colin Crossd779da42015-12-17 18:00:23 -0800323
Dan Willemsen45133ac2018-03-09 21:22:06 -0800324 transMk := PathForOutput(ctx, "Android"+String(ctx.Config().productVariables.Make_suffix)+".mk")
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700325 if ctx.Failed() {
326 return
327 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700328
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700329 err := translateAndroidMk(ctx, transMk.String(), androidMkModulesList)
Dan Willemsen218f6562015-07-08 18:13:11 -0700330 if err != nil {
331 ctx.Errorf(err.Error())
332 }
333
Colin Cross0875c522017-11-28 17:34:01 -0800334 ctx.Build(pctx, BuildParams{
335 Rule: blueprint.Phony,
336 Output: transMk,
Dan Willemsen218f6562015-07-08 18:13:11 -0700337 })
338}
339
Colin Cross2465c3d2018-09-28 10:19:18 -0700340func translateAndroidMk(ctx SingletonContext, mkFile string, mods []blueprint.Module) error {
Dan Willemsen218f6562015-07-08 18:13:11 -0700341 buf := &bytes.Buffer{}
342
Dan Willemsen97750522016-02-09 17:43:51 -0800343 fmt.Fprintln(buf, "LOCAL_MODULE_MAKEFILE := $(lastword $(MAKEFILE_LIST))")
Dan Willemsen218f6562015-07-08 18:13:11 -0700344
Dan Willemsen70e17fa2016-07-25 16:00:20 -0700345 type_stats := make(map[string]int)
Dan Willemsen218f6562015-07-08 18:13:11 -0700346 for _, mod := range mods {
347 err := translateAndroidMkModule(ctx, buf, mod)
348 if err != nil {
349 os.Remove(mkFile)
350 return err
351 }
Dan Willemsen70e17fa2016-07-25 16:00:20 -0700352
Colin Cross2465c3d2018-09-28 10:19:18 -0700353 if amod, ok := mod.(Module); ok && ctx.PrimaryModule(amod) == amod {
354 type_stats[ctx.ModuleType(amod)] += 1
Dan Willemsen70e17fa2016-07-25 16:00:20 -0700355 }
356 }
357
358 keys := []string{}
359 fmt.Fprintln(buf, "\nSTATS.SOONG_MODULE_TYPE :=")
360 for k := range type_stats {
361 keys = append(keys, k)
362 }
363 sort.Strings(keys)
364 for _, mod_type := range keys {
365 fmt.Fprintln(buf, "STATS.SOONG_MODULE_TYPE +=", mod_type)
366 fmt.Fprintf(buf, "STATS.SOONG_MODULE_TYPE.%s := %d\n", mod_type, type_stats[mod_type])
Dan Willemsen218f6562015-07-08 18:13:11 -0700367 }
368
369 // Don't write to the file if it hasn't changed
370 if _, err := os.Stat(mkFile); !os.IsNotExist(err) {
371 if data, err := ioutil.ReadFile(mkFile); err == nil {
372 matches := buf.Len() == len(data)
373
374 if matches {
375 for i, value := range buf.Bytes() {
376 if value != data[i] {
377 matches = false
378 break
379 }
380 }
381 }
382
383 if matches {
384 return nil
385 }
386 }
387 }
388
389 return ioutil.WriteFile(mkFile, buf.Bytes(), 0666)
390}
391
Colin Cross0875c522017-11-28 17:34:01 -0800392func translateAndroidMkModule(ctx SingletonContext, w io.Writer, mod blueprint.Module) error {
Colin Cross953d3a22018-09-05 16:23:54 -0700393 defer func() {
394 if r := recover(); r != nil {
395 panic(fmt.Errorf("%s in translateAndroidMkModule for module %s variant %s",
396 r, ctx.ModuleName(mod), ctx.ModuleSubDir(mod)))
397 }
398 }()
399
Colin Cross2465c3d2018-09-28 10:19:18 -0700400 switch x := mod.(type) {
401 case AndroidMkDataProvider:
402 return translateAndroidModule(ctx, w, mod, x)
403 case bootstrap.GoBinaryTool:
404 return translateGoBinaryModule(ctx, w, mod, x)
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700405 case AndroidMkEntriesProvider:
406 return translateAndroidMkEntriesModule(ctx, w, mod, x)
Colin Cross2465c3d2018-09-28 10:19:18 -0700407 default:
Dan Willemsen218f6562015-07-08 18:13:11 -0700408 return nil
409 }
Colin Cross2465c3d2018-09-28 10:19:18 -0700410}
411
412func translateGoBinaryModule(ctx SingletonContext, w io.Writer, mod blueprint.Module,
413 goBinary bootstrap.GoBinaryTool) error {
414
415 name := ctx.ModuleName(mod)
416 fmt.Fprintln(w, ".PHONY:", name)
417 fmt.Fprintln(w, name+":", goBinary.InstallPath())
418 fmt.Fprintln(w, "")
419
420 return nil
421}
422
Jooyung Han12df5fb2019-07-11 16:18:47 +0900423func (data *AndroidMkData) fillInData(config Config, bpPath string, mod blueprint.Module) {
424 // Get the preamble content through AndroidMkEntries logic.
425 entries := AndroidMkEntries{
426 Class: data.Class,
427 SubName: data.SubName,
428 DistFile: data.DistFile,
429 OutputFile: data.OutputFile,
430 Disabled: data.Disabled,
431 Include: data.Include,
432 Required: data.Required,
433 Host_required: data.Host_required,
434 Target_required: data.Target_required,
435 }
436 entries.fillInEntries(config, bpPath, mod)
437
438 // preamble doesn't need the footer content.
439 entries.footer = bytes.Buffer{}
440 entries.write(&data.preamble)
441
442 // copy entries back to data since it is used in Custom
443 data.Required = entries.Required
444 data.Host_required = entries.Host_required
445 data.Target_required = entries.Target_required
446}
447
Colin Cross2465c3d2018-09-28 10:19:18 -0700448func translateAndroidModule(ctx SingletonContext, w io.Writer, mod blueprint.Module,
449 provider AndroidMkDataProvider) error {
Dan Willemsen218f6562015-07-08 18:13:11 -0700450
Colin Cross635c3b02016-05-18 15:37:25 -0700451 amod := mod.(Module).base()
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700452 if shouldSkipAndroidMkProcessing(amod) {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800453 return nil
454 }
455
Colin Cross91825d22017-08-10 16:59:47 -0700456 data := provider.AndroidMk()
Colin Cross53499412017-09-07 13:20:25 -0700457 if data.Include == "" {
458 data.Include = "$(BUILD_PREBUILT)"
459 }
460
Jooyung Han12df5fb2019-07-11 16:18:47 +0900461 data.fillInData(ctx.Config(), ctx.BlueprintFile(mod), mod)
Dan Willemsen01a405a2016-06-13 17:19:03 -0700462
Colin Cross0f86d182017-08-10 17:07:28 -0700463 prefix := ""
464 if amod.ArchSpecific() {
465 switch amod.Os().Class {
466 case Host:
467 prefix = "HOST_"
468 case HostCross:
469 prefix = "HOST_CROSS_"
470 case Device:
471 prefix = "TARGET_"
Colin Crossa2344662016-03-24 13:14:12 -0700472
Dan Willemsen218f6562015-07-08 18:13:11 -0700473 }
474
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700475 if amod.Arch().ArchType != ctx.Config().Targets[amod.Os()][0].Arch.ArchType {
Colin Cross0f86d182017-08-10 17:07:28 -0700476 prefix = "2ND_" + prefix
477 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700478 }
479
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700480 name := provider.BaseModuleName()
Colin Cross0f86d182017-08-10 17:07:28 -0700481 blueprintDir := filepath.Dir(ctx.BlueprintFile(mod))
482
483 if data.Custom != nil {
484 data.Custom(w, name, prefix, blueprintDir, data)
485 } else {
486 WriteAndroidMkData(w, data)
487 }
488
489 return nil
490}
491
492func WriteAndroidMkData(w io.Writer, data AndroidMkData) {
493 if data.Disabled {
494 return
495 }
496
497 if !data.OutputFile.Valid() {
498 return
499 }
500
501 w.Write(data.preamble.Bytes())
502
Colin Crossca860ac2016-01-04 14:34:37 -0800503 for _, extra := range data.Extra {
Colin Cross27a4b052017-08-10 16:32:23 -0700504 extra(w, data.OutputFile.Path())
Dan Willemsen97750522016-02-09 17:43:51 -0800505 }
506
Colin Cross53499412017-09-07 13:20:25 -0700507 fmt.Fprintln(w, "include "+data.Include)
Dan Willemsen218f6562015-07-08 18:13:11 -0700508}
Sasha Smundakb6d23052019-04-01 18:37:36 -0700509
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700510func translateAndroidMkEntriesModule(ctx SingletonContext, w io.Writer, mod blueprint.Module,
511 provider AndroidMkEntriesProvider) error {
512 if shouldSkipAndroidMkProcessing(mod.(Module).base()) {
513 return nil
Sasha Smundakb6d23052019-04-01 18:37:36 -0700514 }
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700515
516 entries := provider.AndroidMkEntries()
517 entries.fillInEntries(ctx.Config(), ctx.BlueprintFile(mod), mod)
518
519 entries.write(w)
520
521 return nil
522}
523
524func shouldSkipAndroidMkProcessing(module *ModuleBase) bool {
525 if !module.commonProperties.NamespaceExportedToMake {
526 // TODO(jeffrygaston) do we want to validate that there are no modules being
527 // exported to Kati that depend on this module?
528 return true
Sasha Smundakb6d23052019-04-01 18:37:36 -0700529 }
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700530
531 return !module.Enabled() ||
532 module.commonProperties.SkipInstall ||
533 // Make does not understand LinuxBionic
534 module.Os() == LinuxBionic
Sasha Smundakb6d23052019-04-01 18:37:36 -0700535}