blob: 5491b3ebaaa05d7dda9e3a5dc254125003fdaece [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 }
100
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800101 // Temporary hack: export sources used to compile framework.jar to Make
102 // to be used for droiddoc
103 // TODO(ccross): remove this once droiddoc is in soong
Mathew Inwoodebe29ce2018-09-04 14:26:19 +0100104 if (library.Name() == "framework") || (library.Name() == "framework-annotation-proc") {
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800105 fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCS :=", strings.Join(library.compiledJavaSrcs.Strings(), " "))
106 fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCJARS :=", strings.Join(library.compiledSrcJars.Strings(), " "))
107 }
Colin Crossa18e9cf2017-08-10 17:00:19 -0700108 },
109 },
Colin Cross92430102017-10-09 14:59:32 -0700110 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
111 android.WriteAndroidMkData(w, data)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900112 library.AndroidMkHostDex(w, name, data)
Colin Cross92430102017-10-09 14:59:32 -0700113 },
Colin Crossa18e9cf2017-08-10 17:00:19 -0700114 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700115}
116
Paul Duffin42df1442019-03-20 12:45:53 +0000117// Called for modules that are a component of a test suite.
118func testSuiteComponent(w io.Writer, test_suites []string) {
119 fmt.Fprintln(w, "LOCAL_MODULE_TAGS := tests")
120 if len(test_suites) > 0 {
121 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
122 strings.Join(test_suites, " "))
123 } else {
124 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE := null-suite")
125 }
126}
127
Colin Cross05638fc2018-04-09 18:40:24 -0700128func (j *Test) AndroidMk() android.AndroidMkData {
129 data := j.Library.AndroidMk()
130 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000131 testSuiteComponent(w, j.testProperties.Test_suites)
Colin Cross303e21f2018-08-07 16:49:25 -0700132 if j.testConfig != nil {
133 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", j.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700134 }
Colin Cross05638fc2018-04-09 18:40:24 -0700135 })
136
Colin Crossd96ca352018-08-10 16:06:24 -0700137 androidMkWriteTestData(j.data, &data)
138
Colin Cross05638fc2018-04-09 18:40:24 -0700139 return data
140}
141
Paul Duffin42df1442019-03-20 12:45:53 +0000142func (j *TestHelperLibrary) AndroidMk() android.AndroidMkData {
143 data := j.Library.AndroidMk()
144 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
145 testSuiteComponent(w, j.testHelperLibraryProperties.Test_suites)
146 })
147
148 return data
149}
150
Colin Crossa18e9cf2017-08-10 17:00:19 -0700151func (prebuilt *Import) AndroidMk() android.AndroidMkData {
152 return android.AndroidMkData{
153 Class: "JAVA_LIBRARIES",
154 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Colin Cross53499412017-09-07 13:20:25 -0700155 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -0700156 Extra: []android.AndroidMkExtraFunc{
157 func(w io.Writer, outputFile android.Path) {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700158 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !Bool(prebuilt.properties.Installable))
Nan Zhanged19fc32017-10-19 13:06:22 -0700159 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800160 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Cross83bb3162018-06-25 15:48:06 -0700161 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
Colin Crossa18e9cf2017-08-10 17:00:19 -0700162 },
163 },
164 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700165}
Colin Cross10a03492017-08-10 17:09:43 -0700166
Colin Cross42be7612019-02-21 18:12:14 -0800167func (prebuilt *DexImport) AndroidMk() android.AndroidMkData {
168 return android.AndroidMkData{
169 Class: "JAVA_LIBRARIES",
170 OutputFile: android.OptionalPathForPath(prebuilt.maybeStrippedDexJarFile),
171 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
172 Extra: []android.AndroidMkExtraFunc{
173 func(w io.Writer, outputFile android.Path) {
174 if prebuilt.dexJarFile != nil {
175 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", prebuilt.dexJarFile.String())
176 // TODO(b/125517186): export the dex jar as a classes jar to match some mis-uses in Make until
177 // boot_jars_package_check.mk can check dex jars.
178 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.dexJarFile.String())
179 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.dexJarFile.String())
180 }
181 if len(prebuilt.dexpreopter.builtInstalled) > 0 {
182 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", prebuilt.dexpreopter.builtInstalled)
183 }
184 },
185 },
186 }
187}
188
Colin Crossfabb6082018-02-20 17:22:23 -0800189func (prebuilt *AARImport) AndroidMk() android.AndroidMkData {
190 return android.AndroidMkData{
191 Class: "JAVA_LIBRARIES",
192 OutputFile: android.OptionalPathForPath(prebuilt.classpathFile),
193 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
194 Extra: []android.AndroidMkExtraFunc{
195 func(w io.Writer, outputFile android.Path) {
196 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossfabb6082018-02-20 17:22:23 -0800197 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.classpathFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800198 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.classpathFile.String())
Colin Crossfabb6082018-02-20 17:22:23 -0800199 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", prebuilt.exportPackage.String())
200 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String())
Colin Cross66f78822018-05-02 12:58:28 -0700201 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", prebuilt.extraAaptPackagesFile.String())
Colin Cross10f7c4a2018-05-23 10:59:28 -0700202 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", prebuilt.manifest.String())
Colin Cross83bb3162018-06-25 15:48:06 -0700203 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
Colin Crossfabb6082018-02-20 17:22:23 -0800204 },
205 },
206 }
207}
208
Colin Cross10a03492017-08-10 17:09:43 -0700209func (binary *Binary) AndroidMk() android.AndroidMkData {
Colin Cross10a03492017-08-10 17:09:43 -0700210
Colin Cross6b4a32d2017-12-05 13:42:45 -0800211 if !binary.isWrapperVariant {
212 return android.AndroidMkData{
213 Class: "JAVA_LIBRARIES",
Colin Cross331a1212018-08-15 20:40:52 -0700214 OutputFile: android.OptionalPathForPath(binary.outputFile),
Colin Cross6b4a32d2017-12-05 13:42:45 -0800215 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Cross331a1212018-08-15 20:40:52 -0700216 Extra: []android.AndroidMkExtraFunc{
217 func(w io.Writer, outputFile android.Path) {
218 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", binary.headerJarFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800219 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", binary.implementationAndResourcesJar.String())
Colin Cross12fc2af2019-01-14 12:35:45 -0800220 if binary.dexJarFile != nil {
221 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", binary.dexJarFile.String())
222 }
223 if len(binary.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -0800224 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", binary.dexpreopter.builtInstalled)
Colin Cross12fc2af2019-01-14 12:35:45 -0800225 }
Colin Cross331a1212018-08-15 20:40:52 -0700226 },
227 },
Colin Cross6b4a32d2017-12-05 13:42:45 -0800228 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
229 android.WriteAndroidMkData(w, data)
Colin Cross19655682017-09-07 17:00:22 -0700230
Colin Cross6b4a32d2017-12-05 13:42:45 -0800231 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
232 },
233 }
234 } else {
235 return android.AndroidMkData{
236 Class: "EXECUTABLES",
237 OutputFile: android.OptionalPathForPath(binary.wrapperFile),
238 Extra: []android.AndroidMkExtraFunc{
239 func(w io.Writer, outputFile android.Path) {
240 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
241 },
242 },
243 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
244 android.WriteAndroidMkData(w, data)
245
246 // Ensure that the wrapper script timestamp is always updated when the jar is updated
247 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
248 fmt.Fprintln(w, "jar_installed_module :=")
249 },
250 }
Colin Cross10a03492017-08-10 17:09:43 -0700251 }
252}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800253
254func (app *AndroidApp) AndroidMk() android.AndroidMkData {
255 return android.AndroidMkData{
256 Class: "APPS",
257 OutputFile: android.OptionalPathForPath(app.outputFile),
258 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
259 Extra: []android.AndroidMkExtraFunc{
260 func(w io.Writer, outputFile android.Path) {
Jaewoong Jung9109d722019-01-30 13:13:52 -0800261 // TODO(jungjw): This, outputting two LOCAL_MODULE lines, works, but is not ideal. Find a better solution.
262 if app.Name() != app.installApkName {
263 fmt.Fprintln(w, "# Overridden by PRODUCT_PACKAGE_NAME_OVERRIDES")
264 fmt.Fprintln(w, "LOCAL_MODULE :=", app.installApkName)
265 }
Colin Cross70798562017-12-13 22:42:59 -0800266 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", app.exportPackage.String())
267 if app.dexJarFile != nil {
268 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String())
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800269 }
Colin Cross331a1212018-08-15 20:40:52 -0700270 if app.implementationAndResourcesJar != nil {
271 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", app.implementationAndResourcesJar.String())
Colin Cross5dfabfb2017-12-14 13:19:01 -0800272 }
273 if app.headerJarFile != nil {
274 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", app.headerJarFile.String())
275 }
Colin Crossf6237212018-10-29 23:14:58 -0700276 if app.bundleFile != nil {
277 fmt.Fprintln(w, "LOCAL_SOONG_BUNDLE :=", app.bundleFile.String())
278 }
Colin Cross70798562017-12-13 22:42:59 -0800279 if app.jacocoReportClassesFile != nil {
280 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", app.jacocoReportClassesFile.String())
281 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800282 if app.proguardDictionary != nil {
283 fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", app.proguardDictionary.String())
284 }
Colin Cross70798562017-12-13 22:42:59 -0800285
286 if app.Name() == "framework-res" {
287 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
288 // Make base_rules.mk not put framework-res in a subdirectory called
289 // framework_res.
290 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
291 }
292
Anton Hansson53c88442019-03-18 15:53:16 +0000293 filterRRO := func(filter overlayType) android.Paths {
294 var paths android.Paths
295 for _, d := range app.rroDirs {
296 if d.overlayType == filter {
297 paths = append(paths, d.path)
298 }
299 }
Colin Crossa140bb02018-04-17 10:52:26 -0700300 // Reverse the order, Soong stores rroDirs in aapt2 order (low to high priority), but Make
301 // expects it in LOCAL_RESOURCE_DIRS order (high to low priority).
Anton Hansson53c88442019-03-18 15:53:16 +0000302 return android.ReversePaths(paths)
303 }
304 deviceRRODirs := filterRRO(device)
305 if len(deviceRRODirs) > 0 {
306 fmt.Fprintln(w, "LOCAL_SOONG_DEVICE_RRO_DIRS :=", strings.Join(deviceRRODirs.Strings(), " "))
307 }
308 productRRODirs := filterRRO(product)
309 if len(productRRODirs) > 0 {
310 fmt.Fprintln(w, "LOCAL_SOONG_PRODUCT_RRO_DIRS :=", strings.Join(productRRODirs.Strings(), " "))
Colin Cross70798562017-12-13 22:42:59 -0800311 }
312
313 if Bool(app.appProperties.Export_package_resources) {
314 fmt.Fprintln(w, "LOCAL_EXPORT_PACKAGE_RESOURCES := true")
315 }
316
317 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", app.manifestPath.String())
318
Colin Cross16056062017-12-13 22:46:28 -0800319 if Bool(app.appProperties.Privileged) {
320 fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true")
321 }
Colin Crosse1731a52017-12-14 11:22:55 -0800322
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900323 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.Pem.String())
Jaewoong Jung9109d722019-01-30 13:13:52 -0800324 if overriddenPkgs := app.getOverriddenPackages(); len(overriddenPkgs) > 0 {
325 fmt.Fprintln(w, "LOCAL_OVERRIDES_PACKAGES :=", strings.Join(overriddenPkgs, " "))
Jason Monkd4122be2018-08-10 09:33:36 -0400326 }
Colin Crossa4f08812018-10-02 22:03:40 -0700327
328 for _, jniLib := range app.installJniLibs {
329 fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), "+=", jniLib.name)
330 }
Colin Cross43f08db2018-11-12 10:13:39 -0800331 if len(app.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -0800332 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", app.dexpreopter.builtInstalled)
Colin Cross43f08db2018-11-12 10:13:39 -0800333 }
Colin Crosse560c4a2019-03-19 16:03:11 -0700334 for _, split := range app.aapt.splits {
335 install := "$(LOCAL_MODULE_PATH)/" + strings.TrimSuffix(app.installApkName, ".apk") + split.suffix + ".apk"
336 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED +=", split.path.String()+":"+install)
337 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800338 },
339 },
340 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700341}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800342
Jaewoong Jung9109d722019-01-30 13:13:52 -0800343func (a *AndroidApp) getOverriddenPackages() []string {
344 var overridden []string
345 if len(a.appProperties.Overrides) > 0 {
346 overridden = append(overridden, a.appProperties.Overrides...)
347 }
348 if a.Name() != a.installApkName {
349 overridden = append(overridden, a.Name())
350 }
351 return overridden
352}
353
Colin Crossae5caf52018-05-22 11:11:52 -0700354func (a *AndroidTest) AndroidMk() android.AndroidMkData {
355 data := a.AndroidApp.AndroidMk()
356 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000357 testSuiteComponent(w, a.testProperties.Test_suites)
Colin Cross303e21f2018-08-07 16:49:25 -0700358 if a.testConfig != nil {
359 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", a.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700360 }
Colin Crossae5caf52018-05-22 11:11:52 -0700361 })
Colin Crossd96ca352018-08-10 16:06:24 -0700362 androidMkWriteTestData(a.data, &data)
Colin Crossae5caf52018-05-22 11:11:52 -0700363
364 return data
365}
366
Colin Cross252fc6f2018-10-04 15:22:03 -0700367func (a *AndroidTestHelperApp) AndroidMk() android.AndroidMkData {
368 data := a.AndroidApp.AndroidMk()
369 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000370 testSuiteComponent(w, a.appTestHelperAppProperties.Test_suites)
Colin Cross252fc6f2018-10-04 15:22:03 -0700371 })
372
373 return data
374}
375
Colin Crossa97c5d32018-03-28 14:58:31 -0700376func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
377 data := a.Library.AndroidMk()
378
379 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossa54974c2018-10-29 23:15:37 -0700380 if a.aarFile != nil {
381 fmt.Fprintln(w, "LOCAL_SOONG_AAR :=", a.aarFile.String())
382 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700383
384 if a.Name() == "framework-res" {
385 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
386 // Make base_rules.mk not put framework-res in a subdirectory called
387 // framework_res.
388 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
389 }
390
391 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
Colin Cross66f78822018-05-02 12:58:28 -0700392 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", a.extraAaptPackagesFile.String())
Colin Cross90c25c62019-04-19 16:22:57 -0700393 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.mergedManifestFile.String())
Colin Cross89c31582018-04-30 15:55:11 -0700394 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
395 strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
Colin Crossa97c5d32018-03-28 14:58:31 -0700396 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossa97c5d32018-03-28 14:58:31 -0700397 })
398
399 return data
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800400}
Nan Zhang581fd212018-01-10 16:06:12 -0800401
402func (jd *Javadoc) AndroidMk() android.AndroidMkData {
403 return android.AndroidMkData{
404 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800405 OutputFile: android.OptionalPathForPath(jd.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700406 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800407 Extra: []android.AndroidMkExtraFunc{
408 func(w io.Writer, outputFile android.Path) {
Colin Cross38b40df2018-04-10 16:14:46 -0700409 if BoolDefault(jd.properties.Installable, true) {
Nan Zhang581fd212018-01-10 16:06:12 -0800410 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", jd.docZip.String())
411 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800412 if jd.stubsSrcJar != nil {
413 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", jd.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800414 }
415 },
416 },
417 }
418}
419
420func (ddoc *Droiddoc) AndroidMk() android.AndroidMkData {
421 return android.AndroidMkData{
422 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800423 OutputFile: android.OptionalPathForPath(ddoc.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700424 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800425 Extra: []android.AndroidMkExtraFunc{
426 func(w io.Writer, outputFile android.Path) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700427 if BoolDefault(ddoc.Javadoc.properties.Installable, true) && ddoc.Javadoc.docZip != nil {
Nan Zhang581fd212018-01-10 16:06:12 -0800428 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", ddoc.Javadoc.docZip.String())
429 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800430 if ddoc.Javadoc.stubsSrcJar != nil {
431 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", ddoc.Javadoc.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800432 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700433 if ddoc.checkCurrentApiTimestamp != nil {
434 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-current-api")
435 fmt.Fprintln(w, ddoc.Name()+"-check-current-api:",
436 ddoc.checkCurrentApiTimestamp.String())
437
438 fmt.Fprintln(w, ".PHONY: checkapi")
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900439 fmt.Fprintln(w, "checkapi:",
Nan Zhang61819ce2018-05-04 18:49:16 -0700440 ddoc.checkCurrentApiTimestamp.String())
441
442 fmt.Fprintln(w, ".PHONY: droidcore")
443 fmt.Fprintln(w, "droidcore: checkapi")
444 }
445 if ddoc.updateCurrentApiTimestamp != nil {
Dan Willemsena03c43a2018-07-24 13:00:52 -0700446 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-update-current-api")
Nan Zhang61819ce2018-05-04 18:49:16 -0700447 fmt.Fprintln(w, ddoc.Name()+"-update-current-api:",
448 ddoc.updateCurrentApiTimestamp.String())
449
450 fmt.Fprintln(w, ".PHONY: update-api")
451 fmt.Fprintln(w, "update-api:",
452 ddoc.updateCurrentApiTimestamp.String())
453 }
454 if ddoc.checkLastReleasedApiTimestamp != nil {
455 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-last-released-api")
456 fmt.Fprintln(w, ddoc.Name()+"-check-last-released-api:",
457 ddoc.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100458
Adrian Roos62e34b92019-01-30 19:51:39 +0100459 if ddoc.Name() == "api-stubs-docs" || ddoc.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100460 fmt.Fprintln(w, ".PHONY: checkapi")
461 fmt.Fprintln(w, "checkapi:",
462 ddoc.checkLastReleasedApiTimestamp.String())
463
464 fmt.Fprintln(w, ".PHONY: droidcore")
465 fmt.Fprintln(w, "droidcore: checkapi")
466 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700467 }
Nan Zhang28c68b92018-03-13 16:17:01 -0700468 apiFilePrefix := "INTERNAL_PLATFORM_"
469 if String(ddoc.properties.Api_tag_name) != "" {
470 apiFilePrefix += String(ddoc.properties.Api_tag_name) + "_"
471 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700472 if ddoc.apiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700473 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", ddoc.apiFile.String())
474 }
David Brazdilfbe4cc32018-05-31 13:56:46 +0100475 if ddoc.dexApiFile != nil {
476 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", ddoc.dexApiFile.String())
477 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700478 if ddoc.privateApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700479 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", ddoc.privateApiFile.String())
480 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700481 if ddoc.privateDexApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700482 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", ddoc.privateDexApiFile.String())
483 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700484 if ddoc.removedApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700485 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", ddoc.removedApiFile.String())
486 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700487 if ddoc.removedDexApiFile != nil {
David Brazdilaac0c3c2018-04-24 16:23:29 +0100488 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", ddoc.removedDexApiFile.String())
489 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700490 if ddoc.exactApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700491 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", ddoc.exactApiFile.String())
492 }
Nan Zhang66dc2362018-08-14 20:41:04 -0700493 if ddoc.proguardFile != nil {
494 fmt.Fprintln(w, apiFilePrefix+"PROGUARD_FILE := ", ddoc.proguardFile.String())
495 }
Nan Zhang581fd212018-01-10 16:06:12 -0800496 },
497 },
498 }
499}
Colin Crossd96ca352018-08-10 16:06:24 -0700500
Nan Zhang1598a9e2018-09-04 17:14:32 -0700501func (dstubs *Droidstubs) AndroidMk() android.AndroidMkData {
502 return android.AndroidMkData{
503 Class: "JAVA_LIBRARIES",
504 OutputFile: android.OptionalPathForPath(dstubs.stubsSrcJar),
505 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
506 Extra: []android.AndroidMkExtraFunc{
507 func(w io.Writer, outputFile android.Path) {
508 if dstubs.Javadoc.stubsSrcJar != nil {
509 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", dstubs.Javadoc.stubsSrcJar.String())
510 }
Nan Zhangd23ac692018-09-18 10:41:33 -0700511 if dstubs.apiVersionsXml != nil {
512 fmt.Fprintln(w, "LOCAL_DROIDDOC_API_VERSIONS_XML := ", dstubs.apiVersionsXml.String())
513 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700514 if dstubs.annotationsZip != nil {
515 fmt.Fprintln(w, "LOCAL_DROIDDOC_ANNOTATIONS_ZIP := ", dstubs.annotationsZip.String())
516 }
Nan Zhang71bbe632018-09-17 14:32:21 -0700517 if dstubs.jdiffDocZip != nil {
518 fmt.Fprintln(w, "LOCAL_DROIDDOC_JDIFF_DOC_ZIP := ", dstubs.jdiffDocZip.String())
519 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700520 if dstubs.checkCurrentApiTimestamp != nil {
521 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-current-api")
522 fmt.Fprintln(w, dstubs.Name()+"-check-current-api:",
523 dstubs.checkCurrentApiTimestamp.String())
524
525 fmt.Fprintln(w, ".PHONY: checkapi")
526 fmt.Fprintln(w, "checkapi:",
527 dstubs.checkCurrentApiTimestamp.String())
528
529 fmt.Fprintln(w, ".PHONY: droidcore")
530 fmt.Fprintln(w, "droidcore: checkapi")
531 }
532 if dstubs.updateCurrentApiTimestamp != nil {
533 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-update-current-api")
534 fmt.Fprintln(w, dstubs.Name()+"-update-current-api:",
535 dstubs.updateCurrentApiTimestamp.String())
536
537 fmt.Fprintln(w, ".PHONY: update-api")
538 fmt.Fprintln(w, "update-api:",
539 dstubs.updateCurrentApiTimestamp.String())
540 }
541 if dstubs.checkLastReleasedApiTimestamp != nil {
542 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-last-released-api")
543 fmt.Fprintln(w, dstubs.Name()+"-check-last-released-api:",
544 dstubs.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100545
Adrian Roos62e34b92019-01-30 19:51:39 +0100546 if dstubs.Name() == "api-stubs-docs" || dstubs.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100547 fmt.Fprintln(w, ".PHONY: checkapi")
548 fmt.Fprintln(w, "checkapi:",
549 dstubs.checkLastReleasedApiTimestamp.String())
550
551 fmt.Fprintln(w, ".PHONY: droidcore")
552 fmt.Fprintln(w, "droidcore: checkapi")
553 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700554 }
Pete Gillin581d6082018-10-22 15:55:04 +0100555 if dstubs.checkNullabilityWarningsTimestamp != nil {
556 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings")
557 fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:",
558 dstubs.checkNullabilityWarningsTimestamp.String())
559
560 fmt.Fprintln(w, ".PHONY:", "droidcore")
561 fmt.Fprintln(w, "droidcore: ", dstubs.Name()+"-check-nullability-warnings")
562 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700563 apiFilePrefix := "INTERNAL_PLATFORM_"
564 if String(dstubs.properties.Api_tag_name) != "" {
565 apiFilePrefix += String(dstubs.properties.Api_tag_name) + "_"
566 }
567 if dstubs.apiFile != nil {
568 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", dstubs.apiFile.String())
569 }
570 if dstubs.dexApiFile != nil {
571 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", dstubs.dexApiFile.String())
572 }
573 if dstubs.privateApiFile != nil {
574 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", dstubs.privateApiFile.String())
575 }
576 if dstubs.privateDexApiFile != nil {
577 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", dstubs.privateDexApiFile.String())
578 }
579 if dstubs.removedApiFile != nil {
580 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", dstubs.removedApiFile.String())
581 }
582 if dstubs.removedDexApiFile != nil {
583 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", dstubs.removedDexApiFile.String())
584 }
585 if dstubs.exactApiFile != nil {
586 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", dstubs.exactApiFile.String())
587 }
588 },
589 },
590 }
591}
592
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700593func (app *AndroidAppImport) AndroidMk() android.AndroidMkData {
594 return android.AndroidMkData{
595 Class: "APPS",
596 OutputFile: android.OptionalPathForPath(app.outputFile),
597 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
598 Extra: []android.AndroidMkExtraFunc{
599 func(w io.Writer, outputFile android.Path) {
600 if Bool(app.properties.Privileged) {
601 fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true")
602 }
603 if app.certificate != nil {
604 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.Pem.String())
605 } else {
606 fmt.Fprintln(w, "LOCAL_CERTIFICATE := PRESIGNED")
607 }
608 if len(app.properties.Overrides) > 0 {
609 fmt.Fprintln(w, "LOCAL_OVERRIDES_PACKAGES :=", strings.Join(app.properties.Overrides, " "))
610 }
611 if len(app.dexpreopter.builtInstalled) > 0 {
612 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", app.dexpreopter.builtInstalled)
613 }
614 },
615 },
616 }
617}
618
Colin Crossd96ca352018-08-10 16:06:24 -0700619func androidMkWriteTestData(data android.Paths, ret *android.AndroidMkData) {
620 var testFiles []string
621 for _, d := range data {
622 testFiles = append(testFiles, d.String()+":"+d.Rel())
623 }
624 if len(testFiles) > 0 {
625 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
626 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUPPORT_FILES := "+strings.Join(testFiles, " "))
627 })
628 }
629}