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