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