blob: 0e8e4224804db0ce1755b42d54fc7d74652ff0ab [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"
Colin Cross10a03492017-08-10 17:09:43 -070020 "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
Sundong Ahn054b19a2018-10-19 13:46:09 +090025func (library *Library) AndroidMkHostDex(w io.Writer, name string, data android.AndroidMkData) {
26 if Bool(library.deviceProperties.Hostdex) && !library.Host() {
27 fmt.Fprintln(w, "include $(CLEAR_VARS)")
28 fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex")
29 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
30 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES")
Colin Cross56abb832019-01-14 14:13:51 -080031 if library.dexJarFile != nil {
32 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.dexJarFile.String())
33 } else {
34 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationAndResourcesJar.String())
35 }
Sundong Ahn054b19a2018-10-19 13:46:09 +090036 if library.dexJarFile != nil {
37 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
38 }
39 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
40 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String())
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -070041 if len(data.Required) > 0 {
42 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(data.Required, " "))
43 }
44 if len(data.Host_required) > 0 {
45 fmt.Fprintln(w, "LOCAL_HOST_REQUIRED_MODULES :=", strings.Join(data.Host_required, " "))
46 }
47 if len(data.Target_required) > 0 {
48 fmt.Fprintln(w, "LOCAL_TARGET_REQUIRED_MODULES :=", strings.Join(data.Target_required, " "))
49 }
Colin Cross7f87f4f2019-04-24 13:41:45 -070050 if r := library.deviceProperties.Target.Hostdex.Required; len(r) > 0 {
51 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(r, " "))
52 }
Sundong Ahn054b19a2018-10-19 13:46:09 +090053 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
54 }
55}
56
Colin Crossa18e9cf2017-08-10 17:00:19 -070057func (library *Library) AndroidMk() android.AndroidMkData {
Jiyong Park7f7766d2019-07-25 22:02:35 +090058 if !library.IsForPlatform() {
59 return android.AndroidMkData{
60 Disabled: true,
61 }
62 }
Colin Crossa18e9cf2017-08-10 17:00:19 -070063 return android.AndroidMkData{
64 Class: "JAVA_LIBRARIES",
Colin Cross43f08db2018-11-12 10:13:39 -080065 OutputFile: android.OptionalPathForPath(library.outputFile),
Colin Cross53499412017-09-07 13:20:25 -070066 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -070067 Extra: []android.AndroidMkExtraFunc{
68 func(w io.Writer, outputFile android.Path) {
Colin Cross5beccee2017-12-07 15:28:59 -080069 if len(library.logtagsSrcs) > 0 {
70 var logtags []string
71 for _, l := range library.logtagsSrcs {
72 logtags = append(logtags, l.Rel())
73 }
74 fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES :=", strings.Join(logtags, " "))
75 }
76
Colin Cross9ae1b922018-06-26 17:59:05 -070077 if library.installFile == nil {
Colin Cross2c429dc2017-08-31 16:45:16 -070078 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
79 }
Colin Cross6ade34f2017-09-15 13:00:47 -070080 if library.dexJarFile != nil {
81 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -080082 }
83 if len(library.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -080084 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", library.dexpreopter.builtInstalled)
Colin Cross6ade34f2017-09-15 13:00:47 -070085 }
Colin Cross83bb3162018-06-25 15:48:06 -070086 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", library.sdkVersion())
Colin Cross43f08db2018-11-12 10:13:39 -080087 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String())
Nan Zhanged19fc32017-10-19 13:06:22 -070088 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
Colin Crosscb933592017-11-22 13:49:43 -080089
90 if library.jacocoReportClassesFile != nil {
91 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", library.jacocoReportClassesFile.String())
92 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -080093
Jiyong Park1be96912018-05-28 18:02:19 +090094 if len(library.exportedSdkLibs) != 0 {
95 fmt.Fprintln(w, "LOCAL_EXPORT_SDK_LIBRARIES :=", strings.Join(library.exportedSdkLibs, " "))
96 }
97
Vladimir Marko0975ee02019-04-02 10:29:55 +010098 if len(library.additionalCheckedModules) != 0 {
99 fmt.Fprintln(w, "LOCAL_ADDITIONAL_CHECKED_MODULE +=", strings.Join(library.additionalCheckedModules.Strings(), " "))
100 }
101
Colin Crosse8a7dc92019-04-23 13:00:09 -0700102 if library.proguardDictionary != nil {
103 fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", library.proguardDictionary.String())
104 }
Colin Crossa18e9cf2017-08-10 17:00:19 -0700105 },
106 },
Colin Cross92430102017-10-09 14:59:32 -0700107 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
108 android.WriteAndroidMkData(w, data)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900109 library.AndroidMkHostDex(w, name, data)
Colin Cross92430102017-10-09 14:59:32 -0700110 },
Colin Crossa18e9cf2017-08-10 17:00:19 -0700111 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700112}
113
Paul Duffin42df1442019-03-20 12:45:53 +0000114// Called for modules that are a component of a test suite.
115func testSuiteComponent(w io.Writer, test_suites []string) {
116 fmt.Fprintln(w, "LOCAL_MODULE_TAGS := tests")
117 if len(test_suites) > 0 {
118 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
119 strings.Join(test_suites, " "))
120 } else {
121 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE := null-suite")
122 }
123}
124
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -0700125func testSuiteComponentEntries(entries *android.AndroidMkEntries, test_suites []string) {
126 entries.SetString("LOCAL_MODULE_TAGS", "tests")
127 if len(test_suites) > 0 {
128 entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", test_suites...)
129 } else {
130 entries.SetString("LOCAL_COMPATIBILITY_SUITE", "null-suite")
131 }
132}
133
Colin Cross05638fc2018-04-09 18:40:24 -0700134func (j *Test) AndroidMk() android.AndroidMkData {
135 data := j.Library.AndroidMk()
136 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000137 testSuiteComponent(w, j.testProperties.Test_suites)
Colin Cross303e21f2018-08-07 16:49:25 -0700138 if j.testConfig != nil {
139 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", j.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700140 }
Colin Cross05638fc2018-04-09 18:40:24 -0700141 })
142
Colin Crossd96ca352018-08-10 16:06:24 -0700143 androidMkWriteTestData(j.data, &data)
144
Colin Cross05638fc2018-04-09 18:40:24 -0700145 return data
146}
147
Paul Duffin42df1442019-03-20 12:45:53 +0000148func (j *TestHelperLibrary) AndroidMk() android.AndroidMkData {
149 data := j.Library.AndroidMk()
150 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
151 testSuiteComponent(w, j.testHelperLibraryProperties.Test_suites)
152 })
153
154 return data
155}
156
Colin Crossa18e9cf2017-08-10 17:00:19 -0700157func (prebuilt *Import) AndroidMk() android.AndroidMkData {
Jiyong Park7f7766d2019-07-25 22:02:35 +0900158 if !prebuilt.IsForPlatform() {
159 return android.AndroidMkData{
160 Disabled: true,
161 }
162 }
Colin Crossa18e9cf2017-08-10 17:00:19 -0700163 return android.AndroidMkData{
164 Class: "JAVA_LIBRARIES",
165 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Colin Cross53499412017-09-07 13:20:25 -0700166 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -0700167 Extra: []android.AndroidMkExtraFunc{
168 func(w io.Writer, outputFile android.Path) {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700169 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !Bool(prebuilt.properties.Installable))
Nan Zhanged19fc32017-10-19 13:06:22 -0700170 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800171 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Cross83bb3162018-06-25 15:48:06 -0700172 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
Colin Crossa18e9cf2017-08-10 17:00:19 -0700173 },
174 },
175 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700176}
Colin Cross10a03492017-08-10 17:09:43 -0700177
Colin Cross42be7612019-02-21 18:12:14 -0800178func (prebuilt *DexImport) AndroidMk() android.AndroidMkData {
Jiyong Park7f7766d2019-07-25 22:02:35 +0900179 if !prebuilt.IsForPlatform() {
180 return android.AndroidMkData{
181 Disabled: true,
182 }
183 }
Colin Cross42be7612019-02-21 18:12:14 -0800184 return android.AndroidMkData{
185 Class: "JAVA_LIBRARIES",
186 OutputFile: android.OptionalPathForPath(prebuilt.maybeStrippedDexJarFile),
187 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
188 Extra: []android.AndroidMkExtraFunc{
189 func(w io.Writer, outputFile android.Path) {
190 if prebuilt.dexJarFile != nil {
191 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", prebuilt.dexJarFile.String())
192 // TODO(b/125517186): export the dex jar as a classes jar to match some mis-uses in Make until
193 // boot_jars_package_check.mk can check dex jars.
194 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.dexJarFile.String())
195 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.dexJarFile.String())
196 }
197 if len(prebuilt.dexpreopter.builtInstalled) > 0 {
198 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", prebuilt.dexpreopter.builtInstalled)
199 }
200 },
201 },
202 }
203}
204
Colin Crossfabb6082018-02-20 17:22:23 -0800205func (prebuilt *AARImport) AndroidMk() android.AndroidMkData {
206 return android.AndroidMkData{
207 Class: "JAVA_LIBRARIES",
208 OutputFile: android.OptionalPathForPath(prebuilt.classpathFile),
209 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
210 Extra: []android.AndroidMkExtraFunc{
211 func(w io.Writer, outputFile android.Path) {
212 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossfabb6082018-02-20 17:22:23 -0800213 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.classpathFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800214 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.classpathFile.String())
Colin Crossfabb6082018-02-20 17:22:23 -0800215 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", prebuilt.exportPackage.String())
216 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String())
Colin Cross66f78822018-05-02 12:58:28 -0700217 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", prebuilt.extraAaptPackagesFile.String())
Colin Cross10f7c4a2018-05-23 10:59:28 -0700218 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", prebuilt.manifest.String())
Colin Cross83bb3162018-06-25 15:48:06 -0700219 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
Colin Crossfabb6082018-02-20 17:22:23 -0800220 },
221 },
222 }
223}
224
Colin Cross10a03492017-08-10 17:09:43 -0700225func (binary *Binary) AndroidMk() android.AndroidMkData {
Colin Cross10a03492017-08-10 17:09:43 -0700226
Colin Cross6b4a32d2017-12-05 13:42:45 -0800227 if !binary.isWrapperVariant {
228 return android.AndroidMkData{
229 Class: "JAVA_LIBRARIES",
Colin Cross331a1212018-08-15 20:40:52 -0700230 OutputFile: android.OptionalPathForPath(binary.outputFile),
Colin Cross6b4a32d2017-12-05 13:42:45 -0800231 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Cross331a1212018-08-15 20:40:52 -0700232 Extra: []android.AndroidMkExtraFunc{
233 func(w io.Writer, outputFile android.Path) {
234 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", binary.headerJarFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800235 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", binary.implementationAndResourcesJar.String())
Colin Cross12fc2af2019-01-14 12:35:45 -0800236 if binary.dexJarFile != nil {
237 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", binary.dexJarFile.String())
238 }
239 if len(binary.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -0800240 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", binary.dexpreopter.builtInstalled)
Colin Cross12fc2af2019-01-14 12:35:45 -0800241 }
Colin Cross331a1212018-08-15 20:40:52 -0700242 },
243 },
Colin Cross6b4a32d2017-12-05 13:42:45 -0800244 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
245 android.WriteAndroidMkData(w, data)
Colin Cross19655682017-09-07 17:00:22 -0700246
Colin Cross6b4a32d2017-12-05 13:42:45 -0800247 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
248 },
249 }
250 } else {
251 return android.AndroidMkData{
252 Class: "EXECUTABLES",
253 OutputFile: android.OptionalPathForPath(binary.wrapperFile),
254 Extra: []android.AndroidMkExtraFunc{
255 func(w io.Writer, outputFile android.Path) {
256 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
257 },
258 },
259 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
260 android.WriteAndroidMkData(w, data)
261
262 // Ensure that the wrapper script timestamp is always updated when the jar is updated
263 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
264 fmt.Fprintln(w, "jar_installed_module :=")
265 },
266 }
Colin Cross10a03492017-08-10 17:09:43 -0700267 }
268}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800269
270func (app *AndroidApp) AndroidMk() android.AndroidMkData {
271 return android.AndroidMkData{
272 Class: "APPS",
273 OutputFile: android.OptionalPathForPath(app.outputFile),
274 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
275 Extra: []android.AndroidMkExtraFunc{
276 func(w io.Writer, outputFile android.Path) {
Jaewoong Jung9109d722019-01-30 13:13:52 -0800277 // TODO(jungjw): This, outputting two LOCAL_MODULE lines, works, but is not ideal. Find a better solution.
278 if app.Name() != app.installApkName {
279 fmt.Fprintln(w, "# Overridden by PRODUCT_PACKAGE_NAME_OVERRIDES")
280 fmt.Fprintln(w, "LOCAL_MODULE :=", app.installApkName)
281 }
Colin Cross70798562017-12-13 22:42:59 -0800282 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", app.exportPackage.String())
283 if app.dexJarFile != nil {
284 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String())
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800285 }
Colin Cross331a1212018-08-15 20:40:52 -0700286 if app.implementationAndResourcesJar != nil {
287 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", app.implementationAndResourcesJar.String())
Colin Cross5dfabfb2017-12-14 13:19:01 -0800288 }
289 if app.headerJarFile != nil {
290 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", app.headerJarFile.String())
291 }
Colin Crossf6237212018-10-29 23:14:58 -0700292 if app.bundleFile != nil {
293 fmt.Fprintln(w, "LOCAL_SOONG_BUNDLE :=", app.bundleFile.String())
294 }
Colin Cross70798562017-12-13 22:42:59 -0800295 if app.jacocoReportClassesFile != nil {
296 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", app.jacocoReportClassesFile.String())
297 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800298 if app.proguardDictionary != nil {
299 fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", app.proguardDictionary.String())
300 }
Colin Cross70798562017-12-13 22:42:59 -0800301
302 if app.Name() == "framework-res" {
303 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
304 // Make base_rules.mk not put framework-res in a subdirectory called
305 // framework_res.
306 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
307 }
308
Anton Hansson53c88442019-03-18 15:53:16 +0000309 filterRRO := func(filter overlayType) android.Paths {
310 var paths android.Paths
311 for _, d := range app.rroDirs {
312 if d.overlayType == filter {
313 paths = append(paths, d.path)
314 }
315 }
Colin Crossa140bb02018-04-17 10:52:26 -0700316 // Reverse the order, Soong stores rroDirs in aapt2 order (low to high priority), but Make
317 // expects it in LOCAL_RESOURCE_DIRS order (high to low priority).
Anton Hansson53c88442019-03-18 15:53:16 +0000318 return android.ReversePaths(paths)
319 }
320 deviceRRODirs := filterRRO(device)
321 if len(deviceRRODirs) > 0 {
322 fmt.Fprintln(w, "LOCAL_SOONG_DEVICE_RRO_DIRS :=", strings.Join(deviceRRODirs.Strings(), " "))
323 }
324 productRRODirs := filterRRO(product)
325 if len(productRRODirs) > 0 {
326 fmt.Fprintln(w, "LOCAL_SOONG_PRODUCT_RRO_DIRS :=", strings.Join(productRRODirs.Strings(), " "))
Colin Cross70798562017-12-13 22:42:59 -0800327 }
328
329 if Bool(app.appProperties.Export_package_resources) {
330 fmt.Fprintln(w, "LOCAL_EXPORT_PACKAGE_RESOURCES := true")
331 }
332
333 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", app.manifestPath.String())
334
Colin Cross16056062017-12-13 22:46:28 -0800335 if Bool(app.appProperties.Privileged) {
336 fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true")
337 }
Colin Crosse1731a52017-12-14 11:22:55 -0800338
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900339 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.Pem.String())
Jaewoong Jung9109d722019-01-30 13:13:52 -0800340 if overriddenPkgs := app.getOverriddenPackages(); len(overriddenPkgs) > 0 {
341 fmt.Fprintln(w, "LOCAL_OVERRIDES_PACKAGES :=", strings.Join(overriddenPkgs, " "))
Jason Monkd4122be2018-08-10 09:33:36 -0400342 }
Colin Crossa4f08812018-10-02 22:03:40 -0700343
344 for _, jniLib := range app.installJniLibs {
345 fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), "+=", jniLib.name)
346 }
Colin Cross43f08db2018-11-12 10:13:39 -0800347 if len(app.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -0800348 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", app.dexpreopter.builtInstalled)
Colin Cross43f08db2018-11-12 10:13:39 -0800349 }
Colin Crosse560c4a2019-03-19 16:03:11 -0700350 for _, split := range app.aapt.splits {
351 install := "$(LOCAL_MODULE_PATH)/" + strings.TrimSuffix(app.installApkName, ".apk") + split.suffix + ".apk"
352 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED +=", split.path.String()+":"+install)
353 }
Jaewoong Jung98772792019-07-01 17:15:13 -0700354 if app.noticeOutputs.Merged.Valid() {
355 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n",
356 app.installApkName, app.noticeOutputs.Merged.String(), app.installApkName+"_NOTICE")
357 }
358 if app.noticeOutputs.TxtOutput.Valid() {
359 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n",
360 app.installApkName, app.noticeOutputs.TxtOutput.String(), app.installApkName+"_NOTICE.txt")
361 }
362 if app.noticeOutputs.HtmlOutput.Valid() {
363 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n",
364 app.installApkName, app.noticeOutputs.HtmlOutput.String(), app.installApkName+"_NOTICE.html")
365 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800366 },
367 },
368 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700369}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800370
Jaewoong Jung9109d722019-01-30 13:13:52 -0800371func (a *AndroidApp) getOverriddenPackages() []string {
372 var overridden []string
373 if len(a.appProperties.Overrides) > 0 {
374 overridden = append(overridden, a.appProperties.Overrides...)
375 }
376 if a.Name() != a.installApkName {
377 overridden = append(overridden, a.Name())
378 }
379 return overridden
380}
381
Colin Crossae5caf52018-05-22 11:11:52 -0700382func (a *AndroidTest) AndroidMk() android.AndroidMkData {
383 data := a.AndroidApp.AndroidMk()
384 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000385 testSuiteComponent(w, a.testProperties.Test_suites)
Colin Cross303e21f2018-08-07 16:49:25 -0700386 if a.testConfig != nil {
387 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", a.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700388 }
Colin Crossae5caf52018-05-22 11:11:52 -0700389 })
Colin Crossd96ca352018-08-10 16:06:24 -0700390 androidMkWriteTestData(a.data, &data)
Colin Crossae5caf52018-05-22 11:11:52 -0700391
392 return data
393}
394
Colin Cross252fc6f2018-10-04 15:22:03 -0700395func (a *AndroidTestHelperApp) AndroidMk() android.AndroidMkData {
396 data := a.AndroidApp.AndroidMk()
397 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000398 testSuiteComponent(w, a.appTestHelperAppProperties.Test_suites)
Colin Cross252fc6f2018-10-04 15:22:03 -0700399 })
400
401 return data
402}
403
Colin Crossa97c5d32018-03-28 14:58:31 -0700404func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
405 data := a.Library.AndroidMk()
406
407 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossa54974c2018-10-29 23:15:37 -0700408 if a.aarFile != nil {
409 fmt.Fprintln(w, "LOCAL_SOONG_AAR :=", a.aarFile.String())
410 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700411
412 if a.Name() == "framework-res" {
413 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
414 // Make base_rules.mk not put framework-res in a subdirectory called
415 // framework_res.
416 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
417 }
418
419 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
Colin Cross66f78822018-05-02 12:58:28 -0700420 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", a.extraAaptPackagesFile.String())
Colin Cross90c25c62019-04-19 16:22:57 -0700421 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.mergedManifestFile.String())
Colin Cross89c31582018-04-30 15:55:11 -0700422 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
423 strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
Colin Crossa97c5d32018-03-28 14:58:31 -0700424 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossa97c5d32018-03-28 14:58:31 -0700425 })
426
427 return data
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800428}
Nan Zhang581fd212018-01-10 16:06:12 -0800429
430func (jd *Javadoc) AndroidMk() android.AndroidMkData {
431 return android.AndroidMkData{
432 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800433 OutputFile: android.OptionalPathForPath(jd.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700434 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800435 Extra: []android.AndroidMkExtraFunc{
436 func(w io.Writer, outputFile android.Path) {
Colin Cross38b40df2018-04-10 16:14:46 -0700437 if BoolDefault(jd.properties.Installable, true) {
Nan Zhang581fd212018-01-10 16:06:12 -0800438 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", jd.docZip.String())
439 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800440 if jd.stubsSrcJar != nil {
441 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", jd.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800442 }
443 },
444 },
445 }
446}
447
448func (ddoc *Droiddoc) AndroidMk() android.AndroidMkData {
449 return android.AndroidMkData{
450 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800451 OutputFile: android.OptionalPathForPath(ddoc.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700452 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800453 Extra: []android.AndroidMkExtraFunc{
454 func(w io.Writer, outputFile android.Path) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700455 if BoolDefault(ddoc.Javadoc.properties.Installable, true) && ddoc.Javadoc.docZip != nil {
Nan Zhang581fd212018-01-10 16:06:12 -0800456 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", ddoc.Javadoc.docZip.String())
457 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800458 if ddoc.Javadoc.stubsSrcJar != nil {
459 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", ddoc.Javadoc.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800460 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700461 if ddoc.checkCurrentApiTimestamp != nil {
462 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-current-api")
463 fmt.Fprintln(w, ddoc.Name()+"-check-current-api:",
464 ddoc.checkCurrentApiTimestamp.String())
465
466 fmt.Fprintln(w, ".PHONY: checkapi")
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900467 fmt.Fprintln(w, "checkapi:",
Nan Zhang61819ce2018-05-04 18:49:16 -0700468 ddoc.checkCurrentApiTimestamp.String())
469
470 fmt.Fprintln(w, ".PHONY: droidcore")
471 fmt.Fprintln(w, "droidcore: checkapi")
472 }
473 if ddoc.updateCurrentApiTimestamp != nil {
Dan Willemsena03c43a2018-07-24 13:00:52 -0700474 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-update-current-api")
Nan Zhang61819ce2018-05-04 18:49:16 -0700475 fmt.Fprintln(w, ddoc.Name()+"-update-current-api:",
476 ddoc.updateCurrentApiTimestamp.String())
477
478 fmt.Fprintln(w, ".PHONY: update-api")
479 fmt.Fprintln(w, "update-api:",
480 ddoc.updateCurrentApiTimestamp.String())
481 }
482 if ddoc.checkLastReleasedApiTimestamp != nil {
483 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-last-released-api")
484 fmt.Fprintln(w, ddoc.Name()+"-check-last-released-api:",
485 ddoc.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100486
Adrian Roos62e34b92019-01-30 19:51:39 +0100487 if ddoc.Name() == "api-stubs-docs" || ddoc.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100488 fmt.Fprintln(w, ".PHONY: checkapi")
489 fmt.Fprintln(w, "checkapi:",
490 ddoc.checkLastReleasedApiTimestamp.String())
491
492 fmt.Fprintln(w, ".PHONY: droidcore")
493 fmt.Fprintln(w, "droidcore: checkapi")
494 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700495 }
Nan Zhang28c68b92018-03-13 16:17:01 -0700496 apiFilePrefix := "INTERNAL_PLATFORM_"
497 if String(ddoc.properties.Api_tag_name) != "" {
498 apiFilePrefix += String(ddoc.properties.Api_tag_name) + "_"
499 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700500 if ddoc.apiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700501 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", ddoc.apiFile.String())
502 }
David Brazdilfbe4cc32018-05-31 13:56:46 +0100503 if ddoc.dexApiFile != nil {
504 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", ddoc.dexApiFile.String())
505 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700506 if ddoc.privateApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700507 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", ddoc.privateApiFile.String())
508 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700509 if ddoc.privateDexApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700510 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", ddoc.privateDexApiFile.String())
511 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700512 if ddoc.removedApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700513 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", ddoc.removedApiFile.String())
514 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700515 if ddoc.removedDexApiFile != nil {
David Brazdilaac0c3c2018-04-24 16:23:29 +0100516 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", ddoc.removedDexApiFile.String())
517 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700518 if ddoc.exactApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700519 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", ddoc.exactApiFile.String())
520 }
Nan Zhang66dc2362018-08-14 20:41:04 -0700521 if ddoc.proguardFile != nil {
522 fmt.Fprintln(w, apiFilePrefix+"PROGUARD_FILE := ", ddoc.proguardFile.String())
523 }
Nan Zhang581fd212018-01-10 16:06:12 -0800524 },
525 },
526 }
527}
Colin Crossd96ca352018-08-10 16:06:24 -0700528
Nan Zhang1598a9e2018-09-04 17:14:32 -0700529func (dstubs *Droidstubs) AndroidMk() android.AndroidMkData {
530 return android.AndroidMkData{
531 Class: "JAVA_LIBRARIES",
532 OutputFile: android.OptionalPathForPath(dstubs.stubsSrcJar),
533 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
534 Extra: []android.AndroidMkExtraFunc{
535 func(w io.Writer, outputFile android.Path) {
536 if dstubs.Javadoc.stubsSrcJar != nil {
537 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", dstubs.Javadoc.stubsSrcJar.String())
538 }
Nan Zhangd23ac692018-09-18 10:41:33 -0700539 if dstubs.apiVersionsXml != nil {
540 fmt.Fprintln(w, "LOCAL_DROIDDOC_API_VERSIONS_XML := ", dstubs.apiVersionsXml.String())
541 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700542 if dstubs.annotationsZip != nil {
543 fmt.Fprintln(w, "LOCAL_DROIDDOC_ANNOTATIONS_ZIP := ", dstubs.annotationsZip.String())
544 }
Nan Zhang71bbe632018-09-17 14:32:21 -0700545 if dstubs.jdiffDocZip != nil {
546 fmt.Fprintln(w, "LOCAL_DROIDDOC_JDIFF_DOC_ZIP := ", dstubs.jdiffDocZip.String())
547 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700548 if dstubs.checkCurrentApiTimestamp != nil {
549 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-current-api")
550 fmt.Fprintln(w, dstubs.Name()+"-check-current-api:",
551 dstubs.checkCurrentApiTimestamp.String())
552
553 fmt.Fprintln(w, ".PHONY: checkapi")
554 fmt.Fprintln(w, "checkapi:",
555 dstubs.checkCurrentApiTimestamp.String())
556
557 fmt.Fprintln(w, ".PHONY: droidcore")
558 fmt.Fprintln(w, "droidcore: checkapi")
559 }
560 if dstubs.updateCurrentApiTimestamp != nil {
561 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-update-current-api")
562 fmt.Fprintln(w, dstubs.Name()+"-update-current-api:",
563 dstubs.updateCurrentApiTimestamp.String())
564
565 fmt.Fprintln(w, ".PHONY: update-api")
566 fmt.Fprintln(w, "update-api:",
567 dstubs.updateCurrentApiTimestamp.String())
568 }
569 if dstubs.checkLastReleasedApiTimestamp != nil {
570 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-last-released-api")
571 fmt.Fprintln(w, dstubs.Name()+"-check-last-released-api:",
572 dstubs.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100573
Adrian Roos62e34b92019-01-30 19:51:39 +0100574 if dstubs.Name() == "api-stubs-docs" || dstubs.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100575 fmt.Fprintln(w, ".PHONY: checkapi")
576 fmt.Fprintln(w, "checkapi:",
577 dstubs.checkLastReleasedApiTimestamp.String())
578
579 fmt.Fprintln(w, ".PHONY: droidcore")
580 fmt.Fprintln(w, "droidcore: checkapi")
581 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700582 }
Pete Gillin581d6082018-10-22 15:55:04 +0100583 if dstubs.checkNullabilityWarningsTimestamp != nil {
584 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings")
585 fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:",
586 dstubs.checkNullabilityWarningsTimestamp.String())
587
588 fmt.Fprintln(w, ".PHONY:", "droidcore")
589 fmt.Fprintln(w, "droidcore: ", dstubs.Name()+"-check-nullability-warnings")
590 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700591 apiFilePrefix := "INTERNAL_PLATFORM_"
592 if String(dstubs.properties.Api_tag_name) != "" {
593 apiFilePrefix += String(dstubs.properties.Api_tag_name) + "_"
594 }
595 if dstubs.apiFile != nil {
596 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", dstubs.apiFile.String())
597 }
598 if dstubs.dexApiFile != nil {
599 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", dstubs.dexApiFile.String())
600 }
601 if dstubs.privateApiFile != nil {
602 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", dstubs.privateApiFile.String())
603 }
604 if dstubs.privateDexApiFile != nil {
605 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", dstubs.privateDexApiFile.String())
606 }
607 if dstubs.removedApiFile != nil {
608 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", dstubs.removedApiFile.String())
609 }
610 if dstubs.removedDexApiFile != nil {
611 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", dstubs.removedDexApiFile.String())
612 }
613 if dstubs.exactApiFile != nil {
614 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", dstubs.exactApiFile.String())
615 }
616 },
617 },
618 }
619}
620
Jaewoong Jung8aae22e2019-07-17 10:21:49 -0700621func (a *AndroidAppImport) AndroidMkEntries() android.AndroidMkEntries {
622 return android.AndroidMkEntries{
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700623 Class: "APPS",
Jaewoong Jung8aae22e2019-07-17 10:21:49 -0700624 OutputFile: android.OptionalPathForPath(a.outputFile),
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700625 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700626 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
627 func(entries *android.AndroidMkEntries) {
628 entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", Bool(a.properties.Privileged))
629 if a.certificate != nil {
630 entries.SetString("LOCAL_CERTIFICATE", a.certificate.Pem.String())
631 } else {
632 entries.SetString("LOCAL_CERTIFICATE", "PRESIGNED")
633 }
634 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", a.properties.Overrides...)
635 if len(a.dexpreopter.builtInstalled) > 0 {
636 entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", a.dexpreopter.builtInstalled)
637 }
638 entries.AddStrings("LOCAL_INSTALLED_MODULE_STEM", a.installPath.Rel())
639 },
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700640 },
641 }
642}
643
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -0700644func (a *AndroidTestImport) AndroidMkEntries() android.AndroidMkEntries {
645 entries := a.AndroidAppImport.AndroidMkEntries()
646 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
647 testSuiteComponentEntries(entries, a.testProperties.Test_suites)
648 androidMkEntriesWriteTestData(a.data, entries)
649 })
650 return entries
651}
652
Colin Crossd96ca352018-08-10 16:06:24 -0700653func androidMkWriteTestData(data android.Paths, ret *android.AndroidMkData) {
654 var testFiles []string
655 for _, d := range data {
656 testFiles = append(testFiles, d.String()+":"+d.Rel())
657 }
658 if len(testFiles) > 0 {
659 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
660 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUPPORT_FILES := "+strings.Join(testFiles, " "))
661 })
662 }
663}
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -0700664
665func androidMkEntriesWriteTestData(data android.Paths, entries *android.AndroidMkEntries) {
666 var testFiles []string
667 for _, d := range data {
668 testFiles = append(testFiles, d.String()+":"+d.Rel())
669 }
670 entries.AddStrings("LOCAL_COMPATIBILITY_SUPPORT_FILES", testFiles...)
671}