Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 18 | "fmt" |
| 19 | "io" |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 20 | "strings" |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 21 | |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 22 | "github.com/google/blueprint/proptools" |
| 23 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 24 | "android/soong/android" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 25 | ) |
| 26 | |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 27 | func (library *Library) AndroidMk() android.AndroidMkData { |
| 28 | return android.AndroidMkData{ |
| 29 | Class: "JAVA_LIBRARIES", |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 30 | OutputFile: android.OptionalPathForPath(library.implementationJarFile), |
Colin Cross | 5349941 | 2017-09-07 13:20:25 -0700 | [diff] [blame] | 31 | Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 32 | Extra: []android.AndroidMkExtraFunc{ |
| 33 | func(w io.Writer, outputFile android.Path) { |
Colin Cross | 5beccee | 2017-12-07 15:28:59 -0800 | [diff] [blame] | 34 | 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 Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 42 | if library.properties.Installable != nil && *library.properties.Installable == false { |
| 43 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true") |
| 44 | } |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 45 | if library.dexJarFile != nil { |
| 46 | fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String()) |
Colin Cross | 1bd8780 | 2017-12-05 15:31:19 -0800 | [diff] [blame] | 47 | 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 Cross | a22116e | 2017-10-19 14:18:58 -0700 | [diff] [blame] | 59 | } |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 60 | } |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 61 | fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(library.deviceProperties.Sdk_version)) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 62 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String()) |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 63 | |
| 64 | if library.jacocoReportClassesFile != nil { |
| 65 | fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", library.jacocoReportClassesFile.String()) |
| 66 | } |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 67 | |
| 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 Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 75 | }, |
| 76 | }, |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 77 | 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 Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 85 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationJarFile.String()) |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 86 | 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 Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 92 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.implementationJarFile.String()) |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 93 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " ")) |
| 94 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk") |
| 95 | } |
| 96 | }, |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 97 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 100 | func (prebuilt *Import) AndroidMk() android.AndroidMkData { |
| 101 | return android.AndroidMkData{ |
| 102 | Class: "JAVA_LIBRARIES", |
| 103 | OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile), |
Colin Cross | 5349941 | 2017-09-07 13:20:25 -0700 | [diff] [blame] | 104 | Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 105 | Extra: []android.AndroidMkExtraFunc{ |
| 106 | func(w io.Writer, outputFile android.Path) { |
Colin Cross | 535e2cf | 2017-10-20 17:57:49 -0700 | [diff] [blame] | 107 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !proptools.Bool(prebuilt.properties.Installable)) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 108 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String()) |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 109 | fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(prebuilt.properties.Sdk_version)) |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 110 | }, |
| 111 | }, |
| 112 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 113 | } |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 114 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 115 | func (prebuilt *AARImport) AndroidMk() android.AndroidMkData { |
| 116 | return android.AndroidMkData{ |
| 117 | Class: "JAVA_LIBRARIES", |
| 118 | OutputFile: android.OptionalPathForPath(prebuilt.classpathFile), |
| 119 | Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", |
| 120 | Extra: []android.AndroidMkExtraFunc{ |
| 121 | func(w io.Writer, outputFile android.Path) { |
| 122 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true") |
| 123 | fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false") |
| 124 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.classpathFile.String()) |
| 125 | fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", prebuilt.exportPackage.String()) |
| 126 | fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String()) |
| 127 | fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(prebuilt.properties.Sdk_version)) |
| 128 | }, |
| 129 | }, |
| 130 | } |
| 131 | } |
| 132 | |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 133 | func (binary *Binary) AndroidMk() android.AndroidMkData { |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 134 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 135 | if !binary.isWrapperVariant { |
| 136 | return android.AndroidMkData{ |
| 137 | Class: "JAVA_LIBRARIES", |
| 138 | OutputFile: android.OptionalPathForPath(binary.implementationJarFile), |
| 139 | Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", |
| 140 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 141 | android.WriteAndroidMkData(w, data) |
Colin Cross | 1965568 | 2017-09-07 17:00:22 -0700 | [diff] [blame] | 142 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 143 | fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)") |
| 144 | }, |
| 145 | } |
| 146 | } else { |
| 147 | return android.AndroidMkData{ |
| 148 | Class: "EXECUTABLES", |
| 149 | OutputFile: android.OptionalPathForPath(binary.wrapperFile), |
| 150 | Extra: []android.AndroidMkExtraFunc{ |
| 151 | func(w io.Writer, outputFile android.Path) { |
| 152 | fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false") |
| 153 | }, |
| 154 | }, |
| 155 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 156 | android.WriteAndroidMkData(w, data) |
| 157 | |
| 158 | // Ensure that the wrapper script timestamp is always updated when the jar is updated |
| 159 | fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)") |
| 160 | fmt.Fprintln(w, "jar_installed_module :=") |
| 161 | }, |
| 162 | } |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 163 | } |
| 164 | } |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 165 | |
| 166 | func (app *AndroidApp) AndroidMk() android.AndroidMkData { |
| 167 | return android.AndroidMkData{ |
| 168 | Class: "APPS", |
| 169 | OutputFile: android.OptionalPathForPath(app.outputFile), |
| 170 | Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk", |
| 171 | Extra: []android.AndroidMkExtraFunc{ |
| 172 | func(w io.Writer, outputFile android.Path) { |
Colin Cross | 7079856 | 2017-12-13 22:42:59 -0800 | [diff] [blame] | 173 | fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", app.exportPackage.String()) |
| 174 | if app.dexJarFile != nil { |
| 175 | fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String()) |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 176 | } |
Colin Cross | 5dfabfb | 2017-12-14 13:19:01 -0800 | [diff] [blame] | 177 | if app.implementationJarFile != nil { |
| 178 | fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", app.implementationJarFile) |
| 179 | } |
| 180 | if app.headerJarFile != nil { |
| 181 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", app.headerJarFile.String()) |
| 182 | } |
Colin Cross | 7079856 | 2017-12-13 22:42:59 -0800 | [diff] [blame] | 183 | if app.jacocoReportClassesFile != nil { |
| 184 | fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", app.jacocoReportClassesFile.String()) |
| 185 | } |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 186 | if app.proguardDictionary != nil { |
| 187 | fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", app.proguardDictionary.String()) |
| 188 | } |
Colin Cross | 7079856 | 2017-12-13 22:42:59 -0800 | [diff] [blame] | 189 | |
| 190 | if app.Name() == "framework-res" { |
| 191 | fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)") |
| 192 | // Make base_rules.mk not put framework-res in a subdirectory called |
| 193 | // framework_res. |
| 194 | fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true") |
| 195 | } |
| 196 | |
| 197 | if len(app.rroDirs) > 0 { |
| 198 | fmt.Fprintln(w, "LOCAL_SOONG_RRO_DIRS :=", strings.Join(app.rroDirs.Strings(), " ")) |
| 199 | } |
| 200 | |
| 201 | if Bool(app.appProperties.Export_package_resources) { |
| 202 | fmt.Fprintln(w, "LOCAL_EXPORT_PACKAGE_RESOURCES := true") |
| 203 | } |
| 204 | |
| 205 | fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", app.manifestPath.String()) |
| 206 | |
Colin Cross | 1605606 | 2017-12-13 22:46:28 -0800 | [diff] [blame] | 207 | if Bool(app.appProperties.Privileged) { |
| 208 | fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true") |
| 209 | } |
Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 210 | |
| 211 | fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.pem.String()) |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 212 | }, |
| 213 | }, |
| 214 | } |
| 215 | |
| 216 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 217 | |
| 218 | func (jd *Javadoc) AndroidMk() android.AndroidMkData { |
| 219 | return android.AndroidMkData{ |
| 220 | Class: "JAVA_LIBRARIES", |
| 221 | OutputFile: android.OptionalPathForPath(jd.stubsJar), |
| 222 | Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", |
| 223 | Extra: []android.AndroidMkExtraFunc{ |
| 224 | func(w io.Writer, outputFile android.Path) { |
| 225 | if jd.properties.Installable == nil || *jd.properties.Installable == true { |
| 226 | fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", jd.docZip.String()) |
| 227 | } |
| 228 | if jd.stubsJar != nil { |
| 229 | fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_JAR := ", jd.stubsJar.String()) |
| 230 | } |
| 231 | }, |
| 232 | }, |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | func (ddoc *Droiddoc) AndroidMk() android.AndroidMkData { |
| 237 | return android.AndroidMkData{ |
| 238 | Class: "JAVA_LIBRARIES", |
| 239 | OutputFile: android.OptionalPathForPath(ddoc.stubsJar), |
| 240 | Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", |
| 241 | Extra: []android.AndroidMkExtraFunc{ |
| 242 | func(w io.Writer, outputFile android.Path) { |
| 243 | if ddoc.Javadoc.properties.Installable == nil || *ddoc.Javadoc.properties.Installable == true { |
| 244 | fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", ddoc.Javadoc.docZip.String()) |
| 245 | } |
| 246 | if ddoc.Javadoc.stubsJar != nil { |
| 247 | fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_JAR := ", ddoc.Javadoc.stubsJar.String()) |
| 248 | } |
| 249 | }, |
| 250 | }, |
| 251 | } |
| 252 | } |