blob: e349de4ae0cdffb7683977ecadbb335e0a8054fe [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",
Colin Cross6ade34f2017-09-15 13:00:47 -070030 OutputFile: android.OptionalPathForPath(library.classpathFile),
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())
39 }
40 fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", library.deviceProperties.Sdk_version)
Colin Crossa18e9cf2017-08-10 17:00:19 -070041 },
42 },
Colin Cross92430102017-10-09 14:59:32 -070043 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
44 android.WriteAndroidMkData(w, data)
45
46 if proptools.Bool(library.deviceProperties.Hostdex) && !library.Host() {
47 fmt.Fprintln(w, "include $(CLEAR_VARS)")
48 fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex")
49 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
50 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES")
51 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.classpathFile.String())
52 if library.properties.Installable != nil && *library.properties.Installable == false {
53 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
54 }
55 if library.dexJarFile != nil {
56 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
57 }
58 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " "))
59 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
60 }
61 },
Colin Crossa18e9cf2017-08-10 17:00:19 -070062 }
Dan Willemsen218f6562015-07-08 18:13:11 -070063}
64
Colin Crossa18e9cf2017-08-10 17:00:19 -070065func (prebuilt *Import) AndroidMk() android.AndroidMkData {
66 return android.AndroidMkData{
67 Class: "JAVA_LIBRARIES",
68 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
Colin Cross53499412017-09-07 13:20:25 -070069 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Crossa18e9cf2017-08-10 17:00:19 -070070 Extra: []android.AndroidMkExtraFunc{
71 func(w io.Writer, outputFile android.Path) {
Colin Cross2c429dc2017-08-31 16:45:16 -070072 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Colin Crossa18e9cf2017-08-10 17:00:19 -070073 },
74 },
75 }
Dan Willemsen218f6562015-07-08 18:13:11 -070076}
Colin Cross10a03492017-08-10 17:09:43 -070077
78func (binary *Binary) AndroidMk() android.AndroidMkData {
79 return android.AndroidMkData{
80 Class: "JAVA_LIBRARIES",
Colin Cross6ade34f2017-09-15 13:00:47 -070081 OutputFile: android.OptionalPathForPath(binary.classpathFile),
Colin Cross53499412017-09-07 13:20:25 -070082 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Colin Cross10a03492017-08-10 17:09:43 -070083 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
84 android.WriteAndroidMkData(w, data)
85
Colin Cross19655682017-09-07 17:00:22 -070086 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
Colin Cross10a03492017-08-10 17:09:43 -070087 fmt.Fprintln(w, "include $(CLEAR_VARS)")
88 fmt.Fprintln(w, "LOCAL_MODULE := "+name)
89 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := EXECUTABLES")
90 if strings.Contains(prefix, "HOST_") {
91 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
92 }
93 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
Colin Cross19655682017-09-07 17:00:22 -070094 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", binary.wrapperFile.String())
Colin Cross10a03492017-08-10 17:09:43 -070095 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
Colin Cross19655682017-09-07 17:00:22 -070096
97 // Ensure that the wrapper script timestamp is always updated when the jar is updated
98 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
99 fmt.Fprintln(w, "jar_installed_module :=")
Colin Cross10a03492017-08-10 17:09:43 -0700100 },
101 }
102}