blob: 86e000d7f958151cb71f5183c479bf686d0eeaf3 [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 Crossb4972e32017-11-22 16:02:44 -080039 if library.deviceProperties.Dex_preopt != nil && *library.deviceProperties.Dex_preopt == false {
Colin Crossa22116e2017-10-19 14:18:58 -070040 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
41 }
Colin Cross6ade34f2017-09-15 13:00:47 -070042 }
Nan Zhangea568a42017-11-08 21:20:04 -080043 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(library.deviceProperties.Sdk_version))
Nan Zhanged19fc32017-10-19 13:06:22 -070044 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
Colin Crosscb933592017-11-22 13:49:43 -080045
46 if library.jacocoReportClassesFile != nil {
47 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", library.jacocoReportClassesFile.String())
48 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -080049
50 // Temporary hack: export sources used to compile framework.jar to Make
51 // to be used for droiddoc
52 // TODO(ccross): remove this once droiddoc is in soong
53 if library.Name() == "framework" {
54 fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCS :=", strings.Join(library.compiledJavaSrcs.Strings(), " "))
55 fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCJARS :=", strings.Join(library.compiledSrcJars.Strings(), " "))
56 }
Colin Crossa18e9cf2017-08-10 17:00:19 -070057 },
58 },
Colin Cross92430102017-10-09 14:59:32 -070059 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
60 android.WriteAndroidMkData(w, data)
61
62 if proptools.Bool(library.deviceProperties.Hostdex) && !library.Host() {
63 fmt.Fprintln(w, "include $(CLEAR_VARS)")
64 fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex")
65 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
66 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES")
Nan Zhanged19fc32017-10-19 13:06:22 -070067 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationJarFile.String())
Colin Cross92430102017-10-09 14:59:32 -070068 if library.properties.Installable != nil && *library.properties.Installable == false {
69 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
70 }
71 if library.dexJarFile != nil {
72 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
73 }
Nan Zhanged19fc32017-10-19 13:06:22 -070074 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.implementationJarFile.String())
Colin Cross92430102017-10-09 14:59:32 -070075 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " "))
76 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
77 }
78 },
Colin Crossa18e9cf2017-08-10 17:00:19 -070079 }
Dan Willemsen218f6562015-07-08 18:13:11 -070080}
81
Colin Crossa18e9cf2017-08-10 17:00:19 -070082func (prebuilt *Import) AndroidMk() android.AndroidMkData {
83 return android.AndroidMkData{
84 Class: "JAVA_LIBRARIES",
85 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Colin Cross53499412017-09-07 13:20:25 -070086 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -070087 Extra: []android.AndroidMkExtraFunc{
88 func(w io.Writer, outputFile android.Path) {
Colin Cross535e2cf2017-10-20 17:57:49 -070089 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !proptools.Bool(prebuilt.properties.Installable))
Nan Zhanged19fc32017-10-19 13:06:22 -070090 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
Nan Zhangea568a42017-11-08 21:20:04 -080091 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(prebuilt.properties.Sdk_version))
Colin Crossa18e9cf2017-08-10 17:00:19 -070092 },
93 },
94 }
Dan Willemsen218f6562015-07-08 18:13:11 -070095}
Colin Cross10a03492017-08-10 17:09:43 -070096
97func (binary *Binary) AndroidMk() android.AndroidMkData {
98 return android.AndroidMkData{
99 Class: "JAVA_LIBRARIES",
Nan Zhanged19fc32017-10-19 13:06:22 -0700100 OutputFile: android.OptionalPathForPath(binary.implementationJarFile),
Colin Cross53499412017-09-07 13:20:25 -0700101 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Cross10a03492017-08-10 17:09:43 -0700102 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
103 android.WriteAndroidMkData(w, data)
104
Colin Cross19655682017-09-07 17:00:22 -0700105 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
Colin Cross10a03492017-08-10 17:09:43 -0700106 fmt.Fprintln(w, "include $(CLEAR_VARS)")
107 fmt.Fprintln(w, "LOCAL_MODULE := "+name)
108 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := EXECUTABLES")
109 if strings.Contains(prefix, "HOST_") {
110 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
111 }
112 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
Colin Cross19655682017-09-07 17:00:22 -0700113 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", binary.wrapperFile.String())
Colin Cross10a03492017-08-10 17:09:43 -0700114 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Cross19655682017-09-07 17:00:22 -0700115
116 // Ensure that the wrapper script timestamp is always updated when the jar is updated
117 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
118 fmt.Fprintln(w, "jar_installed_module :=")
Colin Cross10a03492017-08-10 17:09:43 -0700119 },
120 }
121}
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800122
123func (app *AndroidApp) AndroidMk() android.AndroidMkData {
124 return android.AndroidMkData{
125 Class: "APPS",
126 OutputFile: android.OptionalPathForPath(app.outputFile),
127 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
128 Extra: []android.AndroidMkExtraFunc{
129 func(w io.Writer, outputFile android.Path) {
130 if Bool(app.appProperties.Export_package_resources) {
131 if app.dexJarFile != nil {
132 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String())
133 }
134 fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", app.exportPackage.String())
135
136 if app.jacocoReportClassesFile != nil {
137 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", app.jacocoReportClassesFile.String())
138 }
139
140 if app.Name() == "framework-res" {
141 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
142 // Make base_rules.mk not put framework-res in a subdirectory called
143 // framework_res.
144 fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
145 }
146 }
147 },
148 },
149 }
150
151}