| 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 |  | 
|  | 29 | func (a *apexBundle) AndroidMk() android.AndroidMkData { | 
|  | 30 | if a.properties.HideFromMake { | 
|  | 31 | return android.AndroidMkData{ | 
|  | 32 | Disabled: true, | 
|  | 33 | } | 
|  | 34 | } | 
| Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 35 | return a.androidMkForType() | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 36 | } | 
|  | 37 |  | 
| Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 38 | // nameInMake converts apexFileClass into the corresponding class name in Make. | 
|  | 39 | func (class apexFileClass) nameInMake() string { | 
|  | 40 | switch class { | 
|  | 41 | case etc: | 
|  | 42 | return "ETC" | 
|  | 43 | case nativeSharedLib: | 
|  | 44 | return "SHARED_LIBRARIES" | 
| Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 45 | case nativeExecutable, shBinary: | 
| Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 46 | return "EXECUTABLES" | 
|  | 47 | case javaSharedLib: | 
|  | 48 | return "JAVA_LIBRARIES" | 
|  | 49 | case nativeTest: | 
|  | 50 | return "NATIVE_TESTS" | 
|  | 51 | case app, appSet: | 
|  | 52 | // b/142537672 Why isn't this APP? We want to have full control over | 
|  | 53 | // the paths and file names of the apk file under the flattend APEX. | 
|  | 54 | // If this is set to APP, then the paths and file names are modified | 
|  | 55 | // by the Make build system. For example, it is installed to | 
|  | 56 | // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of | 
|  | 57 | // /system/apex/<apexname>/app/<Appname> because the build system automatically | 
|  | 58 | // appends module name (which is <apexname>.<Appname> to the path. | 
|  | 59 | return "ETC" | 
|  | 60 | default: | 
|  | 61 | panic(fmt.Errorf("unknown class %d", class)) | 
|  | 62 | } | 
|  | 63 | } | 
|  | 64 |  | 
| Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 65 | // Return the full module name for a dependency module, which appends the apex module name unless re-using a system lib. | 
| Jingwen Chen | 2d37b64 | 2023-03-14 16:11:38 +0000 | [diff] [blame] | 66 | func (a *apexBundle) fullModuleName(apexBundleName string, linkToSystemLib bool, fi *apexFile) string { | 
| Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 67 | if linkToSystemLib { | 
|  | 68 | return fi.androidMkModuleName | 
|  | 69 | } | 
| Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 70 | return fi.androidMkModuleName + "." + apexBundleName | 
| Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 71 | } | 
|  | 72 |  | 
| Jingwen Chen | 2d37b64 | 2023-03-14 16:11:38 +0000 | [diff] [blame] | 73 | // androidMkForFiles generates Make definitions for the contents of an | 
|  | 74 | // apexBundle (apexBundle#filesInfo).  The filesInfo structure can either be | 
|  | 75 | // populated by Soong for unconverted APEXes, or Bazel in mixed mode. Use | 
|  | 76 | // apexFile#isBazelPrebuilt to differentiate. | 
| Jooyung Han | 63dff46 | 2023-02-09 00:11:27 +0000 | [diff] [blame] | 77 | func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, moduleDir string, | 
| Jooyung Han | 07931c7 | 2020-09-11 17:19:20 +0900 | [diff] [blame] | 78 | apexAndroidMkData android.AndroidMkData) []string { | 
|  | 79 |  | 
| Jooyung Han | 63dff46 | 2023-02-09 00:11:27 +0000 | [diff] [blame] | 80 | // apexBundleName comes from the 'name' property or soong module. | 
|  | 81 | // apexName comes from 'name' property of apex_manifest. | 
| Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 82 | // An apex is installed to /system/apex/<apexBundleName> and is activated at /apex/<apexName> | 
|  | 83 | // In many cases, the two names are the same, but could be different in general. | 
| Jooyung Han | 63dff46 | 2023-02-09 00:11:27 +0000 | [diff] [blame] | 84 | // However, symbol files for apex files are installed under /apex/<apexBundleName> to avoid | 
|  | 85 | // conflicts between two apexes with the same apexName. | 
| Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 86 |  | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 87 | moduleNames := []string{} | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 88 |  | 
|  | 89 | for _, fi := range a.filesInfo { | 
| Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 90 | linkToSystemLib := a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform() | 
| Jingwen Chen | 2d37b64 | 2023-03-14 16:11:38 +0000 | [diff] [blame] | 91 | moduleName := a.fullModuleName(apexBundleName, linkToSystemLib, &fi) | 
| Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 92 |  | 
| Jiyong Park | 57621b2 | 2021-01-20 20:33:11 +0900 | [diff] [blame] | 93 | // This name will be added to LOCAL_REQUIRED_MODULES of the APEX. We need to be | 
|  | 94 | // arch-specific otherwise we will end up installing both ABIs even when only | 
|  | 95 | // either of the ABI is requested. | 
|  | 96 | aName := moduleName | 
|  | 97 | switch fi.multilib { | 
|  | 98 | case "lib32": | 
|  | 99 | aName = aName + ":32" | 
|  | 100 | case "lib64": | 
|  | 101 | aName = aName + ":64" | 
|  | 102 | } | 
|  | 103 | if !android.InList(aName, moduleNames) { | 
|  | 104 | moduleNames = append(moduleNames, aName) | 
| Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 105 | } | 
|  | 106 |  | 
|  | 107 | if linkToSystemLib { | 
|  | 108 | // No need to copy the file since it's linked to the system file | 
|  | 109 | continue | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 110 | } | 
|  | 111 |  | 
| Sasha Smundak | 5c4729d | 2022-12-01 10:49:23 -0800 | [diff] [blame] | 112 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)  # apex.apexBundle.files") | 
| Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 113 | if fi.moduleDir != "" { | 
|  | 114 | fmt.Fprintln(w, "LOCAL_PATH :=", fi.moduleDir) | 
|  | 115 | } else { | 
|  | 116 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) | 
|  | 117 | } | 
| Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 118 | fmt.Fprintln(w, "LOCAL_MODULE :=", moduleName) | 
| Jingwen Chen | 2d37b64 | 2023-03-14 16:11:38 +0000 | [diff] [blame] | 119 |  | 
| Anton Hansson | 1ee62c0 | 2020-06-30 11:51:53 +0100 | [diff] [blame] | 120 | if fi.module != nil && fi.module.Owner() != "" { | 
|  | 121 | fmt.Fprintln(w, "LOCAL_MODULE_OWNER :=", fi.module.Owner()) | 
|  | 122 | } | 
| Jooyung Han | 63dff46 | 2023-02-09 00:11:27 +0000 | [diff] [blame] | 123 | // /apex/<apexBundleName>/{lib|framework|...} | 
|  | 124 | pathForSymbol := filepath.Join("$(PRODUCT_OUT)", "apex", apexBundleName, fi.installDir) | 
| Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 125 | modulePath := pathForSymbol | 
|  | 126 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", modulePath) | 
| LaMont Jones | b509938 | 2024-01-10 23:42:36 +0000 | [diff] [blame] | 127 | // AconfigUpdateAndroidMkData may have added elements to Extra.  Process them here. | 
|  | 128 | for _, extra := range apexAndroidMkData.Extra { | 
|  | 129 | extra(w, fi.builtFile) | 
|  | 130 | } | 
| Jiyong Park | 19972c7 | 2020-01-28 20:05:29 +0900 | [diff] [blame] | 131 |  | 
| Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 132 | // For non-flattend APEXes, the merged notice file is attached to the APEX itself. | 
|  | 133 | // We don't need to have notice file for the individual modules in it. Otherwise, | 
|  | 134 | // we will have duplicated notice entries. | 
|  | 135 | fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true") | 
| Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 136 | fmt.Fprintln(w, "LOCAL_SOONG_INSTALLED_MODULE :=", filepath.Join(modulePath, fi.stem())) | 
|  | 137 | 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] | 138 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String()) | 
| Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 139 | if fi.checkbuildTarget != nil { | 
|  | 140 | fmt.Fprintln(w, "LOCAL_CHECKED_MODULE :=", fi.checkbuildTarget.String()) | 
|  | 141 | } else { | 
|  | 142 | fmt.Fprintln(w, "LOCAL_CHECKED_MODULE :=", fi.builtFile.String()) | 
|  | 143 | } | 
| Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 144 | fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.nameInMake()) | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 145 | if fi.module != nil { | 
| Jingwen Chen | 2d37b64 | 2023-03-14 16:11:38 +0000 | [diff] [blame] | 146 | // This apexFile's module comes from Soong | 
| Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 147 | if fi.module.Target().Arch.ArchType != android.Common { | 
|  | 148 | archStr := fi.module.Target().Arch.ArchType.String() | 
|  | 149 | fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr) | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 150 | } | 
|  | 151 | } | 
| Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 152 | if fi.jacocoReportClassesFile != nil { | 
|  | 153 | fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", fi.jacocoReportClassesFile.String()) | 
|  | 154 | } | 
| Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 155 | switch fi.class { | 
|  | 156 | case javaSharedLib: | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 157 | // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar  Therefore | 
|  | 158 | // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise | 
|  | 159 | // we will have foo.jar.jar | 
| Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 160 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.stem(), ".jar")) | 
| Paul Duffin | 44b481b | 2020-06-17 16:59:43 +0100 | [diff] [blame] | 161 | if javaModule, ok := fi.module.(java.ApexDependency); ok { | 
| Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 162 | fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String()) | 
|  | 163 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String()) | 
|  | 164 | } else { | 
|  | 165 | fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", fi.builtFile.String()) | 
|  | 166 | fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", fi.builtFile.String()) | 
|  | 167 | } | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 168 | fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String()) | 
|  | 169 | fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false") | 
|  | 170 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk") | 
| Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 171 | case app: | 
| Colin Cross | 503c1d0 | 2020-01-28 14:00:53 -0800 | [diff] [blame] | 172 | fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", fi.certificate.AndroidMkString()) | 
| Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 173 | // soong_app_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .apk  Therefore | 
|  | 174 | // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise | 
|  | 175 | // we will have foo.apk.apk | 
| Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 176 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.stem(), ".apk")) | 
| Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 177 | if app, ok := fi.module.(*java.AndroidApp); ok { | 
| Sasha Smundak | dcb6129 | 2022-12-08 10:41:33 -0800 | [diff] [blame] | 178 | android.AndroidMkEmitAssignList(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE", app.JniCoverageOutputs().Strings()) | 
| Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 179 | if jniLibSymbols := app.JNISymbolsInstalls(modulePath); len(jniLibSymbols) > 0 { | 
|  | 180 | fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_SYMBOLS :=", jniLibSymbols.String()) | 
|  | 181 | } | 
| Jaewoong Jung | 87a33e7 | 2020-03-26 14:01:48 -0700 | [diff] [blame] | 182 | } | 
| Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 183 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_app_prebuilt.mk") | 
| Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 184 | case appSet: | 
|  | 185 | as, ok := fi.module.(*java.AndroidAppSet) | 
|  | 186 | if !ok { | 
|  | 187 | panic(fmt.Sprintf("Expected %s to be AndroidAppSet", fi.module)) | 
|  | 188 | } | 
| Colin Cross | ffbcd1d | 2021-11-12 12:19:42 -0800 | [diff] [blame] | 189 | fmt.Fprintln(w, "LOCAL_APK_SET_INSTALL_FILE :=", as.PackedAdditionalOutputs().String()) | 
| Colin Cross | 4fb652d | 2020-07-09 19:05:35 -0700 | [diff] [blame] | 190 | fmt.Fprintln(w, "LOCAL_APKCERTS_FILE :=", as.APKCertsFile().String()) | 
| Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 191 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_android_app_set.mk") | 
|  | 192 | case nativeSharedLib, nativeExecutable, nativeTest: | 
| Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 193 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.stem()) | 
| Colin Cross | 8ff1058 | 2023-12-07 13:10:56 -0800 | [diff] [blame] | 194 | if ccMod, ok := fi.module.(*cc.Module); ok { | 
|  | 195 | if ccMod.UnstrippedOutputFile() != nil { | 
|  | 196 | fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", ccMod.UnstrippedOutputFile().String()) | 
|  | 197 | } | 
|  | 198 | ccMod.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w) | 
|  | 199 | if ccMod.CoverageOutputFile().Valid() { | 
|  | 200 | fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", ccMod.CoverageOutputFile().String()) | 
|  | 201 | } | 
|  | 202 | } else if rustMod, ok := fi.module.(*rust.Module); ok { | 
|  | 203 | if rustMod.UnstrippedOutputFile() != nil { | 
|  | 204 | fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", rustMod.UnstrippedOutputFile().String()) | 
| Jiyong Park | c7a4688 | 2023-02-02 11:33:39 +0900 | [diff] [blame] | 205 | } | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 206 | } | 
| Ivan Lozano | d06cc74 | 2021-11-12 13:27:58 -0500 | [diff] [blame] | 207 | fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk") | 
| Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 208 | default: | 
| Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 209 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.stem()) | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 210 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") | 
|  | 211 | } | 
| Jiyong Park | 31af267 | 2020-02-11 09:36:25 +0900 | [diff] [blame] | 212 |  | 
|  | 213 | // m <module_name> will build <module_name>.<apex_name> as well. | 
| Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 214 | if fi.androidMkModuleName != moduleName { | 
| Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 215 | fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName) | 
|  | 216 | fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName) | 
| Jiyong Park | 31af267 | 2020-02-11 09:36:25 +0900 | [diff] [blame] | 217 | } | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 218 | } | 
|  | 219 | return moduleNames | 
|  | 220 | } | 
|  | 221 |  | 
| Jiakai Zhang | d70dff7 | 2022-02-24 15:06:05 +0000 | [diff] [blame] | 222 | func (a *apexBundle) writeRequiredModules(w io.Writer, moduleNames []string) { | 
| Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 223 | var required []string | 
|  | 224 | var targetRequired []string | 
|  | 225 | var hostRequired []string | 
| Cole Faust | 43ddd08 | 2024-06-17 12:32:40 -0700 | [diff] [blame] | 226 | required = append(required, a.required...) | 
| Jiyong Park | cacc4f3 | 2021-10-28 14:26:03 +0900 | [diff] [blame] | 227 | targetRequired = append(targetRequired, a.TargetRequiredModuleNames()...) | 
|  | 228 | hostRequired = append(hostRequired, a.HostRequiredModuleNames()...) | 
| Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 229 | for _, fi := range a.filesInfo { | 
|  | 230 | required = append(required, fi.requiredModuleNames...) | 
|  | 231 | targetRequired = append(targetRequired, fi.targetRequiredModuleNames...) | 
|  | 232 | hostRequired = append(hostRequired, fi.hostRequiredModuleNames...) | 
|  | 233 | } | 
| Jingwen Chen | 29743c8 | 2023-01-25 17:49:46 +0000 | [diff] [blame] | 234 | android.AndroidMkEmitAssignList(w, "LOCAL_REQUIRED_MODULES", moduleNames, a.makeModulesToInstall, required) | 
| Sasha Smundak | dcb6129 | 2022-12-08 10:41:33 -0800 | [diff] [blame] | 235 | android.AndroidMkEmitAssignList(w, "LOCAL_TARGET_REQUIRED_MODULES", targetRequired) | 
|  | 236 | android.AndroidMkEmitAssignList(w, "LOCAL_HOST_REQUIRED_MODULES", hostRequired) | 
| Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 237 | } | 
|  | 238 |  | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 239 | func (a *apexBundle) androidMkForType() android.AndroidMkData { | 
|  | 240 | return android.AndroidMkData{ | 
| LaMont Jones | b509938 | 2024-01-10 23:42:36 +0000 | [diff] [blame] | 241 | // While we do not provide a value for `Extra`, AconfigUpdateAndroidMkData may add some, which we must honor. | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 242 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { | 
| Diwas Sharma | bb9202e | 2023-01-26 18:42:21 +0000 | [diff] [blame] | 243 | moduleNames := []string{} | 
| Diwas Sharma | bb9202e | 2023-01-26 18:42:21 +0000 | [diff] [blame] | 244 | if a.installable() { | 
| Jooyung Han | 63dff46 | 2023-02-09 00:11:27 +0000 | [diff] [blame] | 245 | moduleNames = a.androidMkForFiles(w, name, moduleDir, data) | 
| Diwas Sharma | bb9202e | 2023-01-26 18:42:21 +0000 | [diff] [blame] | 246 | } | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 247 |  | 
| Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 248 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)  # apex.apexBundle") | 
|  | 249 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) | 
| Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 250 | fmt.Fprintln(w, "LOCAL_MODULE :=", name) | 
| Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 251 | fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class? | 
|  | 252 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFile.String()) | 
|  | 253 | fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.String()) | 
| Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 254 | stemSuffix := imageApexSuffix | 
| Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 255 | if a.isCompressed { | 
|  | 256 | stemSuffix = imageCapexSuffix | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 257 | } | 
| Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 258 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+stemSuffix) | 
|  | 259 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable()) | 
|  | 260 | if a.installable() { | 
|  | 261 | fmt.Fprintln(w, "LOCAL_SOONG_INSTALLED_MODULE :=", a.installedFile.String()) | 
|  | 262 | fmt.Fprintln(w, "LOCAL_SOONG_INSTALL_PAIRS :=", a.outputFile.String()+":"+a.installedFile.String()) | 
| Cole Faust | d22afe9 | 2023-08-18 16:05:44 -0700 | [diff] [blame] | 263 | fmt.Fprintln(w, "LOCAL_SOONG_INSTALL_SYMLINKS := ", strings.Join(a.compatSymlinks.Strings(), " ")) | 
| Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 264 | } | 
| Jooyung Han | 286957d | 2023-10-30 16:17:56 +0900 | [diff] [blame] | 265 | fmt.Fprintln(w, "LOCAL_APEX_KEY_PATH := ", a.apexKeysPath.String()) | 
| Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 266 |  | 
|  | 267 | // Because apex writes .mk with Custom(), we need to write manually some common properties | 
|  | 268 | // which are available via data.Entries | 
|  | 269 | commonProperties := []string{ | 
|  | 270 | "LOCAL_FULL_INIT_RC", "LOCAL_FULL_VINTF_FRAGMENTS", | 
|  | 271 | "LOCAL_PROPRIETARY_MODULE", "LOCAL_VENDOR_MODULE", "LOCAL_ODM_MODULE", "LOCAL_PRODUCT_MODULE", "LOCAL_SYSTEM_EXT_MODULE", | 
|  | 272 | "LOCAL_MODULE_OWNER", | 
|  | 273 | } | 
|  | 274 | for _, name := range commonProperties { | 
|  | 275 | if value, ok := data.Entries.EntryMap[name]; ok { | 
|  | 276 | android.AndroidMkEmitAssignList(w, name, value) | 
|  | 277 | } | 
|  | 278 | } | 
|  | 279 |  | 
|  | 280 | android.AndroidMkEmitAssignList(w, "LOCAL_OVERRIDES_MODULES", a.overridableProperties.Overrides) | 
|  | 281 | a.writeRequiredModules(w, moduleNames) | 
| LaMont Jones | b509938 | 2024-01-10 23:42:36 +0000 | [diff] [blame] | 282 | // AconfigUpdateAndroidMkData may have added elements to Extra.  Process them here. | 
|  | 283 | for _, extra := range data.Extra { | 
|  | 284 | extra(w, a.outputFile) | 
|  | 285 | } | 
| Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 286 |  | 
|  | 287 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") | 
| Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 288 | fmt.Fprintln(w, "ALL_MODULES.$(my_register_name).BUNDLE :=", a.bundleModuleFile.String()) | 
| Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 289 | android.AndroidMkEmitAssignList(w, "ALL_MODULES.$(my_register_name).LINT_REPORTS", a.lintReports.Strings()) | 
|  | 290 |  | 
|  | 291 | if a.installedFilesFile != nil { | 
|  | 292 | goal := "checkbuild" | 
|  | 293 | distFile := name + "-installed-files.txt" | 
|  | 294 | fmt.Fprintln(w, ".PHONY:", goal) | 
|  | 295 | fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", | 
|  | 296 | goal, a.installedFilesFile.String(), distFile) | 
|  | 297 | fmt.Fprintf(w, "$(call declare-0p-target,%s)\n", a.installedFilesFile.String()) | 
|  | 298 | } | 
|  | 299 | for _, dist := range data.Entries.GetDistForGoals(a) { | 
| Yu Liu | e70976d | 2024-10-15 20:45:35 +0000 | [diff] [blame] | 300 | fmt.Fprintln(w, dist) | 
| Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 301 | } | 
|  | 302 |  | 
|  | 303 | distCoverageFiles(w, "ndk_apis_usedby_apex", a.nativeApisUsedByModuleFile.String()) | 
|  | 304 | distCoverageFiles(w, "ndk_apis_backedby_apex", a.nativeApisBackedByModuleFile.String()) | 
|  | 305 | distCoverageFiles(w, "java_apis_used_by_apex", a.javaApisUsedByModuleFile.String()) | 
| Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 306 | }} | 
|  | 307 | } | 
| sophiez | 0234737 | 2021-11-02 17:58:02 -0700 | [diff] [blame] | 308 |  | 
|  | 309 | func distCoverageFiles(w io.Writer, dir string, distfile string) { | 
|  | 310 | if distfile != "" { | 
|  | 311 | goal := "apps_only" | 
|  | 312 | fmt.Fprintf(w, "ifneq (,$(filter $(my_register_name),$(TARGET_BUILD_APPS)))\n"+ | 
|  | 313 | " $(call dist-for-goals,%s,%s:%s/$(notdir %s))\n"+ | 
|  | 314 | "endif\n", goal, distfile, dir, distfile) | 
|  | 315 | } | 
|  | 316 | } |