blob: df83faa2380260bcd9de5dbd743419287cc6a637 [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 Crossa18e9cf2017-08-10 17:00:19 -070049 },
50 },
Colin Cross92430102017-10-09 14:59:32 -070051 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
52 android.WriteAndroidMkData(w, data)
53
54 if proptools.Bool(library.deviceProperties.Hostdex) && !library.Host() {
55 fmt.Fprintln(w, "include $(CLEAR_VARS)")
56 fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex")
57 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
58 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES")
Nan Zhanged19fc32017-10-19 13:06:22 -070059 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationJarFile.String())
Colin Cross92430102017-10-09 14:59:32 -070060 if library.properties.Installable != nil && *library.properties.Installable == false {
61 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
62 }
63 if library.dexJarFile != nil {
64 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
65 }
Nan Zhanged19fc32017-10-19 13:06:22 -070066 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.implementationJarFile.String())
Colin Cross92430102017-10-09 14:59:32 -070067 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " "))
68 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
69 }
70 },
Colin Crossa18e9cf2017-08-10 17:00:19 -070071 }
Dan Willemsen218f6562015-07-08 18:13:11 -070072}
73
Colin Crossa18e9cf2017-08-10 17:00:19 -070074func (prebuilt *Import) AndroidMk() android.AndroidMkData {
75 return android.AndroidMkData{
76 Class: "JAVA_LIBRARIES",
77 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Colin Cross53499412017-09-07 13:20:25 -070078 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -070079 Extra: []android.AndroidMkExtraFunc{
80 func(w io.Writer, outputFile android.Path) {
Colin Cross535e2cf2017-10-20 17:57:49 -070081 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !proptools.Bool(prebuilt.properties.Installable))
Nan Zhanged19fc32017-10-19 13:06:22 -070082 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
Nan Zhangea568a42017-11-08 21:20:04 -080083 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(prebuilt.properties.Sdk_version))
Colin Crossa18e9cf2017-08-10 17:00:19 -070084 },
85 },
86 }
Dan Willemsen218f6562015-07-08 18:13:11 -070087}
Colin Cross10a03492017-08-10 17:09:43 -070088
89func (binary *Binary) AndroidMk() android.AndroidMkData {
90 return android.AndroidMkData{
91 Class: "JAVA_LIBRARIES",
Nan Zhanged19fc32017-10-19 13:06:22 -070092 OutputFile: android.OptionalPathForPath(binary.implementationJarFile),
Colin Cross53499412017-09-07 13:20:25 -070093 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Cross10a03492017-08-10 17:09:43 -070094 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
95 android.WriteAndroidMkData(w, data)
96
Colin Cross19655682017-09-07 17:00:22 -070097 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
Colin Cross10a03492017-08-10 17:09:43 -070098 fmt.Fprintln(w, "include $(CLEAR_VARS)")
99 fmt.Fprintln(w, "LOCAL_MODULE := "+name)
100 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := EXECUTABLES")
101 if strings.Contains(prefix, "HOST_") {
102 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
103 }
104 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
Colin Cross19655682017-09-07 17:00:22 -0700105 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", binary.wrapperFile.String())
Colin Cross10a03492017-08-10 17:09:43 -0700106 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Cross19655682017-09-07 17:00:22 -0700107
108 // Ensure that the wrapper script timestamp is always updated when the jar is updated
109 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
110 fmt.Fprintln(w, "jar_installed_module :=")
Colin Cross10a03492017-08-10 17:09:43 -0700111 },
112 }
113}