blob: e7f79d24da896d2f916c47a1aa0e52cea34de241 [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 Crossa22116e2017-10-19 14:18:58 -070039 if library.deviceProperties.Dex_preopt == nil || *library.deviceProperties.Dex_preopt == false {
40 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
41 }
Colin Cross6ade34f2017-09-15 13:00:47 -070042 }
43 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", 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 Cross2c429dc2017-08-31 16:45:16 -070077 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Nan Zhanged19fc32017-10-19 13:06:22 -070078 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
Colin Crossa18e9cf2017-08-10 17:00:19 -070079 },
80 },
81 }
Dan Willemsen218f6562015-07-08 18:13:11 -070082}
Colin Cross10a03492017-08-10 17:09:43 -070083
84func (binary *Binary) AndroidMk() android.AndroidMkData {
85 return android.AndroidMkData{
86 Class: "JAVA_LIBRARIES",
Nan Zhanged19fc32017-10-19 13:06:22 -070087 OutputFile: android.OptionalPathForPath(binary.implementationJarFile),
Colin Cross53499412017-09-07 13:20:25 -070088 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Cross10a03492017-08-10 17:09:43 -070089 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
90 android.WriteAndroidMkData(w, data)
91
Colin Cross19655682017-09-07 17:00:22 -070092 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
Colin Cross10a03492017-08-10 17:09:43 -070093 fmt.Fprintln(w, "include $(CLEAR_VARS)")
94 fmt.Fprintln(w, "LOCAL_MODULE := "+name)
95 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := EXECUTABLES")
96 if strings.Contains(prefix, "HOST_") {
97 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
98 }
99 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
Colin Cross19655682017-09-07 17:00:22 -0700100 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", binary.wrapperFile.String())
Colin Cross10a03492017-08-10 17:09:43 -0700101 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Cross19655682017-09-07 17:00:22 -0700102
103 // Ensure that the wrapper script timestamp is always updated when the jar is updated
104 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
105 fmt.Fprintln(w, "jar_installed_module :=")
Colin Cross10a03492017-08-10 17:09:43 -0700106 },
107 }
108}