Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 18 | "fmt" |
| 19 | "io" |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 20 | "strings" |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 21 | |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 22 | "github.com/google/blueprint/proptools" |
| 23 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 24 | "android/soong/android" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 25 | ) |
| 26 | |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 27 | func (library *Library) AndroidMk() android.AndroidMkData { |
| 28 | return android.AndroidMkData{ |
| 29 | Class: "JAVA_LIBRARIES", |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 30 | OutputFile: android.OptionalPathForPath(library.implementationJarFile), |
Colin Cross | 5349941 | 2017-09-07 13:20:25 -0700 | [diff] [blame] | 31 | Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 32 | Extra: []android.AndroidMkExtraFunc{ |
| 33 | func(w io.Writer, outputFile android.Path) { |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 34 | if library.properties.Installable != nil && *library.properties.Installable == false { |
| 35 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true") |
| 36 | } |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 37 | if library.dexJarFile != nil { |
| 38 | fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String()) |
Colin Cross | b4972e3 | 2017-11-22 16:02:44 -0800 | [diff] [blame] | 39 | if library.deviceProperties.Dex_preopt != nil && *library.deviceProperties.Dex_preopt == false { |
Colin Cross | a22116e | 2017-10-19 14:18:58 -0700 | [diff] [blame] | 40 | fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false") |
| 41 | } |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 42 | } |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 43 | fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(library.deviceProperties.Sdk_version)) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 44 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String()) |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 45 | |
| 46 | if library.jacocoReportClassesFile != nil { |
| 47 | fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", library.jacocoReportClassesFile.String()) |
| 48 | } |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame^] | 49 | |
| 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 Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 57 | }, |
| 58 | }, |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 59 | 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 Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 67 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationJarFile.String()) |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 68 | 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 Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 74 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.implementationJarFile.String()) |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 75 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " ")) |
| 76 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk") |
| 77 | } |
| 78 | }, |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 79 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 82 | func (prebuilt *Import) AndroidMk() android.AndroidMkData { |
| 83 | return android.AndroidMkData{ |
| 84 | Class: "JAVA_LIBRARIES", |
| 85 | OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile), |
Colin Cross | 5349941 | 2017-09-07 13:20:25 -0700 | [diff] [blame] | 86 | Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 87 | Extra: []android.AndroidMkExtraFunc{ |
| 88 | func(w io.Writer, outputFile android.Path) { |
Colin Cross | 535e2cf | 2017-10-20 17:57:49 -0700 | [diff] [blame] | 89 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !proptools.Bool(prebuilt.properties.Installable)) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 90 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String()) |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 91 | fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(prebuilt.properties.Sdk_version)) |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 92 | }, |
| 93 | }, |
| 94 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 95 | } |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 96 | |
| 97 | func (binary *Binary) AndroidMk() android.AndroidMkData { |
| 98 | return android.AndroidMkData{ |
| 99 | Class: "JAVA_LIBRARIES", |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 100 | OutputFile: android.OptionalPathForPath(binary.implementationJarFile), |
Colin Cross | 5349941 | 2017-09-07 13:20:25 -0700 | [diff] [blame] | 101 | Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 102 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 103 | android.WriteAndroidMkData(w, data) |
| 104 | |
Colin Cross | 1965568 | 2017-09-07 17:00:22 -0700 | [diff] [blame] | 105 | fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)") |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 106 | 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 Cross | 1965568 | 2017-09-07 17:00:22 -0700 | [diff] [blame] | 113 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", binary.wrapperFile.String()) |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 114 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") |
Colin Cross | 1965568 | 2017-09-07 17:00:22 -0700 | [diff] [blame] | 115 | |
| 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 Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 119 | }, |
| 120 | } |
| 121 | } |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame^] | 122 | |
| 123 | func (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 | } |