blob: 90fdd0f77916b24dc76db41eacfb246b8e095517 [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 {
58 return android.AndroidMkData{
59 Class: "JAVA_LIBRARIES",
Colin Cross43f08db2018-11-12 10:13:39 -080060 OutputFile: android.OptionalPathForPath(library.outputFile),
Colin Cross53499412017-09-07 13:20:25 -070061 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -070062 Extra: []android.AndroidMkExtraFunc{
63 func(w io.Writer, outputFile android.Path) {
Colin Cross5beccee2017-12-07 15:28:59 -080064 if len(library.logtagsSrcs) > 0 {
65 var logtags []string
66 for _, l := range library.logtagsSrcs {
67 logtags = append(logtags, l.Rel())
68 }
69 fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES :=", strings.Join(logtags, " "))
70 }
71
Colin Cross9ae1b922018-06-26 17:59:05 -070072 if library.installFile == nil {
Colin Cross2c429dc2017-08-31 16:45:16 -070073 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
74 }
Colin Cross6ade34f2017-09-15 13:00:47 -070075 if library.dexJarFile != nil {
76 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -080077 }
78 if len(library.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -080079 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", library.dexpreopter.builtInstalled)
Colin Cross6ade34f2017-09-15 13:00:47 -070080 }
Colin Cross83bb3162018-06-25 15:48:06 -070081 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", library.sdkVersion())
Colin Cross43f08db2018-11-12 10:13:39 -080082 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String())
Nan Zhanged19fc32017-10-19 13:06:22 -070083 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
Colin Crosscb933592017-11-22 13:49:43 -080084
85 if library.jacocoReportClassesFile != nil {
86 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", library.jacocoReportClassesFile.String())
87 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -080088
Jiyong Park1be96912018-05-28 18:02:19 +090089 if len(library.exportedSdkLibs) != 0 {
90 fmt.Fprintln(w, "LOCAL_EXPORT_SDK_LIBRARIES :=", strings.Join(library.exportedSdkLibs, " "))
91 }
92
Vladimir Marko0975ee02019-04-02 10:29:55 +010093 if len(library.additionalCheckedModules) != 0 {
94 fmt.Fprintln(w, "LOCAL_ADDITIONAL_CHECKED_MODULE +=", strings.Join(library.additionalCheckedModules.Strings(), " "))
95 }
96
Colin Crosse8a7dc92019-04-23 13:00:09 -070097 if library.proguardDictionary != nil {
98 fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", library.proguardDictionary.String())
99 }
Colin Crossa18e9cf2017-08-10 17:00:19 -0700100 },
101 },
Colin Cross92430102017-10-09 14:59:32 -0700102 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
103 android.WriteAndroidMkData(w, data)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900104 library.AndroidMkHostDex(w, name, data)
Colin Cross92430102017-10-09 14:59:32 -0700105 },
Colin Crossa18e9cf2017-08-10 17:00:19 -0700106 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700107}
108
Paul Duffin42df1442019-03-20 12:45:53 +0000109// Called for modules that are a component of a test suite.
110func testSuiteComponent(w io.Writer, test_suites []string) {
111 fmt.Fprintln(w, "LOCAL_MODULE_TAGS := tests")
112 if len(test_suites) > 0 {
113 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
114 strings.Join(test_suites, " "))
115 } else {
116 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE := null-suite")
117 }
118}
119
Colin Cross05638fc2018-04-09 18:40:24 -0700120func (j *Test) AndroidMk() android.AndroidMkData {
121 data := j.Library.AndroidMk()
122 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000123 testSuiteComponent(w, j.testProperties.Test_suites)
Colin Cross303e21f2018-08-07 16:49:25 -0700124 if j.testConfig != nil {
125 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", j.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700126 }
Colin Cross05638fc2018-04-09 18:40:24 -0700127 })
128
Colin Crossd96ca352018-08-10 16:06:24 -0700129 androidMkWriteTestData(j.data, &data)
130
Colin Cross05638fc2018-04-09 18:40:24 -0700131 return data
132}
133
Paul Duffin42df1442019-03-20 12:45:53 +0000134func (j *TestHelperLibrary) AndroidMk() android.AndroidMkData {
135 data := j.Library.AndroidMk()
136 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
137 testSuiteComponent(w, j.testHelperLibraryProperties.Test_suites)
138 })
139
140 return data
141}
142
Colin Crossa18e9cf2017-08-10 17:00:19 -0700143func (prebuilt *Import) AndroidMk() android.AndroidMkData {
144 return android.AndroidMkData{
145 Class: "JAVA_LIBRARIES",
146 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Colin Cross53499412017-09-07 13:20:25 -0700147 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -0700148 Extra: []android.AndroidMkExtraFunc{
149 func(w io.Writer, outputFile android.Path) {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700150 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !Bool(prebuilt.properties.Installable))
Nan Zhanged19fc32017-10-19 13:06:22 -0700151 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800152 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Cross83bb3162018-06-25 15:48:06 -0700153 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
Colin Crossa18e9cf2017-08-10 17:00:19 -0700154 },
155 },
156 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700157}
Colin Cross10a03492017-08-10 17:09:43 -0700158
Colin Cross42be7612019-02-21 18:12:14 -0800159func (prebuilt *DexImport) AndroidMk() android.AndroidMkData {
160 return android.AndroidMkData{
161 Class: "JAVA_LIBRARIES",
162 OutputFile: android.OptionalPathForPath(prebuilt.maybeStrippedDexJarFile),
163 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
164 Extra: []android.AndroidMkExtraFunc{
165 func(w io.Writer, outputFile android.Path) {
166 if prebuilt.dexJarFile != nil {
167 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", prebuilt.dexJarFile.String())
168 // TODO(b/125517186): export the dex jar as a classes jar to match some mis-uses in Make until
169 // boot_jars_package_check.mk can check dex jars.
170 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.dexJarFile.String())
171 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.dexJarFile.String())
172 }
173 if len(prebuilt.dexpreopter.builtInstalled) > 0 {
174 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", prebuilt.dexpreopter.builtInstalled)
175 }
176 },
177 },
178 }
179}
180
Colin Crossfabb6082018-02-20 17:22:23 -0800181func (prebuilt *AARImport) AndroidMk() android.AndroidMkData {
182 return android.AndroidMkData{
183 Class: "JAVA_LIBRARIES",
184 OutputFile: android.OptionalPathForPath(prebuilt.classpathFile),
185 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
186 Extra: []android.AndroidMkExtraFunc{
187 func(w io.Writer, outputFile android.Path) {
188 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossfabb6082018-02-20 17:22:23 -0800189 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.classpathFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800190 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.classpathFile.String())
Colin Crossfabb6082018-02-20 17:22:23 -0800191 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", prebuilt.exportPackage.String())
192 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String())
Colin Cross66f78822018-05-02 12:58:28 -0700193 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", prebuilt.extraAaptPackagesFile.String())
Colin Cross10f7c4a2018-05-23 10:59:28 -0700194 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", prebuilt.manifest.String())
Colin Cross83bb3162018-06-25 15:48:06 -0700195 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
Colin Crossfabb6082018-02-20 17:22:23 -0800196 },
197 },
198 }
199}
200
Colin Cross10a03492017-08-10 17:09:43 -0700201func (binary *Binary) AndroidMk() android.AndroidMkData {
Colin Cross10a03492017-08-10 17:09:43 -0700202
Colin Cross6b4a32d2017-12-05 13:42:45 -0800203 if !binary.isWrapperVariant {
204 return android.AndroidMkData{
205 Class: "JAVA_LIBRARIES",
Colin Cross331a1212018-08-15 20:40:52 -0700206 OutputFile: android.OptionalPathForPath(binary.outputFile),
Colin Cross6b4a32d2017-12-05 13:42:45 -0800207 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Cross331a1212018-08-15 20:40:52 -0700208 Extra: []android.AndroidMkExtraFunc{
209 func(w io.Writer, outputFile android.Path) {
210 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", binary.headerJarFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800211 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", binary.implementationAndResourcesJar.String())
Colin Cross12fc2af2019-01-14 12:35:45 -0800212 if binary.dexJarFile != nil {
213 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", binary.dexJarFile.String())
214 }
215 if len(binary.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -0800216 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", binary.dexpreopter.builtInstalled)
Colin Cross12fc2af2019-01-14 12:35:45 -0800217 }
Colin Cross331a1212018-08-15 20:40:52 -0700218 },
219 },
Colin Cross6b4a32d2017-12-05 13:42:45 -0800220 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
221 android.WriteAndroidMkData(w, data)
Colin Cross19655682017-09-07 17:00:22 -0700222
Colin Cross6b4a32d2017-12-05 13:42:45 -0800223 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
224 },
225 }
226 } else {
227 return android.AndroidMkData{
228 Class: "EXECUTABLES",
229 OutputFile: android.OptionalPathForPath(binary.wrapperFile),
230 Extra: []android.AndroidMkExtraFunc{
231 func(w io.Writer, outputFile android.Path) {
232 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
233 },
234 },
235 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
236 android.WriteAndroidMkData(w, data)
237
238 // Ensure that the wrapper script timestamp is always updated when the jar is updated
239 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
240 fmt.Fprintln(w, "jar_installed_module :=")
241 },
242 }
Colin Cross10a03492017-08-10 17:09:43 -0700243 }
244}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800245
246func (app *AndroidApp) AndroidMk() android.AndroidMkData {
247 return android.AndroidMkData{
248 Class: "APPS",
249 OutputFile: android.OptionalPathForPath(app.outputFile),
250 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
251 Extra: []android.AndroidMkExtraFunc{
252 func(w io.Writer, outputFile android.Path) {
Jaewoong Jung9109d722019-01-30 13:13:52 -0800253 // TODO(jungjw): This, outputting two LOCAL_MODULE lines, works, but is not ideal. Find a better solution.
254 if app.Name() != app.installApkName {
255 fmt.Fprintln(w, "# Overridden by PRODUCT_PACKAGE_NAME_OVERRIDES")
256 fmt.Fprintln(w, "LOCAL_MODULE :=", app.installApkName)
257 }
Colin Cross70798562017-12-13 22:42:59 -0800258 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", app.exportPackage.String())
259 if app.dexJarFile != nil {
260 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String())
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800261 }
Colin Cross331a1212018-08-15 20:40:52 -0700262 if app.implementationAndResourcesJar != nil {
263 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", app.implementationAndResourcesJar.String())
Colin Cross5dfabfb2017-12-14 13:19:01 -0800264 }
265 if app.headerJarFile != nil {
266 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", app.headerJarFile.String())
267 }
Colin Crossf6237212018-10-29 23:14:58 -0700268 if app.bundleFile != nil {
269 fmt.Fprintln(w, "LOCAL_SOONG_BUNDLE :=", app.bundleFile.String())
270 }
Colin Cross70798562017-12-13 22:42:59 -0800271 if app.jacocoReportClassesFile != nil {
272 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", app.jacocoReportClassesFile.String())
273 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800274 if app.proguardDictionary != nil {
275 fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", app.proguardDictionary.String())
276 }
Colin Cross70798562017-12-13 22:42:59 -0800277
278 if app.Name() == "framework-res" {
279 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
280 // Make base_rules.mk not put framework-res in a subdirectory called
281 // framework_res.
282 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
283 }
284
Anton Hansson53c88442019-03-18 15:53:16 +0000285 filterRRO := func(filter overlayType) android.Paths {
286 var paths android.Paths
287 for _, d := range app.rroDirs {
288 if d.overlayType == filter {
289 paths = append(paths, d.path)
290 }
291 }
Colin Crossa140bb02018-04-17 10:52:26 -0700292 // Reverse the order, Soong stores rroDirs in aapt2 order (low to high priority), but Make
293 // expects it in LOCAL_RESOURCE_DIRS order (high to low priority).
Anton Hansson53c88442019-03-18 15:53:16 +0000294 return android.ReversePaths(paths)
295 }
296 deviceRRODirs := filterRRO(device)
297 if len(deviceRRODirs) > 0 {
298 fmt.Fprintln(w, "LOCAL_SOONG_DEVICE_RRO_DIRS :=", strings.Join(deviceRRODirs.Strings(), " "))
299 }
300 productRRODirs := filterRRO(product)
301 if len(productRRODirs) > 0 {
302 fmt.Fprintln(w, "LOCAL_SOONG_PRODUCT_RRO_DIRS :=", strings.Join(productRRODirs.Strings(), " "))
Colin Cross70798562017-12-13 22:42:59 -0800303 }
304
305 if Bool(app.appProperties.Export_package_resources) {
306 fmt.Fprintln(w, "LOCAL_EXPORT_PACKAGE_RESOURCES := true")
307 }
308
309 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", app.manifestPath.String())
310
Colin Cross16056062017-12-13 22:46:28 -0800311 if Bool(app.appProperties.Privileged) {
312 fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true")
313 }
Colin Crosse1731a52017-12-14 11:22:55 -0800314
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900315 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.Pem.String())
Jaewoong Jung9109d722019-01-30 13:13:52 -0800316 if overriddenPkgs := app.getOverriddenPackages(); len(overriddenPkgs) > 0 {
317 fmt.Fprintln(w, "LOCAL_OVERRIDES_PACKAGES :=", strings.Join(overriddenPkgs, " "))
Jason Monkd4122be2018-08-10 09:33:36 -0400318 }
Colin Crossa4f08812018-10-02 22:03:40 -0700319
320 for _, jniLib := range app.installJniLibs {
321 fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), "+=", jniLib.name)
322 }
Colin Cross43f08db2018-11-12 10:13:39 -0800323 if len(app.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -0800324 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", app.dexpreopter.builtInstalled)
Colin Cross43f08db2018-11-12 10:13:39 -0800325 }
Colin Crosse560c4a2019-03-19 16:03:11 -0700326 for _, split := range app.aapt.splits {
327 install := "$(LOCAL_MODULE_PATH)/" + strings.TrimSuffix(app.installApkName, ".apk") + split.suffix + ".apk"
328 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED +=", split.path.String()+":"+install)
329 }
Jaewoong Jung98772792019-07-01 17:15:13 -0700330 if app.noticeOutputs.Merged.Valid() {
331 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n",
332 app.installApkName, app.noticeOutputs.Merged.String(), app.installApkName+"_NOTICE")
333 }
334 if app.noticeOutputs.TxtOutput.Valid() {
335 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n",
336 app.installApkName, app.noticeOutputs.TxtOutput.String(), app.installApkName+"_NOTICE.txt")
337 }
338 if app.noticeOutputs.HtmlOutput.Valid() {
339 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n",
340 app.installApkName, app.noticeOutputs.HtmlOutput.String(), app.installApkName+"_NOTICE.html")
341 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800342 },
343 },
344 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700345}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800346
Jaewoong Jung9109d722019-01-30 13:13:52 -0800347func (a *AndroidApp) getOverriddenPackages() []string {
348 var overridden []string
349 if len(a.appProperties.Overrides) > 0 {
350 overridden = append(overridden, a.appProperties.Overrides...)
351 }
352 if a.Name() != a.installApkName {
353 overridden = append(overridden, a.Name())
354 }
355 return overridden
356}
357
Colin Crossae5caf52018-05-22 11:11:52 -0700358func (a *AndroidTest) AndroidMk() android.AndroidMkData {
359 data := a.AndroidApp.AndroidMk()
360 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000361 testSuiteComponent(w, a.testProperties.Test_suites)
Colin Cross303e21f2018-08-07 16:49:25 -0700362 if a.testConfig != nil {
363 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", a.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700364 }
Colin Crossae5caf52018-05-22 11:11:52 -0700365 })
Colin Crossd96ca352018-08-10 16:06:24 -0700366 androidMkWriteTestData(a.data, &data)
Colin Crossae5caf52018-05-22 11:11:52 -0700367
368 return data
369}
370
Colin Cross252fc6f2018-10-04 15:22:03 -0700371func (a *AndroidTestHelperApp) AndroidMk() android.AndroidMkData {
372 data := a.AndroidApp.AndroidMk()
373 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000374 testSuiteComponent(w, a.appTestHelperAppProperties.Test_suites)
Colin Cross252fc6f2018-10-04 15:22:03 -0700375 })
376
377 return data
378}
379
Colin Crossa97c5d32018-03-28 14:58:31 -0700380func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
381 data := a.Library.AndroidMk()
382
383 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossa54974c2018-10-29 23:15:37 -0700384 if a.aarFile != nil {
385 fmt.Fprintln(w, "LOCAL_SOONG_AAR :=", a.aarFile.String())
386 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700387
388 if a.Name() == "framework-res" {
389 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
390 // Make base_rules.mk not put framework-res in a subdirectory called
391 // framework_res.
392 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
393 }
394
395 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
Colin Cross66f78822018-05-02 12:58:28 -0700396 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", a.extraAaptPackagesFile.String())
Colin Cross90c25c62019-04-19 16:22:57 -0700397 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.mergedManifestFile.String())
Colin Cross89c31582018-04-30 15:55:11 -0700398 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
399 strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
Colin Crossa97c5d32018-03-28 14:58:31 -0700400 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossa97c5d32018-03-28 14:58:31 -0700401 })
402
403 return data
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800404}
Nan Zhang581fd212018-01-10 16:06:12 -0800405
406func (jd *Javadoc) AndroidMk() android.AndroidMkData {
407 return android.AndroidMkData{
408 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800409 OutputFile: android.OptionalPathForPath(jd.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700410 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800411 Extra: []android.AndroidMkExtraFunc{
412 func(w io.Writer, outputFile android.Path) {
Colin Cross38b40df2018-04-10 16:14:46 -0700413 if BoolDefault(jd.properties.Installable, true) {
Nan Zhang581fd212018-01-10 16:06:12 -0800414 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", jd.docZip.String())
415 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800416 if jd.stubsSrcJar != nil {
417 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", jd.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800418 }
419 },
420 },
421 }
422}
423
424func (ddoc *Droiddoc) AndroidMk() android.AndroidMkData {
425 return android.AndroidMkData{
426 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800427 OutputFile: android.OptionalPathForPath(ddoc.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700428 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800429 Extra: []android.AndroidMkExtraFunc{
430 func(w io.Writer, outputFile android.Path) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700431 if BoolDefault(ddoc.Javadoc.properties.Installable, true) && ddoc.Javadoc.docZip != nil {
Nan Zhang581fd212018-01-10 16:06:12 -0800432 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", ddoc.Javadoc.docZip.String())
433 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800434 if ddoc.Javadoc.stubsSrcJar != nil {
435 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", ddoc.Javadoc.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800436 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700437 if ddoc.checkCurrentApiTimestamp != nil {
438 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-current-api")
439 fmt.Fprintln(w, ddoc.Name()+"-check-current-api:",
440 ddoc.checkCurrentApiTimestamp.String())
441
442 fmt.Fprintln(w, ".PHONY: checkapi")
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900443 fmt.Fprintln(w, "checkapi:",
Nan Zhang61819ce2018-05-04 18:49:16 -0700444 ddoc.checkCurrentApiTimestamp.String())
445
446 fmt.Fprintln(w, ".PHONY: droidcore")
447 fmt.Fprintln(w, "droidcore: checkapi")
448 }
449 if ddoc.updateCurrentApiTimestamp != nil {
Dan Willemsena03c43a2018-07-24 13:00:52 -0700450 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-update-current-api")
Nan Zhang61819ce2018-05-04 18:49:16 -0700451 fmt.Fprintln(w, ddoc.Name()+"-update-current-api:",
452 ddoc.updateCurrentApiTimestamp.String())
453
454 fmt.Fprintln(w, ".PHONY: update-api")
455 fmt.Fprintln(w, "update-api:",
456 ddoc.updateCurrentApiTimestamp.String())
457 }
458 if ddoc.checkLastReleasedApiTimestamp != nil {
459 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-last-released-api")
460 fmt.Fprintln(w, ddoc.Name()+"-check-last-released-api:",
461 ddoc.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100462
Adrian Roos62e34b92019-01-30 19:51:39 +0100463 if ddoc.Name() == "api-stubs-docs" || ddoc.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100464 fmt.Fprintln(w, ".PHONY: checkapi")
465 fmt.Fprintln(w, "checkapi:",
466 ddoc.checkLastReleasedApiTimestamp.String())
467
468 fmt.Fprintln(w, ".PHONY: droidcore")
469 fmt.Fprintln(w, "droidcore: checkapi")
470 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700471 }
Nan Zhang28c68b92018-03-13 16:17:01 -0700472 apiFilePrefix := "INTERNAL_PLATFORM_"
473 if String(ddoc.properties.Api_tag_name) != "" {
474 apiFilePrefix += String(ddoc.properties.Api_tag_name) + "_"
475 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700476 if ddoc.apiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700477 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", ddoc.apiFile.String())
478 }
David Brazdilfbe4cc32018-05-31 13:56:46 +0100479 if ddoc.dexApiFile != nil {
480 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", ddoc.dexApiFile.String())
481 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700482 if ddoc.privateApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700483 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", ddoc.privateApiFile.String())
484 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700485 if ddoc.privateDexApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700486 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", ddoc.privateDexApiFile.String())
487 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700488 if ddoc.removedApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700489 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", ddoc.removedApiFile.String())
490 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700491 if ddoc.removedDexApiFile != nil {
David Brazdilaac0c3c2018-04-24 16:23:29 +0100492 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", ddoc.removedDexApiFile.String())
493 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700494 if ddoc.exactApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700495 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", ddoc.exactApiFile.String())
496 }
Nan Zhang66dc2362018-08-14 20:41:04 -0700497 if ddoc.proguardFile != nil {
498 fmt.Fprintln(w, apiFilePrefix+"PROGUARD_FILE := ", ddoc.proguardFile.String())
499 }
Nan Zhang581fd212018-01-10 16:06:12 -0800500 },
501 },
502 }
503}
Colin Crossd96ca352018-08-10 16:06:24 -0700504
Nan Zhang1598a9e2018-09-04 17:14:32 -0700505func (dstubs *Droidstubs) AndroidMk() android.AndroidMkData {
506 return android.AndroidMkData{
507 Class: "JAVA_LIBRARIES",
508 OutputFile: android.OptionalPathForPath(dstubs.stubsSrcJar),
509 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
510 Extra: []android.AndroidMkExtraFunc{
511 func(w io.Writer, outputFile android.Path) {
512 if dstubs.Javadoc.stubsSrcJar != nil {
513 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", dstubs.Javadoc.stubsSrcJar.String())
514 }
Nan Zhangd23ac692018-09-18 10:41:33 -0700515 if dstubs.apiVersionsXml != nil {
516 fmt.Fprintln(w, "LOCAL_DROIDDOC_API_VERSIONS_XML := ", dstubs.apiVersionsXml.String())
517 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700518 if dstubs.annotationsZip != nil {
519 fmt.Fprintln(w, "LOCAL_DROIDDOC_ANNOTATIONS_ZIP := ", dstubs.annotationsZip.String())
520 }
Nan Zhang71bbe632018-09-17 14:32:21 -0700521 if dstubs.jdiffDocZip != nil {
522 fmt.Fprintln(w, "LOCAL_DROIDDOC_JDIFF_DOC_ZIP := ", dstubs.jdiffDocZip.String())
523 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700524 if dstubs.checkCurrentApiTimestamp != nil {
525 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-current-api")
526 fmt.Fprintln(w, dstubs.Name()+"-check-current-api:",
527 dstubs.checkCurrentApiTimestamp.String())
528
529 fmt.Fprintln(w, ".PHONY: checkapi")
530 fmt.Fprintln(w, "checkapi:",
531 dstubs.checkCurrentApiTimestamp.String())
532
533 fmt.Fprintln(w, ".PHONY: droidcore")
534 fmt.Fprintln(w, "droidcore: checkapi")
535 }
536 if dstubs.updateCurrentApiTimestamp != nil {
537 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-update-current-api")
538 fmt.Fprintln(w, dstubs.Name()+"-update-current-api:",
539 dstubs.updateCurrentApiTimestamp.String())
540
541 fmt.Fprintln(w, ".PHONY: update-api")
542 fmt.Fprintln(w, "update-api:",
543 dstubs.updateCurrentApiTimestamp.String())
544 }
545 if dstubs.checkLastReleasedApiTimestamp != nil {
546 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-last-released-api")
547 fmt.Fprintln(w, dstubs.Name()+"-check-last-released-api:",
548 dstubs.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100549
Adrian Roos62e34b92019-01-30 19:51:39 +0100550 if dstubs.Name() == "api-stubs-docs" || dstubs.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100551 fmt.Fprintln(w, ".PHONY: checkapi")
552 fmt.Fprintln(w, "checkapi:",
553 dstubs.checkLastReleasedApiTimestamp.String())
554
555 fmt.Fprintln(w, ".PHONY: droidcore")
556 fmt.Fprintln(w, "droidcore: checkapi")
557 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700558 }
Pete Gillin581d6082018-10-22 15:55:04 +0100559 if dstubs.checkNullabilityWarningsTimestamp != nil {
560 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings")
561 fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:",
562 dstubs.checkNullabilityWarningsTimestamp.String())
563
564 fmt.Fprintln(w, ".PHONY:", "droidcore")
565 fmt.Fprintln(w, "droidcore: ", dstubs.Name()+"-check-nullability-warnings")
566 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700567 apiFilePrefix := "INTERNAL_PLATFORM_"
568 if String(dstubs.properties.Api_tag_name) != "" {
569 apiFilePrefix += String(dstubs.properties.Api_tag_name) + "_"
570 }
571 if dstubs.apiFile != nil {
572 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", dstubs.apiFile.String())
573 }
574 if dstubs.dexApiFile != nil {
575 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", dstubs.dexApiFile.String())
576 }
577 if dstubs.privateApiFile != nil {
578 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", dstubs.privateApiFile.String())
579 }
580 if dstubs.privateDexApiFile != nil {
581 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", dstubs.privateDexApiFile.String())
582 }
583 if dstubs.removedApiFile != nil {
584 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", dstubs.removedApiFile.String())
585 }
586 if dstubs.removedDexApiFile != nil {
587 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", dstubs.removedDexApiFile.String())
588 }
589 if dstubs.exactApiFile != nil {
590 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", dstubs.exactApiFile.String())
591 }
592 },
593 },
594 }
595}
596
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700597func (app *AndroidAppImport) AndroidMk() android.AndroidMkData {
598 return android.AndroidMkData{
599 Class: "APPS",
600 OutputFile: android.OptionalPathForPath(app.outputFile),
601 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
602 Extra: []android.AndroidMkExtraFunc{
603 func(w io.Writer, outputFile android.Path) {
604 if Bool(app.properties.Privileged) {
605 fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true")
606 }
607 if app.certificate != nil {
608 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.Pem.String())
609 } else {
610 fmt.Fprintln(w, "LOCAL_CERTIFICATE := PRESIGNED")
611 }
612 if len(app.properties.Overrides) > 0 {
613 fmt.Fprintln(w, "LOCAL_OVERRIDES_PACKAGES :=", strings.Join(app.properties.Overrides, " "))
614 }
615 if len(app.dexpreopter.builtInstalled) > 0 {
616 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", app.dexpreopter.builtInstalled)
617 }
618 },
619 },
620 }
621}
622
Colin Crossd96ca352018-08-10 16:06:24 -0700623func androidMkWriteTestData(data android.Paths, ret *android.AndroidMkData) {
624 var testFiles []string
625 for _, d := range data {
626 testFiles = append(testFiles, d.String()+":"+d.Rel())
627 }
628 if len(testFiles) > 0 {
629 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
630 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUPPORT_FILES := "+strings.Join(testFiles, " "))
631 })
632 }
633}