Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 1 | // Copyright (C) 2019 The Android Open Source Project |
| 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 apex |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "io" |
| 20 | "path/filepath" |
| 21 | "strings" |
| 22 | |
| 23 | "android/soong/android" |
| 24 | "android/soong/cc" |
Jaewoong Jung | 87a33e7 | 2020-03-26 14:01:48 -0700 | [diff] [blame] | 25 | "android/soong/java" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 26 | |
| 27 | "github.com/google/blueprint/proptools" |
| 28 | ) |
| 29 | |
| 30 | func (a *apexBundle) AndroidMk() android.AndroidMkData { |
| 31 | if a.properties.HideFromMake { |
| 32 | return android.AndroidMkData{ |
| 33 | Disabled: true, |
| 34 | } |
| 35 | } |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 36 | return a.androidMkForType() |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 37 | } |
| 38 | |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 39 | func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, moduleDir string) []string { |
| 40 | // apexBundleName comes from the 'name' property; apexName comes from 'apex_name' property. |
| 41 | // An apex is installed to /system/apex/<apexBundleName> and is activated at /apex/<apexName> |
| 42 | // In many cases, the two names are the same, but could be different in general. |
| 43 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 44 | moduleNames := []string{} |
| 45 | apexType := a.properties.ApexType |
| 46 | // To avoid creating duplicate build rules, run this function only when primaryApexType is true |
| 47 | // to install symbol files in $(PRODUCT_OUT}/apex. |
| 48 | // And if apexType is flattened, run this function to install files in $(PRODUCT_OUT}/system/apex. |
| 49 | if !a.primaryApexType && apexType != flattenedApex { |
| 50 | return moduleNames |
| 51 | } |
| 52 | |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 53 | // b/140136207. When there are overriding APEXes for a VNDK APEX, the symbols file for the overridden |
| 54 | // APEX and the overriding APEX will have the same installation paths at /apex/com.android.vndk.v<ver> |
| 55 | // as their apexName will be the same. To avoid the path conflicts, skip installing the symbol files |
| 56 | // for the overriding VNDK APEXes. |
| 57 | symbolFilesNotNeeded := a.vndkApex && len(a.overridableProperties.Overrides) > 0 |
| 58 | if symbolFilesNotNeeded && apexType != flattenedApex { |
| 59 | return moduleNames |
| 60 | } |
| 61 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 62 | var postInstallCommands []string |
| 63 | for _, fi := range a.filesInfo { |
| 64 | if a.linkToSystemLib && fi.transitiveDep && fi.AvailableToPlatform() { |
| 65 | // TODO(jiyong): pathOnDevice should come from fi.module, not being calculated here |
| 66 | linkTarget := filepath.Join("/system", fi.Path()) |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 67 | linkPath := filepath.Join(a.installDir.ToMakePath().String(), apexBundleName, fi.Path()) |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 68 | mkdirCmd := "mkdir -p " + filepath.Dir(linkPath) |
| 69 | linkCmd := "ln -sfn " + linkTarget + " " + linkPath |
| 70 | postInstallCommands = append(postInstallCommands, mkdirCmd, linkCmd) |
| 71 | } |
| 72 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 73 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 74 | seenDataOutPaths := make(map[string]bool) |
| 75 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 76 | for _, fi := range a.filesInfo { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 77 | if ccMod, ok := fi.module.(*cc.Module); ok && ccMod.Properties.HideFromMake { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 78 | continue |
| 79 | } |
| 80 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 81 | linkToSystemLib := a.linkToSystemLib && fi.transitiveDep && fi.AvailableToPlatform() |
| 82 | |
| 83 | var moduleName string |
| 84 | if linkToSystemLib { |
| 85 | moduleName = fi.moduleName |
| 86 | } else { |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 87 | moduleName = fi.moduleName + "." + apexBundleName + a.suffix |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | if !android.InList(moduleName, moduleNames) { |
| 91 | moduleNames = append(moduleNames, moduleName) |
| 92 | } |
| 93 | |
| 94 | if linkToSystemLib { |
| 95 | // No need to copy the file since it's linked to the system file |
| 96 | continue |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 100 | if fi.moduleDir != "" { |
| 101 | fmt.Fprintln(w, "LOCAL_PATH :=", fi.moduleDir) |
| 102 | } else { |
| 103 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 104 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 105 | fmt.Fprintln(w, "LOCAL_MODULE :=", moduleName) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 106 | // /apex/<apex_name>/{lib|framework|...} |
| 107 | pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", apexName, fi.installDir) |
Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 108 | var modulePath string |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 109 | if apexType == flattenedApex { |
| 110 | // /system/apex/<name>/{lib|framework|...} |
Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 111 | modulePath = filepath.Join(a.installDir.ToMakePath().String(), apexBundleName, fi.installDir) |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 112 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", modulePath) |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 113 | if a.primaryApexType && !symbolFilesNotNeeded { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 114 | fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated) |
| 115 | } |
| 116 | if len(fi.symlinks) > 0 { |
| 117 | fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " ")) |
| 118 | } |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 119 | newDataPaths := []android.DataPath{} |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 120 | for _, path := range fi.dataPaths { |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 121 | dataOutPath := modulePath + ":" + path.SrcPath.Rel() |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 122 | if ok := seenDataOutPaths[dataOutPath]; !ok { |
| 123 | newDataPaths = append(newDataPaths, path) |
| 124 | seenDataOutPaths[dataOutPath] = true |
| 125 | } |
| 126 | } |
| 127 | if len(newDataPaths) > 0 { |
| 128 | fmt.Fprintln(w, "LOCAL_TEST_DATA :=", strings.Join(cc.AndroidMkDataPaths(newDataPaths), " ")) |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 129 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 130 | |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 131 | if fi.module != nil && len(fi.module.NoticeFiles()) > 0 { |
| 132 | fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", strings.Join(fi.module.NoticeFiles().Strings(), " ")) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 133 | } |
| 134 | } else { |
Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 135 | modulePath = pathWhenActivated |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 136 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated) |
Jiyong Park | 19972c7 | 2020-01-28 20:05:29 +0900 | [diff] [blame] | 137 | |
| 138 | // For non-flattend APEXes, the merged notice file is attached to the APEX itself. |
| 139 | // We don't need to have notice file for the individual modules in it. Otherwise, |
| 140 | // we will have duplicated notice entries. |
| 141 | fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 142 | } |
| 143 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String()) |
| 144 | fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake()) |
| 145 | if fi.module != nil { |
| 146 | archStr := fi.module.Target().Arch.ArchType.String() |
| 147 | host := false |
| 148 | switch fi.module.Target().Os.Class { |
| 149 | case android.Host: |
| 150 | if fi.module.Target().Arch.ArchType != android.Common { |
| 151 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr) |
| 152 | } |
| 153 | host = true |
| 154 | case android.HostCross: |
| 155 | if fi.module.Target().Arch.ArchType != android.Common { |
| 156 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr) |
| 157 | } |
| 158 | host = true |
| 159 | case android.Device: |
| 160 | if fi.module.Target().Arch.ArchType != android.Common { |
| 161 | fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr) |
| 162 | } |
| 163 | } |
| 164 | if host { |
| 165 | makeOs := fi.module.Target().Os.String() |
| 166 | if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic { |
| 167 | makeOs = "linux" |
| 168 | } |
| 169 | fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs) |
| 170 | fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") |
| 171 | } |
| 172 | } |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 173 | if fi.jacocoReportClassesFile != nil { |
| 174 | fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", fi.jacocoReportClassesFile.String()) |
| 175 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 176 | switch fi.class { |
| 177 | case javaSharedLib: |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 178 | // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore |
| 179 | // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise |
| 180 | // we will have foo.jar.jar |
Jiyong Park | f1493cc | 2020-05-29 21:29:20 +0900 | [diff] [blame] | 181 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.Stem(), ".jar")) |
Paul Duffin | 44b481b | 2020-06-17 16:59:43 +0100 | [diff] [blame] | 182 | if javaModule, ok := fi.module.(java.ApexDependency); ok { |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 183 | fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String()) |
| 184 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String()) |
| 185 | } else { |
| 186 | fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", fi.builtFile.String()) |
| 187 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", fi.builtFile.String()) |
| 188 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 189 | fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String()) |
| 190 | fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false") |
| 191 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk") |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 192 | case app: |
Colin Cross | 503c1d0 | 2020-01-28 14:00:53 -0800 | [diff] [blame] | 193 | fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", fi.certificate.AndroidMkString()) |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 194 | // soong_app_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .apk Therefore |
| 195 | // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise |
| 196 | // we will have foo.apk.apk |
Jiyong Park | f1493cc | 2020-05-29 21:29:20 +0900 | [diff] [blame] | 197 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.Stem(), ".apk")) |
Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 198 | if app, ok := fi.module.(*java.AndroidApp); ok { |
| 199 | if jniCoverageOutputs := app.JniCoverageOutputs(); len(jniCoverageOutputs) > 0 { |
| 200 | fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", strings.Join(jniCoverageOutputs.Strings(), " ")) |
| 201 | } |
| 202 | if jniLibSymbols := app.JNISymbolsInstalls(modulePath); len(jniLibSymbols) > 0 { |
| 203 | fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_SYMBOLS :=", jniLibSymbols.String()) |
| 204 | } |
Jaewoong Jung | 87a33e7 | 2020-03-26 14:01:48 -0700 | [diff] [blame] | 205 | } |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 206 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_app_prebuilt.mk") |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 207 | case appSet: |
| 208 | as, ok := fi.module.(*java.AndroidAppSet) |
| 209 | if !ok { |
| 210 | panic(fmt.Sprintf("Expected %s to be AndroidAppSet", fi.module)) |
| 211 | } |
| 212 | fmt.Fprintln(w, "LOCAL_APK_SET_MASTER_FILE :=", as.MasterFile()) |
Colin Cross | 4fb652d | 2020-07-09 19:05:35 -0700 | [diff] [blame] | 213 | fmt.Fprintln(w, "LOCAL_APKCERTS_FILE :=", as.APKCertsFile().String()) |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 214 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_android_app_set.mk") |
| 215 | case nativeSharedLib, nativeExecutable, nativeTest: |
Jiyong Park | f1493cc | 2020-05-29 21:29:20 +0900 | [diff] [blame] | 216 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.Stem()) |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 217 | if ccMod, ok := fi.module.(*cc.Module); ok { |
| 218 | if ccMod.UnstrippedOutputFile() != nil { |
| 219 | fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", ccMod.UnstrippedOutputFile().String()) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 220 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 221 | ccMod.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w) |
| 222 | if ccMod.CoverageOutputFile().Valid() { |
| 223 | fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", ccMod.CoverageOutputFile().String()) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk") |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 227 | default: |
Jiyong Park | f1493cc | 2020-05-29 21:29:20 +0900 | [diff] [blame] | 228 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.Stem()) |
Jiyong Park | 7aa3f76 | 2020-01-28 16:51:34 +0900 | [diff] [blame] | 229 | if fi.builtFile == a.manifestPbOut && apexType == flattenedApex { |
Jooyung Han | 75de261 | 2020-01-24 02:02:45 +0900 | [diff] [blame] | 230 | if a.primaryApexType { |
| 231 | // Make apex_manifest.pb module for this APEX to override all other |
| 232 | // modules in the APEXes being overridden by this APEX |
| 233 | var patterns []string |
| 234 | for _, o := range a.overridableProperties.Overrides { |
| 235 | patterns = append(patterns, "%."+o+a.suffix) |
| 236 | } |
Yo Chiang | 12d9f7a | 2020-06-16 17:32:19 +0800 | [diff] [blame] | 237 | if len(patterns) > 0 { |
| 238 | fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES :=", strings.Join(patterns, " ")) |
| 239 | } |
Jiyong Park | 7aa3f76 | 2020-01-28 16:51:34 +0900 | [diff] [blame] | 240 | if len(a.compatSymlinks) > 0 { |
Jooyung Han | 75de261 | 2020-01-24 02:02:45 +0900 | [diff] [blame] | 241 | // For flattened apexes, compat symlinks are attached to apex_manifest.json which is guaranteed for every apex |
| 242 | postInstallCommands = append(postInstallCommands, a.compatSymlinks...) |
| 243 | } |
| 244 | } |
| 245 | if len(postInstallCommands) > 0 { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 246 | fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", strings.Join(postInstallCommands, " && ")) |
Jiyong Park | 0abc1b4 | 2020-01-09 17:43:39 +0900 | [diff] [blame] | 247 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 248 | } |
| 249 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") |
| 250 | } |
Jiyong Park | 31af267 | 2020-02-11 09:36:25 +0900 | [diff] [blame] | 251 | |
| 252 | // m <module_name> will build <module_name>.<apex_name> as well. |
| 253 | if fi.moduleName != moduleName && a.primaryApexType { |
| 254 | fmt.Fprintln(w, ".PHONY: "+fi.moduleName) |
| 255 | fmt.Fprintln(w, fi.moduleName+": "+moduleName) |
| 256 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 257 | } |
| 258 | return moduleNames |
| 259 | } |
| 260 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 261 | func (a *apexBundle) writeRequiredModules(w io.Writer) { |
| 262 | var required []string |
| 263 | var targetRequired []string |
| 264 | var hostRequired []string |
| 265 | for _, fi := range a.filesInfo { |
| 266 | required = append(required, fi.requiredModuleNames...) |
| 267 | targetRequired = append(targetRequired, fi.targetRequiredModuleNames...) |
| 268 | hostRequired = append(hostRequired, fi.hostRequiredModuleNames...) |
| 269 | } |
| 270 | |
| 271 | if len(required) > 0 { |
| 272 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(required, " ")) |
| 273 | } |
| 274 | if len(targetRequired) > 0 { |
| 275 | fmt.Fprintln(w, "LOCAL_TARGET_REQUIRED_MODULES +=", strings.Join(targetRequired, " ")) |
| 276 | } |
| 277 | if len(hostRequired) > 0 { |
| 278 | fmt.Fprintln(w, "LOCAL_HOST_REQUIRED_MODULES +=", strings.Join(hostRequired, " ")) |
| 279 | } |
| 280 | } |
| 281 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 282 | func (a *apexBundle) androidMkForType() android.AndroidMkData { |
| 283 | return android.AndroidMkData{ |
| 284 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 285 | moduleNames := []string{} |
| 286 | apexType := a.properties.ApexType |
| 287 | if a.installable() { |
| 288 | apexName := proptools.StringDefault(a.properties.Apex_name, name) |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 289 | moduleNames = a.androidMkForFiles(w, name, apexName, moduleDir) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | if apexType == flattenedApex { |
| 293 | // Only image APEXes can be flattened. |
| 294 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 295 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 296 | fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix) |
| 297 | if len(moduleNames) > 0 { |
| 298 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " ")) |
| 299 | } |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 300 | a.writeRequiredModules(w) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 301 | fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 302 | |
| 303 | } else { |
| 304 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 305 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 306 | fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix) |
| 307 | fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class? |
| 308 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFile.String()) |
| 309 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String()) |
| 310 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix()) |
| 311 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable()) |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 312 | |
| 313 | // Because apex writes .mk with Custom(), we need to write manually some common properties |
| 314 | // which are available via data.Entries |
| 315 | commonProperties := []string{ |
| 316 | "LOCAL_INIT_RC", "LOCAL_VINTF_FRAGMENTS", |
| 317 | "LOCAL_PROPRIETARY_MODULE", "LOCAL_VENDOR_MODULE", "LOCAL_ODM_MODULE", "LOCAL_PRODUCT_MODULE", "LOCAL_SYSTEM_EXT_MODULE", |
| 318 | "LOCAL_MODULE_OWNER", |
| 319 | } |
| 320 | for _, name := range commonProperties { |
| 321 | if value, ok := data.Entries.EntryMap[name]; ok { |
| 322 | fmt.Fprintln(w, name+" := "+strings.Join(value, " ")) |
| 323 | } |
| 324 | } |
| 325 | |
Yo Chiang | 12d9f7a | 2020-06-16 17:32:19 +0800 | [diff] [blame] | 326 | if len(a.overridableProperties.Overrides) > 0 { |
| 327 | fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES :=", strings.Join(a.overridableProperties.Overrides, " ")) |
| 328 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 329 | if len(moduleNames) > 0 { |
| 330 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " ")) |
| 331 | } |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 332 | if len(a.requiredDeps) > 0 { |
| 333 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.requiredDeps, " ")) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 334 | } |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 335 | a.writeRequiredModules(w) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 336 | var postInstallCommands []string |
| 337 | if a.prebuiltFileToDelete != "" { |
| 338 | postInstallCommands = append(postInstallCommands, "rm -rf "+ |
| 339 | filepath.Join(a.installDir.ToMakePath().String(), a.prebuiltFileToDelete)) |
| 340 | } |
| 341 | // For unflattened apexes, compat symlinks are attached to apex package itself as LOCAL_POST_INSTALL_CMD |
| 342 | postInstallCommands = append(postInstallCommands, a.compatSymlinks...) |
| 343 | if len(postInstallCommands) > 0 { |
| 344 | fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", strings.Join(postInstallCommands, " && ")) |
| 345 | } |
Jiyong Park | 19972c7 | 2020-01-28 20:05:29 +0900 | [diff] [blame] | 346 | |
| 347 | if a.mergedNotices.Merged.Valid() { |
| 348 | fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", a.mergedNotices.Merged.Path().String()) |
| 349 | } |
| 350 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 351 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") |
| 352 | |
| 353 | if apexType == imageApex { |
Yo Chiang | ef2d489 | 2020-05-08 15:38:40 +0800 | [diff] [blame] | 354 | fmt.Fprintln(w, "ALL_MODULES.$(my_register_name).BUNDLE :=", a.bundleModuleFile.String()) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 355 | } |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame^] | 356 | if len(a.lintReports) > 0 { |
| 357 | fmt.Fprintln(w, "ALL_MODULES.$(my_register_name).LINT_REPORTS :=", |
| 358 | strings.Join(a.lintReports.Strings(), " ")) |
| 359 | } |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 360 | |
| 361 | if a.installedFilesFile != nil { |
Colin Cross | 1c85e8e | 2020-02-26 16:55:51 -0800 | [diff] [blame] | 362 | goal := "checkbuild" |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 363 | distFile := name + "-installed-files.txt" |
| 364 | fmt.Fprintln(w, ".PHONY:", goal) |
| 365 | fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", |
| 366 | goal, a.installedFilesFile.String(), distFile) |
| 367 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 368 | } |
| 369 | }} |
| 370 | } |