blob: 7a939e8498262a8cb668dcb7e01be51dbe71619d [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, " "))
Colin Cross363360c2019-04-24 13:41:45 -070042 if r := library.deviceProperties.Target.Hostdex.Required; len(r) > 0 {
43 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(r, " "))
44 }
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
274 if app.Name() == "framework-res" {
275 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 {
323 install := "$(LOCAL_MODULE_PATH)/" + strings.TrimSuffix(app.installApkName, ".apk") + split.suffix + ".apk"
324 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED +=", split.path.String()+":"+install)
325 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800326 },
327 },
328 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700329}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800330
Jaewoong Jung9109d722019-01-30 13:13:52 -0800331func (a *AndroidApp) getOverriddenPackages() []string {
332 var overridden []string
333 if len(a.appProperties.Overrides) > 0 {
334 overridden = append(overridden, a.appProperties.Overrides...)
335 }
336 if a.Name() != a.installApkName {
337 overridden = append(overridden, a.Name())
338 }
339 return overridden
340}
341
Colin Crossae5caf52018-05-22 11:11:52 -0700342func (a *AndroidTest) AndroidMk() android.AndroidMkData {
343 data := a.AndroidApp.AndroidMk()
344 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000345 testSuiteComponent(w, a.testProperties.Test_suites)
Colin Cross303e21f2018-08-07 16:49:25 -0700346 if a.testConfig != nil {
347 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", a.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700348 }
Colin Crossae5caf52018-05-22 11:11:52 -0700349 })
Colin Crossd96ca352018-08-10 16:06:24 -0700350 androidMkWriteTestData(a.data, &data)
Colin Crossae5caf52018-05-22 11:11:52 -0700351
352 return data
353}
354
Colin Cross252fc6f2018-10-04 15:22:03 -0700355func (a *AndroidTestHelperApp) AndroidMk() android.AndroidMkData {
356 data := a.AndroidApp.AndroidMk()
357 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Paul Duffin42df1442019-03-20 12:45:53 +0000358 testSuiteComponent(w, a.appTestHelperAppProperties.Test_suites)
Colin Cross252fc6f2018-10-04 15:22:03 -0700359 })
360
361 return data
362}
363
Colin Crossa97c5d32018-03-28 14:58:31 -0700364func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
365 data := a.Library.AndroidMk()
366
367 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossa54974c2018-10-29 23:15:37 -0700368 if a.aarFile != nil {
369 fmt.Fprintln(w, "LOCAL_SOONG_AAR :=", a.aarFile.String())
370 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700371 if a.proguardDictionary != nil {
372 fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", a.proguardDictionary.String())
373 }
374
375 if a.Name() == "framework-res" {
376 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
377 // Make base_rules.mk not put framework-res in a subdirectory called
378 // framework_res.
379 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
380 }
381
382 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
Colin Cross66f78822018-05-02 12:58:28 -0700383 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", a.extraAaptPackagesFile.String())
Colin Crossa97c5d32018-03-28 14:58:31 -0700384 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.manifestPath.String())
Colin Cross89c31582018-04-30 15:55:11 -0700385 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
386 strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
Colin Crossa97c5d32018-03-28 14:58:31 -0700387 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossa97c5d32018-03-28 14:58:31 -0700388 })
389
390 return data
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800391}
Nan Zhang581fd212018-01-10 16:06:12 -0800392
393func (jd *Javadoc) AndroidMk() android.AndroidMkData {
394 return android.AndroidMkData{
395 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800396 OutputFile: android.OptionalPathForPath(jd.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700397 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800398 Extra: []android.AndroidMkExtraFunc{
399 func(w io.Writer, outputFile android.Path) {
Colin Cross38b40df2018-04-10 16:14:46 -0700400 if BoolDefault(jd.properties.Installable, true) {
Nan Zhang581fd212018-01-10 16:06:12 -0800401 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", jd.docZip.String())
402 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800403 if jd.stubsSrcJar != nil {
404 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", jd.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800405 }
406 },
407 },
408 }
409}
410
411func (ddoc *Droiddoc) AndroidMk() android.AndroidMkData {
412 return android.AndroidMkData{
413 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800414 OutputFile: android.OptionalPathForPath(ddoc.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700415 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800416 Extra: []android.AndroidMkExtraFunc{
417 func(w io.Writer, outputFile android.Path) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700418 if BoolDefault(ddoc.Javadoc.properties.Installable, true) && ddoc.Javadoc.docZip != nil {
Nan Zhang581fd212018-01-10 16:06:12 -0800419 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", ddoc.Javadoc.docZip.String())
420 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800421 if ddoc.Javadoc.stubsSrcJar != nil {
422 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", ddoc.Javadoc.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800423 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700424 if ddoc.checkCurrentApiTimestamp != nil {
425 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-current-api")
426 fmt.Fprintln(w, ddoc.Name()+"-check-current-api:",
427 ddoc.checkCurrentApiTimestamp.String())
428
429 fmt.Fprintln(w, ".PHONY: checkapi")
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900430 fmt.Fprintln(w, "checkapi:",
Nan Zhang61819ce2018-05-04 18:49:16 -0700431 ddoc.checkCurrentApiTimestamp.String())
432
433 fmt.Fprintln(w, ".PHONY: droidcore")
434 fmt.Fprintln(w, "droidcore: checkapi")
435 }
436 if ddoc.updateCurrentApiTimestamp != nil {
Dan Willemsena03c43a2018-07-24 13:00:52 -0700437 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-update-current-api")
Nan Zhang61819ce2018-05-04 18:49:16 -0700438 fmt.Fprintln(w, ddoc.Name()+"-update-current-api:",
439 ddoc.updateCurrentApiTimestamp.String())
440
441 fmt.Fprintln(w, ".PHONY: update-api")
442 fmt.Fprintln(w, "update-api:",
443 ddoc.updateCurrentApiTimestamp.String())
444 }
445 if ddoc.checkLastReleasedApiTimestamp != nil {
446 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-last-released-api")
447 fmt.Fprintln(w, ddoc.Name()+"-check-last-released-api:",
448 ddoc.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100449
Adrian Roos62e34b92019-01-30 19:51:39 +0100450 if ddoc.Name() == "api-stubs-docs" || ddoc.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100451 fmt.Fprintln(w, ".PHONY: checkapi")
452 fmt.Fprintln(w, "checkapi:",
453 ddoc.checkLastReleasedApiTimestamp.String())
454
455 fmt.Fprintln(w, ".PHONY: droidcore")
456 fmt.Fprintln(w, "droidcore: checkapi")
457 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700458 }
Nan Zhang28c68b92018-03-13 16:17:01 -0700459 apiFilePrefix := "INTERNAL_PLATFORM_"
460 if String(ddoc.properties.Api_tag_name) != "" {
461 apiFilePrefix += String(ddoc.properties.Api_tag_name) + "_"
462 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700463 if ddoc.apiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700464 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", ddoc.apiFile.String())
465 }
David Brazdilfbe4cc32018-05-31 13:56:46 +0100466 if ddoc.dexApiFile != nil {
467 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", ddoc.dexApiFile.String())
468 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700469 if ddoc.privateApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700470 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", ddoc.privateApiFile.String())
471 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700472 if ddoc.privateDexApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700473 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", ddoc.privateDexApiFile.String())
474 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700475 if ddoc.removedApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700476 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", ddoc.removedApiFile.String())
477 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700478 if ddoc.removedDexApiFile != nil {
David Brazdilaac0c3c2018-04-24 16:23:29 +0100479 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", ddoc.removedDexApiFile.String())
480 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700481 if ddoc.exactApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700482 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", ddoc.exactApiFile.String())
483 }
Nan Zhang66dc2362018-08-14 20:41:04 -0700484 if ddoc.proguardFile != nil {
485 fmt.Fprintln(w, apiFilePrefix+"PROGUARD_FILE := ", ddoc.proguardFile.String())
486 }
Nan Zhang581fd212018-01-10 16:06:12 -0800487 },
488 },
489 }
490}
Colin Crossd96ca352018-08-10 16:06:24 -0700491
Nan Zhang1598a9e2018-09-04 17:14:32 -0700492func (dstubs *Droidstubs) AndroidMk() android.AndroidMkData {
493 return android.AndroidMkData{
494 Class: "JAVA_LIBRARIES",
495 OutputFile: android.OptionalPathForPath(dstubs.stubsSrcJar),
496 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
497 Extra: []android.AndroidMkExtraFunc{
498 func(w io.Writer, outputFile android.Path) {
499 if dstubs.Javadoc.stubsSrcJar != nil {
500 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", dstubs.Javadoc.stubsSrcJar.String())
501 }
Nan Zhangd23ac692018-09-18 10:41:33 -0700502 if dstubs.apiVersionsXml != nil {
503 fmt.Fprintln(w, "LOCAL_DROIDDOC_API_VERSIONS_XML := ", dstubs.apiVersionsXml.String())
504 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700505 if dstubs.annotationsZip != nil {
506 fmt.Fprintln(w, "LOCAL_DROIDDOC_ANNOTATIONS_ZIP := ", dstubs.annotationsZip.String())
507 }
Nan Zhang71bbe632018-09-17 14:32:21 -0700508 if dstubs.jdiffDocZip != nil {
509 fmt.Fprintln(w, "LOCAL_DROIDDOC_JDIFF_DOC_ZIP := ", dstubs.jdiffDocZip.String())
510 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700511 if dstubs.checkCurrentApiTimestamp != nil {
512 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-current-api")
513 fmt.Fprintln(w, dstubs.Name()+"-check-current-api:",
514 dstubs.checkCurrentApiTimestamp.String())
515
516 fmt.Fprintln(w, ".PHONY: checkapi")
517 fmt.Fprintln(w, "checkapi:",
518 dstubs.checkCurrentApiTimestamp.String())
519
520 fmt.Fprintln(w, ".PHONY: droidcore")
521 fmt.Fprintln(w, "droidcore: checkapi")
522 }
523 if dstubs.updateCurrentApiTimestamp != nil {
524 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-update-current-api")
525 fmt.Fprintln(w, dstubs.Name()+"-update-current-api:",
526 dstubs.updateCurrentApiTimestamp.String())
527
528 fmt.Fprintln(w, ".PHONY: update-api")
529 fmt.Fprintln(w, "update-api:",
530 dstubs.updateCurrentApiTimestamp.String())
531 }
532 if dstubs.checkLastReleasedApiTimestamp != nil {
533 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-last-released-api")
534 fmt.Fprintln(w, dstubs.Name()+"-check-last-released-api:",
535 dstubs.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100536
Adrian Roos62e34b92019-01-30 19:51:39 +0100537 if dstubs.Name() == "api-stubs-docs" || dstubs.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100538 fmt.Fprintln(w, ".PHONY: checkapi")
539 fmt.Fprintln(w, "checkapi:",
540 dstubs.checkLastReleasedApiTimestamp.String())
541
542 fmt.Fprintln(w, ".PHONY: droidcore")
543 fmt.Fprintln(w, "droidcore: checkapi")
544 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700545 }
Pete Gillin581d6082018-10-22 15:55:04 +0100546 if dstubs.checkNullabilityWarningsTimestamp != nil {
547 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings")
548 fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:",
549 dstubs.checkNullabilityWarningsTimestamp.String())
550
551 fmt.Fprintln(w, ".PHONY:", "droidcore")
552 fmt.Fprintln(w, "droidcore: ", dstubs.Name()+"-check-nullability-warnings")
553 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700554 apiFilePrefix := "INTERNAL_PLATFORM_"
555 if String(dstubs.properties.Api_tag_name) != "" {
556 apiFilePrefix += String(dstubs.properties.Api_tag_name) + "_"
557 }
558 if dstubs.apiFile != nil {
559 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", dstubs.apiFile.String())
560 }
561 if dstubs.dexApiFile != nil {
562 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", dstubs.dexApiFile.String())
563 }
564 if dstubs.privateApiFile != nil {
565 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", dstubs.privateApiFile.String())
566 }
567 if dstubs.privateDexApiFile != nil {
568 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", dstubs.privateDexApiFile.String())
569 }
570 if dstubs.removedApiFile != nil {
571 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", dstubs.removedApiFile.String())
572 }
573 if dstubs.removedDexApiFile != nil {
574 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", dstubs.removedDexApiFile.String())
575 }
576 if dstubs.exactApiFile != nil {
577 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", dstubs.exactApiFile.String())
578 }
579 },
580 },
581 }
582}
583
Colin Crossd96ca352018-08-10 16:06:24 -0700584func androidMkWriteTestData(data android.Paths, ret *android.AndroidMkData) {
585 var testFiles []string
586 for _, d := range data {
587 testFiles = append(testFiles, d.String()+":"+d.Rel())
588 }
589 if len(testFiles) > 0 {
590 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
591 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUPPORT_FILES := "+strings.Join(testFiles, " "))
592 })
593 }
594}