blob: ad0e171f37c2ab0083e949acbcc22c477637583d [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
Colin Cross05638fc2018-04-09 18:40:24 -0700125func (j *Test) AndroidMk() android.AndroidMkData {
126 data := j.Library.AndroidMk()
127 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000128 testSuiteComponent(w, j.testProperties.Test_suites)
Colin Cross303e21f2018-08-07 16:49:25 -0700129 if j.testConfig != nil {
130 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", j.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700131 }
Colin Cross05638fc2018-04-09 18:40:24 -0700132 })
133
Colin Crossd96ca352018-08-10 16:06:24 -0700134 androidMkWriteTestData(j.data, &data)
135
Colin Cross05638fc2018-04-09 18:40:24 -0700136 return data
137}
138
Paul Duffin42df1442019-03-20 12:45:53 +0000139func (j *TestHelperLibrary) AndroidMk() android.AndroidMkData {
140 data := j.Library.AndroidMk()
141 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
142 testSuiteComponent(w, j.testHelperLibraryProperties.Test_suites)
143 })
144
145 return data
146}
147
Colin Crossa18e9cf2017-08-10 17:00:19 -0700148func (prebuilt *Import) AndroidMk() android.AndroidMkData {
Jiyong Park7f7766d2019-07-25 22:02:35 +0900149 if !prebuilt.IsForPlatform() {
150 return android.AndroidMkData{
151 Disabled: true,
152 }
153 }
Colin Crossa18e9cf2017-08-10 17:00:19 -0700154 return android.AndroidMkData{
155 Class: "JAVA_LIBRARIES",
156 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Colin Cross53499412017-09-07 13:20:25 -0700157 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -0700158 Extra: []android.AndroidMkExtraFunc{
159 func(w io.Writer, outputFile android.Path) {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700160 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !Bool(prebuilt.properties.Installable))
Nan Zhanged19fc32017-10-19 13:06:22 -0700161 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800162 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Cross83bb3162018-06-25 15:48:06 -0700163 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
Colin Crossa18e9cf2017-08-10 17:00:19 -0700164 },
165 },
166 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700167}
Colin Cross10a03492017-08-10 17:09:43 -0700168
Colin Cross42be7612019-02-21 18:12:14 -0800169func (prebuilt *DexImport) AndroidMk() android.AndroidMkData {
Jiyong Park7f7766d2019-07-25 22:02:35 +0900170 if !prebuilt.IsForPlatform() {
171 return android.AndroidMkData{
172 Disabled: true,
173 }
174 }
Colin Cross42be7612019-02-21 18:12:14 -0800175 return android.AndroidMkData{
176 Class: "JAVA_LIBRARIES",
177 OutputFile: android.OptionalPathForPath(prebuilt.maybeStrippedDexJarFile),
178 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
179 Extra: []android.AndroidMkExtraFunc{
180 func(w io.Writer, outputFile android.Path) {
181 if prebuilt.dexJarFile != nil {
182 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", prebuilt.dexJarFile.String())
183 // TODO(b/125517186): export the dex jar as a classes jar to match some mis-uses in Make until
184 // boot_jars_package_check.mk can check dex jars.
185 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.dexJarFile.String())
186 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.dexJarFile.String())
187 }
188 if len(prebuilt.dexpreopter.builtInstalled) > 0 {
189 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", prebuilt.dexpreopter.builtInstalled)
190 }
191 },
192 },
193 }
194}
195
Colin Crossfabb6082018-02-20 17:22:23 -0800196func (prebuilt *AARImport) AndroidMk() android.AndroidMkData {
197 return android.AndroidMkData{
198 Class: "JAVA_LIBRARIES",
199 OutputFile: android.OptionalPathForPath(prebuilt.classpathFile),
200 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
201 Extra: []android.AndroidMkExtraFunc{
202 func(w io.Writer, outputFile android.Path) {
203 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossfabb6082018-02-20 17:22:23 -0800204 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.classpathFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800205 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.classpathFile.String())
Colin Crossfabb6082018-02-20 17:22:23 -0800206 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", prebuilt.exportPackage.String())
207 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String())
Colin Cross66f78822018-05-02 12:58:28 -0700208 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", prebuilt.extraAaptPackagesFile.String())
Colin Cross10f7c4a2018-05-23 10:59:28 -0700209 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", prebuilt.manifest.String())
Colin Cross83bb3162018-06-25 15:48:06 -0700210 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
Colin Crossfabb6082018-02-20 17:22:23 -0800211 },
212 },
213 }
214}
215
Colin Cross10a03492017-08-10 17:09:43 -0700216func (binary *Binary) AndroidMk() android.AndroidMkData {
Colin Cross10a03492017-08-10 17:09:43 -0700217
Colin Cross6b4a32d2017-12-05 13:42:45 -0800218 if !binary.isWrapperVariant {
219 return android.AndroidMkData{
220 Class: "JAVA_LIBRARIES",
Colin Cross331a1212018-08-15 20:40:52 -0700221 OutputFile: android.OptionalPathForPath(binary.outputFile),
Colin Cross6b4a32d2017-12-05 13:42:45 -0800222 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Cross331a1212018-08-15 20:40:52 -0700223 Extra: []android.AndroidMkExtraFunc{
224 func(w io.Writer, outputFile android.Path) {
225 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", binary.headerJarFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800226 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", binary.implementationAndResourcesJar.String())
Colin Cross12fc2af2019-01-14 12:35:45 -0800227 if binary.dexJarFile != nil {
228 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", binary.dexJarFile.String())
229 }
230 if len(binary.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -0800231 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", binary.dexpreopter.builtInstalled)
Colin Cross12fc2af2019-01-14 12:35:45 -0800232 }
Colin Cross331a1212018-08-15 20:40:52 -0700233 },
234 },
Colin Cross6b4a32d2017-12-05 13:42:45 -0800235 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
236 android.WriteAndroidMkData(w, data)
Colin Cross19655682017-09-07 17:00:22 -0700237
Colin Cross6b4a32d2017-12-05 13:42:45 -0800238 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
239 },
240 }
241 } else {
242 return android.AndroidMkData{
243 Class: "EXECUTABLES",
244 OutputFile: android.OptionalPathForPath(binary.wrapperFile),
245 Extra: []android.AndroidMkExtraFunc{
246 func(w io.Writer, outputFile android.Path) {
247 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
248 },
249 },
250 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
251 android.WriteAndroidMkData(w, data)
252
253 // Ensure that the wrapper script timestamp is always updated when the jar is updated
254 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
255 fmt.Fprintln(w, "jar_installed_module :=")
256 },
257 }
Colin Cross10a03492017-08-10 17:09:43 -0700258 }
259}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800260
261func (app *AndroidApp) AndroidMk() android.AndroidMkData {
262 return android.AndroidMkData{
263 Class: "APPS",
264 OutputFile: android.OptionalPathForPath(app.outputFile),
265 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
266 Extra: []android.AndroidMkExtraFunc{
267 func(w io.Writer, outputFile android.Path) {
Jaewoong Jung9109d722019-01-30 13:13:52 -0800268 // TODO(jungjw): This, outputting two LOCAL_MODULE lines, works, but is not ideal. Find a better solution.
269 if app.Name() != app.installApkName {
270 fmt.Fprintln(w, "# Overridden by PRODUCT_PACKAGE_NAME_OVERRIDES")
271 fmt.Fprintln(w, "LOCAL_MODULE :=", app.installApkName)
272 }
Colin Cross70798562017-12-13 22:42:59 -0800273 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", app.exportPackage.String())
274 if app.dexJarFile != nil {
275 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String())
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800276 }
Colin Cross331a1212018-08-15 20:40:52 -0700277 if app.implementationAndResourcesJar != nil {
278 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", app.implementationAndResourcesJar.String())
Colin Cross5dfabfb2017-12-14 13:19:01 -0800279 }
280 if app.headerJarFile != nil {
281 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", app.headerJarFile.String())
282 }
Colin Crossf6237212018-10-29 23:14:58 -0700283 if app.bundleFile != nil {
284 fmt.Fprintln(w, "LOCAL_SOONG_BUNDLE :=", app.bundleFile.String())
285 }
Colin Cross70798562017-12-13 22:42:59 -0800286 if app.jacocoReportClassesFile != nil {
287 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", app.jacocoReportClassesFile.String())
288 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800289 if app.proguardDictionary != nil {
290 fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", app.proguardDictionary.String())
291 }
Colin Cross70798562017-12-13 22:42:59 -0800292
293 if app.Name() == "framework-res" {
294 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
295 // Make base_rules.mk not put framework-res in a subdirectory called
296 // framework_res.
297 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
298 }
299
Anton Hansson53c88442019-03-18 15:53:16 +0000300 filterRRO := func(filter overlayType) android.Paths {
301 var paths android.Paths
302 for _, d := range app.rroDirs {
303 if d.overlayType == filter {
304 paths = append(paths, d.path)
305 }
306 }
Colin Crossa140bb02018-04-17 10:52:26 -0700307 // Reverse the order, Soong stores rroDirs in aapt2 order (low to high priority), but Make
308 // expects it in LOCAL_RESOURCE_DIRS order (high to low priority).
Anton Hansson53c88442019-03-18 15:53:16 +0000309 return android.ReversePaths(paths)
310 }
311 deviceRRODirs := filterRRO(device)
312 if len(deviceRRODirs) > 0 {
313 fmt.Fprintln(w, "LOCAL_SOONG_DEVICE_RRO_DIRS :=", strings.Join(deviceRRODirs.Strings(), " "))
314 }
315 productRRODirs := filterRRO(product)
316 if len(productRRODirs) > 0 {
317 fmt.Fprintln(w, "LOCAL_SOONG_PRODUCT_RRO_DIRS :=", strings.Join(productRRODirs.Strings(), " "))
Colin Cross70798562017-12-13 22:42:59 -0800318 }
319
320 if Bool(app.appProperties.Export_package_resources) {
321 fmt.Fprintln(w, "LOCAL_EXPORT_PACKAGE_RESOURCES := true")
322 }
323
324 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", app.manifestPath.String())
325
Colin Cross16056062017-12-13 22:46:28 -0800326 if Bool(app.appProperties.Privileged) {
327 fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true")
328 }
Colin Crosse1731a52017-12-14 11:22:55 -0800329
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900330 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.Pem.String())
Jaewoong Jung9109d722019-01-30 13:13:52 -0800331 if overriddenPkgs := app.getOverriddenPackages(); len(overriddenPkgs) > 0 {
332 fmt.Fprintln(w, "LOCAL_OVERRIDES_PACKAGES :=", strings.Join(overriddenPkgs, " "))
Jason Monkd4122be2018-08-10 09:33:36 -0400333 }
Colin Crossa4f08812018-10-02 22:03:40 -0700334
335 for _, jniLib := range app.installJniLibs {
336 fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), "+=", jniLib.name)
337 }
Colin Cross43f08db2018-11-12 10:13:39 -0800338 if len(app.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -0800339 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", app.dexpreopter.builtInstalled)
Colin Cross43f08db2018-11-12 10:13:39 -0800340 }
Colin Crosse560c4a2019-03-19 16:03:11 -0700341 for _, split := range app.aapt.splits {
342 install := "$(LOCAL_MODULE_PATH)/" + strings.TrimSuffix(app.installApkName, ".apk") + split.suffix + ".apk"
343 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED +=", split.path.String()+":"+install)
344 }
Jaewoong Jung98772792019-07-01 17:15:13 -0700345 if app.noticeOutputs.Merged.Valid() {
346 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n",
347 app.installApkName, app.noticeOutputs.Merged.String(), app.installApkName+"_NOTICE")
348 }
349 if app.noticeOutputs.TxtOutput.Valid() {
350 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n",
351 app.installApkName, app.noticeOutputs.TxtOutput.String(), app.installApkName+"_NOTICE.txt")
352 }
353 if app.noticeOutputs.HtmlOutput.Valid() {
354 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n",
355 app.installApkName, app.noticeOutputs.HtmlOutput.String(), app.installApkName+"_NOTICE.html")
356 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800357 },
358 },
359 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700360}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800361
Jaewoong Jung9109d722019-01-30 13:13:52 -0800362func (a *AndroidApp) getOverriddenPackages() []string {
363 var overridden []string
364 if len(a.appProperties.Overrides) > 0 {
365 overridden = append(overridden, a.appProperties.Overrides...)
366 }
367 if a.Name() != a.installApkName {
368 overridden = append(overridden, a.Name())
369 }
370 return overridden
371}
372
Colin Crossae5caf52018-05-22 11:11:52 -0700373func (a *AndroidTest) AndroidMk() android.AndroidMkData {
374 data := a.AndroidApp.AndroidMk()
375 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000376 testSuiteComponent(w, a.testProperties.Test_suites)
Colin Cross303e21f2018-08-07 16:49:25 -0700377 if a.testConfig != nil {
378 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", a.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700379 }
Colin Crossae5caf52018-05-22 11:11:52 -0700380 })
Colin Crossd96ca352018-08-10 16:06:24 -0700381 androidMkWriteTestData(a.data, &data)
Colin Crossae5caf52018-05-22 11:11:52 -0700382
383 return data
384}
385
Colin Cross252fc6f2018-10-04 15:22:03 -0700386func (a *AndroidTestHelperApp) AndroidMk() android.AndroidMkData {
387 data := a.AndroidApp.AndroidMk()
388 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000389 testSuiteComponent(w, a.appTestHelperAppProperties.Test_suites)
Colin Cross252fc6f2018-10-04 15:22:03 -0700390 })
391
392 return data
393}
394
Colin Crossa97c5d32018-03-28 14:58:31 -0700395func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
396 data := a.Library.AndroidMk()
397
398 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossa54974c2018-10-29 23:15:37 -0700399 if a.aarFile != nil {
400 fmt.Fprintln(w, "LOCAL_SOONG_AAR :=", a.aarFile.String())
401 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700402
403 if a.Name() == "framework-res" {
404 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
405 // Make base_rules.mk not put framework-res in a subdirectory called
406 // framework_res.
407 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
408 }
409
410 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
Colin Cross66f78822018-05-02 12:58:28 -0700411 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", a.extraAaptPackagesFile.String())
Colin Cross90c25c62019-04-19 16:22:57 -0700412 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.mergedManifestFile.String())
Colin Cross89c31582018-04-30 15:55:11 -0700413 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
414 strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
Colin Crossa97c5d32018-03-28 14:58:31 -0700415 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossa97c5d32018-03-28 14:58:31 -0700416 })
417
418 return data
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800419}
Nan Zhang581fd212018-01-10 16:06:12 -0800420
421func (jd *Javadoc) AndroidMk() android.AndroidMkData {
422 return android.AndroidMkData{
423 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800424 OutputFile: android.OptionalPathForPath(jd.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700425 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800426 Extra: []android.AndroidMkExtraFunc{
427 func(w io.Writer, outputFile android.Path) {
Colin Cross38b40df2018-04-10 16:14:46 -0700428 if BoolDefault(jd.properties.Installable, true) {
Nan Zhang581fd212018-01-10 16:06:12 -0800429 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", jd.docZip.String())
430 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800431 if jd.stubsSrcJar != nil {
432 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", jd.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800433 }
434 },
435 },
436 }
437}
438
439func (ddoc *Droiddoc) AndroidMk() android.AndroidMkData {
440 return android.AndroidMkData{
441 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800442 OutputFile: android.OptionalPathForPath(ddoc.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700443 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800444 Extra: []android.AndroidMkExtraFunc{
445 func(w io.Writer, outputFile android.Path) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700446 if BoolDefault(ddoc.Javadoc.properties.Installable, true) && ddoc.Javadoc.docZip != nil {
Nan Zhang581fd212018-01-10 16:06:12 -0800447 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", ddoc.Javadoc.docZip.String())
448 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800449 if ddoc.Javadoc.stubsSrcJar != nil {
450 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", ddoc.Javadoc.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800451 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700452 if ddoc.checkCurrentApiTimestamp != nil {
453 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-current-api")
454 fmt.Fprintln(w, ddoc.Name()+"-check-current-api:",
455 ddoc.checkCurrentApiTimestamp.String())
456
457 fmt.Fprintln(w, ".PHONY: checkapi")
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900458 fmt.Fprintln(w, "checkapi:",
Nan Zhang61819ce2018-05-04 18:49:16 -0700459 ddoc.checkCurrentApiTimestamp.String())
460
461 fmt.Fprintln(w, ".PHONY: droidcore")
462 fmt.Fprintln(w, "droidcore: checkapi")
463 }
464 if ddoc.updateCurrentApiTimestamp != nil {
Dan Willemsena03c43a2018-07-24 13:00:52 -0700465 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-update-current-api")
Nan Zhang61819ce2018-05-04 18:49:16 -0700466 fmt.Fprintln(w, ddoc.Name()+"-update-current-api:",
467 ddoc.updateCurrentApiTimestamp.String())
468
469 fmt.Fprintln(w, ".PHONY: update-api")
470 fmt.Fprintln(w, "update-api:",
471 ddoc.updateCurrentApiTimestamp.String())
472 }
473 if ddoc.checkLastReleasedApiTimestamp != nil {
474 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-last-released-api")
475 fmt.Fprintln(w, ddoc.Name()+"-check-last-released-api:",
476 ddoc.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100477
Adrian Roos62e34b92019-01-30 19:51:39 +0100478 if ddoc.Name() == "api-stubs-docs" || ddoc.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100479 fmt.Fprintln(w, ".PHONY: checkapi")
480 fmt.Fprintln(w, "checkapi:",
481 ddoc.checkLastReleasedApiTimestamp.String())
482
483 fmt.Fprintln(w, ".PHONY: droidcore")
484 fmt.Fprintln(w, "droidcore: checkapi")
485 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700486 }
Nan Zhang28c68b92018-03-13 16:17:01 -0700487 apiFilePrefix := "INTERNAL_PLATFORM_"
488 if String(ddoc.properties.Api_tag_name) != "" {
489 apiFilePrefix += String(ddoc.properties.Api_tag_name) + "_"
490 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700491 if ddoc.apiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700492 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", ddoc.apiFile.String())
493 }
David Brazdilfbe4cc32018-05-31 13:56:46 +0100494 if ddoc.dexApiFile != nil {
495 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", ddoc.dexApiFile.String())
496 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700497 if ddoc.privateApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700498 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", ddoc.privateApiFile.String())
499 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700500 if ddoc.privateDexApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700501 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", ddoc.privateDexApiFile.String())
502 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700503 if ddoc.removedApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700504 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", ddoc.removedApiFile.String())
505 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700506 if ddoc.removedDexApiFile != nil {
David Brazdilaac0c3c2018-04-24 16:23:29 +0100507 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", ddoc.removedDexApiFile.String())
508 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700509 if ddoc.exactApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700510 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", ddoc.exactApiFile.String())
511 }
Nan Zhang66dc2362018-08-14 20:41:04 -0700512 if ddoc.proguardFile != nil {
513 fmt.Fprintln(w, apiFilePrefix+"PROGUARD_FILE := ", ddoc.proguardFile.String())
514 }
Nan Zhang581fd212018-01-10 16:06:12 -0800515 },
516 },
517 }
518}
Colin Crossd96ca352018-08-10 16:06:24 -0700519
Nan Zhang1598a9e2018-09-04 17:14:32 -0700520func (dstubs *Droidstubs) AndroidMk() android.AndroidMkData {
521 return android.AndroidMkData{
522 Class: "JAVA_LIBRARIES",
523 OutputFile: android.OptionalPathForPath(dstubs.stubsSrcJar),
524 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
525 Extra: []android.AndroidMkExtraFunc{
526 func(w io.Writer, outputFile android.Path) {
527 if dstubs.Javadoc.stubsSrcJar != nil {
528 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", dstubs.Javadoc.stubsSrcJar.String())
529 }
Nan Zhangd23ac692018-09-18 10:41:33 -0700530 if dstubs.apiVersionsXml != nil {
531 fmt.Fprintln(w, "LOCAL_DROIDDOC_API_VERSIONS_XML := ", dstubs.apiVersionsXml.String())
532 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700533 if dstubs.annotationsZip != nil {
534 fmt.Fprintln(w, "LOCAL_DROIDDOC_ANNOTATIONS_ZIP := ", dstubs.annotationsZip.String())
535 }
Nan Zhang71bbe632018-09-17 14:32:21 -0700536 if dstubs.jdiffDocZip != nil {
537 fmt.Fprintln(w, "LOCAL_DROIDDOC_JDIFF_DOC_ZIP := ", dstubs.jdiffDocZip.String())
538 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700539 if dstubs.checkCurrentApiTimestamp != nil {
540 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-current-api")
541 fmt.Fprintln(w, dstubs.Name()+"-check-current-api:",
542 dstubs.checkCurrentApiTimestamp.String())
543
544 fmt.Fprintln(w, ".PHONY: checkapi")
545 fmt.Fprintln(w, "checkapi:",
546 dstubs.checkCurrentApiTimestamp.String())
547
548 fmt.Fprintln(w, ".PHONY: droidcore")
549 fmt.Fprintln(w, "droidcore: checkapi")
550 }
551 if dstubs.updateCurrentApiTimestamp != nil {
552 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-update-current-api")
553 fmt.Fprintln(w, dstubs.Name()+"-update-current-api:",
554 dstubs.updateCurrentApiTimestamp.String())
555
556 fmt.Fprintln(w, ".PHONY: update-api")
557 fmt.Fprintln(w, "update-api:",
558 dstubs.updateCurrentApiTimestamp.String())
559 }
560 if dstubs.checkLastReleasedApiTimestamp != nil {
561 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-last-released-api")
562 fmt.Fprintln(w, dstubs.Name()+"-check-last-released-api:",
563 dstubs.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100564
Adrian Roos62e34b92019-01-30 19:51:39 +0100565 if dstubs.Name() == "api-stubs-docs" || dstubs.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100566 fmt.Fprintln(w, ".PHONY: checkapi")
567 fmt.Fprintln(w, "checkapi:",
568 dstubs.checkLastReleasedApiTimestamp.String())
569
570 fmt.Fprintln(w, ".PHONY: droidcore")
571 fmt.Fprintln(w, "droidcore: checkapi")
572 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700573 }
Pete Gillin581d6082018-10-22 15:55:04 +0100574 if dstubs.checkNullabilityWarningsTimestamp != nil {
575 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings")
576 fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:",
577 dstubs.checkNullabilityWarningsTimestamp.String())
578
579 fmt.Fprintln(w, ".PHONY:", "droidcore")
580 fmt.Fprintln(w, "droidcore: ", dstubs.Name()+"-check-nullability-warnings")
581 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700582 apiFilePrefix := "INTERNAL_PLATFORM_"
583 if String(dstubs.properties.Api_tag_name) != "" {
584 apiFilePrefix += String(dstubs.properties.Api_tag_name) + "_"
585 }
586 if dstubs.apiFile != nil {
587 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", dstubs.apiFile.String())
588 }
589 if dstubs.dexApiFile != nil {
590 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", dstubs.dexApiFile.String())
591 }
592 if dstubs.privateApiFile != nil {
593 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", dstubs.privateApiFile.String())
594 }
595 if dstubs.privateDexApiFile != nil {
596 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", dstubs.privateDexApiFile.String())
597 }
598 if dstubs.removedApiFile != nil {
599 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", dstubs.removedApiFile.String())
600 }
601 if dstubs.removedDexApiFile != nil {
602 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", dstubs.removedDexApiFile.String())
603 }
604 if dstubs.exactApiFile != nil {
605 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", dstubs.exactApiFile.String())
606 }
607 },
608 },
609 }
610}
611
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700612func (app *AndroidAppImport) AndroidMk() android.AndroidMkData {
613 return android.AndroidMkData{
614 Class: "APPS",
615 OutputFile: android.OptionalPathForPath(app.outputFile),
616 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
617 Extra: []android.AndroidMkExtraFunc{
618 func(w io.Writer, outputFile android.Path) {
619 if Bool(app.properties.Privileged) {
620 fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true")
621 }
622 if app.certificate != nil {
623 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.Pem.String())
624 } else {
625 fmt.Fprintln(w, "LOCAL_CERTIFICATE := PRESIGNED")
626 }
627 if len(app.properties.Overrides) > 0 {
628 fmt.Fprintln(w, "LOCAL_OVERRIDES_PACKAGES :=", strings.Join(app.properties.Overrides, " "))
629 }
630 if len(app.dexpreopter.builtInstalled) > 0 {
631 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", app.dexpreopter.builtInstalled)
632 }
633 },
634 },
635 }
636}
637
Colin Crossd96ca352018-08-10 16:06:24 -0700638func androidMkWriteTestData(data android.Paths, ret *android.AndroidMkData) {
639 var testFiles []string
640 for _, d := range data {
641 testFiles = append(testFiles, d.String()+":"+d.Rel())
642 }
643 if len(testFiles) > 0 {
644 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
645 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUPPORT_FILES := "+strings.Join(testFiles, " "))
646 })
647 }
648}