blob: 39c2d1342606be863f544c5afb8a584f5e675a8b [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 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800330 },
331 },
332 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700333}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800334
Jaewoong Jung9109d722019-01-30 13:13:52 -0800335func (a *AndroidApp) getOverriddenPackages() []string {
336 var overridden []string
337 if len(a.appProperties.Overrides) > 0 {
338 overridden = append(overridden, a.appProperties.Overrides...)
339 }
340 if a.Name() != a.installApkName {
341 overridden = append(overridden, a.Name())
342 }
343 return overridden
344}
345
Colin Crossae5caf52018-05-22 11:11:52 -0700346func (a *AndroidTest) AndroidMk() android.AndroidMkData {
347 data := a.AndroidApp.AndroidMk()
348 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000349 testSuiteComponent(w, a.testProperties.Test_suites)
Colin Cross303e21f2018-08-07 16:49:25 -0700350 if a.testConfig != nil {
351 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", a.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700352 }
Colin Crossae5caf52018-05-22 11:11:52 -0700353 })
Colin Crossd96ca352018-08-10 16:06:24 -0700354 androidMkWriteTestData(a.data, &data)
Colin Crossae5caf52018-05-22 11:11:52 -0700355
356 return data
357}
358
Colin Cross252fc6f2018-10-04 15:22:03 -0700359func (a *AndroidTestHelperApp) AndroidMk() android.AndroidMkData {
360 data := a.AndroidApp.AndroidMk()
361 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000362 testSuiteComponent(w, a.appTestHelperAppProperties.Test_suites)
Colin Cross252fc6f2018-10-04 15:22:03 -0700363 })
364
365 return data
366}
367
Colin Crossa97c5d32018-03-28 14:58:31 -0700368func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
369 data := a.Library.AndroidMk()
370
371 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossa54974c2018-10-29 23:15:37 -0700372 if a.aarFile != nil {
373 fmt.Fprintln(w, "LOCAL_SOONG_AAR :=", a.aarFile.String())
374 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700375
376 if a.Name() == "framework-res" {
377 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
378 // Make base_rules.mk not put framework-res in a subdirectory called
379 // framework_res.
380 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
381 }
382
383 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
Colin Cross66f78822018-05-02 12:58:28 -0700384 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", a.extraAaptPackagesFile.String())
Colin Cross90c25c62019-04-19 16:22:57 -0700385 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.mergedManifestFile.String())
Colin Cross89c31582018-04-30 15:55:11 -0700386 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
387 strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
Colin Crossa97c5d32018-03-28 14:58:31 -0700388 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossa97c5d32018-03-28 14:58:31 -0700389 })
390
391 return data
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800392}
Nan Zhang581fd212018-01-10 16:06:12 -0800393
394func (jd *Javadoc) AndroidMk() android.AndroidMkData {
395 return android.AndroidMkData{
396 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800397 OutputFile: android.OptionalPathForPath(jd.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700398 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800399 Extra: []android.AndroidMkExtraFunc{
400 func(w io.Writer, outputFile android.Path) {
Colin Cross38b40df2018-04-10 16:14:46 -0700401 if BoolDefault(jd.properties.Installable, true) {
Nan Zhang581fd212018-01-10 16:06:12 -0800402 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", jd.docZip.String())
403 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800404 if jd.stubsSrcJar != nil {
405 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", jd.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800406 }
407 },
408 },
409 }
410}
411
412func (ddoc *Droiddoc) AndroidMk() android.AndroidMkData {
413 return android.AndroidMkData{
414 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800415 OutputFile: android.OptionalPathForPath(ddoc.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700416 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800417 Extra: []android.AndroidMkExtraFunc{
418 func(w io.Writer, outputFile android.Path) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700419 if BoolDefault(ddoc.Javadoc.properties.Installable, true) && ddoc.Javadoc.docZip != nil {
Nan Zhang581fd212018-01-10 16:06:12 -0800420 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", ddoc.Javadoc.docZip.String())
421 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800422 if ddoc.Javadoc.stubsSrcJar != nil {
423 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", ddoc.Javadoc.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800424 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700425 if ddoc.checkCurrentApiTimestamp != nil {
426 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-current-api")
427 fmt.Fprintln(w, ddoc.Name()+"-check-current-api:",
428 ddoc.checkCurrentApiTimestamp.String())
429
430 fmt.Fprintln(w, ".PHONY: checkapi")
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900431 fmt.Fprintln(w, "checkapi:",
Nan Zhang61819ce2018-05-04 18:49:16 -0700432 ddoc.checkCurrentApiTimestamp.String())
433
434 fmt.Fprintln(w, ".PHONY: droidcore")
435 fmt.Fprintln(w, "droidcore: checkapi")
436 }
437 if ddoc.updateCurrentApiTimestamp != nil {
Dan Willemsena03c43a2018-07-24 13:00:52 -0700438 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-update-current-api")
Nan Zhang61819ce2018-05-04 18:49:16 -0700439 fmt.Fprintln(w, ddoc.Name()+"-update-current-api:",
440 ddoc.updateCurrentApiTimestamp.String())
441
442 fmt.Fprintln(w, ".PHONY: update-api")
443 fmt.Fprintln(w, "update-api:",
444 ddoc.updateCurrentApiTimestamp.String())
445 }
446 if ddoc.checkLastReleasedApiTimestamp != nil {
447 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-last-released-api")
448 fmt.Fprintln(w, ddoc.Name()+"-check-last-released-api:",
449 ddoc.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100450
Adrian Roos62e34b92019-01-30 19:51:39 +0100451 if ddoc.Name() == "api-stubs-docs" || ddoc.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100452 fmt.Fprintln(w, ".PHONY: checkapi")
453 fmt.Fprintln(w, "checkapi:",
454 ddoc.checkLastReleasedApiTimestamp.String())
455
456 fmt.Fprintln(w, ".PHONY: droidcore")
457 fmt.Fprintln(w, "droidcore: checkapi")
458 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700459 }
Nan Zhang28c68b92018-03-13 16:17:01 -0700460 apiFilePrefix := "INTERNAL_PLATFORM_"
461 if String(ddoc.properties.Api_tag_name) != "" {
462 apiFilePrefix += String(ddoc.properties.Api_tag_name) + "_"
463 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700464 if ddoc.apiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700465 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", ddoc.apiFile.String())
466 }
David Brazdilfbe4cc32018-05-31 13:56:46 +0100467 if ddoc.dexApiFile != nil {
468 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", ddoc.dexApiFile.String())
469 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700470 if ddoc.privateApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700471 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", ddoc.privateApiFile.String())
472 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700473 if ddoc.privateDexApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700474 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", ddoc.privateDexApiFile.String())
475 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700476 if ddoc.removedApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700477 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", ddoc.removedApiFile.String())
478 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700479 if ddoc.removedDexApiFile != nil {
David Brazdilaac0c3c2018-04-24 16:23:29 +0100480 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", ddoc.removedDexApiFile.String())
481 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700482 if ddoc.exactApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700483 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", ddoc.exactApiFile.String())
484 }
Nan Zhang66dc2362018-08-14 20:41:04 -0700485 if ddoc.proguardFile != nil {
486 fmt.Fprintln(w, apiFilePrefix+"PROGUARD_FILE := ", ddoc.proguardFile.String())
487 }
Nan Zhang581fd212018-01-10 16:06:12 -0800488 },
489 },
490 }
491}
Colin Crossd96ca352018-08-10 16:06:24 -0700492
Nan Zhang1598a9e2018-09-04 17:14:32 -0700493func (dstubs *Droidstubs) AndroidMk() android.AndroidMkData {
494 return android.AndroidMkData{
495 Class: "JAVA_LIBRARIES",
496 OutputFile: android.OptionalPathForPath(dstubs.stubsSrcJar),
497 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
498 Extra: []android.AndroidMkExtraFunc{
499 func(w io.Writer, outputFile android.Path) {
500 if dstubs.Javadoc.stubsSrcJar != nil {
501 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", dstubs.Javadoc.stubsSrcJar.String())
502 }
Nan Zhangd23ac692018-09-18 10:41:33 -0700503 if dstubs.apiVersionsXml != nil {
504 fmt.Fprintln(w, "LOCAL_DROIDDOC_API_VERSIONS_XML := ", dstubs.apiVersionsXml.String())
505 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700506 if dstubs.annotationsZip != nil {
507 fmt.Fprintln(w, "LOCAL_DROIDDOC_ANNOTATIONS_ZIP := ", dstubs.annotationsZip.String())
508 }
Nan Zhang71bbe632018-09-17 14:32:21 -0700509 if dstubs.jdiffDocZip != nil {
510 fmt.Fprintln(w, "LOCAL_DROIDDOC_JDIFF_DOC_ZIP := ", dstubs.jdiffDocZip.String())
511 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700512 if dstubs.checkCurrentApiTimestamp != nil {
513 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-current-api")
514 fmt.Fprintln(w, dstubs.Name()+"-check-current-api:",
515 dstubs.checkCurrentApiTimestamp.String())
516
517 fmt.Fprintln(w, ".PHONY: checkapi")
518 fmt.Fprintln(w, "checkapi:",
519 dstubs.checkCurrentApiTimestamp.String())
520
521 fmt.Fprintln(w, ".PHONY: droidcore")
522 fmt.Fprintln(w, "droidcore: checkapi")
523 }
524 if dstubs.updateCurrentApiTimestamp != nil {
525 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-update-current-api")
526 fmt.Fprintln(w, dstubs.Name()+"-update-current-api:",
527 dstubs.updateCurrentApiTimestamp.String())
528
529 fmt.Fprintln(w, ".PHONY: update-api")
530 fmt.Fprintln(w, "update-api:",
531 dstubs.updateCurrentApiTimestamp.String())
532 }
533 if dstubs.checkLastReleasedApiTimestamp != nil {
534 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-last-released-api")
535 fmt.Fprintln(w, dstubs.Name()+"-check-last-released-api:",
536 dstubs.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100537
Adrian Roos62e34b92019-01-30 19:51:39 +0100538 if dstubs.Name() == "api-stubs-docs" || dstubs.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100539 fmt.Fprintln(w, ".PHONY: checkapi")
540 fmt.Fprintln(w, "checkapi:",
541 dstubs.checkLastReleasedApiTimestamp.String())
542
543 fmt.Fprintln(w, ".PHONY: droidcore")
544 fmt.Fprintln(w, "droidcore: checkapi")
545 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700546 }
Pete Gillin581d6082018-10-22 15:55:04 +0100547 if dstubs.checkNullabilityWarningsTimestamp != nil {
548 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings")
549 fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:",
550 dstubs.checkNullabilityWarningsTimestamp.String())
551
552 fmt.Fprintln(w, ".PHONY:", "droidcore")
553 fmt.Fprintln(w, "droidcore: ", dstubs.Name()+"-check-nullability-warnings")
554 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700555 apiFilePrefix := "INTERNAL_PLATFORM_"
556 if String(dstubs.properties.Api_tag_name) != "" {
557 apiFilePrefix += String(dstubs.properties.Api_tag_name) + "_"
558 }
559 if dstubs.apiFile != nil {
560 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", dstubs.apiFile.String())
561 }
562 if dstubs.dexApiFile != nil {
563 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", dstubs.dexApiFile.String())
564 }
565 if dstubs.privateApiFile != nil {
566 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", dstubs.privateApiFile.String())
567 }
568 if dstubs.privateDexApiFile != nil {
569 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", dstubs.privateDexApiFile.String())
570 }
571 if dstubs.removedApiFile != nil {
572 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", dstubs.removedApiFile.String())
573 }
574 if dstubs.removedDexApiFile != nil {
575 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", dstubs.removedDexApiFile.String())
576 }
577 if dstubs.exactApiFile != nil {
578 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", dstubs.exactApiFile.String())
579 }
580 },
581 },
582 }
583}
584
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700585func (app *AndroidAppImport) AndroidMk() android.AndroidMkData {
586 return android.AndroidMkData{
587 Class: "APPS",
588 OutputFile: android.OptionalPathForPath(app.outputFile),
589 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
590 Extra: []android.AndroidMkExtraFunc{
591 func(w io.Writer, outputFile android.Path) {
592 if Bool(app.properties.Privileged) {
593 fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true")
594 }
595 if app.certificate != nil {
596 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.Pem.String())
597 } else {
598 fmt.Fprintln(w, "LOCAL_CERTIFICATE := PRESIGNED")
599 }
600 if len(app.properties.Overrides) > 0 {
601 fmt.Fprintln(w, "LOCAL_OVERRIDES_PACKAGES :=", strings.Join(app.properties.Overrides, " "))
602 }
603 if len(app.dexpreopter.builtInstalled) > 0 {
604 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", app.dexpreopter.builtInstalled)
605 }
606 },
607 },
608 }
609}
610
Colin Crossd96ca352018-08-10 16:06:24 -0700611func androidMkWriteTestData(data android.Paths, ret *android.AndroidMkData) {
612 var testFiles []string
613 for _, d := range data {
614 testFiles = append(testFiles, d.String()+":"+d.Rel())
615 }
616 if len(testFiles) > 0 {
617 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
618 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUPPORT_FILES := "+strings.Join(testFiles, " "))
619 })
620 }
621}