blob: 1a4b27d7a4bbe461dbb1e10f48e0a2676be86725 [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 Crossa18e9cf2017-08-10 17:00:19 -070045 },
46 },
Colin Cross92430102017-10-09 14:59:32 -070047 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
48 android.WriteAndroidMkData(w, data)
49
50 if proptools.Bool(library.deviceProperties.Hostdex) && !library.Host() {
51 fmt.Fprintln(w, "include $(CLEAR_VARS)")
52 fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex")
53 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
54 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES")
Nan Zhanged19fc32017-10-19 13:06:22 -070055 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationJarFile.String())
Colin Cross92430102017-10-09 14:59:32 -070056 if library.properties.Installable != nil && *library.properties.Installable == false {
57 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
58 }
59 if library.dexJarFile != nil {
60 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
61 }
Nan Zhanged19fc32017-10-19 13:06:22 -070062 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.implementationJarFile.String())
Colin Cross92430102017-10-09 14:59:32 -070063 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " "))
64 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
65 }
66 },
Colin Crossa18e9cf2017-08-10 17:00:19 -070067 }
Dan Willemsen218f6562015-07-08 18:13:11 -070068}
69
Colin Crossa18e9cf2017-08-10 17:00:19 -070070func (prebuilt *Import) AndroidMk() android.AndroidMkData {
71 return android.AndroidMkData{
72 Class: "JAVA_LIBRARIES",
73 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Colin Cross53499412017-09-07 13:20:25 -070074 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -070075 Extra: []android.AndroidMkExtraFunc{
76 func(w io.Writer, outputFile android.Path) {
Colin Cross535e2cf2017-10-20 17:57:49 -070077 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !proptools.Bool(prebuilt.properties.Installable))
Nan Zhanged19fc32017-10-19 13:06:22 -070078 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
Nan Zhangea568a42017-11-08 21:20:04 -080079 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(prebuilt.properties.Sdk_version))
Colin Crossa18e9cf2017-08-10 17:00:19 -070080 },
81 },
82 }
Dan Willemsen218f6562015-07-08 18:13:11 -070083}
Colin Cross10a03492017-08-10 17:09:43 -070084
85func (binary *Binary) AndroidMk() android.AndroidMkData {
86 return android.AndroidMkData{
87 Class: "JAVA_LIBRARIES",
Nan Zhanged19fc32017-10-19 13:06:22 -070088 OutputFile: android.OptionalPathForPath(binary.implementationJarFile),
Colin Cross53499412017-09-07 13:20:25 -070089 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Cross10a03492017-08-10 17:09:43 -070090 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
91 android.WriteAndroidMkData(w, data)
92
Colin Cross19655682017-09-07 17:00:22 -070093 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
Colin Cross10a03492017-08-10 17:09:43 -070094 fmt.Fprintln(w, "include $(CLEAR_VARS)")
95 fmt.Fprintln(w, "LOCAL_MODULE := "+name)
96 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := EXECUTABLES")
97 if strings.Contains(prefix, "HOST_") {
98 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
99 }
100 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
Colin Cross19655682017-09-07 17:00:22 -0700101 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", binary.wrapperFile.String())
Colin Cross10a03492017-08-10 17:09:43 -0700102 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Cross19655682017-09-07 17:00:22 -0700103
104 // Ensure that the wrapper script timestamp is always updated when the jar is updated
105 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
106 fmt.Fprintln(w, "jar_installed_module :=")
Colin Cross10a03492017-08-10 17:09:43 -0700107 },
108 }
109}