xref: /aosp_15_r20/build/soong/java/androidmk.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
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
15package java
16
17import (
18	"fmt"
19	"io"
20
21	"android/soong/android"
22
23	"github.com/google/blueprint/proptools"
24)
25
26func (library *Library) AndroidMkEntriesHostDex() android.AndroidMkEntries {
27	hostDexNeeded := Bool(library.deviceProperties.Hostdex) && !library.Host()
28	if library.hideApexVariantFromMake {
29		hostDexNeeded = false
30	}
31
32	if hostDexNeeded {
33		var output android.Path
34		if library.dexJarFile.IsSet() {
35			output = library.dexJarFile.Path()
36		} else {
37			output = library.implementationAndResourcesJar
38		}
39		return android.AndroidMkEntries{
40			Class:      "JAVA_LIBRARIES",
41			SubName:    "-hostdex",
42			OutputFile: android.OptionalPathForPath(output),
43			Required:   library.deviceProperties.Target.Hostdex.Required,
44			Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
45			ExtraEntries: []android.AndroidMkExtraEntriesFunc{
46				func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
47					entries.SetBool("LOCAL_IS_HOST_MODULE", true)
48					entries.SetPath("LOCAL_PREBUILT_MODULE_FILE", output)
49					if library.dexJarFile.IsSet() {
50						entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile.Path())
51					}
52					entries.SetPath("LOCAL_SOONG_INSTALLED_MODULE", library.hostdexInstallFile)
53					entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile)
54					entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar)
55					entries.SetString("LOCAL_MODULE_STEM", library.Stem()+"-hostdex")
56				},
57			},
58		}
59	}
60	return android.AndroidMkEntries{Disabled: true}
61}
62
63func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
64	var entriesList []android.AndroidMkEntries
65
66	if library.Os() == android.Windows {
67		// Make does not support Windows Java modules
68		return nil
69	}
70
71	if library.hideApexVariantFromMake {
72		// For a java library built for an APEX, we don't need a Make module for itself. Otherwise, it
73		// will conflict with the platform variant because they have the same module name in the
74		// makefile. However, we need to add its dexpreopt outputs as sub-modules, if it is preopted.
75		dexpreoptEntries := library.dexpreopter.AndroidMkEntriesForApex()
76		if len(dexpreoptEntries) > 0 {
77			entriesList = append(entriesList, dexpreoptEntries...)
78		}
79		entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true})
80	} else if !library.ApexModuleBase.AvailableFor(android.AvailableToPlatform) {
81		// Platform variant.  If not available for the platform, we don't need Make module.
82		entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true})
83	} else if proptools.Bool(library.properties.Headers_only) {
84		// If generating headers only then don't expose to Make.
85		entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true})
86	} else {
87		entriesList = append(entriesList, android.AndroidMkEntries{
88			Class:      "JAVA_LIBRARIES",
89			OutputFile: android.OptionalPathForPath(library.outputFile),
90			Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
91			ExtraEntries: []android.AndroidMkExtraEntriesFunc{
92				func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
93					if len(library.logtagsSrcs) > 0 {
94						entries.AddStrings("LOCAL_SOONG_LOGTAGS_FILES", library.logtagsSrcs.Strings()...)
95					}
96
97					if library.installFile == nil {
98						entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true)
99					}
100					if library.dexJarFile.IsSet() {
101						entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile.Path())
102					}
103					if len(library.dexpreopter.builtInstalled) > 0 {
104						entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", library.dexpreopter.builtInstalled)
105					}
106					entries.SetString("LOCAL_SDK_VERSION", library.sdkVersion.String())
107					entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar)
108					entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile)
109
110					if library.jacocoReportClassesFile != nil {
111						entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", library.jacocoReportClassesFile)
112					}
113
114					requiredUsesLibs, optionalUsesLibs := library.classLoaderContexts.UsesLibs()
115					entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", append(requiredUsesLibs, optionalUsesLibs...)...)
116
117					entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_DICT", library.dexer.proguardDictionary)
118					entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_USAGE_ZIP", library.dexer.proguardUsageZip)
119					entries.SetString("LOCAL_MODULE_STEM", library.Stem())
120
121					entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", library.linter.reports)
122
123					if library.dexpreopter.configPath != nil {
124						entries.SetPath("LOCAL_SOONG_DEXPREOPT_CONFIG", library.dexpreopter.configPath)
125					}
126				},
127			},
128		})
129	}
130
131	entriesList = append(entriesList, library.AndroidMkEntriesHostDex())
132
133	return entriesList
134}
135
136func (j *JavaFuzzTest) AndroidMkEntries() []android.AndroidMkEntries {
137	entriesList := j.Library.AndroidMkEntries()
138	entries := &entriesList[0]
139	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
140		entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", "null-suite")
141		androidMkWriteTestData(android.Paths{j.implementationJarFile}, entries)
142		androidMkWriteTestData(j.jniFilePaths, entries)
143		if j.fuzzPackagedModule.Corpus != nil {
144			androidMkWriteTestData(j.fuzzPackagedModule.Corpus, entries)
145		}
146		if j.fuzzPackagedModule.Dictionary != nil {
147			androidMkWriteTestData(android.Paths{j.fuzzPackagedModule.Dictionary}, entries)
148		}
149	})
150	return entriesList
151}
152
153// Called for modules that are a component of a test suite.
154func testSuiteComponent(entries *android.AndroidMkEntries, test_suites []string, perTestcaseDirectory bool) {
155	entries.SetString("LOCAL_MODULE_TAGS", "tests")
156	if len(test_suites) > 0 {
157		entries.AddCompatibilityTestSuites(test_suites...)
158	} else {
159		entries.AddCompatibilityTestSuites("null-suite")
160	}
161	entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", perTestcaseDirectory)
162}
163
164func (j *Test) AndroidMkEntries() []android.AndroidMkEntries {
165	entriesList := j.Library.AndroidMkEntries()
166	entries := &entriesList[0]
167	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
168		testSuiteComponent(entries, j.testProperties.Test_suites, Bool(j.testProperties.Per_testcase_directory))
169		if j.testConfig != nil {
170			entries.SetPath("LOCAL_FULL_TEST_CONFIG", j.testConfig)
171		}
172		androidMkWriteExtraTestConfigs(j.extraTestConfigs, entries)
173		androidMkWriteTestData(j.data, entries)
174		if !BoolDefault(j.testProperties.Auto_gen_config, true) {
175			entries.SetString("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", "true")
176		}
177		entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", j.testProperties.Test_mainline_modules...)
178
179		j.testProperties.Test_options.CommonTestOptions.SetAndroidMkEntries(entries)
180	})
181
182	return entriesList
183}
184
185func androidMkWriteExtraTestConfigs(extraTestConfigs android.Paths, entries *android.AndroidMkEntries) {
186	if len(extraTestConfigs) > 0 {
187		entries.AddStrings("LOCAL_EXTRA_FULL_TEST_CONFIGS", extraTestConfigs.Strings()...)
188	}
189}
190
191func (j *TestHelperLibrary) AndroidMkEntries() []android.AndroidMkEntries {
192	entriesList := j.Library.AndroidMkEntries()
193	entries := &entriesList[0]
194	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
195		testSuiteComponent(entries, j.testHelperLibraryProperties.Test_suites, Bool(j.testHelperLibraryProperties.Per_testcase_directory))
196	})
197
198	return entriesList
199}
200
201func (prebuilt *Import) AndroidMkEntries() []android.AndroidMkEntries {
202	if prebuilt.hideApexVariantFromMake {
203		return []android.AndroidMkEntries{}
204	}
205	return []android.AndroidMkEntries{android.AndroidMkEntries{
206		Class:        "JAVA_LIBRARIES",
207		OverrideName: prebuilt.BaseModuleName(),
208		OutputFile:   android.OptionalPathForPath(prebuilt.combinedImplementationFile),
209		Include:      "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
210		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
211			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
212				entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", !Bool(prebuilt.properties.Installable))
213				if prebuilt.dexJarFile.IsSet() {
214					entries.SetPath("LOCAL_SOONG_DEX_JAR", prebuilt.dexJarFile.Path())
215				}
216				entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.combinedHeaderFile)
217				entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.combinedImplementationFile)
218				entries.SetString("LOCAL_SDK_VERSION", prebuilt.sdkVersion.String())
219				entries.SetString("LOCAL_MODULE_STEM", prebuilt.Stem())
220				// TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
221			},
222		},
223	}}
224}
225
226func (prebuilt *DexImport) AndroidMkEntries() []android.AndroidMkEntries {
227	if prebuilt.hideApexVariantFromMake {
228		return []android.AndroidMkEntries{android.AndroidMkEntries{
229			Disabled: true,
230		}}
231	}
232	return []android.AndroidMkEntries{android.AndroidMkEntries{
233		Class:      "JAVA_LIBRARIES",
234		OutputFile: android.OptionalPathForPath(prebuilt.dexJarFile.Path()),
235		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
236		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
237			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
238				if prebuilt.dexJarFile.IsSet() {
239					entries.SetPath("LOCAL_SOONG_DEX_JAR", prebuilt.dexJarFile.Path())
240				}
241				if len(prebuilt.dexpreopter.builtInstalled) > 0 {
242					entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", prebuilt.dexpreopter.builtInstalled)
243				}
244				entries.SetString("LOCAL_MODULE_STEM", prebuilt.Stem())
245				// TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
246			},
247		},
248	}}
249}
250
251func (prebuilt *AARImport) AndroidMkEntries() []android.AndroidMkEntries {
252	if prebuilt.hideApexVariantFromMake {
253		return []android.AndroidMkEntries{{
254			Disabled: true,
255		}}
256	}
257	return []android.AndroidMkEntries{android.AndroidMkEntries{
258		Class:      "JAVA_LIBRARIES",
259		OutputFile: android.OptionalPathForPath(prebuilt.implementationJarFile),
260		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
261		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
262			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
263				entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
264				entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.headerJarFile)
265				entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.implementationJarFile)
266				entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", prebuilt.exportPackage)
267				entries.SetPath("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", prebuilt.transitiveAaptResourcePackagesFile)
268				entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", prebuilt.proguardFlags)
269				entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", prebuilt.extraAaptPackagesFile)
270				entries.SetPath("LOCAL_FULL_MANIFEST_FILE", prebuilt.manifest)
271				entries.SetString("LOCAL_SDK_VERSION", prebuilt.sdkVersion.String())
272				// TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
273			},
274		},
275	}}
276}
277
278func (binary *Binary) AndroidMkEntries() []android.AndroidMkEntries {
279	if binary.Os() == android.Windows {
280		// Make does not support Windows Java modules
281		return nil
282	}
283
284	return []android.AndroidMkEntries{{
285		Class:      "JAVA_LIBRARIES",
286		OutputFile: android.OptionalPathForPath(binary.outputFile),
287		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
288		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
289			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
290				entries.SetPath("LOCAL_SOONG_HEADER_JAR", binary.headerJarFile)
291				entries.SetPath("LOCAL_SOONG_CLASSES_JAR", binary.implementationAndResourcesJar)
292				if binary.dexJarFile.IsSet() {
293					entries.SetPath("LOCAL_SOONG_DEX_JAR", binary.dexJarFile.Path())
294				}
295				if len(binary.dexpreopter.builtInstalled) > 0 {
296					entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", binary.dexpreopter.builtInstalled)
297				}
298				entries.AddStrings("LOCAL_REQUIRED_MODULES", binary.androidMkNamesOfJniLibs...)
299			},
300		},
301	}}
302}
303
304func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries {
305	if app.hideApexVariantFromMake || app.IsHideFromMake() {
306		return []android.AndroidMkEntries{android.AndroidMkEntries{
307			Disabled: true,
308		}}
309	}
310	return []android.AndroidMkEntries{android.AndroidMkEntries{
311		Class:      "APPS",
312		OutputFile: android.OptionalPathForPath(app.outputFile),
313		Include:    "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
314		Required:   app.requiredModuleNames,
315		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
316			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
317				// App module names can be overridden.
318				entries.SetString("LOCAL_MODULE", app.installApkName)
319				entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", app.appProperties.PreventInstall)
320				if app.headerJarFile != nil {
321					entries.SetPath("LOCAL_SOONG_HEADER_JAR", app.headerJarFile)
322				}
323				entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", app.exportPackage)
324				if app.dexJarFile.IsSet() {
325					entries.SetPath("LOCAL_SOONG_DEX_JAR", app.dexJarFile.Path())
326				}
327				if app.implementationAndResourcesJar != nil {
328					entries.SetPath("LOCAL_SOONG_CLASSES_JAR", app.implementationAndResourcesJar)
329				}
330				if app.headerJarFile != nil {
331					entries.SetPath("LOCAL_SOONG_HEADER_JAR", app.headerJarFile)
332				}
333				if app.bundleFile != nil {
334					entries.SetPath("LOCAL_SOONG_BUNDLE", app.bundleFile)
335				}
336				if app.jacocoReportClassesFile != nil {
337					entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", app.jacocoReportClassesFile)
338				}
339				entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_DICT", app.dexer.proguardDictionary)
340				entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_USAGE_ZIP", app.dexer.proguardUsageZip)
341
342				if app.Name() == "framework-res" {
343					entries.SetString("LOCAL_MODULE_PATH", "$(TARGET_OUT_JAVA_LIBRARIES)")
344					// Make base_rules.mk not put framework-res in a subdirectory called
345					// framework_res.
346					entries.SetBoolIfTrue("LOCAL_NO_STANDARD_LIBRARIES", true)
347				}
348
349				entries.SetBoolIfTrue("LOCAL_EXPORT_PACKAGE_RESOURCES", Bool(app.appProperties.Export_package_resources))
350
351				entries.SetPath("LOCAL_FULL_MANIFEST_FILE", app.manifestPath)
352
353				entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", app.Privileged())
354
355				entries.SetString("LOCAL_CERTIFICATE", app.certificate.AndroidMkString())
356				entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", app.getOverriddenPackages()...)
357
358				if app.embeddedJniLibs {
359					jniSymbols := app.JNISymbolsInstalls(app.installPathForJNISymbols.String())
360					entries.SetString("LOCAL_SOONG_JNI_LIBS_SYMBOLS", jniSymbols.String())
361				} else {
362					var names []string
363					for _, jniLib := range app.jniLibs {
364						names = append(names, jniLib.name+":"+jniLib.target.Arch.ArchType.Bitness())
365					}
366					entries.AddStrings("LOCAL_REQUIRED_MODULES", names...)
367				}
368
369				if len(app.jniCoverageOutputs) > 0 {
370					entries.AddStrings("LOCAL_PREBUILT_COVERAGE_ARCHIVE", app.jniCoverageOutputs.Strings()...)
371				}
372				if len(app.dexpreopter.builtInstalled) > 0 {
373					entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", app.dexpreopter.builtInstalled)
374				}
375				if app.dexpreopter.configPath != nil {
376					entries.SetPath("LOCAL_SOONG_DEXPREOPT_CONFIG", app.dexpreopter.configPath)
377				}
378				for _, extra := range app.extraOutputFiles {
379					install := app.onDeviceDir + "/" + extra.Base()
380					entries.AddStrings("LOCAL_SOONG_BUILT_INSTALLED", extra.String()+":"+install)
381				}
382
383				entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", app.linter.reports)
384
385				entries.AddStrings("LOCAL_SOONG_LOGTAGS_FILES", app.logtagsSrcs.Strings()...)
386			},
387		},
388		ExtraFooters: []android.AndroidMkExtraFootersFunc{
389			func(w io.Writer, name, prefix, moduleDir string) {
390				if app.javaApiUsedByOutputFile.String() != "" {
391					fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s/$(notdir %s))\n",
392						app.installApkName, app.javaApiUsedByOutputFile.String(), "java_apis_used_by_apex", app.javaApiUsedByOutputFile.String())
393				}
394			},
395		}},
396	}
397}
398
399func (a *AutogenRuntimeResourceOverlay) AndroidMkEntries() []android.AndroidMkEntries {
400	if a.IsHideFromMake() || a.outputFile == nil {
401		return []android.AndroidMkEntries{android.AndroidMkEntries{
402			Disabled: true,
403		}}
404	}
405	return []android.AndroidMkEntries{android.AndroidMkEntries{
406		Class:      "APPS",
407		OutputFile: android.OptionalPathForPath(a.outputFile),
408		Include:    "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
409		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
410			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
411				entries.SetString("LOCAL_CERTIFICATE", a.certificate.AndroidMkString())
412			},
413		},
414	}}
415}
416
417func (a *AndroidApp) getOverriddenPackages() []string {
418	var overridden []string
419	if len(a.overridableAppProperties.Overrides) > 0 {
420		overridden = append(overridden, a.overridableAppProperties.Overrides...)
421	}
422	return overridden
423}
424
425func (a *AndroidTest) AndroidMkEntries() []android.AndroidMkEntries {
426	entriesList := a.AndroidApp.AndroidMkEntries()
427	entries := &entriesList[0]
428	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
429		testSuiteComponent(entries, a.testProperties.Test_suites, Bool(a.testProperties.Per_testcase_directory))
430		if a.testConfig != nil {
431			entries.SetPath("LOCAL_FULL_TEST_CONFIG", a.testConfig)
432		}
433		androidMkWriteExtraTestConfigs(a.extraTestConfigs, entries)
434		androidMkWriteTestData(a.data, entries)
435		entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", a.testProperties.Test_mainline_modules...)
436	})
437
438	return entriesList
439}
440
441func (a *AndroidTestHelperApp) AndroidMkEntries() []android.AndroidMkEntries {
442	entriesList := a.AndroidApp.AndroidMkEntries()
443	entries := &entriesList[0]
444	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
445		testSuiteComponent(entries, a.appTestHelperAppProperties.Test_suites, Bool(a.appTestHelperAppProperties.Per_testcase_directory))
446		// introduce a flag variable to control the generation of the .config file
447		entries.SetString("LOCAL_DISABLE_TEST_CONFIG", "true")
448	})
449
450	return entriesList
451}
452
453func (a *AndroidLibrary) AndroidMkEntries() []android.AndroidMkEntries {
454	if a.hideApexVariantFromMake {
455		return []android.AndroidMkEntries{{
456			Disabled: true,
457		}}
458	}
459	entriesList := a.Library.AndroidMkEntries()
460	entries := &entriesList[0]
461
462	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
463		if a.aarFile != nil {
464			entries.SetPath("LOCAL_SOONG_AAR", a.aarFile)
465		}
466
467		if a.Name() == "framework-res" {
468			entries.SetString("LOCAL_MODULE_PATH", "$(TARGET_OUT_JAVA_LIBRARIES)")
469			// Make base_rules.mk not put framework-res in a subdirectory called
470			// framework_res.
471			entries.SetBoolIfTrue("LOCAL_NO_STANDARD_LIBRARIES", true)
472		}
473
474		entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", a.exportPackage)
475		entries.SetPath("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", a.transitiveAaptResourcePackagesFile)
476		entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", a.extraAaptPackagesFile)
477		entries.SetPath("LOCAL_FULL_MANIFEST_FILE", a.mergedManifestFile)
478		entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", a.combinedExportedProguardFlagsFile)
479		entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true)
480	})
481
482	return entriesList
483}
484
485func (jd *Javadoc) AndroidMkEntries() []android.AndroidMkEntries {
486	return []android.AndroidMkEntries{android.AndroidMkEntries{
487		Class:      "JAVA_LIBRARIES",
488		OutputFile: android.OptionalPathForPath(jd.stubsSrcJar),
489		Include:    "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
490		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
491			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
492				if BoolDefault(jd.properties.Installable, true) {
493					entries.SetPath("LOCAL_DROIDDOC_DOC_ZIP", jd.docZip)
494				}
495				if jd.exportableStubsSrcJar != nil {
496					entries.SetPath("LOCAL_DROIDDOC_STUBS_SRCJAR", jd.exportableStubsSrcJar)
497				}
498			},
499		},
500	}}
501}
502
503func (ddoc *Droiddoc) AndroidMkEntries() []android.AndroidMkEntries {
504	return []android.AndroidMkEntries{android.AndroidMkEntries{
505		Class:      "JAVA_LIBRARIES",
506		OutputFile: android.OptionalPathForPath(ddoc.Javadoc.docZip),
507		Include:    "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
508		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
509			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
510				if ddoc.Javadoc.docZip != nil {
511					entries.SetPath("LOCAL_DROIDDOC_DOC_ZIP", ddoc.Javadoc.docZip)
512				}
513				entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !BoolDefault(ddoc.Javadoc.properties.Installable, true))
514			},
515		},
516	}}
517}
518
519func (dstubs *Droidstubs) AndroidMkEntries() []android.AndroidMkEntries {
520	// If the stubsSrcJar is not generated (because generate_stubs is false) then
521	// use the api file as the output file to ensure the relevant phony targets
522	// are created in make if only the api txt file is being generated. This is
523	// needed because an invalid output file would prevent the make entries from
524	// being written.
525	//
526	// Note that dstubs.apiFile can be also be nil if WITHOUT_CHECKS_API is true.
527	// TODO(b/146727827): Revert when we do not need to generate stubs and API separately.
528
529	outputFile := android.OptionalPathForPath(dstubs.stubsSrcJar)
530	if !outputFile.Valid() {
531		outputFile = android.OptionalPathForPath(dstubs.apiFile)
532	}
533	if !outputFile.Valid() {
534		outputFile = android.OptionalPathForPath(dstubs.everythingArtifacts.apiVersionsXml)
535	}
536	return []android.AndroidMkEntries{android.AndroidMkEntries{
537		Class:      "JAVA_LIBRARIES",
538		OutputFile: outputFile,
539		Include:    "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
540		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
541			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
542				if dstubs.Javadoc.exportableStubsSrcJar != nil {
543					entries.SetPath("LOCAL_DROIDDOC_STUBS_SRCJAR", dstubs.Javadoc.exportableStubsSrcJar)
544				}
545				if dstubs.everythingArtifacts.apiVersionsXml != nil {
546					entries.SetPath("LOCAL_DROIDDOC_API_VERSIONS_XML", dstubs.exportableArtifacts.apiVersionsXml)
547				}
548				if dstubs.everythingArtifacts.annotationsZip != nil {
549					entries.SetPath("LOCAL_DROIDDOC_ANNOTATIONS_ZIP", dstubs.exportableArtifacts.annotationsZip)
550				}
551				if dstubs.everythingArtifacts.metadataZip != nil {
552					entries.SetPath("LOCAL_DROIDDOC_METADATA_ZIP", dstubs.exportableArtifacts.metadataZip)
553				}
554			},
555		},
556		ExtraFooters: []android.AndroidMkExtraFootersFunc{
557			func(w io.Writer, name, prefix, moduleDir string) {
558				if dstubs.apiFile != nil {
559					fmt.Fprintf(w, ".PHONY: %s %s.txt\n", dstubs.Name(), dstubs.Name())
560					fmt.Fprintf(w, "%s %s.txt: %s\n", dstubs.Name(), dstubs.Name(), dstubs.apiFile)
561				}
562				if dstubs.removedApiFile != nil {
563					fmt.Fprintf(w, ".PHONY: %s %s.txt\n", dstubs.Name(), dstubs.Name())
564					fmt.Fprintf(w, "%s %s.txt: %s\n", dstubs.Name(), dstubs.Name(), dstubs.removedApiFile)
565				}
566				if dstubs.checkCurrentApiTimestamp != nil {
567					fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-current-api")
568					fmt.Fprintln(w, dstubs.Name()+"-check-current-api:",
569						dstubs.checkCurrentApiTimestamp.String())
570
571					fmt.Fprintln(w, ".PHONY: checkapi")
572					fmt.Fprintln(w, "checkapi:",
573						dstubs.checkCurrentApiTimestamp.String())
574
575					fmt.Fprintln(w, ".PHONY: droidcore")
576					fmt.Fprintln(w, "droidcore: checkapi")
577				}
578				if dstubs.updateCurrentApiTimestamp != nil {
579					fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-update-current-api")
580					fmt.Fprintln(w, dstubs.Name()+"-update-current-api:",
581						dstubs.updateCurrentApiTimestamp.String())
582
583					fmt.Fprintln(w, ".PHONY: update-api")
584					fmt.Fprintln(w, "update-api:",
585						dstubs.updateCurrentApiTimestamp.String())
586				}
587				if dstubs.checkLastReleasedApiTimestamp != nil {
588					fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-last-released-api")
589					fmt.Fprintln(w, dstubs.Name()+"-check-last-released-api:",
590						dstubs.checkLastReleasedApiTimestamp.String())
591
592					fmt.Fprintln(w, ".PHONY: checkapi")
593					fmt.Fprintln(w, "checkapi:",
594						dstubs.checkLastReleasedApiTimestamp.String())
595
596					fmt.Fprintln(w, ".PHONY: droidcore")
597					fmt.Fprintln(w, "droidcore: checkapi")
598				}
599				if dstubs.apiLintTimestamp != nil {
600					fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-api-lint")
601					fmt.Fprintln(w, dstubs.Name()+"-api-lint:",
602						dstubs.apiLintTimestamp.String())
603
604					fmt.Fprintln(w, ".PHONY: checkapi")
605					fmt.Fprintln(w, "checkapi:",
606						dstubs.Name()+"-api-lint")
607
608					fmt.Fprintln(w, ".PHONY: droidcore")
609					fmt.Fprintln(w, "droidcore: checkapi")
610
611					if dstubs.apiLintReport != nil {
612						fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", dstubs.Name()+"-api-lint",
613							dstubs.apiLintReport.String(), "apilint/"+dstubs.Name()+"-lint-report.txt")
614						fmt.Fprintf(w, "$(call declare-0p-target,%s)\n", dstubs.apiLintReport.String())
615					}
616				}
617				if dstubs.checkNullabilityWarningsTimestamp != nil {
618					fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings")
619					fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:",
620						dstubs.checkNullabilityWarningsTimestamp.String())
621
622					fmt.Fprintln(w, ".PHONY:", "droidcore")
623					fmt.Fprintln(w, "droidcore: ", dstubs.Name()+"-check-nullability-warnings")
624				}
625			},
626		},
627	}}
628}
629
630func (a *AndroidAppImport) AndroidMkEntries() []android.AndroidMkEntries {
631	if a.hideApexVariantFromMake {
632		// The non-platform variant is placed inside APEX. No reason to
633		// make it available to Make.
634		return nil
635	}
636	return []android.AndroidMkEntries{android.AndroidMkEntries{
637		Class:        "APPS",
638		OutputFile:   android.OptionalPathForPath(a.outputFile),
639		OverrideName: a.BaseModuleName(), // TODO (spandandas): Add a test
640		Include:      "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
641		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
642			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
643				entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", a.Privileged())
644				entries.SetString("LOCAL_CERTIFICATE", a.certificate.AndroidMkString())
645				entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", a.properties.Overrides...)
646				if len(a.dexpreopter.builtInstalled) > 0 {
647					entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", a.dexpreopter.builtInstalled)
648				}
649				entries.AddStrings("LOCAL_INSTALLED_MODULE_STEM", a.installPath.Rel())
650				if Bool(a.properties.Export_package_resources) {
651					entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", a.outputFile)
652				}
653				// TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
654			},
655		},
656	}}
657}
658
659func (a *AndroidTestImport) AndroidMkEntries() []android.AndroidMkEntries {
660	entriesList := a.AndroidAppImport.AndroidMkEntries()
661	entries := &entriesList[0]
662	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
663		testSuiteComponent(entries, a.testProperties.Test_suites, Bool(a.testProperties.Per_testcase_directory))
664		androidMkWriteTestData(a.data, entries)
665	})
666	return entriesList
667}
668
669func androidMkWriteTestData(data android.Paths, entries *android.AndroidMkEntries) {
670	var testFiles []string
671	for _, d := range data {
672		testFiles = append(testFiles, d.String()+":"+d.Rel())
673	}
674	entries.AddStrings("LOCAL_COMPATIBILITY_SUPPORT_FILES", testFiles...)
675}
676
677func (r *RuntimeResourceOverlay) AndroidMkEntries() []android.AndroidMkEntries {
678	return []android.AndroidMkEntries{android.AndroidMkEntries{
679		Class:      "ETC",
680		OutputFile: android.OptionalPathForPath(r.outputFile),
681		Include:    "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
682		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
683			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
684				entries.SetString("LOCAL_CERTIFICATE", r.certificate.AndroidMkString())
685				entries.SetPath("LOCAL_MODULE_PATH", r.installDir)
686				entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", r.properties.Overrides...)
687				// TODO: LOCAL_ACONFIG_FILES -- Might eventually need aconfig flags?
688			},
689		},
690	}}
691}
692
693func (apkSet *AndroidAppSet) AndroidMkEntries() []android.AndroidMkEntries {
694	return []android.AndroidMkEntries{
695		android.AndroidMkEntries{
696			Class:      "APPS",
697			OutputFile: android.OptionalPathForPath(apkSet.primaryOutput),
698			Include:    "$(BUILD_SYSTEM)/soong_android_app_set.mk",
699			ExtraEntries: []android.AndroidMkExtraEntriesFunc{
700				func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
701					entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", apkSet.Privileged())
702					entries.SetPath("LOCAL_APK_SET_INSTALL_FILE", apkSet.PackedAdditionalOutputs())
703					entries.SetPath("LOCAL_APKCERTS_FILE", apkSet.apkcertsFile)
704					entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", apkSet.properties.Overrides...)
705					// TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts -- Both declarations and values
706				},
707			},
708		},
709	}
710}
711
712func (al *ApiLibrary) AndroidMkEntries() []android.AndroidMkEntries {
713	var entriesList []android.AndroidMkEntries
714
715	entriesList = append(entriesList, android.AndroidMkEntries{
716		Class:      "JAVA_LIBRARIES",
717		OutputFile: android.OptionalPathForPath(al.stubsJar),
718		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
719		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
720			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
721				entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true)
722				entries.SetPath("LOCAL_SOONG_CLASSES_JAR", al.stubsJar)
723				entries.SetPath("LOCAL_SOONG_HEADER_JAR", al.stubsJar)
724			},
725		},
726	})
727
728	return entriesList
729}
730