blob: 4fca08d9fa4714eed9329e7d201fcb3303c56cd6 [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
15package java
16
17import (
Colin Cross74d73e22017-08-02 11:05:49 -070018 "fmt"
19 "io"
Jihoon Kangf78a8902022-09-01 22:47:07 +000020 "strings"
Colin Cross74d73e22017-08-02 11:05:49 -070021
Colin Cross635c3b02016-05-18 15:37:25 -070022 "android/soong/android"
Dan Willemsen218f6562015-07-08 18:13:11 -070023)
24
Jiyong Park55bd98b2019-12-11 17:27:07 +090025func (library *Library) AndroidMkEntriesHostDex() android.AndroidMkEntries {
26 hostDexNeeded := Bool(library.deviceProperties.Hostdex) && !library.Host()
Colin Cross56a83212020-09-15 18:30:11 -070027 if library.hideApexVariantFromMake {
Jiyong Park55bd98b2019-12-11 17:27:07 +090028 hostDexNeeded = false
Sundong Ahn054b19a2018-10-19 13:46:09 +090029 }
Jiyong Park55bd98b2019-12-11 17:27:07 +090030
31 if hostDexNeeded {
32 var output android.Path
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +010033 if library.dexJarFile.IsSet() {
34 output = library.dexJarFile.Path()
Jiyong Park55bd98b2019-12-11 17:27:07 +090035 } else {
36 output = library.implementationAndResourcesJar
37 }
38 return android.AndroidMkEntries{
39 Class: "JAVA_LIBRARIES",
40 SubName: "-hostdex",
41 OutputFile: android.OptionalPathForPath(output),
42 Required: library.deviceProperties.Target.Hostdex.Required,
43 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
44 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -070045 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jiyong Park55bd98b2019-12-11 17:27:07 +090046 entries.SetBool("LOCAL_IS_HOST_MODULE", true)
47 entries.SetPath("LOCAL_PREBUILT_MODULE_FILE", output)
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +010048 if library.dexJarFile.IsSet() {
49 entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile.Path())
Jiyong Park55bd98b2019-12-11 17:27:07 +090050 }
Colin Cross3108ce12021-11-10 14:38:50 -080051 entries.SetPath("LOCAL_SOONG_INSTALLED_MODULE", library.hostdexInstallFile)
Jiyong Park55bd98b2019-12-11 17:27:07 +090052 entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile)
53 entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar)
54 entries.SetString("LOCAL_MODULE_STEM", library.Stem()+"-hostdex")
55 },
56 },
57 }
58 }
59 return android.AndroidMkEntries{Disabled: true}
Sundong Ahn054b19a2018-10-19 13:46:09 +090060}
61
Jiyong Park0b0e1b92019-12-03 13:24:29 +090062func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
Jiyong Park55bd98b2019-12-11 17:27:07 +090063 var entriesList []android.AndroidMkEntries
64
Dan Willemsen9fe14102021-07-13 21:52:04 -070065 if library.Os() == android.Windows {
66 // Make does not support Windows Java modules
67 return nil
68 }
69
Colin Cross56a83212020-09-15 18:30:11 -070070 if library.hideApexVariantFromMake {
Jiakai Zhang519c5c82021-09-16 06:15:39 +000071 // For a java library built for an APEX, we don't need a Make module for itself. Otherwise, it
72 // will conflict with the platform variant because they have the same module name in the
73 // makefile. However, we need to add its dexpreopt outputs as sub-modules, if it is preopted.
74 dexpreoptEntries := library.dexpreopter.AndroidMkEntriesForApex()
75 if len(dexpreoptEntries) > 0 {
76 entriesList = append(entriesList, dexpreoptEntries...)
77 }
Colin Cross56a83212020-09-15 18:30:11 -070078 entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true})
Jingwen Chen8ac7d7d2023-03-20 11:05:16 +000079 } else if !library.ApexModuleBase.AvailableFor(android.AvailableToPlatform) {
80 // Platform variant. If not available for the platform, we don't need Make module.
81 entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true})
Colin Crossb549b772020-06-03 17:14:31 +000082 } else {
Colin Cross56a83212020-09-15 18:30:11 -070083 entriesList = append(entriesList, android.AndroidMkEntries{
Jiyong Park55bd98b2019-12-11 17:27:07 +090084 Class: "JAVA_LIBRARIES",
85 OutputFile: android.OptionalPathForPath(library.outputFile),
86 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
87 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -070088 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jiyong Park55bd98b2019-12-11 17:27:07 +090089 if len(library.logtagsSrcs) > 0 {
90 var logtags []string
91 for _, l := range library.logtagsSrcs {
92 logtags = append(logtags, l.Rel())
93 }
94 entries.AddStrings("LOCAL_LOGTAGS_FILES", logtags...)
Colin Cross5beccee2017-12-07 15:28:59 -080095 }
Colin Cross5beccee2017-12-07 15:28:59 -080096
Jingwen Chen8ac7d7d2023-03-20 11:05:16 +000097 if library.installFile == nil {
Jiyong Park55bd98b2019-12-11 17:27:07 +090098 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true)
99 }
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +0100100 if library.dexJarFile.IsSet() {
101 entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile.Path())
Jiyong Park55bd98b2019-12-11 17:27:07 +0900102 }
103 if len(library.dexpreopter.builtInstalled) > 0 {
104 entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", library.dexpreopter.builtInstalled)
105 }
Jiyong Park92315372021-04-02 08:45:46 +0900106 entries.SetString("LOCAL_SDK_VERSION", library.sdkVersion.String())
Jiyong Park55bd98b2019-12-11 17:27:07 +0900107 entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar)
108 entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile)
Colin Crosscb933592017-11-22 13:49:43 -0800109
Jiyong Park55bd98b2019-12-11 17:27:07 +0900110 if library.jacocoReportClassesFile != nil {
111 entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", library.jacocoReportClassesFile)
112 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800113
Ulya Trafimovichfc0f6e32021-08-12 16:16:11 +0100114 requiredUsesLibs, optionalUsesLibs := library.classLoaderContexts.UsesLibs()
115 entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", append(requiredUsesLibs, optionalUsesLibs...)...)
Jiyong Park1be96912018-05-28 18:02:19 +0900116
Colin Crosscb6143a2020-08-14 17:39:29 -0700117 entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_DICT", library.dexer.proguardDictionary)
118 entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_USAGE_ZIP", library.dexer.proguardUsageZip)
Jiyong Park55bd98b2019-12-11 17:27:07 +0900119 entries.SetString("LOCAL_MODULE_STEM", library.Stem())
Colin Crossc0efd1d2020-07-03 11:56:24 -0700120
Colin Cross08dca382020-07-21 20:31:17 -0700121 entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", library.linter.reports)
Ulya Trafimovich76b08522021-01-14 17:52:43 +0000122
123 if library.dexpreopter.configPath != nil {
124 entries.SetPath("LOCAL_SOONG_DEXPREOPT_CONFIG", library.dexpreopter.configPath)
125 }
Joe Onorato6fe59eb2023-07-16 13:20:33 -0700126
127 entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", library.getTransitiveAconfigFiles().ToList())
Jiyong Park55bd98b2019-12-11 17:27:07 +0900128 },
Colin Crossa18e9cf2017-08-10 17:00:19 -0700129 },
Colin Cross56a83212020-09-15 18:30:11 -0700130 })
Jiyong Park55bd98b2019-12-11 17:27:07 +0900131 }
132
Colin Cross56a83212020-09-15 18:30:11 -0700133 entriesList = append(entriesList, library.AndroidMkEntriesHostDex())
Jiyong Park55bd98b2019-12-11 17:27:07 +0900134
Jiyong Park55bd98b2019-12-11 17:27:07 +0900135 return entriesList
Dan Willemsen218f6562015-07-08 18:13:11 -0700136}
137
Cory Barkereaf7f5e2023-02-03 00:20:52 +0000138func (j *JavaFuzzTest) AndroidMkEntries() []android.AndroidMkEntries {
Muhammad Haseeb Ahmad7e744052022-03-25 22:50:53 +0000139 entriesList := j.Library.AndroidMkEntries()
140 entries := &entriesList[0]
141 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
142 entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", "null-suite")
Muhammad Haseeb Ahmadeb14ff22022-09-28 17:53:11 +0000143 androidMkWriteTestData(android.Paths{j.implementationJarFile}, entries)
Cory Barkereaf7f5e2023-02-03 00:20:52 +0000144 androidMkWriteTestData(j.jniFilePaths, entries)
145 if j.fuzzPackagedModule.Corpus != nil {
146 androidMkWriteTestData(j.fuzzPackagedModule.Corpus, entries)
147 }
148 if j.fuzzPackagedModule.Dictionary != nil {
149 androidMkWriteTestData(android.Paths{j.fuzzPackagedModule.Dictionary}, entries)
150 }
Muhammad Haseeb Ahmad7e744052022-03-25 22:50:53 +0000151 })
152 return entriesList
153}
154
Paul Duffin42df1442019-03-20 12:45:53 +0000155// Called for modules that are a component of a test suite.
Colin Crosscfb0f5e2021-09-24 15:47:17 -0700156func testSuiteComponent(entries *android.AndroidMkEntries, test_suites []string, perTestcaseDirectory bool) {
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -0700157 entries.SetString("LOCAL_MODULE_TAGS", "tests")
158 if len(test_suites) > 0 {
Liz Kammer57f5b332020-11-24 12:42:58 -0800159 entries.AddCompatibilityTestSuites(test_suites...)
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -0700160 } else {
Liz Kammer57f5b332020-11-24 12:42:58 -0800161 entries.AddCompatibilityTestSuites("null-suite")
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -0700162 }
Colin Crosscfb0f5e2021-09-24 15:47:17 -0700163 entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", perTestcaseDirectory)
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -0700164}
165
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900166func (j *Test) AndroidMkEntries() []android.AndroidMkEntries {
167 entriesList := j.Library.AndroidMkEntries()
168 entries := &entriesList[0]
Colin Crossaa255532020-07-03 13:18:24 -0700169 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crosscfb0f5e2021-09-24 15:47:17 -0700170 testSuiteComponent(entries, j.testProperties.Test_suites, Bool(j.testProperties.Per_testcase_directory))
Colin Cross303e21f2018-08-07 16:49:25 -0700171 if j.testConfig != nil {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700172 entries.SetPath("LOCAL_FULL_TEST_CONFIG", j.testConfig)
Julien Despreze146e392018-08-02 15:00:46 -0700173 }
Dan Shi95d19422020-08-15 12:24:26 -0700174 androidMkWriteExtraTestConfigs(j.extraTestConfigs, entries)
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700175 androidMkWriteTestData(j.data, entries)
Dan Shi2468d012020-01-06 15:47:57 -0800176 if !BoolDefault(j.testProperties.Auto_gen_config, true) {
177 entries.SetString("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", "true")
178 }
kellyhung74b00522020-08-17 18:46:00 +0800179 entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", j.testProperties.Test_mainline_modules...)
Zhenhuang Wang0ac5a432022-08-12 18:49:20 +0800180
181 j.testProperties.Test_options.CommonTestOptions.SetAndroidMkEntries(entries)
Colin Cross05638fc2018-04-09 18:40:24 -0700182 })
183
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900184 return entriesList
Colin Cross05638fc2018-04-09 18:40:24 -0700185}
186
Dan Shi95d19422020-08-15 12:24:26 -0700187func androidMkWriteExtraTestConfigs(extraTestConfigs android.Paths, entries *android.AndroidMkEntries) {
188 if len(extraTestConfigs) > 0 {
189 entries.AddStrings("LOCAL_EXTRA_FULL_TEST_CONFIGS", extraTestConfigs.Strings()...)
190 }
191}
192
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900193func (j *TestHelperLibrary) AndroidMkEntries() []android.AndroidMkEntries {
194 entriesList := j.Library.AndroidMkEntries()
195 entries := &entriesList[0]
Colin Crossaa255532020-07-03 13:18:24 -0700196 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crosscfb0f5e2021-09-24 15:47:17 -0700197 testSuiteComponent(entries, j.testHelperLibraryProperties.Test_suites, Bool(j.testHelperLibraryProperties.Per_testcase_directory))
Paul Duffin42df1442019-03-20 12:45:53 +0000198 })
199
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900200 return entriesList
Paul Duffin42df1442019-03-20 12:45:53 +0000201}
202
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900203func (prebuilt *Import) AndroidMkEntries() []android.AndroidMkEntries {
Jiakai Zhang28bc9a82021-12-20 15:08:57 +0000204 if prebuilt.hideApexVariantFromMake {
205 // For a library imported from a prebuilt APEX, we don't need a Make module for itself, as we
206 // don't need to install it. However, we need to add its dexpreopt outputs as sub-modules, if it
207 // is preopted.
208 dexpreoptEntries := prebuilt.dexpreopter.AndroidMkEntriesForApex()
209 return append(dexpreoptEntries, android.AndroidMkEntries{Disabled: true})
210 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900211 return []android.AndroidMkEntries{android.AndroidMkEntries{
Colin Crossa18e9cf2017-08-10 17:00:19 -0700212 Class: "JAVA_LIBRARIES",
213 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Colin Cross53499412017-09-07 13:20:25 -0700214 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700215 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700216 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700217 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", !Bool(prebuilt.properties.Installable))
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +0100218 if prebuilt.dexJarFile.IsSet() {
219 entries.SetPath("LOCAL_SOONG_DEX_JAR", prebuilt.dexJarFile.Path())
Bill Peckhamfb04df42021-01-11 12:27:24 -0800220 }
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700221 entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.combinedClasspathFile)
222 entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.combinedClasspathFile)
Jiyong Park92315372021-04-02 08:45:46 +0900223 entries.SetString("LOCAL_SDK_VERSION", prebuilt.sdkVersion.String())
Jiyong Park0b238752019-10-29 11:23:10 +0900224 entries.SetString("LOCAL_MODULE_STEM", prebuilt.Stem())
Joe Onorato6fe59eb2023-07-16 13:20:33 -0700225 // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
Colin Crossa18e9cf2017-08-10 17:00:19 -0700226 },
227 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900228 }}
Dan Willemsen218f6562015-07-08 18:13:11 -0700229}
Colin Cross10a03492017-08-10 17:09:43 -0700230
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900231func (prebuilt *DexImport) AndroidMkEntries() []android.AndroidMkEntries {
Colin Cross56a83212020-09-15 18:30:11 -0700232 if prebuilt.hideApexVariantFromMake {
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900233 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jiyong Park7f7766d2019-07-25 22:02:35 +0900234 Disabled: true,
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900235 }}
Jiyong Park7f7766d2019-07-25 22:02:35 +0900236 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900237 return []android.AndroidMkEntries{android.AndroidMkEntries{
Colin Cross42be7612019-02-21 18:12:14 -0800238 Class: "JAVA_LIBRARIES",
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +0100239 OutputFile: android.OptionalPathForPath(prebuilt.dexJarFile.Path()),
Colin Cross42be7612019-02-21 18:12:14 -0800240 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700241 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700242 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +0100243 if prebuilt.dexJarFile.IsSet() {
244 entries.SetPath("LOCAL_SOONG_DEX_JAR", prebuilt.dexJarFile.Path())
Colin Cross42be7612019-02-21 18:12:14 -0800245 }
246 if len(prebuilt.dexpreopter.builtInstalled) > 0 {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700247 entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", prebuilt.dexpreopter.builtInstalled)
Colin Cross42be7612019-02-21 18:12:14 -0800248 }
Jiyong Park0b238752019-10-29 11:23:10 +0900249 entries.SetString("LOCAL_MODULE_STEM", prebuilt.Stem())
Joe Onorato6fe59eb2023-07-16 13:20:33 -0700250 // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
Colin Cross42be7612019-02-21 18:12:14 -0800251 },
252 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900253 }}
Colin Cross42be7612019-02-21 18:12:14 -0800254}
255
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900256func (prebuilt *AARImport) AndroidMkEntries() []android.AndroidMkEntries {
Colin Cross56a83212020-09-15 18:30:11 -0700257 if prebuilt.hideApexVariantFromMake {
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900258 return []android.AndroidMkEntries{{
259 Disabled: true,
260 }}
261 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900262 return []android.AndroidMkEntries{android.AndroidMkEntries{
Colin Crossfabb6082018-02-20 17:22:23 -0800263 Class: "JAVA_LIBRARIES",
264 OutputFile: android.OptionalPathForPath(prebuilt.classpathFile),
265 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700266 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700267 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700268 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
269 entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.classpathFile)
270 entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.classpathFile)
271 entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", prebuilt.exportPackage)
272 entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", prebuilt.proguardFlags)
273 entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", prebuilt.extraAaptPackagesFile)
274 entries.SetPath("LOCAL_FULL_MANIFEST_FILE", prebuilt.manifest)
Jiyong Park92315372021-04-02 08:45:46 +0900275 entries.SetString("LOCAL_SDK_VERSION", prebuilt.sdkVersion.String())
Joe Onorato6fe59eb2023-07-16 13:20:33 -0700276 // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
Colin Crossfabb6082018-02-20 17:22:23 -0800277 },
278 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900279 }}
Colin Crossfabb6082018-02-20 17:22:23 -0800280}
281
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900282func (binary *Binary) AndroidMkEntries() []android.AndroidMkEntries {
Dan Willemsen9fe14102021-07-13 21:52:04 -0700283 if binary.Os() == android.Windows {
284 // Make does not support Windows Java modules
285 return nil
286 }
Colin Cross10a03492017-08-10 17:09:43 -0700287
Colin Cross6b4a32d2017-12-05 13:42:45 -0800288 if !binary.isWrapperVariant {
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900289 return []android.AndroidMkEntries{android.AndroidMkEntries{
Colin Cross6b4a32d2017-12-05 13:42:45 -0800290 Class: "JAVA_LIBRARIES",
Colin Cross331a1212018-08-15 20:40:52 -0700291 OutputFile: android.OptionalPathForPath(binary.outputFile),
Colin Cross6b4a32d2017-12-05 13:42:45 -0800292 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700293 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700294 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700295 entries.SetPath("LOCAL_SOONG_HEADER_JAR", binary.headerJarFile)
296 entries.SetPath("LOCAL_SOONG_CLASSES_JAR", binary.implementationAndResourcesJar)
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +0100297 if binary.dexJarFile.IsSet() {
298 entries.SetPath("LOCAL_SOONG_DEX_JAR", binary.dexJarFile.Path())
Colin Cross12fc2af2019-01-14 12:35:45 -0800299 }
300 if len(binary.dexpreopter.builtInstalled) > 0 {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700301 entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", binary.dexpreopter.builtInstalled)
Colin Cross12fc2af2019-01-14 12:35:45 -0800302 }
Joe Onorato6fe59eb2023-07-16 13:20:33 -0700303 entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", binary.getTransitiveAconfigFiles().ToList())
Colin Cross331a1212018-08-15 20:40:52 -0700304 },
305 },
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700306 ExtraFooters: []android.AndroidMkExtraFootersFunc{
Jaewoong Jung02b11a62020-12-07 10:23:54 -0800307 func(w io.Writer, name, prefix, moduleDir string) {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700308 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
309 },
Colin Cross6b4a32d2017-12-05 13:42:45 -0800310 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900311 }}
Colin Cross6b4a32d2017-12-05 13:42:45 -0800312 } else {
Colin Cross44b85d02021-02-19 17:37:04 -0800313 outputFile := binary.wrapperFile
Colin Cross44b85d02021-02-19 17:37:04 -0800314
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900315 return []android.AndroidMkEntries{android.AndroidMkEntries{
Colin Cross6b4a32d2017-12-05 13:42:45 -0800316 Class: "EXECUTABLES",
Colin Cross44b85d02021-02-19 17:37:04 -0800317 OutputFile: android.OptionalPathForPath(outputFile),
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700318 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700319 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700320 entries.SetBool("LOCAL_STRIP_MODULE", false)
Colin Cross6b4a32d2017-12-05 13:42:45 -0800321 },
322 },
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700323 ExtraFooters: []android.AndroidMkExtraFootersFunc{
Jaewoong Jung02b11a62020-12-07 10:23:54 -0800324 func(w io.Writer, name, prefix, moduleDir string) {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700325 // Ensure that the wrapper script timestamp is always updated when the jar is updated
326 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
327 fmt.Fprintln(w, "jar_installed_module :=")
328 },
Colin Cross6b4a32d2017-12-05 13:42:45 -0800329 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900330 }}
Colin Cross10a03492017-08-10 17:09:43 -0700331 }
332}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800333
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900334func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries {
Colin Crossaaa0c1f2022-05-16 16:19:54 -0700335 if app.hideApexVariantFromMake || app.IsHideFromMake() {
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900336 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jiyong Park52cd06f2019-11-11 10:14:32 +0900337 Disabled: true,
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900338 }}
Jiyong Park52cd06f2019-11-11 10:14:32 +0900339 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900340 return []android.AndroidMkEntries{android.AndroidMkEntries{
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800341 Class: "APPS",
342 OutputFile: android.OptionalPathForPath(app.outputFile),
343 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700344 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700345 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700346 // App module names can be overridden.
347 entries.SetString("LOCAL_MODULE", app.installApkName)
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700348 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", app.appProperties.PreventInstall)
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700349 entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", app.exportPackage)
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +0100350 if app.dexJarFile.IsSet() {
351 entries.SetPath("LOCAL_SOONG_DEX_JAR", app.dexJarFile.Path())
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800352 }
Colin Cross331a1212018-08-15 20:40:52 -0700353 if app.implementationAndResourcesJar != nil {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700354 entries.SetPath("LOCAL_SOONG_CLASSES_JAR", app.implementationAndResourcesJar)
Colin Cross5dfabfb2017-12-14 13:19:01 -0800355 }
356 if app.headerJarFile != nil {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700357 entries.SetPath("LOCAL_SOONG_HEADER_JAR", app.headerJarFile)
Colin Cross5dfabfb2017-12-14 13:19:01 -0800358 }
Colin Crossf6237212018-10-29 23:14:58 -0700359 if app.bundleFile != nil {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700360 entries.SetPath("LOCAL_SOONG_BUNDLE", app.bundleFile)
Colin Crossf6237212018-10-29 23:14:58 -0700361 }
Colin Cross70798562017-12-13 22:42:59 -0800362 if app.jacocoReportClassesFile != nil {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700363 entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", app.jacocoReportClassesFile)
Colin Cross70798562017-12-13 22:42:59 -0800364 }
Colin Crosscb6143a2020-08-14 17:39:29 -0700365 entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_DICT", app.dexer.proguardDictionary)
366 entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_USAGE_ZIP", app.dexer.proguardUsageZip)
Colin Cross70798562017-12-13 22:42:59 -0800367
368 if app.Name() == "framework-res" {
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700369 entries.SetString("LOCAL_MODULE_PATH", "$(TARGET_OUT_JAVA_LIBRARIES)")
Colin Cross70798562017-12-13 22:42:59 -0800370 // Make base_rules.mk not put framework-res in a subdirectory called
371 // framework_res.
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700372 entries.SetBoolIfTrue("LOCAL_NO_STANDARD_LIBRARIES", true)
Colin Cross70798562017-12-13 22:42:59 -0800373 }
374
Anton Hansson53c88442019-03-18 15:53:16 +0000375 filterRRO := func(filter overlayType) android.Paths {
376 var paths android.Paths
Colin Cross4c90f992023-06-13 16:44:58 -0700377 seen := make(map[android.Path]bool)
378 for _, d := range app.rroDirsDepSet.ToList() {
Anton Hansson53c88442019-03-18 15:53:16 +0000379 if d.overlayType == filter {
Colin Cross4c90f992023-06-13 16:44:58 -0700380 if seen[d.path] {
381 continue
382 }
383 seen[d.path] = true
Anton Hansson53c88442019-03-18 15:53:16 +0000384 paths = append(paths, d.path)
385 }
386 }
Colin Crossa140bb02018-04-17 10:52:26 -0700387 // Reverse the order, Soong stores rroDirs in aapt2 order (low to high priority), but Make
388 // expects it in LOCAL_RESOURCE_DIRS order (high to low priority).
Anton Hansson53c88442019-03-18 15:53:16 +0000389 return android.ReversePaths(paths)
390 }
391 deviceRRODirs := filterRRO(device)
392 if len(deviceRRODirs) > 0 {
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700393 entries.AddStrings("LOCAL_SOONG_DEVICE_RRO_DIRS", deviceRRODirs.Strings()...)
Anton Hansson53c88442019-03-18 15:53:16 +0000394 }
395 productRRODirs := filterRRO(product)
396 if len(productRRODirs) > 0 {
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700397 entries.AddStrings("LOCAL_SOONG_PRODUCT_RRO_DIRS", productRRODirs.Strings()...)
Colin Cross70798562017-12-13 22:42:59 -0800398 }
399
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700400 entries.SetBoolIfTrue("LOCAL_EXPORT_PACKAGE_RESOURCES", Bool(app.appProperties.Export_package_resources))
Colin Cross70798562017-12-13 22:42:59 -0800401
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700402 entries.SetPath("LOCAL_FULL_MANIFEST_FILE", app.manifestPath)
Colin Cross70798562017-12-13 22:42:59 -0800403
Jiyong Parkf7487312019-10-17 12:54:30 +0900404 entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", app.Privileged())
Colin Crosse1731a52017-12-14 11:22:55 -0800405
Jaewoong Jung78ec5d82020-01-31 10:11:47 -0800406 entries.SetString("LOCAL_CERTIFICATE", app.certificate.AndroidMkString())
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700407 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", app.getOverriddenPackages()...)
Colin Crossa4f08812018-10-02 22:03:40 -0700408
Colin Cross403cc152020-07-06 14:15:24 -0700409 if app.embeddedJniLibs {
410 jniSymbols := app.JNISymbolsInstalls(app.installPathForJNISymbols.String())
411 entries.SetString("LOCAL_SOONG_JNI_LIBS_SYMBOLS", jniSymbols.String())
412 } else {
413 for _, jniLib := range app.jniLibs {
414 entries.AddStrings("LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), jniLib.name)
Jihoon Kangf78a8902022-09-01 22:47:07 +0000415 var partitionTag string
416
417 // Mimic the creation of partition_tag in build/make,
418 // which defaults to an empty string when the partition is system.
419 // Otherwise, capitalize with a leading _
420 if jniLib.partition == "system" {
421 partitionTag = ""
422 } else {
423 split := strings.Split(jniLib.partition, "/")
424 partitionTag = "_" + strings.ToUpper(split[len(split)-1])
425 }
426 entries.AddStrings("LOCAL_SOONG_JNI_LIBS_PARTITION_"+jniLib.target.Arch.ArchType.String(),
427 jniLib.name+":"+partitionTag)
Colin Cross403cc152020-07-06 14:15:24 -0700428 }
Colin Crossa4f08812018-10-02 22:03:40 -0700429 }
Colin Cross403cc152020-07-06 14:15:24 -0700430
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700431 if len(app.jniCoverageOutputs) > 0 {
432 entries.AddStrings("LOCAL_PREBUILT_COVERAGE_ARCHIVE", app.jniCoverageOutputs.Strings()...)
433 }
Colin Cross43f08db2018-11-12 10:13:39 -0800434 if len(app.dexpreopter.builtInstalled) > 0 {
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700435 entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", app.dexpreopter.builtInstalled)
Colin Cross43f08db2018-11-12 10:13:39 -0800436 }
Jeongik Chac6246672021-04-08 00:00:19 +0900437 if app.dexpreopter.configPath != nil {
438 entries.SetPath("LOCAL_SOONG_DEXPREOPT_CONFIG", app.dexpreopter.configPath)
439 }
Jaewoong Jung5a498812019-11-07 14:14:38 -0800440 for _, extra := range app.extraOutputFiles {
441 install := app.onDeviceDir + "/" + extra.Base()
442 entries.AddStrings("LOCAL_SOONG_BUILT_INSTALLED", extra.String()+":"+install)
Colin Crosse560c4a2019-03-19 16:03:11 -0700443 }
Colin Crossc0efd1d2020-07-03 11:56:24 -0700444
Colin Cross08dca382020-07-21 20:31:17 -0700445 entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", app.linter.reports)
Joe Onorato6fe59eb2023-07-16 13:20:33 -0700446
447 if app.Name() != "framework-res" {
448 entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", app.getTransitiveAconfigFiles().ToList())
449 }
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700450 },
451 },
Matt Banda8c801262022-04-01 17:48:31 +0000452 ExtraFooters: []android.AndroidMkExtraFootersFunc{
453 func(w io.Writer, name, prefix, moduleDir string) {
454 if app.javaApiUsedByOutputFile.String() != "" {
455 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s/$(notdir %s))\n",
456 app.installApkName, app.javaApiUsedByOutputFile.String(), "java_apis_used_by_apex", app.javaApiUsedByOutputFile.String())
457 }
458 },
459 }},
460 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700461}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800462
Jaewoong Jung9109d722019-01-30 13:13:52 -0800463func (a *AndroidApp) getOverriddenPackages() []string {
464 var overridden []string
zhidoua2ce78f2022-02-17 02:33:12 +0000465 if len(a.overridableAppProperties.Overrides) > 0 {
466 overridden = append(overridden, a.overridableAppProperties.Overrides...)
Jaewoong Jung9109d722019-01-30 13:13:52 -0800467 }
Jaewoong Jung9109d722019-01-30 13:13:52 -0800468 return overridden
469}
470
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900471func (a *AndroidTest) AndroidMkEntries() []android.AndroidMkEntries {
472 entriesList := a.AndroidApp.AndroidMkEntries()
473 entries := &entriesList[0]
Colin Crossaa255532020-07-03 13:18:24 -0700474 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crosscfb0f5e2021-09-24 15:47:17 -0700475 testSuiteComponent(entries, a.testProperties.Test_suites, Bool(a.testProperties.Per_testcase_directory))
Colin Cross303e21f2018-08-07 16:49:25 -0700476 if a.testConfig != nil {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700477 entries.SetPath("LOCAL_FULL_TEST_CONFIG", a.testConfig)
Julien Despreze146e392018-08-02 15:00:46 -0700478 }
Dan Shi95d19422020-08-15 12:24:26 -0700479 androidMkWriteExtraTestConfigs(a.extraTestConfigs, entries)
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700480 androidMkWriteTestData(a.data, entries)
kellyhung74b00522020-08-17 18:46:00 +0800481 entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", a.testProperties.Test_mainline_modules...)
Colin Cross252fc6f2018-10-04 15:22:03 -0700482 })
483
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900484 return entriesList
Colin Cross252fc6f2018-10-04 15:22:03 -0700485}
486
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900487func (a *AndroidTestHelperApp) AndroidMkEntries() []android.AndroidMkEntries {
488 entriesList := a.AndroidApp.AndroidMkEntries()
489 entries := &entriesList[0]
Colin Crossaa255532020-07-03 13:18:24 -0700490 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crosscfb0f5e2021-09-24 15:47:17 -0700491 testSuiteComponent(entries, a.appTestHelperAppProperties.Test_suites, Bool(a.appTestHelperAppProperties.Per_testcase_directory))
Yuntao Xu7a318552021-05-27 10:30:26 -0700492 // introduce a flag variable to control the generation of the .config file
493 entries.SetString("LOCAL_DISABLE_TEST_CONFIG", "true")
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700494 })
Colin Crossa97c5d32018-03-28 14:58:31 -0700495
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900496 return entriesList
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700497}
498
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900499func (a *AndroidLibrary) AndroidMkEntries() []android.AndroidMkEntries {
Colin Cross56a83212020-09-15 18:30:11 -0700500 if a.hideApexVariantFromMake {
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900501 return []android.AndroidMkEntries{{
502 Disabled: true,
503 }}
504 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900505 entriesList := a.Library.AndroidMkEntries()
506 entries := &entriesList[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700507
Colin Crossaa255532020-07-03 13:18:24 -0700508 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossa54974c2018-10-29 23:15:37 -0700509 if a.aarFile != nil {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700510 entries.SetPath("LOCAL_SOONG_AAR", a.aarFile)
Colin Crossa54974c2018-10-29 23:15:37 -0700511 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700512
513 if a.Name() == "framework-res" {
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700514 entries.SetString("LOCAL_MODULE_PATH", "$(TARGET_OUT_JAVA_LIBRARIES)")
Colin Crossa97c5d32018-03-28 14:58:31 -0700515 // Make base_rules.mk not put framework-res in a subdirectory called
516 // framework_res.
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700517 entries.SetBoolIfTrue("LOCAL_NO_STANDARD_LIBRARIES", true)
Colin Crossa97c5d32018-03-28 14:58:31 -0700518 }
519
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700520 entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", a.exportPackage)
521 entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", a.extraAaptPackagesFile)
522 entries.SetPath("LOCAL_FULL_MANIFEST_FILE", a.mergedManifestFile)
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700523 entries.AddStrings("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", a.exportedProguardFlagFiles.Strings()...)
524 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true)
Joe Onorato6fe59eb2023-07-16 13:20:33 -0700525 entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", a.getTransitiveAconfigFiles().ToList())
Colin Crossa97c5d32018-03-28 14:58:31 -0700526 })
527
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900528 return entriesList
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800529}
Nan Zhang581fd212018-01-10 16:06:12 -0800530
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900531func (jd *Javadoc) AndroidMkEntries() []android.AndroidMkEntries {
532 return []android.AndroidMkEntries{android.AndroidMkEntries{
Nan Zhang581fd212018-01-10 16:06:12 -0800533 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800534 OutputFile: android.OptionalPathForPath(jd.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700535 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700536 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700537 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Cross38b40df2018-04-10 16:14:46 -0700538 if BoolDefault(jd.properties.Installable, true) {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700539 entries.SetPath("LOCAL_DROIDDOC_DOC_ZIP", jd.docZip)
Nan Zhang581fd212018-01-10 16:06:12 -0800540 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800541 if jd.stubsSrcJar != nil {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700542 entries.SetPath("LOCAL_DROIDDOC_STUBS_SRCJAR", jd.stubsSrcJar)
Nan Zhang581fd212018-01-10 16:06:12 -0800543 }
544 },
545 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900546 }}
Nan Zhang581fd212018-01-10 16:06:12 -0800547}
548
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900549func (ddoc *Droiddoc) AndroidMkEntries() []android.AndroidMkEntries {
550 return []android.AndroidMkEntries{android.AndroidMkEntries{
Nan Zhang581fd212018-01-10 16:06:12 -0800551 Class: "JAVA_LIBRARIES",
Liz Kammere1ab2502020-09-10 15:29:25 +0000552 OutputFile: android.OptionalPathForPath(ddoc.Javadoc.docZip),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700553 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700554 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700555 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Liz Kammere1ab2502020-09-10 15:29:25 +0000556 if ddoc.Javadoc.docZip != nil {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700557 entries.SetPath("LOCAL_DROIDDOC_DOC_ZIP", ddoc.Javadoc.docZip)
Nan Zhang581fd212018-01-10 16:06:12 -0800558 }
Liz Kammere1ab2502020-09-10 15:29:25 +0000559 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !BoolDefault(ddoc.Javadoc.properties.Installable, true))
Nan Zhang581fd212018-01-10 16:06:12 -0800560 },
561 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900562 }}
Nan Zhang581fd212018-01-10 16:06:12 -0800563}
Colin Crossd96ca352018-08-10 16:06:24 -0700564
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900565func (dstubs *Droidstubs) AndroidMkEntries() []android.AndroidMkEntries {
Paul Duffin3ae29512020-04-08 18:18:03 +0100566 // If the stubsSrcJar is not generated (because generate_stubs is false) then
567 // use the api file as the output file to ensure the relevant phony targets
568 // are created in make if only the api txt file is being generated. This is
569 // needed because an invalid output file would prevent the make entries from
570 // being written.
Jingwen Chen7b27ca72020-07-24 09:13:49 +0000571 //
572 // Note that dstubs.apiFile can be also be nil if WITHOUT_CHECKS_API is true.
Paul Duffin3ae29512020-04-08 18:18:03 +0100573 // TODO(b/146727827): Revert when we do not need to generate stubs and API separately.
Jingwen Chen7b27ca72020-07-24 09:13:49 +0000574
Paul Duffin3ae29512020-04-08 18:18:03 +0100575 outputFile := android.OptionalPathForPath(dstubs.stubsSrcJar)
576 if !outputFile.Valid() {
Jingwen Chen7b27ca72020-07-24 09:13:49 +0000577 outputFile = android.OptionalPathForPath(dstubs.apiFile)
Paul Duffin3ae29512020-04-08 18:18:03 +0100578 }
Anton Hansson4bf00802022-05-09 10:23:59 +0000579 if !outputFile.Valid() {
580 outputFile = android.OptionalPathForPath(dstubs.apiVersionsXml)
581 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900582 return []android.AndroidMkEntries{android.AndroidMkEntries{
Nan Zhang1598a9e2018-09-04 17:14:32 -0700583 Class: "JAVA_LIBRARIES",
Paul Duffin3ae29512020-04-08 18:18:03 +0100584 OutputFile: outputFile,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700585 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700586 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700587 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700588 if dstubs.Javadoc.stubsSrcJar != nil {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700589 entries.SetPath("LOCAL_DROIDDOC_STUBS_SRCJAR", dstubs.Javadoc.stubsSrcJar)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700590 }
Nan Zhangd23ac692018-09-18 10:41:33 -0700591 if dstubs.apiVersionsXml != nil {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700592 entries.SetPath("LOCAL_DROIDDOC_API_VERSIONS_XML", dstubs.apiVersionsXml)
Nan Zhangd23ac692018-09-18 10:41:33 -0700593 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700594 if dstubs.annotationsZip != nil {
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700595 entries.SetPath("LOCAL_DROIDDOC_ANNOTATIONS_ZIP", dstubs.annotationsZip)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700596 }
Jerome Gaillard0f599032019-10-10 19:29:11 +0100597 if dstubs.metadataZip != nil {
598 entries.SetPath("LOCAL_DROIDDOC_METADATA_ZIP", dstubs.metadataZip)
599 }
Jaewoong Jung9a1e8bd2019-09-04 20:17:54 -0700600 },
601 },
602 ExtraFooters: []android.AndroidMkExtraFootersFunc{
Jaewoong Jung02b11a62020-12-07 10:23:54 -0800603 func(w io.Writer, name, prefix, moduleDir string) {
Anton Hansson27d9ec12020-04-17 11:48:24 +0100604 if dstubs.apiFile != nil {
605 fmt.Fprintf(w, ".PHONY: %s %s.txt\n", dstubs.Name(), dstubs.Name())
606 fmt.Fprintf(w, "%s %s.txt: %s\n", dstubs.Name(), dstubs.Name(), dstubs.apiFile)
607 }
608 if dstubs.removedApiFile != nil {
609 fmt.Fprintf(w, ".PHONY: %s %s.txt\n", dstubs.Name(), dstubs.Name())
610 fmt.Fprintf(w, "%s %s.txt: %s\n", dstubs.Name(), dstubs.Name(), dstubs.removedApiFile)
611 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700612 if dstubs.checkCurrentApiTimestamp != nil {
613 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-current-api")
614 fmt.Fprintln(w, dstubs.Name()+"-check-current-api:",
615 dstubs.checkCurrentApiTimestamp.String())
616
617 fmt.Fprintln(w, ".PHONY: checkapi")
618 fmt.Fprintln(w, "checkapi:",
619 dstubs.checkCurrentApiTimestamp.String())
620
621 fmt.Fprintln(w, ".PHONY: droidcore")
622 fmt.Fprintln(w, "droidcore: checkapi")
623 }
624 if dstubs.updateCurrentApiTimestamp != nil {
625 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-update-current-api")
626 fmt.Fprintln(w, dstubs.Name()+"-update-current-api:",
627 dstubs.updateCurrentApiTimestamp.String())
628
629 fmt.Fprintln(w, ".PHONY: update-api")
630 fmt.Fprintln(w, "update-api:",
631 dstubs.updateCurrentApiTimestamp.String())
632 }
633 if dstubs.checkLastReleasedApiTimestamp != nil {
634 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-last-released-api")
635 fmt.Fprintln(w, dstubs.Name()+"-check-last-released-api:",
636 dstubs.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100637
Makoto Onukia573f192020-04-21 11:52:39 -0700638 fmt.Fprintln(w, ".PHONY: checkapi")
639 fmt.Fprintln(w, "checkapi:",
640 dstubs.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100641
Makoto Onukia573f192020-04-21 11:52:39 -0700642 fmt.Fprintln(w, ".PHONY: droidcore")
643 fmt.Fprintln(w, "droidcore: checkapi")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700644 }
Adrian Roos075eedc2019-10-10 12:07:03 +0200645 if dstubs.apiLintTimestamp != nil {
646 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-api-lint")
647 fmt.Fprintln(w, dstubs.Name()+"-api-lint:",
648 dstubs.apiLintTimestamp.String())
649
650 fmt.Fprintln(w, ".PHONY: checkapi")
651 fmt.Fprintln(w, "checkapi:",
Adrian Roos3b8f1cd2019-11-01 13:42:39 +0100652 dstubs.Name()+"-api-lint")
Adrian Roos075eedc2019-10-10 12:07:03 +0200653
654 fmt.Fprintln(w, ".PHONY: droidcore")
655 fmt.Fprintln(w, "droidcore: checkapi")
Adrian Roos3b8f1cd2019-11-01 13:42:39 +0100656
657 if dstubs.apiLintReport != nil {
658 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", dstubs.Name()+"-api-lint",
659 dstubs.apiLintReport.String(), "apilint/"+dstubs.Name()+"-lint-report.txt")
Bob Badour51804382022-04-13 11:27:19 -0700660 fmt.Fprintf(w, "$(call declare-0p-target,%s)\n", dstubs.apiLintReport.String())
Adrian Roos3b8f1cd2019-11-01 13:42:39 +0100661 }
Adrian Roos075eedc2019-10-10 12:07:03 +0200662 }
Pete Gillin581d6082018-10-22 15:55:04 +0100663 if dstubs.checkNullabilityWarningsTimestamp != nil {
664 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings")
665 fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:",
666 dstubs.checkNullabilityWarningsTimestamp.String())
667
668 fmt.Fprintln(w, ".PHONY:", "droidcore")
669 fmt.Fprintln(w, "droidcore: ", dstubs.Name()+"-check-nullability-warnings")
670 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700671 },
672 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900673 }}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700674}
675
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900676func (a *AndroidAppImport) AndroidMkEntries() []android.AndroidMkEntries {
Colin Cross56a83212020-09-15 18:30:11 -0700677 if a.hideApexVariantFromMake {
Jiyong Park592a6a42020-04-21 22:34:28 +0900678 // The non-platform variant is placed inside APEX. No reason to
679 // make it available to Make.
680 return nil
681 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900682 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700683 Class: "APPS",
Jaewoong Jung8aae22e2019-07-17 10:21:49 -0700684 OutputFile: android.OptionalPathForPath(a.outputFile),
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700685 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700686 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700687 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jiyong Parkf7487312019-10-17 12:54:30 +0900688 entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", a.Privileged())
Colin Cross503c1d02020-01-28 14:00:53 -0800689 entries.SetString("LOCAL_CERTIFICATE", a.certificate.AndroidMkString())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700690 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", a.properties.Overrides...)
691 if len(a.dexpreopter.builtInstalled) > 0 {
692 entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", a.dexpreopter.builtInstalled)
693 }
694 entries.AddStrings("LOCAL_INSTALLED_MODULE_STEM", a.installPath.Rel())
Bill Peckhama036da92021-01-08 16:09:09 -0800695 if Bool(a.properties.Export_package_resources) {
696 entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", a.outputFile)
697 }
Joe Onorato6fe59eb2023-07-16 13:20:33 -0700698 // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700699 },
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700700 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900701 }}
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700702}
703
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900704func (a *AndroidTestImport) AndroidMkEntries() []android.AndroidMkEntries {
705 entriesList := a.AndroidAppImport.AndroidMkEntries()
706 entries := &entriesList[0]
Colin Crossaa255532020-07-03 13:18:24 -0700707 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crosscfb0f5e2021-09-24 15:47:17 -0700708 testSuiteComponent(entries, a.testProperties.Test_suites, Bool(a.testProperties.Per_testcase_directory))
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700709 androidMkWriteTestData(a.data, entries)
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -0700710 })
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900711 return entriesList
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -0700712}
713
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700714func androidMkWriteTestData(data android.Paths, entries *android.AndroidMkEntries) {
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -0700715 var testFiles []string
716 for _, d := range data {
717 testFiles = append(testFiles, d.String()+":"+d.Rel())
718 }
719 entries.AddStrings("LOCAL_COMPATIBILITY_SUPPORT_FILES", testFiles...)
720}
Jaewoong Jung9befb0c2020-01-18 10:33:43 -0800721
722func (r *RuntimeResourceOverlay) AndroidMkEntries() []android.AndroidMkEntries {
723 return []android.AndroidMkEntries{android.AndroidMkEntries{
724 Class: "ETC",
725 OutputFile: android.OptionalPathForPath(r.outputFile),
726 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
727 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700728 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jaewoong Jung78ec5d82020-01-31 10:11:47 -0800729 entries.SetString("LOCAL_CERTIFICATE", r.certificate.AndroidMkString())
Colin Crossc68db4b2021-11-11 18:59:15 -0800730 entries.SetPath("LOCAL_MODULE_PATH", r.installDir)
Jaewoong Jungad0177b2020-04-24 15:22:40 -0700731 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", r.properties.Overrides...)
Joe Onorato6fe59eb2023-07-16 13:20:33 -0700732 // TODO: LOCAL_ACONFIG_FILES -- Might eventually need aconfig flags?
Jaewoong Jung9befb0c2020-01-18 10:33:43 -0800733 },
734 },
735 }}
736}
Sasha Smundaka7856c02020-04-23 09:49:59 -0700737
738func (apkSet *AndroidAppSet) AndroidMkEntries() []android.AndroidMkEntries {
739 return []android.AndroidMkEntries{
740 android.AndroidMkEntries{
741 Class: "APPS",
Colin Crossffbcd1d2021-11-12 12:19:42 -0800742 OutputFile: android.OptionalPathForPath(apkSet.primaryOutput),
Sasha Smundaka7856c02020-04-23 09:49:59 -0700743 Include: "$(BUILD_SYSTEM)/soong_android_app_set.mk",
744 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700745 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Sasha Smundaka7856c02020-04-23 09:49:59 -0700746 entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", apkSet.Privileged())
Colin Crossffbcd1d2021-11-12 12:19:42 -0800747 entries.SetPath("LOCAL_APK_SET_INSTALL_FILE", apkSet.PackedAdditionalOutputs())
Jaewoong Jung11c1e0f2020-06-29 19:18:44 -0700748 entries.SetPath("LOCAL_APKCERTS_FILE", apkSet.apkcertsFile)
Sasha Smundaka7856c02020-04-23 09:49:59 -0700749 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", apkSet.properties.Overrides...)
Joe Onorato6fe59eb2023-07-16 13:20:33 -0700750 // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts -- Both declarations and values
Sasha Smundaka7856c02020-04-23 09:49:59 -0700751 },
752 },
753 },
754 }
755}
Jihoon Kang1bff0342023-01-17 20:40:22 +0000756
757func (al *ApiLibrary) AndroidMkEntries() []android.AndroidMkEntries {
758 var entriesList []android.AndroidMkEntries
759
760 entriesList = append(entriesList, android.AndroidMkEntries{
761 Class: "JAVA_LIBRARIES",
762 OutputFile: android.OptionalPathForPath(al.stubsJar),
763 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
764 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
765 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
766 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true)
767 entries.SetPath("LOCAL_SOONG_CLASSES_JAR", al.stubsJar)
768 entries.SetPath("LOCAL_SOONG_HEADER_JAR", al.stubsJar)
769 },
770 },
771 })
772
773 return entriesList
774}