blob: acf597bb29ed69518b2971b2407acbace69af6fb [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 Cross2c429dc2017-08-31 16:45:16 -070034 if library.properties.Installable != nil && *library.properties.Installable == false {
35 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
36 }
Colin Cross6ade34f2017-09-15 13:00:47 -070037 if library.dexJarFile != nil {
38 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
Colin Cross1bd87802017-12-05 15:31:19 -080039 if library.deviceProperties.Dex_preopt.Enabled != nil {
40 fmt.Fprintln(w, "LOCAL_DEX_PREOPT :=", *library.deviceProperties.Dex_preopt.Enabled)
41 }
42 if library.deviceProperties.Dex_preopt.App_image != nil {
43 fmt.Fprintln(w, "LOCAL_DEX_PREOPT_APP_IMAGE :=", *library.deviceProperties.Dex_preopt.App_image)
44 }
45 if library.deviceProperties.Dex_preopt.Profile_guided != nil {
46 fmt.Fprintln(w, "LOCAL_DEX_PREOPT_GENERATE_PROFILE :=", *library.deviceProperties.Dex_preopt.Profile_guided)
47 }
48 if library.deviceProperties.Dex_preopt.Profile != nil {
49 fmt.Fprintln(w, "LOCAL_DEX_PREOPT_GENERATE_PROFILE := true")
50 fmt.Fprintln(w, "LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING := $(LOCAL_PATH)/"+*library.deviceProperties.Dex_preopt.Profile)
Colin Crossa22116e2017-10-19 14:18:58 -070051 }
Colin Cross6ade34f2017-09-15 13:00:47 -070052 }
Nan Zhangea568a42017-11-08 21:20:04 -080053 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(library.deviceProperties.Sdk_version))
Nan Zhanged19fc32017-10-19 13:06:22 -070054 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
Colin Crosscb933592017-11-22 13:49:43 -080055
56 if library.jacocoReportClassesFile != nil {
57 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", library.jacocoReportClassesFile.String())
58 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -080059
60 // Temporary hack: export sources used to compile framework.jar to Make
61 // to be used for droiddoc
62 // TODO(ccross): remove this once droiddoc is in soong
63 if library.Name() == "framework" {
64 fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCS :=", strings.Join(library.compiledJavaSrcs.Strings(), " "))
65 fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCJARS :=", strings.Join(library.compiledSrcJars.Strings(), " "))
66 }
Colin Crossa18e9cf2017-08-10 17:00:19 -070067 },
68 },
Colin Cross92430102017-10-09 14:59:32 -070069 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
70 android.WriteAndroidMkData(w, data)
71
72 if proptools.Bool(library.deviceProperties.Hostdex) && !library.Host() {
73 fmt.Fprintln(w, "include $(CLEAR_VARS)")
74 fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex")
75 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
76 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES")
Nan Zhanged19fc32017-10-19 13:06:22 -070077 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationJarFile.String())
Colin Cross92430102017-10-09 14:59:32 -070078 if library.properties.Installable != nil && *library.properties.Installable == false {
79 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
80 }
81 if library.dexJarFile != nil {
82 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
83 }
Nan Zhanged19fc32017-10-19 13:06:22 -070084 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.implementationJarFile.String())
Colin Cross92430102017-10-09 14:59:32 -070085 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " "))
86 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
87 }
88 },
Colin Crossa18e9cf2017-08-10 17:00:19 -070089 }
Dan Willemsen218f6562015-07-08 18:13:11 -070090}
91
Colin Crossa18e9cf2017-08-10 17:00:19 -070092func (prebuilt *Import) AndroidMk() android.AndroidMkData {
93 return android.AndroidMkData{
94 Class: "JAVA_LIBRARIES",
95 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Colin Cross53499412017-09-07 13:20:25 -070096 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -070097 Extra: []android.AndroidMkExtraFunc{
98 func(w io.Writer, outputFile android.Path) {
Colin Cross535e2cf2017-10-20 17:57:49 -070099 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !proptools.Bool(prebuilt.properties.Installable))
Nan Zhanged19fc32017-10-19 13:06:22 -0700100 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
Nan Zhangea568a42017-11-08 21:20:04 -0800101 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(prebuilt.properties.Sdk_version))
Colin Crossa18e9cf2017-08-10 17:00:19 -0700102 },
103 },
104 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700105}
Colin Cross10a03492017-08-10 17:09:43 -0700106
107func (binary *Binary) AndroidMk() android.AndroidMkData {
Colin Cross10a03492017-08-10 17:09:43 -0700108
Colin Cross6b4a32d2017-12-05 13:42:45 -0800109 if !binary.isWrapperVariant {
110 return android.AndroidMkData{
111 Class: "JAVA_LIBRARIES",
112 OutputFile: android.OptionalPathForPath(binary.implementationJarFile),
113 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
114 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
115 android.WriteAndroidMkData(w, data)
Colin Cross19655682017-09-07 17:00:22 -0700116
Colin Cross6b4a32d2017-12-05 13:42:45 -0800117 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
118 },
119 }
120 } else {
121 return android.AndroidMkData{
122 Class: "EXECUTABLES",
123 OutputFile: android.OptionalPathForPath(binary.wrapperFile),
124 Extra: []android.AndroidMkExtraFunc{
125 func(w io.Writer, outputFile android.Path) {
126 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
127 },
128 },
129 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
130 android.WriteAndroidMkData(w, data)
131
132 // Ensure that the wrapper script timestamp is always updated when the jar is updated
133 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
134 fmt.Fprintln(w, "jar_installed_module :=")
135 },
136 }
Colin Cross10a03492017-08-10 17:09:43 -0700137 }
138}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800139
140func (app *AndroidApp) AndroidMk() android.AndroidMkData {
141 return android.AndroidMkData{
142 Class: "APPS",
143 OutputFile: android.OptionalPathForPath(app.outputFile),
144 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
145 Extra: []android.AndroidMkExtraFunc{
146 func(w io.Writer, outputFile android.Path) {
147 if Bool(app.appProperties.Export_package_resources) {
148 if app.dexJarFile != nil {
149 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String())
150 }
151 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", app.exportPackage.String())
152
153 if app.jacocoReportClassesFile != nil {
154 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", app.jacocoReportClassesFile.String())
155 }
156
157 if app.Name() == "framework-res" {
158 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
159 // Make base_rules.mk not put framework-res in a subdirectory called
160 // framework_res.
161 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
162 }
Colin Cross890ff552017-11-30 20:13:19 -0800163
164 if len(app.rroDirs) > 0 {
165 fmt.Fprintln(w, "LOCAL_SOONG_RRO_DIRS :=", strings.Join(app.rroDirs.Strings(), " "))
166 }
167 fmt.Fprintln(w, "LOCAL_EXPORT_PACKAGE_RESOURCES :=",
168 Bool(app.appProperties.Export_package_resources))
169 fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", app.manifestPath.String())
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800170 }
171 },
172 },
173 }
174
175}