blob: 0c3b1c768b0d812c7f140f54d4c30de730cbab82 [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, " "))
42 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
43 }
44}
45
Colin Crossa18e9cf2017-08-10 17:00:19 -070046func (library *Library) AndroidMk() android.AndroidMkData {
47 return android.AndroidMkData{
48 Class: "JAVA_LIBRARIES",
Colin Cross43f08db2018-11-12 10:13:39 -080049 OutputFile: android.OptionalPathForPath(library.outputFile),
Colin Cross53499412017-09-07 13:20:25 -070050 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -070051 Extra: []android.AndroidMkExtraFunc{
52 func(w io.Writer, outputFile android.Path) {
Colin Cross5beccee2017-12-07 15:28:59 -080053 if len(library.logtagsSrcs) > 0 {
54 var logtags []string
55 for _, l := range library.logtagsSrcs {
56 logtags = append(logtags, l.Rel())
57 }
58 fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES :=", strings.Join(logtags, " "))
59 }
60
Colin Cross9ae1b922018-06-26 17:59:05 -070061 if library.installFile == nil {
Colin Cross2c429dc2017-08-31 16:45:16 -070062 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
63 }
Colin Cross6ade34f2017-09-15 13:00:47 -070064 if library.dexJarFile != nil {
65 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -080066 }
67 if len(library.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -080068 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", library.dexpreopter.builtInstalled)
Colin Cross6ade34f2017-09-15 13:00:47 -070069 }
Colin Cross83bb3162018-06-25 15:48:06 -070070 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", library.sdkVersion())
Colin Cross43f08db2018-11-12 10:13:39 -080071 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String())
Nan Zhanged19fc32017-10-19 13:06:22 -070072 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
Colin Crosscb933592017-11-22 13:49:43 -080073
74 if library.jacocoReportClassesFile != nil {
75 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", library.jacocoReportClassesFile.String())
76 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -080077
Jiyong Park1be96912018-05-28 18:02:19 +090078 if len(library.exportedSdkLibs) != 0 {
79 fmt.Fprintln(w, "LOCAL_EXPORT_SDK_LIBRARIES :=", strings.Join(library.exportedSdkLibs, " "))
80 }
81
Colin Cross5ab4e6d2017-11-22 16:20:45 -080082 // Temporary hack: export sources used to compile framework.jar to Make
83 // to be used for droiddoc
84 // TODO(ccross): remove this once droiddoc is in soong
Mathew Inwoodebe29ce2018-09-04 14:26:19 +010085 if (library.Name() == "framework") || (library.Name() == "framework-annotation-proc") {
Colin Cross5ab4e6d2017-11-22 16:20:45 -080086 fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCS :=", strings.Join(library.compiledJavaSrcs.Strings(), " "))
87 fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCJARS :=", strings.Join(library.compiledSrcJars.Strings(), " "))
88 }
Colin Crossa18e9cf2017-08-10 17:00:19 -070089 },
90 },
Colin Cross92430102017-10-09 14:59:32 -070091 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
92 android.WriteAndroidMkData(w, data)
Sundong Ahn054b19a2018-10-19 13:46:09 +090093 library.AndroidMkHostDex(w, name, data)
Colin Cross92430102017-10-09 14:59:32 -070094 },
Colin Crossa18e9cf2017-08-10 17:00:19 -070095 }
Dan Willemsen218f6562015-07-08 18:13:11 -070096}
97
Colin Cross05638fc2018-04-09 18:40:24 -070098func (j *Test) AndroidMk() android.AndroidMkData {
99 data := j.Library.AndroidMk()
100 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
101 fmt.Fprintln(w, "LOCAL_MODULE_TAGS := tests")
102 if len(j.testProperties.Test_suites) > 0 {
103 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
104 strings.Join(j.testProperties.Test_suites, " "))
Colin Cross303e21f2018-08-07 16:49:25 -0700105 } else {
106 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE := null-suite")
Colin Cross05638fc2018-04-09 18:40:24 -0700107 }
Colin Cross303e21f2018-08-07 16:49:25 -0700108 if j.testConfig != nil {
109 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", j.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700110 }
Colin Cross05638fc2018-04-09 18:40:24 -0700111 })
112
Colin Crossd96ca352018-08-10 16:06:24 -0700113 androidMkWriteTestData(j.data, &data)
114
Colin Cross05638fc2018-04-09 18:40:24 -0700115 return data
116}
117
Colin Crossa18e9cf2017-08-10 17:00:19 -0700118func (prebuilt *Import) AndroidMk() android.AndroidMkData {
119 return android.AndroidMkData{
120 Class: "JAVA_LIBRARIES",
121 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Colin Cross53499412017-09-07 13:20:25 -0700122 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -0700123 Extra: []android.AndroidMkExtraFunc{
124 func(w io.Writer, outputFile android.Path) {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700125 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !Bool(prebuilt.properties.Installable))
Nan Zhanged19fc32017-10-19 13:06:22 -0700126 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800127 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Cross83bb3162018-06-25 15:48:06 -0700128 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
Colin Crossa18e9cf2017-08-10 17:00:19 -0700129 },
130 },
131 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700132}
Colin Cross10a03492017-08-10 17:09:43 -0700133
Colin Cross42be7612019-02-21 18:12:14 -0800134func (prebuilt *DexImport) AndroidMk() android.AndroidMkData {
135 return android.AndroidMkData{
136 Class: "JAVA_LIBRARIES",
137 OutputFile: android.OptionalPathForPath(prebuilt.maybeStrippedDexJarFile),
138 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
139 Extra: []android.AndroidMkExtraFunc{
140 func(w io.Writer, outputFile android.Path) {
141 if prebuilt.dexJarFile != nil {
142 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", prebuilt.dexJarFile.String())
143 // TODO(b/125517186): export the dex jar as a classes jar to match some mis-uses in Make until
144 // boot_jars_package_check.mk can check dex jars.
145 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.dexJarFile.String())
146 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.dexJarFile.String())
147 }
148 if len(prebuilt.dexpreopter.builtInstalled) > 0 {
149 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", prebuilt.dexpreopter.builtInstalled)
150 }
151 },
152 },
153 }
154}
155
Colin Crossfabb6082018-02-20 17:22:23 -0800156func (prebuilt *AARImport) AndroidMk() android.AndroidMkData {
157 return android.AndroidMkData{
158 Class: "JAVA_LIBRARIES",
159 OutputFile: android.OptionalPathForPath(prebuilt.classpathFile),
160 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
161 Extra: []android.AndroidMkExtraFunc{
162 func(w io.Writer, outputFile android.Path) {
163 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossfabb6082018-02-20 17:22:23 -0800164 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.classpathFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800165 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.classpathFile.String())
Colin Crossfabb6082018-02-20 17:22:23 -0800166 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", prebuilt.exportPackage.String())
167 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String())
Colin Cross66f78822018-05-02 12:58:28 -0700168 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", prebuilt.extraAaptPackagesFile.String())
Colin Cross10f7c4a2018-05-23 10:59:28 -0700169 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", prebuilt.manifest.String())
Colin Cross83bb3162018-06-25 15:48:06 -0700170 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
Colin Crossfabb6082018-02-20 17:22:23 -0800171 },
172 },
173 }
174}
175
Colin Cross10a03492017-08-10 17:09:43 -0700176func (binary *Binary) AndroidMk() android.AndroidMkData {
Colin Cross10a03492017-08-10 17:09:43 -0700177
Colin Cross6b4a32d2017-12-05 13:42:45 -0800178 if !binary.isWrapperVariant {
179 return android.AndroidMkData{
180 Class: "JAVA_LIBRARIES",
Colin Cross331a1212018-08-15 20:40:52 -0700181 OutputFile: android.OptionalPathForPath(binary.outputFile),
Colin Cross6b4a32d2017-12-05 13:42:45 -0800182 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Cross331a1212018-08-15 20:40:52 -0700183 Extra: []android.AndroidMkExtraFunc{
184 func(w io.Writer, outputFile android.Path) {
185 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", binary.headerJarFile.String())
Colin Cross43f08db2018-11-12 10:13:39 -0800186 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", binary.implementationAndResourcesJar.String())
Colin Cross12fc2af2019-01-14 12:35:45 -0800187 if binary.dexJarFile != nil {
188 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", binary.dexJarFile.String())
189 }
190 if len(binary.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -0800191 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", binary.dexpreopter.builtInstalled)
Colin Cross12fc2af2019-01-14 12:35:45 -0800192 }
Colin Cross331a1212018-08-15 20:40:52 -0700193 },
194 },
Colin Cross6b4a32d2017-12-05 13:42:45 -0800195 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
196 android.WriteAndroidMkData(w, data)
Colin Cross19655682017-09-07 17:00:22 -0700197
Colin Cross6b4a32d2017-12-05 13:42:45 -0800198 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
199 },
200 }
201 } else {
202 return android.AndroidMkData{
203 Class: "EXECUTABLES",
204 OutputFile: android.OptionalPathForPath(binary.wrapperFile),
205 Extra: []android.AndroidMkExtraFunc{
206 func(w io.Writer, outputFile android.Path) {
207 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
208 },
209 },
210 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
211 android.WriteAndroidMkData(w, data)
212
213 // Ensure that the wrapper script timestamp is always updated when the jar is updated
214 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
215 fmt.Fprintln(w, "jar_installed_module :=")
216 },
217 }
Colin Cross10a03492017-08-10 17:09:43 -0700218 }
219}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800220
221func (app *AndroidApp) AndroidMk() android.AndroidMkData {
222 return android.AndroidMkData{
223 Class: "APPS",
224 OutputFile: android.OptionalPathForPath(app.outputFile),
225 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
226 Extra: []android.AndroidMkExtraFunc{
227 func(w io.Writer, outputFile android.Path) {
Jaewoong Jung9109d722019-01-30 13:13:52 -0800228 // TODO(jungjw): This, outputting two LOCAL_MODULE lines, works, but is not ideal. Find a better solution.
229 if app.Name() != app.installApkName {
230 fmt.Fprintln(w, "# Overridden by PRODUCT_PACKAGE_NAME_OVERRIDES")
231 fmt.Fprintln(w, "LOCAL_MODULE :=", app.installApkName)
232 }
Colin Cross70798562017-12-13 22:42:59 -0800233 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", app.exportPackage.String())
234 if app.dexJarFile != nil {
235 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String())
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800236 }
Colin Cross331a1212018-08-15 20:40:52 -0700237 if app.implementationAndResourcesJar != nil {
238 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", app.implementationAndResourcesJar.String())
Colin Cross5dfabfb2017-12-14 13:19:01 -0800239 }
240 if app.headerJarFile != nil {
241 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", app.headerJarFile.String())
242 }
Colin Crossf6237212018-10-29 23:14:58 -0700243 if app.bundleFile != nil {
244 fmt.Fprintln(w, "LOCAL_SOONG_BUNDLE :=", app.bundleFile.String())
245 }
Colin Cross70798562017-12-13 22:42:59 -0800246 if app.jacocoReportClassesFile != nil {
247 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", app.jacocoReportClassesFile.String())
248 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800249 if app.proguardDictionary != nil {
250 fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", app.proguardDictionary.String())
251 }
Colin Cross70798562017-12-13 22:42:59 -0800252
253 if app.Name() == "framework-res" {
254 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
255 // Make base_rules.mk not put framework-res in a subdirectory called
256 // framework_res.
257 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
258 }
259
260 if len(app.rroDirs) > 0 {
Colin Crossa140bb02018-04-17 10:52:26 -0700261 // Reverse the order, Soong stores rroDirs in aapt2 order (low to high priority), but Make
262 // expects it in LOCAL_RESOURCE_DIRS order (high to low priority).
263 fmt.Fprintln(w, "LOCAL_SOONG_RRO_DIRS :=", strings.Join(android.ReversePaths(app.rroDirs).Strings(), " "))
Colin Cross70798562017-12-13 22:42:59 -0800264 }
265
266 if Bool(app.appProperties.Export_package_resources) {
267 fmt.Fprintln(w, "LOCAL_EXPORT_PACKAGE_RESOURCES := true")
268 }
269
270 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", app.manifestPath.String())
271
Colin Cross16056062017-12-13 22:46:28 -0800272 if Bool(app.appProperties.Privileged) {
273 fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true")
274 }
Colin Crosse1731a52017-12-14 11:22:55 -0800275
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900276 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.Pem.String())
Jaewoong Jung9109d722019-01-30 13:13:52 -0800277 if overriddenPkgs := app.getOverriddenPackages(); len(overriddenPkgs) > 0 {
278 fmt.Fprintln(w, "LOCAL_OVERRIDES_PACKAGES :=", strings.Join(overriddenPkgs, " "))
Jason Monkd4122be2018-08-10 09:33:36 -0400279 }
Colin Crossa4f08812018-10-02 22:03:40 -0700280
281 for _, jniLib := range app.installJniLibs {
282 fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), "+=", jniLib.name)
283 }
Colin Cross43f08db2018-11-12 10:13:39 -0800284 if len(app.dexpreopter.builtInstalled) > 0 {
Colin Crossdeabb942019-02-11 14:11:09 -0800285 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", app.dexpreopter.builtInstalled)
Colin Cross43f08db2018-11-12 10:13:39 -0800286 }
Colin Crosse560c4a2019-03-19 16:03:11 -0700287 for _, split := range app.aapt.splits {
288 install := "$(LOCAL_MODULE_PATH)/" + strings.TrimSuffix(app.installApkName, ".apk") + split.suffix + ".apk"
289 fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED +=", split.path.String()+":"+install)
290 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800291 },
292 },
293 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700294}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800295
Jaewoong Jung9109d722019-01-30 13:13:52 -0800296func (a *AndroidApp) getOverriddenPackages() []string {
297 var overridden []string
298 if len(a.appProperties.Overrides) > 0 {
299 overridden = append(overridden, a.appProperties.Overrides...)
300 }
301 if a.Name() != a.installApkName {
302 overridden = append(overridden, a.Name())
303 }
304 return overridden
305}
306
Colin Crossae5caf52018-05-22 11:11:52 -0700307func (a *AndroidTest) AndroidMk() android.AndroidMkData {
308 data := a.AndroidApp.AndroidMk()
309 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
310 fmt.Fprintln(w, "LOCAL_MODULE_TAGS := tests")
311 if len(a.testProperties.Test_suites) > 0 {
312 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
313 strings.Join(a.testProperties.Test_suites, " "))
Colin Cross303e21f2018-08-07 16:49:25 -0700314 } else {
315 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE := null-suite")
Colin Crossae5caf52018-05-22 11:11:52 -0700316 }
Colin Cross303e21f2018-08-07 16:49:25 -0700317 if a.testConfig != nil {
318 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", a.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700319 }
Colin Crossae5caf52018-05-22 11:11:52 -0700320 })
Colin Crossd96ca352018-08-10 16:06:24 -0700321 androidMkWriteTestData(a.data, &data)
Colin Crossae5caf52018-05-22 11:11:52 -0700322
323 return data
324}
325
Colin Cross252fc6f2018-10-04 15:22:03 -0700326func (a *AndroidTestHelperApp) AndroidMk() android.AndroidMkData {
327 data := a.AndroidApp.AndroidMk()
328 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
329 fmt.Fprintln(w, "LOCAL_MODULE_TAGS := tests")
330 if len(a.appTestHelperAppProperties.Test_suites) > 0 {
331 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
332 strings.Join(a.appTestHelperAppProperties.Test_suites, " "))
333 } else {
334 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE := null-suite")
335 }
336 })
337
338 return data
339}
340
Colin Crossa97c5d32018-03-28 14:58:31 -0700341func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
342 data := a.Library.AndroidMk()
343
344 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossa54974c2018-10-29 23:15:37 -0700345 if a.aarFile != nil {
346 fmt.Fprintln(w, "LOCAL_SOONG_AAR :=", a.aarFile.String())
347 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700348 if a.proguardDictionary != nil {
349 fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", a.proguardDictionary.String())
350 }
351
352 if a.Name() == "framework-res" {
353 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
354 // Make base_rules.mk not put framework-res in a subdirectory called
355 // framework_res.
356 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
357 }
358
359 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
Colin Cross66f78822018-05-02 12:58:28 -0700360 fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", a.extraAaptPackagesFile.String())
Colin Crossa97c5d32018-03-28 14:58:31 -0700361 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.manifestPath.String())
Colin Cross89c31582018-04-30 15:55:11 -0700362 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
363 strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
Colin Crossa97c5d32018-03-28 14:58:31 -0700364 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossa97c5d32018-03-28 14:58:31 -0700365 })
366
367 return data
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800368}
Nan Zhang581fd212018-01-10 16:06:12 -0800369
370func (jd *Javadoc) AndroidMk() android.AndroidMkData {
371 return android.AndroidMkData{
372 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800373 OutputFile: android.OptionalPathForPath(jd.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700374 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800375 Extra: []android.AndroidMkExtraFunc{
376 func(w io.Writer, outputFile android.Path) {
Colin Cross38b40df2018-04-10 16:14:46 -0700377 if BoolDefault(jd.properties.Installable, true) {
Nan Zhang581fd212018-01-10 16:06:12 -0800378 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", jd.docZip.String())
379 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800380 if jd.stubsSrcJar != nil {
381 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", jd.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800382 }
383 },
384 },
385 }
386}
387
388func (ddoc *Droiddoc) AndroidMk() android.AndroidMkData {
389 return android.AndroidMkData{
390 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800391 OutputFile: android.OptionalPathForPath(ddoc.stubsSrcJar),
Colin Cross5fa9d6f2018-08-08 21:44:48 -0700392 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
Nan Zhang581fd212018-01-10 16:06:12 -0800393 Extra: []android.AndroidMkExtraFunc{
394 func(w io.Writer, outputFile android.Path) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700395 if BoolDefault(ddoc.Javadoc.properties.Installable, true) && ddoc.Javadoc.docZip != nil {
Nan Zhang581fd212018-01-10 16:06:12 -0800396 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", ddoc.Javadoc.docZip.String())
397 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800398 if ddoc.Javadoc.stubsSrcJar != nil {
399 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", ddoc.Javadoc.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800400 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700401 if ddoc.checkCurrentApiTimestamp != nil {
402 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-current-api")
403 fmt.Fprintln(w, ddoc.Name()+"-check-current-api:",
404 ddoc.checkCurrentApiTimestamp.String())
405
406 fmt.Fprintln(w, ".PHONY: checkapi")
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900407 fmt.Fprintln(w, "checkapi:",
Nan Zhang61819ce2018-05-04 18:49:16 -0700408 ddoc.checkCurrentApiTimestamp.String())
409
410 fmt.Fprintln(w, ".PHONY: droidcore")
411 fmt.Fprintln(w, "droidcore: checkapi")
412 }
413 if ddoc.updateCurrentApiTimestamp != nil {
Dan Willemsena03c43a2018-07-24 13:00:52 -0700414 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-update-current-api")
Nan Zhang61819ce2018-05-04 18:49:16 -0700415 fmt.Fprintln(w, ddoc.Name()+"-update-current-api:",
416 ddoc.updateCurrentApiTimestamp.String())
417
418 fmt.Fprintln(w, ".PHONY: update-api")
419 fmt.Fprintln(w, "update-api:",
420 ddoc.updateCurrentApiTimestamp.String())
421 }
422 if ddoc.checkLastReleasedApiTimestamp != nil {
423 fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-last-released-api")
424 fmt.Fprintln(w, ddoc.Name()+"-check-last-released-api:",
425 ddoc.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100426
Adrian Roos62e34b92019-01-30 19:51:39 +0100427 if ddoc.Name() == "api-stubs-docs" || ddoc.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100428 fmt.Fprintln(w, ".PHONY: checkapi")
429 fmt.Fprintln(w, "checkapi:",
430 ddoc.checkLastReleasedApiTimestamp.String())
431
432 fmt.Fprintln(w, ".PHONY: droidcore")
433 fmt.Fprintln(w, "droidcore: checkapi")
434 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700435 }
Nan Zhang28c68b92018-03-13 16:17:01 -0700436 apiFilePrefix := "INTERNAL_PLATFORM_"
437 if String(ddoc.properties.Api_tag_name) != "" {
438 apiFilePrefix += String(ddoc.properties.Api_tag_name) + "_"
439 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700440 if ddoc.apiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700441 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", ddoc.apiFile.String())
442 }
David Brazdilfbe4cc32018-05-31 13:56:46 +0100443 if ddoc.dexApiFile != nil {
444 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", ddoc.dexApiFile.String())
445 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700446 if ddoc.privateApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700447 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", ddoc.privateApiFile.String())
448 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700449 if ddoc.privateDexApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700450 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", ddoc.privateDexApiFile.String())
451 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700452 if ddoc.removedApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700453 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", ddoc.removedApiFile.String())
454 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700455 if ddoc.removedDexApiFile != nil {
David Brazdilaac0c3c2018-04-24 16:23:29 +0100456 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", ddoc.removedDexApiFile.String())
457 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700458 if ddoc.exactApiFile != nil {
Nan Zhang28c68b92018-03-13 16:17:01 -0700459 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", ddoc.exactApiFile.String())
460 }
Nan Zhang66dc2362018-08-14 20:41:04 -0700461 if ddoc.proguardFile != nil {
462 fmt.Fprintln(w, apiFilePrefix+"PROGUARD_FILE := ", ddoc.proguardFile.String())
463 }
Nan Zhang581fd212018-01-10 16:06:12 -0800464 },
465 },
466 }
467}
Colin Crossd96ca352018-08-10 16:06:24 -0700468
Nan Zhang1598a9e2018-09-04 17:14:32 -0700469func (dstubs *Droidstubs) AndroidMk() android.AndroidMkData {
470 return android.AndroidMkData{
471 Class: "JAVA_LIBRARIES",
472 OutputFile: android.OptionalPathForPath(dstubs.stubsSrcJar),
473 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
474 Extra: []android.AndroidMkExtraFunc{
475 func(w io.Writer, outputFile android.Path) {
476 if dstubs.Javadoc.stubsSrcJar != nil {
477 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", dstubs.Javadoc.stubsSrcJar.String())
478 }
Nan Zhangd23ac692018-09-18 10:41:33 -0700479 if dstubs.apiVersionsXml != nil {
480 fmt.Fprintln(w, "LOCAL_DROIDDOC_API_VERSIONS_XML := ", dstubs.apiVersionsXml.String())
481 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700482 if dstubs.annotationsZip != nil {
483 fmt.Fprintln(w, "LOCAL_DROIDDOC_ANNOTATIONS_ZIP := ", dstubs.annotationsZip.String())
484 }
Nan Zhang71bbe632018-09-17 14:32:21 -0700485 if dstubs.jdiffDocZip != nil {
486 fmt.Fprintln(w, "LOCAL_DROIDDOC_JDIFF_DOC_ZIP := ", dstubs.jdiffDocZip.String())
487 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700488 if dstubs.checkCurrentApiTimestamp != nil {
489 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-current-api")
490 fmt.Fprintln(w, dstubs.Name()+"-check-current-api:",
491 dstubs.checkCurrentApiTimestamp.String())
492
493 fmt.Fprintln(w, ".PHONY: checkapi")
494 fmt.Fprintln(w, "checkapi:",
495 dstubs.checkCurrentApiTimestamp.String())
496
497 fmt.Fprintln(w, ".PHONY: droidcore")
498 fmt.Fprintln(w, "droidcore: checkapi")
499 }
500 if dstubs.updateCurrentApiTimestamp != nil {
501 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-update-current-api")
502 fmt.Fprintln(w, dstubs.Name()+"-update-current-api:",
503 dstubs.updateCurrentApiTimestamp.String())
504
505 fmt.Fprintln(w, ".PHONY: update-api")
506 fmt.Fprintln(w, "update-api:",
507 dstubs.updateCurrentApiTimestamp.String())
508 }
509 if dstubs.checkLastReleasedApiTimestamp != nil {
510 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-last-released-api")
511 fmt.Fprintln(w, dstubs.Name()+"-check-last-released-api:",
512 dstubs.checkLastReleasedApiTimestamp.String())
Adrian Roose3fe4812019-01-23 14:51:55 +0100513
Adrian Roos62e34b92019-01-30 19:51:39 +0100514 if dstubs.Name() == "api-stubs-docs" || dstubs.Name() == "system-api-stubs-docs" {
Adrian Roose3fe4812019-01-23 14:51:55 +0100515 fmt.Fprintln(w, ".PHONY: checkapi")
516 fmt.Fprintln(w, "checkapi:",
517 dstubs.checkLastReleasedApiTimestamp.String())
518
519 fmt.Fprintln(w, ".PHONY: droidcore")
520 fmt.Fprintln(w, "droidcore: checkapi")
521 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700522 }
Pete Gillin581d6082018-10-22 15:55:04 +0100523 if dstubs.checkNullabilityWarningsTimestamp != nil {
524 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings")
525 fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:",
526 dstubs.checkNullabilityWarningsTimestamp.String())
527
528 fmt.Fprintln(w, ".PHONY:", "droidcore")
529 fmt.Fprintln(w, "droidcore: ", dstubs.Name()+"-check-nullability-warnings")
530 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700531 apiFilePrefix := "INTERNAL_PLATFORM_"
532 if String(dstubs.properties.Api_tag_name) != "" {
533 apiFilePrefix += String(dstubs.properties.Api_tag_name) + "_"
534 }
535 if dstubs.apiFile != nil {
536 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", dstubs.apiFile.String())
537 }
538 if dstubs.dexApiFile != nil {
539 fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", dstubs.dexApiFile.String())
540 }
541 if dstubs.privateApiFile != nil {
542 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", dstubs.privateApiFile.String())
543 }
544 if dstubs.privateDexApiFile != nil {
545 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", dstubs.privateDexApiFile.String())
546 }
547 if dstubs.removedApiFile != nil {
548 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", dstubs.removedApiFile.String())
549 }
550 if dstubs.removedDexApiFile != nil {
551 fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", dstubs.removedDexApiFile.String())
552 }
553 if dstubs.exactApiFile != nil {
554 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", dstubs.exactApiFile.String())
555 }
556 },
557 },
558 }
559}
560
Colin Crossd96ca352018-08-10 16:06:24 -0700561func androidMkWriteTestData(data android.Paths, ret *android.AndroidMkData) {
562 var testFiles []string
563 for _, d := range data {
564 testFiles = append(testFiles, d.String()+":"+d.Rel())
565 }
566 if len(testFiles) > 0 {
567 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
568 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUPPORT_FILES := "+strings.Join(testFiles, " "))
569 })
570 }
571}