blob: 095acd7decaf25cad8a5f80570b1aa07024d5117 [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 }
Sundong Ahn054b19a2018-10-19 13:46:09 +090050 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
51 }
52}
53
Colin Crossa18e9cf2017-08-10 17:00:19 -070054func (library *Library) AndroidMk() android.AndroidMkData {
55 return android.AndroidMkData{
56 Class: "JAVA_LIBRARIES",
Colin Cross43f08db2018-11-12 10:13:39 -080057 OutputFile: android.OptionalPathForPath(library.outputFile),
Colin Cross53499412017-09-07 13:20:25 -070058 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -070059 Extra: []android.AndroidMkExtraFunc{
60 func(w io.Writer, outputFile android.Path) {
Colin Cross5beccee2017-12-07 15:28:59 -080061 if len(library.logtagsSrcs) > 0 {
62 var logtags []string
63 for _, l := range library.logtagsSrcs {
64 logtags = append(logtags, l.Rel())
65 }
66 fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES :=", strings.Join(logtags, " "))
67 }
68
Colin Cross9ae1b922018-06-26 17:59:05 -070069 if library.installFile == nil {
Colin Cross2c429dc2017-08-31 16:45:16 -070070 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
71 }
Colin Cross6ade34f2017-09-15 13:00:47 -070072 if library.dexJarFile != nil {
73 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -080074 }
75 if len(library.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -080076 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", library.dexpreopter.builtInstalled)
Colin Cross6ade34f2017-09-15 13:00:47 -070077 }
Colin Cross83bb3162018-06-25 15:48:06 -070078 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", library.sdkVersion())
Colin Cross43f08db2018-11-12 10:13:39 -080079 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String())
Nan Zhanged19fc32017-10-19 13:06:22 -070080 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
Colin Crosscb933592017-11-22 13:49:43 -080081
82 if library.jacocoReportClassesFile != nil {
83 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", library.jacocoReportClassesFile.String())
84 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -080085
Jiyong Park1be96912018-05-28 18:02:19 +090086 if len(library.exportedSdkLibs) != 0 {
87 fmt.Fprintln(w, "LOCAL_EXPORT_SDK_LIBRARIES :=", strings.Join(library.exportedSdkLibs, " "))
88 }
89
Vladimir Marko0975ee02019-04-02 10:29:55 +010090 if len(library.additionalCheckedModules) != 0 {
91 fmt.Fprintln(w, "LOCAL_ADDITIONAL_CHECKED_MODULE +=", strings.Join(library.additionalCheckedModules.Strings(), " "))
92 }
93
Colin Crosse8a7dc92019-04-23 13:00:09 -070094 if library.proguardDictionary != nil {
95 fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", library.proguardDictionary.String())
96 }
97
Colin Cross5ab4e6d2017-11-22 16:20:45 -080098 // Temporary hack: export sources used to compile framework.jar to Make
99 // to be used for droiddoc
100 // TODO(ccross): remove this once droiddoc is in soong
Mathew Inwoodebe29ce2018-09-04 14:26:19 +0100101 if (library.Name() == "framework") || (library.Name() == "framework-annotation-proc") {
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800102 fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCS :=", strings.Join(library.compiledJavaSrcs.Strings(), " "))
103 fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCJARS :=", strings.Join(library.compiledSrcJars.Strings(), " "))
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 {
149 return android.AndroidMkData{
150 Class: "JAVA_LIBRARIES",
151 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Colin Cross53499412017-09-07 13:20:25 -0700152 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -0700153 Extra: []android.AndroidMkExtraFunc{
154 func(w io.Writer, outputFile android.Path) {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700155 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !Bool(prebuilt.properties.Installable))
Nan Zhanged19fc32017-10-19 13:06:22 -0700156 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800157 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Cross83bb3162018-06-25 15:48:06 -0700158 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
Colin Crossa18e9cf2017-08-10 17:00:19 -0700159 },
160 },
161 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700162}
Colin Cross10a03492017-08-10 17:09:43 -0700163
Colin Cross42be7612019-02-21 18:12:14 -0800164func (prebuilt *DexImport) AndroidMk() android.AndroidMkData {
165 return android.AndroidMkData{
166 Class: "JAVA_LIBRARIES",
167 OutputFile: android.OptionalPathForPath(prebuilt.maybeStrippedDexJarFile),
168 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
169 Extra: []android.AndroidMkExtraFunc{
170 func(w io.Writer, outputFile android.Path) {
171 if prebuilt.dexJarFile != nil {
172 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", prebuilt.dexJarFile.String())
173 // TODO(b/125517186): export the dex jar as a classes jar to match some mis-uses in Make until
174 // boot_jars_package_check.mk can check dex jars.
175 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.dexJarFile.String())
176 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.dexJarFile.String())
177 }
178 if len(prebuilt.dexpreopter.builtInstalled) > 0 {
179 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", prebuilt.dexpreopter.builtInstalled)
180 }
181 },
182 },
183 }
184}
185
Colin Crossfabb6082018-02-20 17:22:23 -0800186func (prebuilt *AARImport) AndroidMk() android.AndroidMkData {
187 return android.AndroidMkData{
188 Class: "JAVA_LIBRARIES",
189 OutputFile: android.OptionalPathForPath(prebuilt.classpathFile),
190 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
191 Extra: []android.AndroidMkExtraFunc{
192 func(w io.Writer, outputFile android.Path) {
193 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossfabb6082018-02-20 17:22:23 -0800194 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.classpathFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800195 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.classpathFile.String())
Colin Crossfabb6082018-02-20 17:22:23 -0800196 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", prebuilt.exportPackage.String())
197 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String())
Colin Cross66f78822018-05-02 12:58:28 -0700198 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", prebuilt.extraAaptPackagesFile.String())
Colin Cross10f7c4a2018-05-23 10:59:28 -0700199 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", prebuilt.manifest.String())
Colin Cross83bb3162018-06-25 15:48:06 -0700200 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
Colin Crossfabb6082018-02-20 17:22:23 -0800201 },
202 },
203 }
204}
205
Colin Cross10a03492017-08-10 17:09:43 -0700206func (binary *Binary) AndroidMk() android.AndroidMkData {
Colin Cross10a03492017-08-10 17:09:43 -0700207
Colin Cross6b4a32d2017-12-05 13:42:45 -0800208 if !binary.isWrapperVariant {
209 return android.AndroidMkData{
210 Class: "JAVA_LIBRARIES",
Colin Cross331a1212018-08-15 20:40:52 -0700211 OutputFile: android.OptionalPathForPath(binary.outputFile),
Colin Cross6b4a32d2017-12-05 13:42:45 -0800212 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Cross331a1212018-08-15 20:40:52 -0700213 Extra: []android.AndroidMkExtraFunc{
214 func(w io.Writer, outputFile android.Path) {
215 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", binary.headerJarFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800216 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", binary.implementationAndResourcesJar.String())
Colin Cross12fc2af2019-01-14 12:35:45 -0800217 if binary.dexJarFile != nil {
218 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", binary.dexJarFile.String())
219 }
220 if len(binary.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -0800221 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", binary.dexpreopter.builtInstalled)
Colin Cross12fc2af2019-01-14 12:35:45 -0800222 }
Colin Cross331a1212018-08-15 20:40:52 -0700223 },
224 },
Colin Cross6b4a32d2017-12-05 13:42:45 -0800225 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
226 android.WriteAndroidMkData(w, data)
Colin Cross19655682017-09-07 17:00:22 -0700227
Colin Cross6b4a32d2017-12-05 13:42:45 -0800228 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
229 },
230 }
231 } else {
232 return android.AndroidMkData{
233 Class: "EXECUTABLES",
234 OutputFile: android.OptionalPathForPath(binary.wrapperFile),
235 Extra: []android.AndroidMkExtraFunc{
236 func(w io.Writer, outputFile android.Path) {
237 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
238 },
239 },
240 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
241 android.WriteAndroidMkData(w, data)
242
243 // Ensure that the wrapper script timestamp is always updated when the jar is updated
244 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
245 fmt.Fprintln(w, "jar_installed_module :=")
246 },
247 }
Colin Cross10a03492017-08-10 17:09:43 -0700248 }
249}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800250
251func (app *AndroidApp) AndroidMk() android.AndroidMkData {
252 return android.AndroidMkData{
253 Class: "APPS",
254 OutputFile: android.OptionalPathForPath(app.outputFile),
255 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
256 Extra: []android.AndroidMkExtraFunc{
257 func(w io.Writer, outputFile android.Path) {
Jaewoong Jung9109d722019-01-30 13:13:52 -0800258 // TODO(jungjw): This, outputting two LOCAL_MODULE lines, works, but is not ideal. Find a better solution.
259 if app.Name() != app.installApkName {
260 fmt.Fprintln(w, "# Overridden by PRODUCT_PACKAGE_NAME_OVERRIDES")
261 fmt.Fprintln(w, "LOCAL_MODULE :=", app.installApkName)
262 }
Colin Cross70798562017-12-13 22:42:59 -0800263 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", app.exportPackage.String())
264 if app.dexJarFile != nil {
265 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String())
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800266 }
Colin Cross331a1212018-08-15 20:40:52 -0700267 if app.implementationAndResourcesJar != nil {
268 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", app.implementationAndResourcesJar.String())
Colin Cross5dfabfb2017-12-14 13:19:01 -0800269 }
270 if app.headerJarFile != nil {
271 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", app.headerJarFile.String())
272 }
Colin Crossf6237212018-10-29 23:14:58 -0700273 if app.bundleFile != nil {
274 fmt.Fprintln(w, "LOCAL_SOONG_BUNDLE :=", app.bundleFile.String())
275 }
Colin Cross70798562017-12-13 22:42:59 -0800276 if app.jacocoReportClassesFile != nil {
277 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", app.jacocoReportClassesFile.String())
278 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800279 if app.proguardDictionary != nil {
280 fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", app.proguardDictionary.String())
281 }
Colin Cross70798562017-12-13 22:42:59 -0800282
283 if app.Name() == "framework-res" {
284 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
285 // Make base_rules.mk not put framework-res in a subdirectory called
286 // framework_res.
287 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
288 }
289
Anton Hansson53c88442019-03-18 15:53:16 +0000290 filterRRO := func(filter overlayType) android.Paths {
291 var paths android.Paths
292 for _, d := range app.rroDirs {
293 if d.overlayType == filter {
294 paths = append(paths, d.path)
295 }
296 }
Colin Crossa140bb02018-04-17 10:52:26 -0700297 // Reverse the order, Soong stores rroDirs in aapt2 order (low to high priority), but Make
298 // expects it in LOCAL_RESOURCE_DIRS order (high to low priority).
Anton Hansson53c88442019-03-18 15:53:16 +0000299 return android.ReversePaths(paths)
300 }
301 deviceRRODirs := filterRRO(device)
302 if len(deviceRRODirs) > 0 {
303 fmt.Fprintln(w, "LOCAL_SOONG_DEVICE_RRO_DIRS :=", strings.Join(deviceRRODirs.Strings(), " "))
304 }
305 productRRODirs := filterRRO(product)
306 if len(productRRODirs) > 0 {
307 fmt.Fprintln(w, "LOCAL_SOONG_PRODUCT_RRO_DIRS :=", strings.Join(productRRODirs.Strings(), " "))
Colin Cross70798562017-12-13 22:42:59 -0800308 }
309
310 if Bool(app.appProperties.Export_package_resources) {
311 fmt.Fprintln(w, "LOCAL_EXPORT_PACKAGE_RESOURCES := true")
312 }
313
314 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", app.manifestPath.String())
315
Colin Cross16056062017-12-13 22:46:28 -0800316 if Bool(app.appProperties.Privileged) {
317 fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true")
318 }
Colin Crosse1731a52017-12-14 11:22:55 -0800319
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900320 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.Pem.String())
Jaewoong Jung9109d722019-01-30 13:13:52 -0800321 if overriddenPkgs := app.getOverriddenPackages(); len(overriddenPkgs) > 0 {
322 fmt.Fprintln(w, "LOCAL_OVERRIDES_PACKAGES :=", strings.Join(overriddenPkgs, " "))
Jason Monkd4122be2018-08-10 09:33:36 -0400323 }
Colin Crossa4f08812018-10-02 22:03:40 -0700324
325 for _, jniLib := range app.installJniLibs {
326 fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), "+=", jniLib.name)
327 }
Colin Cross43f08db2018-11-12 10:13:39 -0800328 if len(app.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -0800329 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", app.dexpreopter.builtInstalled)
Colin Cross43f08db2018-11-12 10:13:39 -0800330 }
Colin Crosse560c4a2019-03-19 16:03:11 -0700331 for _, split := range app.aapt.splits {
332 install := "$(LOCAL_MODULE_PATH)/" + strings.TrimSuffix(app.installApkName, ".apk") + split.suffix + ".apk"
333 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED +=", split.path.String()+":"+install)
334 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800335 },
336 },
337 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700338}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800339
Jaewoong Jung9109d722019-01-30 13:13:52 -0800340func (a *AndroidApp) getOverriddenPackages() []string {
341 var overridden []string
342 if len(a.appProperties.Overrides) > 0 {
343 overridden = append(overridden, a.appProperties.Overrides...)
344 }
345 if a.Name() != a.installApkName {
346 overridden = append(overridden, a.Name())
347 }
348 return overridden
349}
350
Colin Crossae5caf52018-05-22 11:11:52 -0700351func (a *AndroidTest) AndroidMk() android.AndroidMkData {
352 data := a.AndroidApp.AndroidMk()
353 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000354 testSuiteComponent(w, a.testProperties.Test_suites)
Colin Cross303e21f2018-08-07 16:49:25 -0700355 if a.testConfig != nil {
356 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", a.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700357 }
Colin Crossae5caf52018-05-22 11:11:52 -0700358 })
Colin Crossd96ca352018-08-10 16:06:24 -0700359 androidMkWriteTestData(a.data, &data)
Colin Crossae5caf52018-05-22 11:11:52 -0700360
361 return data
362}
363
Colin Cross252fc6f2018-10-04 15:22:03 -0700364func (a *AndroidTestHelperApp) AndroidMk() android.AndroidMkData {
365 data := a.AndroidApp.AndroidMk()
366 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000367 testSuiteComponent(w, a.appTestHelperAppProperties.Test_suites)
Colin Cross252fc6f2018-10-04 15:22:03 -0700368 })
369
370 return data
371}
372
Colin Crossa97c5d32018-03-28 14:58:31 -0700373func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
374 data := a.Library.AndroidMk()
375
376 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossa54974c2018-10-29 23:15:37 -0700377 if a.aarFile != nil {
378 fmt.Fprintln(w, "LOCAL_SOONG_AAR :=", a.aarFile.String())
379 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700380
381 if a.Name() == "framework-res" {
382 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
383 // Make base_rules.mk not put framework-res in a subdirectory called
384 // framework_res.
385 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
386 }
387
388 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
Colin Cross66f78822018-05-02 12:58:28 -0700389 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", a.extraAaptPackagesFile.String())
Colin Crossa97c5d32018-03-28 14:58:31 -0700390 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.manifestPath.String())
Colin Cross89c31582018-04-30 15:55:11 -0700391 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
392 strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
Colin Crossa97c5d32018-03-28 14:58:31 -0700393 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossa97c5d32018-03-28 14:58:31 -0700394 })
395
396 return data
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800397}
Nan Zhang581fd212018-01-10 16:06:12 -0800398
399func (jd *Javadoc) AndroidMk() android.AndroidMkData {
400 return android.AndroidMkData{
401 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800402 OutputFile: android.OptionalPathForPath(jd.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700403 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800404 Extra: []android.AndroidMkExtraFunc{
405 func(w io.Writer, outputFile android.Path) {
Colin Cross38b40df2018-04-10 16:14:46 -0700406 if BoolDefault(jd.properties.Installable, true) {
Nan Zhang581fd212018-01-10 16:06:12 -0800407 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", jd.docZip.String())
408 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800409 if jd.stubsSrcJar != nil {
410 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", jd.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800411 }
412 },
413 },
414 }
415}
416
417func (ddoc *Droiddoc) AndroidMk() android.AndroidMkData {
418 return android.AndroidMkData{
419 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800420 OutputFile: android.OptionalPathForPath(ddoc.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700421 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800422 Extra: []android.AndroidMkExtraFunc{
423 func(w io.Writer, outputFile android.Path) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700424 if BoolDefault(ddoc.Javadoc.properties.Installable, true) && ddoc.Javadoc.docZip != nil {
Nan Zhang581fd212018-01-10 16:06:12 -0800425 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", ddoc.Javadoc.docZip.String())
426 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800427 if ddoc.Javadoc.stubsSrcJar != nil {
428 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", ddoc.Javadoc.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800429 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700430 if ddoc.checkCurrentApiTimestamp != nil {
431 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-current-api")
432 fmt.Fprintln(w, ddoc.Name()+"-check-current-api:",
433 ddoc.checkCurrentApiTimestamp.String())
434
435 fmt.Fprintln(w, ".PHONY: checkapi")
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900436 fmt.Fprintln(w, "checkapi:",
Nan Zhang61819ce2018-05-04 18:49:16 -0700437 ddoc.checkCurrentApiTimestamp.String())
438
439 fmt.Fprintln(w, ".PHONY: droidcore")
440 fmt.Fprintln(w, "droidcore: checkapi")
441 }
442 if ddoc.updateCurrentApiTimestamp != nil {
Dan Willemsena03c43a2018-07-24 13:00:52 -0700443 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-update-current-api")
Nan Zhang61819ce2018-05-04 18:49:16 -0700444 fmt.Fprintln(w, ddoc.Name()+"-update-current-api:",
445 ddoc.updateCurrentApiTimestamp.String())
446
447 fmt.Fprintln(w, ".PHONY: update-api")
448 fmt.Fprintln(w, "update-api:",
449 ddoc.updateCurrentApiTimestamp.String())
450 }
451 if ddoc.checkLastReleasedApiTimestamp != nil {
452 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-last-released-api")
453 fmt.Fprintln(w, ddoc.Name()+"-check-last-released-api:",
454 ddoc.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100455
Adrian Roos62e34b92019-01-30 19:51:39 +0100456 if ddoc.Name() == "api-stubs-docs" || ddoc.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100457 fmt.Fprintln(w, ".PHONY: checkapi")
458 fmt.Fprintln(w, "checkapi:",
459 ddoc.checkLastReleasedApiTimestamp.String())
460
461 fmt.Fprintln(w, ".PHONY: droidcore")
462 fmt.Fprintln(w, "droidcore: checkapi")
463 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700464 }
Nan Zhang28c68b92018-03-13 16:17:01 -0700465 apiFilePrefix := "INTERNAL_PLATFORM_"
466 if String(ddoc.properties.Api_tag_name) != "" {
467 apiFilePrefix += String(ddoc.properties.Api_tag_name) + "_"
468 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700469 if ddoc.apiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700470 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", ddoc.apiFile.String())
471 }
David Brazdilfbe4cc32018-05-31 13:56:46 +0100472 if ddoc.dexApiFile != nil {
473 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", ddoc.dexApiFile.String())
474 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700475 if ddoc.privateApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700476 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", ddoc.privateApiFile.String())
477 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700478 if ddoc.privateDexApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700479 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", ddoc.privateDexApiFile.String())
480 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700481 if ddoc.removedApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700482 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", ddoc.removedApiFile.String())
483 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700484 if ddoc.removedDexApiFile != nil {
David Brazdilaac0c3c2018-04-24 16:23:29 +0100485 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", ddoc.removedDexApiFile.String())
486 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700487 if ddoc.exactApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700488 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", ddoc.exactApiFile.String())
489 }
Nan Zhang66dc2362018-08-14 20:41:04 -0700490 if ddoc.proguardFile != nil {
491 fmt.Fprintln(w, apiFilePrefix+"PROGUARD_FILE := ", ddoc.proguardFile.String())
492 }
Nan Zhang581fd212018-01-10 16:06:12 -0800493 },
494 },
495 }
496}
Colin Crossd96ca352018-08-10 16:06:24 -0700497
Nan Zhang1598a9e2018-09-04 17:14:32 -0700498func (dstubs *Droidstubs) AndroidMk() android.AndroidMkData {
499 return android.AndroidMkData{
500 Class: "JAVA_LIBRARIES",
501 OutputFile: android.OptionalPathForPath(dstubs.stubsSrcJar),
502 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
503 Extra: []android.AndroidMkExtraFunc{
504 func(w io.Writer, outputFile android.Path) {
505 if dstubs.Javadoc.stubsSrcJar != nil {
506 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", dstubs.Javadoc.stubsSrcJar.String())
507 }
Nan Zhangd23ac692018-09-18 10:41:33 -0700508 if dstubs.apiVersionsXml != nil {
509 fmt.Fprintln(w, "LOCAL_DROIDDOC_API_VERSIONS_XML := ", dstubs.apiVersionsXml.String())
510 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700511 if dstubs.annotationsZip != nil {
512 fmt.Fprintln(w, "LOCAL_DROIDDOC_ANNOTATIONS_ZIP := ", dstubs.annotationsZip.String())
513 }
Nan Zhang71bbe632018-09-17 14:32:21 -0700514 if dstubs.jdiffDocZip != nil {
515 fmt.Fprintln(w, "LOCAL_DROIDDOC_JDIFF_DOC_ZIP := ", dstubs.jdiffDocZip.String())
516 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700517 if dstubs.checkCurrentApiTimestamp != nil {
518 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-current-api")
519 fmt.Fprintln(w, dstubs.Name()+"-check-current-api:",
520 dstubs.checkCurrentApiTimestamp.String())
521
522 fmt.Fprintln(w, ".PHONY: checkapi")
523 fmt.Fprintln(w, "checkapi:",
524 dstubs.checkCurrentApiTimestamp.String())
525
526 fmt.Fprintln(w, ".PHONY: droidcore")
527 fmt.Fprintln(w, "droidcore: checkapi")
528 }
529 if dstubs.updateCurrentApiTimestamp != nil {
530 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-update-current-api")
531 fmt.Fprintln(w, dstubs.Name()+"-update-current-api:",
532 dstubs.updateCurrentApiTimestamp.String())
533
534 fmt.Fprintln(w, ".PHONY: update-api")
535 fmt.Fprintln(w, "update-api:",
536 dstubs.updateCurrentApiTimestamp.String())
537 }
538 if dstubs.checkLastReleasedApiTimestamp != nil {
539 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-last-released-api")
540 fmt.Fprintln(w, dstubs.Name()+"-check-last-released-api:",
541 dstubs.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100542
Adrian Roos62e34b92019-01-30 19:51:39 +0100543 if dstubs.Name() == "api-stubs-docs" || dstubs.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100544 fmt.Fprintln(w, ".PHONY: checkapi")
545 fmt.Fprintln(w, "checkapi:",
546 dstubs.checkLastReleasedApiTimestamp.String())
547
548 fmt.Fprintln(w, ".PHONY: droidcore")
549 fmt.Fprintln(w, "droidcore: checkapi")
550 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700551 }
Pete Gillin581d6082018-10-22 15:55:04 +0100552 if dstubs.checkNullabilityWarningsTimestamp != nil {
553 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings")
554 fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:",
555 dstubs.checkNullabilityWarningsTimestamp.String())
556
557 fmt.Fprintln(w, ".PHONY:", "droidcore")
558 fmt.Fprintln(w, "droidcore: ", dstubs.Name()+"-check-nullability-warnings")
559 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700560 apiFilePrefix := "INTERNAL_PLATFORM_"
561 if String(dstubs.properties.Api_tag_name) != "" {
562 apiFilePrefix += String(dstubs.properties.Api_tag_name) + "_"
563 }
564 if dstubs.apiFile != nil {
565 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", dstubs.apiFile.String())
566 }
567 if dstubs.dexApiFile != nil {
568 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", dstubs.dexApiFile.String())
569 }
570 if dstubs.privateApiFile != nil {
571 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", dstubs.privateApiFile.String())
572 }
573 if dstubs.privateDexApiFile != nil {
574 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", dstubs.privateDexApiFile.String())
575 }
576 if dstubs.removedApiFile != nil {
577 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", dstubs.removedApiFile.String())
578 }
579 if dstubs.removedDexApiFile != nil {
580 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", dstubs.removedDexApiFile.String())
581 }
582 if dstubs.exactApiFile != nil {
583 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", dstubs.exactApiFile.String())
584 }
585 },
586 },
587 }
588}
589
Colin Crossd96ca352018-08-10 16:06:24 -0700590func androidMkWriteTestData(data android.Paths, ret *android.AndroidMkData) {
591 var testFiles []string
592 for _, d := range data {
593 testFiles = append(testFiles, d.String()+":"+d.Rel())
594 }
595 if len(testFiles) > 0 {
596 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
597 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUPPORT_FILES := "+strings.Join(testFiles, " "))
598 })
599 }
600}