blob: c9a05c34ecb0abb6542358034ccc314d222066e9 [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 Cross92430102017-10-09 14:59:32 -070022 "github.com/google/blueprint/proptools"
23
Colin Cross635c3b02016-05-18 15:37:25 -070024 "android/soong/android"
Dan Willemsen218f6562015-07-08 18:13:11 -070025)
26
Colin Crossa18e9cf2017-08-10 17:00:19 -070027func (library *Library) AndroidMk() android.AndroidMkData {
28 return android.AndroidMkData{
29 Class: "JAVA_LIBRARIES",
Nan Zhanged19fc32017-10-19 13:06:22 -070030 OutputFile: android.OptionalPathForPath(library.implementationJarFile),
Colin Cross53499412017-09-07 13:20:25 -070031 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -070032 Extra: []android.AndroidMkExtraFunc{
33 func(w io.Writer, outputFile android.Path) {
Colin Cross5beccee2017-12-07 15:28:59 -080034 if len(library.logtagsSrcs) > 0 {
35 var logtags []string
36 for _, l := range library.logtagsSrcs {
37 logtags = append(logtags, l.Rel())
38 }
39 fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES :=", strings.Join(logtags, " "))
40 }
41
Colin Cross2c429dc2017-08-31 16:45:16 -070042 if library.properties.Installable != nil && *library.properties.Installable == false {
43 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
44 }
Colin Cross6ade34f2017-09-15 13:00:47 -070045 if library.dexJarFile != nil {
46 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
Colin Cross1bd87802017-12-05 15:31:19 -080047 if library.deviceProperties.Dex_preopt.Enabled != nil {
48 fmt.Fprintln(w, "LOCAL_DEX_PREOPT :=", *library.deviceProperties.Dex_preopt.Enabled)
49 }
50 if library.deviceProperties.Dex_preopt.App_image != nil {
51 fmt.Fprintln(w, "LOCAL_DEX_PREOPT_APP_IMAGE :=", *library.deviceProperties.Dex_preopt.App_image)
52 }
53 if library.deviceProperties.Dex_preopt.Profile_guided != nil {
54 fmt.Fprintln(w, "LOCAL_DEX_PREOPT_GENERATE_PROFILE :=", *library.deviceProperties.Dex_preopt.Profile_guided)
55 }
56 if library.deviceProperties.Dex_preopt.Profile != nil {
57 fmt.Fprintln(w, "LOCAL_DEX_PREOPT_GENERATE_PROFILE := true")
58 fmt.Fprintln(w, "LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING := $(LOCAL_PATH)/"+*library.deviceProperties.Dex_preopt.Profile)
Colin Crossa22116e2017-10-19 14:18:58 -070059 }
Colin Cross6ade34f2017-09-15 13:00:47 -070060 }
Nan Zhangea568a42017-11-08 21:20:04 -080061 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(library.deviceProperties.Sdk_version))
Nan Zhanged19fc32017-10-19 13:06:22 -070062 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
Colin Crosscb933592017-11-22 13:49:43 -080063
64 if library.jacocoReportClassesFile != nil {
65 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", library.jacocoReportClassesFile.String())
66 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -080067
68 // Temporary hack: export sources used to compile framework.jar to Make
69 // to be used for droiddoc
70 // TODO(ccross): remove this once droiddoc is in soong
71 if library.Name() == "framework" {
72 fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCS :=", strings.Join(library.compiledJavaSrcs.Strings(), " "))
73 fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCJARS :=", strings.Join(library.compiledSrcJars.Strings(), " "))
74 }
Colin Crossa18e9cf2017-08-10 17:00:19 -070075 },
76 },
Colin Cross92430102017-10-09 14:59:32 -070077 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
78 android.WriteAndroidMkData(w, data)
79
80 if proptools.Bool(library.deviceProperties.Hostdex) && !library.Host() {
81 fmt.Fprintln(w, "include $(CLEAR_VARS)")
82 fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex")
83 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
84 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES")
Nan Zhanged19fc32017-10-19 13:06:22 -070085 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationJarFile.String())
Colin Cross92430102017-10-09 14:59:32 -070086 if library.properties.Installable != nil && *library.properties.Installable == false {
87 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
88 }
89 if library.dexJarFile != nil {
90 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
91 }
Nan Zhanged19fc32017-10-19 13:06:22 -070092 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.implementationJarFile.String())
Colin Cross92430102017-10-09 14:59:32 -070093 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " "))
94 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
95 }
96 },
Colin Crossa18e9cf2017-08-10 17:00:19 -070097 }
Dan Willemsen218f6562015-07-08 18:13:11 -070098}
99
Colin Cross05638fc2018-04-09 18:40:24 -0700100func (j *Test) AndroidMk() android.AndroidMkData {
101 data := j.Library.AndroidMk()
102 data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
103 fmt.Fprintln(w, "LOCAL_MODULE_TAGS := tests")
104 if len(j.testProperties.Test_suites) > 0 {
105 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
106 strings.Join(j.testProperties.Test_suites, " "))
107 }
108 })
109
110 return data
111}
112
Colin Crossa18e9cf2017-08-10 17:00:19 -0700113func (prebuilt *Import) AndroidMk() android.AndroidMkData {
114 return android.AndroidMkData{
115 Class: "JAVA_LIBRARIES",
116 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Colin Cross53499412017-09-07 13:20:25 -0700117 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -0700118 Extra: []android.AndroidMkExtraFunc{
119 func(w io.Writer, outputFile android.Path) {
Colin Cross535e2cf2017-10-20 17:57:49 -0700120 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !proptools.Bool(prebuilt.properties.Installable))
Nan Zhanged19fc32017-10-19 13:06:22 -0700121 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
Nan Zhangea568a42017-11-08 21:20:04 -0800122 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(prebuilt.properties.Sdk_version))
Colin Crossa18e9cf2017-08-10 17:00:19 -0700123 },
124 },
125 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700126}
Colin Cross10a03492017-08-10 17:09:43 -0700127
Colin Crossfabb6082018-02-20 17:22:23 -0800128func (prebuilt *AARImport) AndroidMk() android.AndroidMkData {
129 return android.AndroidMkData{
130 Class: "JAVA_LIBRARIES",
131 OutputFile: android.OptionalPathForPath(prebuilt.classpathFile),
132 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
133 Extra: []android.AndroidMkExtraFunc{
134 func(w io.Writer, outputFile android.Path) {
135 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
136 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
137 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.classpathFile.String())
138 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", prebuilt.exportPackage.String())
139 fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String())
140 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(prebuilt.properties.Sdk_version))
141 },
142 },
143 }
144}
145
Colin Cross10a03492017-08-10 17:09:43 -0700146func (binary *Binary) AndroidMk() android.AndroidMkData {
Colin Cross10a03492017-08-10 17:09:43 -0700147
Colin Cross6b4a32d2017-12-05 13:42:45 -0800148 if !binary.isWrapperVariant {
149 return android.AndroidMkData{
150 Class: "JAVA_LIBRARIES",
151 OutputFile: android.OptionalPathForPath(binary.implementationJarFile),
152 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
153 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
154 android.WriteAndroidMkData(w, data)
Colin Cross19655682017-09-07 17:00:22 -0700155
Colin Cross6b4a32d2017-12-05 13:42:45 -0800156 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
157 },
158 }
159 } else {
160 return android.AndroidMkData{
161 Class: "EXECUTABLES",
162 OutputFile: android.OptionalPathForPath(binary.wrapperFile),
163 Extra: []android.AndroidMkExtraFunc{
164 func(w io.Writer, outputFile android.Path) {
165 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
166 },
167 },
168 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
169 android.WriteAndroidMkData(w, data)
170
171 // Ensure that the wrapper script timestamp is always updated when the jar is updated
172 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
173 fmt.Fprintln(w, "jar_installed_module :=")
174 },
175 }
Colin Cross10a03492017-08-10 17:09:43 -0700176 }
177}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800178
179func (app *AndroidApp) AndroidMk() android.AndroidMkData {
180 return android.AndroidMkData{
181 Class: "APPS",
182 OutputFile: android.OptionalPathForPath(app.outputFile),
183 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
184 Extra: []android.AndroidMkExtraFunc{
185 func(w io.Writer, outputFile android.Path) {
Colin Cross70798562017-12-13 22:42:59 -0800186 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", app.exportPackage.String())
187 if app.dexJarFile != nil {
188 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String())
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800189 }
Colin Cross5dfabfb2017-12-14 13:19:01 -0800190 if app.implementationJarFile != nil {
191 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", app.implementationJarFile)
192 }
193 if app.headerJarFile != nil {
194 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", app.headerJarFile.String())
195 }
Colin Cross70798562017-12-13 22:42:59 -0800196 if app.jacocoReportClassesFile != nil {
197 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", app.jacocoReportClassesFile.String())
198 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800199 if app.proguardDictionary != nil {
200 fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", app.proguardDictionary.String())
201 }
Colin Cross70798562017-12-13 22:42:59 -0800202
203 if app.Name() == "framework-res" {
204 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
205 // Make base_rules.mk not put framework-res in a subdirectory called
206 // framework_res.
207 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
208 }
209
210 if len(app.rroDirs) > 0 {
211 fmt.Fprintln(w, "LOCAL_SOONG_RRO_DIRS :=", strings.Join(app.rroDirs.Strings(), " "))
212 }
213
214 if Bool(app.appProperties.Export_package_resources) {
215 fmt.Fprintln(w, "LOCAL_EXPORT_PACKAGE_RESOURCES := true")
216 }
217
218 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", app.manifestPath.String())
219
Colin Cross16056062017-12-13 22:46:28 -0800220 if Bool(app.appProperties.Privileged) {
221 fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true")
222 }
Colin Crosse1731a52017-12-14 11:22:55 -0800223
224 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.pem.String())
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800225 },
226 },
227 }
228
229}
Nan Zhang581fd212018-01-10 16:06:12 -0800230
231func (jd *Javadoc) AndroidMk() android.AndroidMkData {
232 return android.AndroidMkData{
233 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800234 OutputFile: android.OptionalPathForPath(jd.stubsSrcJar),
Nan Zhang581fd212018-01-10 16:06:12 -0800235 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
236 Extra: []android.AndroidMkExtraFunc{
237 func(w io.Writer, outputFile android.Path) {
Colin Cross38b40df2018-04-10 16:14:46 -0700238 if BoolDefault(jd.properties.Installable, true) {
Nan Zhang581fd212018-01-10 16:06:12 -0800239 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", jd.docZip.String())
240 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800241 if jd.stubsSrcJar != nil {
242 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", jd.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800243 }
244 },
245 },
246 }
247}
248
249func (ddoc *Droiddoc) AndroidMk() android.AndroidMkData {
250 return android.AndroidMkData{
251 Class: "JAVA_LIBRARIES",
Nan Zhangccff0f72018-03-08 17:26:16 -0800252 OutputFile: android.OptionalPathForPath(ddoc.stubsSrcJar),
Nan Zhang581fd212018-01-10 16:06:12 -0800253 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
254 Extra: []android.AndroidMkExtraFunc{
255 func(w io.Writer, outputFile android.Path) {
Colin Cross38b40df2018-04-10 16:14:46 -0700256 if BoolDefault(ddoc.Javadoc.properties.Installable, true) {
Nan Zhang581fd212018-01-10 16:06:12 -0800257 fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", ddoc.Javadoc.docZip.String())
258 }
Nan Zhangccff0f72018-03-08 17:26:16 -0800259 if ddoc.Javadoc.stubsSrcJar != nil {
260 fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", ddoc.Javadoc.stubsSrcJar.String())
Nan Zhang581fd212018-01-10 16:06:12 -0800261 }
Nan Zhang28c68b92018-03-13 16:17:01 -0700262 apiFilePrefix := "INTERNAL_PLATFORM_"
263 if String(ddoc.properties.Api_tag_name) != "" {
264 apiFilePrefix += String(ddoc.properties.Api_tag_name) + "_"
265 }
266 if String(ddoc.properties.Api_filename) != "" {
267 fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", ddoc.apiFile.String())
268 }
269 if String(ddoc.properties.Private_api_filename) != "" {
270 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", ddoc.privateApiFile.String())
271 }
272 if String(ddoc.properties.Private_dex_api_filename) != "" {
273 fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", ddoc.privateDexApiFile.String())
274 }
275 if String(ddoc.properties.Removed_api_filename) != "" {
276 fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", ddoc.removedApiFile.String())
277 }
278 if String(ddoc.properties.Exact_api_filename) != "" {
279 fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", ddoc.exactApiFile.String())
280 }
Nan Zhang581fd212018-01-10 16:06:12 -0800281 },
282 },
283 }
284}