blob: 9d238c5e5687dcb200dd06c2ad1a7d31ff2bd2f4 [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())
41 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " "))
Jaewoong Jung87a94c02019-04-03 15:47:29 -070042 if len(data.Required) > 0 {
43 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(data.Required, " "))
Colin Cross363360c2019-04-24 13:41:45 -070044 }
Sundong Ahn054b19a2018-10-19 13:46:09 +090045 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
46 }
47}
48
Colin Crossa18e9cf2017-08-10 17:00:19 -070049func (library *Library) AndroidMk() android.AndroidMkData {
50 return android.AndroidMkData{
51 Class: "JAVA_LIBRARIES",
Colin Cross43f08db2018-11-12 10:13:39 -080052 OutputFile: android.OptionalPathForPath(library.outputFile),
Colin Cross53499412017-09-07 13:20:25 -070053 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -070054 Extra: []android.AndroidMkExtraFunc{
55 func(w io.Writer, outputFile android.Path) {
Colin Cross5beccee2017-12-07 15:28:59 -080056 if len(library.logtagsSrcs) > 0 {
57 var logtags []string
58 for _, l := range library.logtagsSrcs {
59 logtags = append(logtags, l.Rel())
60 }
61 fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES :=", strings.Join(logtags, " "))
62 }
63
Colin Cross9ae1b922018-06-26 17:59:05 -070064 if library.installFile == nil {
Colin Cross2c429dc2017-08-31 16:45:16 -070065 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
66 }
Colin Cross6ade34f2017-09-15 13:00:47 -070067 if library.dexJarFile != nil {
68 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -080069 }
70 if len(library.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -080071 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", library.dexpreopter.builtInstalled)
Colin Cross6ade34f2017-09-15 13:00:47 -070072 }
Colin Cross83bb3162018-06-25 15:48:06 -070073 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", library.sdkVersion())
Colin Cross43f08db2018-11-12 10:13:39 -080074 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String())
Nan Zhanged19fc32017-10-19 13:06:22 -070075 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
Colin Crosscb933592017-11-22 13:49:43 -080076
77 if library.jacocoReportClassesFile != nil {
78 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", library.jacocoReportClassesFile.String())
79 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -080080
Jiyong Park1be96912018-05-28 18:02:19 +090081 if len(library.exportedSdkLibs) != 0 {
82 fmt.Fprintln(w, "LOCAL_EXPORT_SDK_LIBRARIES :=", strings.Join(library.exportedSdkLibs, " "))
83 }
84
Vladimir Markoe26f4a52019-04-02 10:29:55 +010085 if len(library.additionalCheckedModules) != 0 {
86 fmt.Fprintln(w, "LOCAL_ADDITIONAL_CHECKED_MODULE +=", strings.Join(library.additionalCheckedModules.Strings(), " "))
87 }
88
Colin Cross5ab4e6d2017-11-22 16:20:45 -080089 // Temporary hack: export sources used to compile framework.jar to Make
90 // to be used for droiddoc
91 // TODO(ccross): remove this once droiddoc is in soong
Mathew Inwoodebe29ce2018-09-04 14:26:19 +010092 if (library.Name() == "framework") || (library.Name() == "framework-annotation-proc") {
Colin Cross5ab4e6d2017-11-22 16:20:45 -080093 fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCS :=", strings.Join(library.compiledJavaSrcs.Strings(), " "))
94 fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCJARS :=", strings.Join(library.compiledSrcJars.Strings(), " "))
95 }
Colin Crossa18e9cf2017-08-10 17:00:19 -070096 },
97 },
Colin Cross92430102017-10-09 14:59:32 -070098 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
99 android.WriteAndroidMkData(w, data)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900100 library.AndroidMkHostDex(w, name, data)
Colin Cross92430102017-10-09 14:59:32 -0700101 },
Colin Crossa18e9cf2017-08-10 17:00:19 -0700102 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700103}
104
Paul Duffin42df1442019-03-20 12:45:53 +0000105// Called for modules that are a component of a test suite.
106func testSuiteComponent(w io.Writer, test_suites []string) {
107 fmt.Fprintln(w, "LOCAL_MODULE_TAGS := tests")
108 if len(test_suites) > 0 {
109 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
110 strings.Join(test_suites, " "))
111 } else {
112 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE := null-suite")
113 }
114}
115
Colin Cross05638fc2018-04-09 18:40:24 -0700116func (j *Test) AndroidMk() android.AndroidMkData {
117 data := j.Library.AndroidMk()
118 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000119 testSuiteComponent(w, j.testProperties.Test_suites)
Colin Cross303e21f2018-08-07 16:49:25 -0700120 if j.testConfig != nil {
121 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", j.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700122 }
Colin Cross05638fc2018-04-09 18:40:24 -0700123 })
124
Colin Crossd96ca352018-08-10 16:06:24 -0700125 androidMkWriteTestData(j.data, &data)
126
Colin Cross05638fc2018-04-09 18:40:24 -0700127 return data
128}
129
Paul Duffin42df1442019-03-20 12:45:53 +0000130func (j *TestHelperLibrary) AndroidMk() android.AndroidMkData {
131 data := j.Library.AndroidMk()
132 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
133 testSuiteComponent(w, j.testHelperLibraryProperties.Test_suites)
134 })
135
136 return data
137}
138
Colin Crossa18e9cf2017-08-10 17:00:19 -0700139func (prebuilt *Import) AndroidMk() android.AndroidMkData {
140 return android.AndroidMkData{
141 Class: "JAVA_LIBRARIES",
142 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Colin Cross53499412017-09-07 13:20:25 -0700143 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -0700144 Extra: []android.AndroidMkExtraFunc{
145 func(w io.Writer, outputFile android.Path) {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700146 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !Bool(prebuilt.properties.Installable))
Nan Zhanged19fc32017-10-19 13:06:22 -0700147 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800148 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Cross83bb3162018-06-25 15:48:06 -0700149 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
Colin Crossa18e9cf2017-08-10 17:00:19 -0700150 },
151 },
152 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700153}
Colin Cross10a03492017-08-10 17:09:43 -0700154
Colin Cross42be7612019-02-21 18:12:14 -0800155func (prebuilt *DexImport) AndroidMk() android.AndroidMkData {
156 return android.AndroidMkData{
157 Class: "JAVA_LIBRARIES",
158 OutputFile: android.OptionalPathForPath(prebuilt.maybeStrippedDexJarFile),
159 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
160 Extra: []android.AndroidMkExtraFunc{
161 func(w io.Writer, outputFile android.Path) {
162 if prebuilt.dexJarFile != nil {
163 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", prebuilt.dexJarFile.String())
164 // TODO(b/125517186): export the dex jar as a classes jar to match some mis-uses in Make until
165 // boot_jars_package_check.mk can check dex jars.
166 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.dexJarFile.String())
167 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.dexJarFile.String())
168 }
169 if len(prebuilt.dexpreopter.builtInstalled) > 0 {
170 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", prebuilt.dexpreopter.builtInstalled)
171 }
172 },
173 },
174 }
175}
176
Colin Crossfabb6082018-02-20 17:22:23 -0800177func (prebuilt *AARImport) AndroidMk() android.AndroidMkData {
178 return android.AndroidMkData{
179 Class: "JAVA_LIBRARIES",
180 OutputFile: android.OptionalPathForPath(prebuilt.classpathFile),
181 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
182 Extra: []android.AndroidMkExtraFunc{
183 func(w io.Writer, outputFile android.Path) {
184 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossfabb6082018-02-20 17:22:23 -0800185 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.classpathFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800186 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.classpathFile.String())
Colin Crossfabb6082018-02-20 17:22:23 -0800187 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", prebuilt.exportPackage.String())
188 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String())
Colin Cross66f78822018-05-02 12:58:28 -0700189 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", prebuilt.extraAaptPackagesFile.String())
Colin Cross10f7c4a2018-05-23 10:59:28 -0700190 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", prebuilt.manifest.String())
Colin Cross83bb3162018-06-25 15:48:06 -0700191 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
Colin Crossfabb6082018-02-20 17:22:23 -0800192 },
193 },
194 }
195}
196
Colin Cross10a03492017-08-10 17:09:43 -0700197func (binary *Binary) AndroidMk() android.AndroidMkData {
Colin Cross10a03492017-08-10 17:09:43 -0700198
Colin Cross6b4a32d2017-12-05 13:42:45 -0800199 if !binary.isWrapperVariant {
200 return android.AndroidMkData{
201 Class: "JAVA_LIBRARIES",
Colin Cross331a1212018-08-15 20:40:52 -0700202 OutputFile: android.OptionalPathForPath(binary.outputFile),
Colin Cross6b4a32d2017-12-05 13:42:45 -0800203 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Cross331a1212018-08-15 20:40:52 -0700204 Extra: []android.AndroidMkExtraFunc{
205 func(w io.Writer, outputFile android.Path) {
206 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", binary.headerJarFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800207 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", binary.implementationAndResourcesJar.String())
Colin Cross12fc2af2019-01-14 12:35:45 -0800208 if binary.dexJarFile != nil {
209 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", binary.dexJarFile.String())
210 }
211 if len(binary.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -0800212 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", binary.dexpreopter.builtInstalled)
Colin Cross12fc2af2019-01-14 12:35:45 -0800213 }
Colin Cross331a1212018-08-15 20:40:52 -0700214 },
215 },
Colin Cross6b4a32d2017-12-05 13:42:45 -0800216 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
217 android.WriteAndroidMkData(w, data)
Colin Cross19655682017-09-07 17:00:22 -0700218
Colin Cross6b4a32d2017-12-05 13:42:45 -0800219 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
220 },
221 }
222 } else {
223 return android.AndroidMkData{
224 Class: "EXECUTABLES",
225 OutputFile: android.OptionalPathForPath(binary.wrapperFile),
226 Extra: []android.AndroidMkExtraFunc{
227 func(w io.Writer, outputFile android.Path) {
228 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
229 },
230 },
231 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
232 android.WriteAndroidMkData(w, data)
233
234 // Ensure that the wrapper script timestamp is always updated when the jar is updated
235 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
236 fmt.Fprintln(w, "jar_installed_module :=")
237 },
238 }
Colin Cross10a03492017-08-10 17:09:43 -0700239 }
240}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800241
242func (app *AndroidApp) AndroidMk() android.AndroidMkData {
243 return android.AndroidMkData{
244 Class: "APPS",
245 OutputFile: android.OptionalPathForPath(app.outputFile),
246 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
247 Extra: []android.AndroidMkExtraFunc{
248 func(w io.Writer, outputFile android.Path) {
Jaewoong Jung9109d722019-01-30 13:13:52 -0800249 // TODO(jungjw): This, outputting two LOCAL_MODULE lines, works, but is not ideal. Find a better solution.
250 if app.Name() != app.installApkName {
251 fmt.Fprintln(w, "# Overridden by PRODUCT_PACKAGE_NAME_OVERRIDES")
252 fmt.Fprintln(w, "LOCAL_MODULE :=", app.installApkName)
253 }
Colin Cross70798562017-12-13 22:42:59 -0800254 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", app.exportPackage.String())
255 if app.dexJarFile != nil {
256 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String())
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800257 }
Colin Cross331a1212018-08-15 20:40:52 -0700258 if app.implementationAndResourcesJar != nil {
259 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", app.implementationAndResourcesJar.String())
Colin Cross5dfabfb2017-12-14 13:19:01 -0800260 }
261 if app.headerJarFile != nil {
262 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", app.headerJarFile.String())
263 }
Colin Crossf6237212018-10-29 23:14:58 -0700264 if app.bundleFile != nil {
265 fmt.Fprintln(w, "LOCAL_SOONG_BUNDLE :=", app.bundleFile.String())
266 }
Colin Cross70798562017-12-13 22:42:59 -0800267 if app.jacocoReportClassesFile != nil {
268 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", app.jacocoReportClassesFile.String())
269 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800270 if app.proguardDictionary != nil {
271 fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", app.proguardDictionary.String())
272 }
Colin Cross70798562017-12-13 22:42:59 -0800273
Rashed Abdel-Tawab47d35aa2018-08-09 14:08:53 -0700274 if app.Name() == "framework-res" || app.Name() == "org.lineageos.platform-res" {
Colin Cross70798562017-12-13 22:42:59 -0800275 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
276 // Make base_rules.mk not put framework-res in a subdirectory called
277 // framework_res.
278 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
279 }
280
Anton Hansson53c88442019-03-18 15:53:16 +0000281 filterRRO := func(filter overlayType) android.Paths {
282 var paths android.Paths
283 for _, d := range app.rroDirs {
284 if d.overlayType == filter {
285 paths = append(paths, d.path)
286 }
287 }
Colin Crossa140bb02018-04-17 10:52:26 -0700288 // Reverse the order, Soong stores rroDirs in aapt2 order (low to high priority), but Make
289 // expects it in LOCAL_RESOURCE_DIRS order (high to low priority).
Anton Hansson53c88442019-03-18 15:53:16 +0000290 return android.ReversePaths(paths)
291 }
292 deviceRRODirs := filterRRO(device)
293 if len(deviceRRODirs) > 0 {
294 fmt.Fprintln(w, "LOCAL_SOONG_DEVICE_RRO_DIRS :=", strings.Join(deviceRRODirs.Strings(), " "))
295 }
296 productRRODirs := filterRRO(product)
297 if len(productRRODirs) > 0 {
298 fmt.Fprintln(w, "LOCAL_SOONG_PRODUCT_RRO_DIRS :=", strings.Join(productRRODirs.Strings(), " "))
Colin Cross70798562017-12-13 22:42:59 -0800299 }
300
301 if Bool(app.appProperties.Export_package_resources) {
302 fmt.Fprintln(w, "LOCAL_EXPORT_PACKAGE_RESOURCES := true")
303 }
304
305 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", app.manifestPath.String())
306
Colin Cross16056062017-12-13 22:46:28 -0800307 if Bool(app.appProperties.Privileged) {
308 fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true")
309 }
Colin Crosse1731a52017-12-14 11:22:55 -0800310
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900311 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.Pem.String())
Jaewoong Jung9109d722019-01-30 13:13:52 -0800312 if overriddenPkgs := app.getOverriddenPackages(); len(overriddenPkgs) > 0 {
313 fmt.Fprintln(w, "LOCAL_OVERRIDES_PACKAGES :=", strings.Join(overriddenPkgs, " "))
Jason Monkd4122be2018-08-10 09:33:36 -0400314 }
Colin Crossa4f08812018-10-02 22:03:40 -0700315
316 for _, jniLib := range app.installJniLibs {
317 fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), "+=", jniLib.name)
318 }
Colin Cross43f08db2018-11-12 10:13:39 -0800319 if len(app.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -0800320 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", app.dexpreopter.builtInstalled)
Colin Cross43f08db2018-11-12 10:13:39 -0800321 }
Colin Crosse560c4a2019-03-19 16:03:11 -0700322 for _, split := range app.aapt.splits {
Jaewoong Jung0b09bdb2019-09-27 17:13:15 -0700323 install := app.onDeviceDir + "/" +
324 strings.TrimSuffix(app.installApkName, ".apk") + "_" + split.suffix + ".apk"
Colin Crosse560c4a2019-03-19 16:03:11 -0700325 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED +=", split.path.String()+":"+install)
326 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800327 },
328 },
329 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700330}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800331
Jaewoong Jung9109d722019-01-30 13:13:52 -0800332func (a *AndroidApp) getOverriddenPackages() []string {
333 var overridden []string
334 if len(a.appProperties.Overrides) > 0 {
335 overridden = append(overridden, a.appProperties.Overrides...)
336 }
337 if a.Name() != a.installApkName {
338 overridden = append(overridden, a.Name())
339 }
340 return overridden
341}
342
Colin Crossae5caf52018-05-22 11:11:52 -0700343func (a *AndroidTest) AndroidMk() android.AndroidMkData {
344 data := a.AndroidApp.AndroidMk()
345 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000346 testSuiteComponent(w, a.testProperties.Test_suites)
Colin Cross303e21f2018-08-07 16:49:25 -0700347 if a.testConfig != nil {
348 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", a.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700349 }
Colin Crossae5caf52018-05-22 11:11:52 -0700350 })
Colin Crossd96ca352018-08-10 16:06:24 -0700351 androidMkWriteTestData(a.data, &data)
Colin Crossae5caf52018-05-22 11:11:52 -0700352
353 return data
354}
355
Colin Cross252fc6f2018-10-04 15:22:03 -0700356func (a *AndroidTestHelperApp) AndroidMk() android.AndroidMkData {
357 data := a.AndroidApp.AndroidMk()
358 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000359 testSuiteComponent(w, a.appTestHelperAppProperties.Test_suites)
Colin Cross252fc6f2018-10-04 15:22:03 -0700360 })
361
362 return data
363}
364
Colin Crossa97c5d32018-03-28 14:58:31 -0700365func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
366 data := a.Library.AndroidMk()
367
368 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossa54974c2018-10-29 23:15:37 -0700369 if a.aarFile != nil {
370 fmt.Fprintln(w, "LOCAL_SOONG_AAR :=", a.aarFile.String())
371 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700372 if a.proguardDictionary != nil {
373 fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", a.proguardDictionary.String())
374 }
375
Rashed Abdel-Tawab47d35aa2018-08-09 14:08:53 -0700376 if a.Name() == "framework-res" || a.Name() == "org.lineageos.platform-res" {
Colin Crossa97c5d32018-03-28 14:58:31 -0700377 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 Crossb31188e2019-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 }
Jerome Gaillard0b09ad72019-10-10 19:29:11 +0100512 if dstubs.metadataZip != nil {
513 fmt.Fprintln(w, "LOCAL_DROIDDOC_METADATA_ZIP := ", dstubs.metadataZip.String())
514 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700515 if dstubs.checkCurrentApiTimestamp != nil {
516 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-current-api")
517 fmt.Fprintln(w, dstubs.Name()+"-check-current-api:",
518 dstubs.checkCurrentApiTimestamp.String())
519
520 fmt.Fprintln(w, ".PHONY: checkapi")
521 fmt.Fprintln(w, "checkapi:",
522 dstubs.checkCurrentApiTimestamp.String())
523
524 fmt.Fprintln(w, ".PHONY: droidcore")
525 fmt.Fprintln(w, "droidcore: checkapi")
526 }
527 if dstubs.updateCurrentApiTimestamp != nil {
528 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-update-current-api")
529 fmt.Fprintln(w, dstubs.Name()+"-update-current-api:",
530 dstubs.updateCurrentApiTimestamp.String())
531
532 fmt.Fprintln(w, ".PHONY: update-api")
533 fmt.Fprintln(w, "update-api:",
534 dstubs.updateCurrentApiTimestamp.String())
535 }
536 if dstubs.checkLastReleasedApiTimestamp != nil {
537 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-last-released-api")
538 fmt.Fprintln(w, dstubs.Name()+"-check-last-released-api:",
539 dstubs.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100540
Adrian Roos62e34b92019-01-30 19:51:39 +0100541 if dstubs.Name() == "api-stubs-docs" || dstubs.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100542 fmt.Fprintln(w, ".PHONY: checkapi")
543 fmt.Fprintln(w, "checkapi:",
544 dstubs.checkLastReleasedApiTimestamp.String())
545
546 fmt.Fprintln(w, ".PHONY: droidcore")
547 fmt.Fprintln(w, "droidcore: checkapi")
548 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700549 }
Pete Gillin581d6082018-10-22 15:55:04 +0100550 if dstubs.checkNullabilityWarningsTimestamp != nil {
551 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings")
552 fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:",
553 dstubs.checkNullabilityWarningsTimestamp.String())
554
555 fmt.Fprintln(w, ".PHONY:", "droidcore")
556 fmt.Fprintln(w, "droidcore: ", dstubs.Name()+"-check-nullability-warnings")
557 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700558 apiFilePrefix := "INTERNAL_PLATFORM_"
559 if String(dstubs.properties.Api_tag_name) != "" {
560 apiFilePrefix += String(dstubs.properties.Api_tag_name) + "_"
561 }
562 if dstubs.apiFile != nil {
563 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", dstubs.apiFile.String())
564 }
565 if dstubs.dexApiFile != nil {
566 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", dstubs.dexApiFile.String())
567 }
568 if dstubs.privateApiFile != nil {
569 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", dstubs.privateApiFile.String())
570 }
571 if dstubs.privateDexApiFile != nil {
572 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", dstubs.privateDexApiFile.String())
573 }
574 if dstubs.removedApiFile != nil {
575 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", dstubs.removedApiFile.String())
576 }
577 if dstubs.removedDexApiFile != nil {
578 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", dstubs.removedDexApiFile.String())
579 }
580 if dstubs.exactApiFile != nil {
581 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", dstubs.exactApiFile.String())
582 }
583 },
584 },
585 }
586}
587
Jaewoong Jung9b008e42019-07-17 10:21:49 -0700588func (a *AndroidAppImport) AndroidMkEntries() android.AndroidMkEntries {
589 return android.AndroidMkEntries{
Jaewoong Jung33695b92019-04-15 09:48:31 -0700590 Class: "APPS",
Jaewoong Jung9b008e42019-07-17 10:21:49 -0700591 OutputFile: android.OptionalPathForPath(a.outputFile),
Jaewoong Jung33695b92019-04-15 09:48:31 -0700592 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
Jaewoong Jung283a9ee2019-08-27 17:33:16 -0700593 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
594 func(entries *android.AndroidMkEntries) {
595 entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", Bool(a.properties.Privileged))
596 if a.certificate != nil {
597 entries.SetString("LOCAL_CERTIFICATE", a.certificate.Pem.String())
598 } else {
599 entries.SetString("LOCAL_CERTIFICATE", "PRESIGNED")
600 }
601 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", a.properties.Overrides...)
602 if len(a.dexpreopter.builtInstalled) > 0 {
603 entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", a.dexpreopter.builtInstalled)
604 }
605 entries.AddStrings("LOCAL_INSTALLED_MODULE_STEM", a.installPath.Rel())
606 },
Jaewoong Jung33695b92019-04-15 09:48:31 -0700607 },
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}