blob: 7f03621094718a1c1e56938da96d96e41029805f [file] [log] [blame]
Jiyong Park09d77522019-11-18 11:16:27 +09001// 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
15package apex
16
17import (
18 "fmt"
19 "io"
20 "path/filepath"
21 "strings"
22
23 "android/soong/android"
24 "android/soong/cc"
Jaewoong Jung87a33e72020-03-26 14:01:48 -070025 "android/soong/java"
Jiyong Parkc7a46882023-02-02 11:33:39 +090026 "android/soong/rust"
Jiyong Park09d77522019-11-18 11:16:27 +090027)
28
29func (a *apexBundle) AndroidMk() android.AndroidMkData {
30 if a.properties.HideFromMake {
31 return android.AndroidMkData{
32 Disabled: true,
33 }
34 }
Jooyung Han2ed99d02020-06-24 23:26:26 +090035 return a.androidMkForType()
Jiyong Park09d77522019-11-18 11:16:27 +090036}
37
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090038// nameInMake converts apexFileClass into the corresponding class name in Make.
39func (class apexFileClass) nameInMake() string {
40 switch class {
41 case etc:
42 return "ETC"
43 case nativeSharedLib:
44 return "SHARED_LIBRARIES"
45 case nativeExecutable, shBinary, pyBinary, goBinary:
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 Badourb4999222021-01-07 03:34:31 +000065// Return the full module name for a dependency module, which appends the apex module name unless re-using a system lib.
66func (a *apexBundle) fullModuleName(apexBundleName string, fi *apexFile) string {
67 linkToSystemLib := a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform()
68
69 if linkToSystemLib {
70 return fi.androidMkModuleName
71 }
72 return fi.androidMkModuleName + "." + apexBundleName + a.suffix
73}
74
Jooyung Han63dff462023-02-09 00:11:27 +000075func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, moduleDir string,
Jooyung Han07931c72020-09-11 17:19:20 +090076 apexAndroidMkData android.AndroidMkData) []string {
77
Jooyung Han63dff462023-02-09 00:11:27 +000078 // apexBundleName comes from the 'name' property or soong module.
79 // apexName comes from 'name' property of apex_manifest.
Jiyong Parkdb334862020-02-05 17:19:28 +090080 // An apex is installed to /system/apex/<apexBundleName> and is activated at /apex/<apexName>
81 // In many cases, the two names are the same, but could be different in general.
Jooyung Han63dff462023-02-09 00:11:27 +000082 // However, symbol files for apex files are installed under /apex/<apexBundleName> to avoid
83 // conflicts between two apexes with the same apexName.
Jiyong Parkdb334862020-02-05 17:19:28 +090084
Jiyong Park09d77522019-11-18 11:16:27 +090085 moduleNames := []string{}
86 apexType := a.properties.ApexType
87 // To avoid creating duplicate build rules, run this function only when primaryApexType is true
88 // to install symbol files in $(PRODUCT_OUT}/apex.
89 // And if apexType is flattened, run this function to install files in $(PRODUCT_OUT}/system/apex.
90 if !a.primaryApexType && apexType != flattenedApex {
91 return moduleNames
92 }
93
Liz Kammer5bd365f2020-05-27 15:15:11 -070094 seenDataOutPaths := make(map[string]bool)
95
Jiyong Park09d77522019-11-18 11:16:27 +090096 for _, fi := range a.filesInfo {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090097 linkToSystemLib := a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform()
Jiyong Park7cd10e32020-01-14 09:22:18 +090098
Bob Badourb4999222021-01-07 03:34:31 +000099 moduleName := a.fullModuleName(apexBundleName, &fi)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900100
Jiyong Park57621b22021-01-20 20:33:11 +0900101 // This name will be added to LOCAL_REQUIRED_MODULES of the APEX. We need to be
102 // arch-specific otherwise we will end up installing both ABIs even when only
103 // either of the ABI is requested.
104 aName := moduleName
105 switch fi.multilib {
106 case "lib32":
107 aName = aName + ":32"
108 case "lib64":
109 aName = aName + ":64"
110 }
111 if !android.InList(aName, moduleNames) {
112 moduleNames = append(moduleNames, aName)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900113 }
114
115 if linkToSystemLib {
116 // No need to copy the file since it's linked to the system file
117 continue
Jiyong Park09d77522019-11-18 11:16:27 +0900118 }
119
Sasha Smundak5c4729d2022-12-01 10:49:23 -0800120 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS) # apex.apexBundle.files")
Jiyong Park1833cef2019-12-13 13:28:36 +0900121 if fi.moduleDir != "" {
122 fmt.Fprintln(w, "LOCAL_PATH :=", fi.moduleDir)
123 } else {
124 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
125 }
Jiyong Park7cd10e32020-01-14 09:22:18 +0900126 fmt.Fprintln(w, "LOCAL_MODULE :=", moduleName)
Anton Hansson1ee62c02020-06-30 11:51:53 +0100127 if fi.module != nil && fi.module.Owner() != "" {
128 fmt.Fprintln(w, "LOCAL_MODULE_OWNER :=", fi.module.Owner())
129 }
Jooyung Han63dff462023-02-09 00:11:27 +0000130 // /apex/<apexBundleName>/{lib|framework|...}
131 pathForSymbol := filepath.Join("$(PRODUCT_OUT)", "apex", apexBundleName, fi.installDir)
Colin Cross403cc152020-07-06 14:15:24 -0700132 var modulePath string
Jiyong Park09d77522019-11-18 11:16:27 +0900133 if apexType == flattenedApex {
Jooyung Han63dff462023-02-09 00:11:27 +0000134 // /system/apex/<apexBundleName>/{lib|framework|...}
Colin Crossc68db4b2021-11-11 18:59:15 -0800135 modulePath = filepath.Join(a.installDir.String(), apexBundleName, fi.installDir)
Liz Kammer5bd365f2020-05-27 15:15:11 -0700136 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", modulePath)
Jooyung Han2cd2f9a2023-02-06 18:29:08 +0900137 if a.primaryApexType {
Jooyung Han63dff462023-02-09 00:11:27 +0000138 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathForSymbol)
Jiyong Park09d77522019-11-18 11:16:27 +0900139 }
Sasha Smundakdcb61292022-12-08 10:41:33 -0800140 android.AndroidMkEmitAssignList(w, "LOCAL_MODULE_SYMLINKS", fi.symlinks)
Chris Parsons216e10a2020-07-09 17:12:52 -0400141 newDataPaths := []android.DataPath{}
Liz Kammer5bd365f2020-05-27 15:15:11 -0700142 for _, path := range fi.dataPaths {
Chris Parsons216e10a2020-07-09 17:12:52 -0400143 dataOutPath := modulePath + ":" + path.SrcPath.Rel()
Liz Kammer5bd365f2020-05-27 15:15:11 -0700144 if ok := seenDataOutPaths[dataOutPath]; !ok {
145 newDataPaths = append(newDataPaths, path)
146 seenDataOutPaths[dataOutPath] = true
147 }
148 }
Sasha Smundakdcb61292022-12-08 10:41:33 -0800149 android.AndroidMkEmitAssignList(w, "LOCAL_TEST_DATA", android.AndroidMkDataPaths(newDataPaths))
Jiyong Park09d77522019-11-18 11:16:27 +0900150 } else {
Jooyung Han63dff462023-02-09 00:11:27 +0000151 modulePath = pathForSymbol
152 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", modulePath)
Jiyong Park19972c72020-01-28 20:05:29 +0900153
154 // For non-flattend APEXes, the merged notice file is attached to the APEX itself.
155 // We don't need to have notice file for the individual modules in it. Otherwise,
156 // we will have duplicated notice entries.
157 fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
Jiyong Park09d77522019-11-18 11:16:27 +0900158 }
Colin Cross6340ea52021-11-04 12:01:18 -0700159 fmt.Fprintln(w, "LOCAL_SOONG_INSTALLED_MODULE :=", filepath.Join(modulePath, fi.stem()))
160 fmt.Fprintln(w, "LOCAL_SOONG_INSTALL_PAIRS :=", fi.builtFile.String()+":"+filepath.Join(modulePath, fi.stem()))
Jiyong Park09d77522019-11-18 11:16:27 +0900161 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900162 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.nameInMake())
Jiyong Park09d77522019-11-18 11:16:27 +0900163 if fi.module != nil {
164 archStr := fi.module.Target().Arch.ArchType.String()
165 host := false
166 switch fi.module.Target().Os.Class {
167 case android.Host:
Jiyong Park1613e552020-09-14 19:43:17 +0900168 if fi.module.Target().HostCross {
169 if fi.module.Target().Arch.ArchType != android.Common {
170 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
171 }
172 } else {
173 if fi.module.Target().Arch.ArchType != android.Common {
174 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
175 }
Jiyong Park09d77522019-11-18 11:16:27 +0900176 }
177 host = true
178 case android.Device:
179 if fi.module.Target().Arch.ArchType != android.Common {
180 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
181 }
182 }
183 if host {
184 makeOs := fi.module.Target().Os.String()
Colin Crossc74ea4b2021-08-16 14:46:46 -0700185 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic || fi.module.Target().Os == android.LinuxMusl {
Jiyong Park09d77522019-11-18 11:16:27 +0900186 makeOs = "linux"
187 }
188 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
189 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
190 }
191 }
Jiyong Park618922e2020-01-08 13:35:43 +0900192 if fi.jacocoReportClassesFile != nil {
193 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", fi.jacocoReportClassesFile.String())
194 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700195 switch fi.class {
196 case javaSharedLib:
Jiyong Park09d77522019-11-18 11:16:27 +0900197 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
198 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
199 // we will have foo.jar.jar
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900200 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.stem(), ".jar"))
Paul Duffin44b481b2020-06-17 16:59:43 +0100201 if javaModule, ok := fi.module.(java.ApexDependency); ok {
Jiyong Park9e83f0b2020-06-11 00:35:03 +0900202 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
203 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
204 } else {
205 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", fi.builtFile.String())
206 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", fi.builtFile.String())
207 }
Jiyong Park09d77522019-11-18 11:16:27 +0900208 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
209 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
210 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700211 case app:
Colin Cross503c1d02020-01-28 14:00:53 -0800212 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", fi.certificate.AndroidMkString())
Jiyong Park618922e2020-01-08 13:35:43 +0900213 // soong_app_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .apk Therefore
214 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
215 // we will have foo.apk.apk
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900216 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.stem(), ".apk"))
Colin Cross403cc152020-07-06 14:15:24 -0700217 if app, ok := fi.module.(*java.AndroidApp); ok {
Sasha Smundakdcb61292022-12-08 10:41:33 -0800218 android.AndroidMkEmitAssignList(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE", app.JniCoverageOutputs().Strings())
Colin Cross403cc152020-07-06 14:15:24 -0700219 if jniLibSymbols := app.JNISymbolsInstalls(modulePath); len(jniLibSymbols) > 0 {
220 fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_SYMBOLS :=", jniLibSymbols.String())
221 }
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700222 }
Jiyong Park618922e2020-01-08 13:35:43 +0900223 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_app_prebuilt.mk")
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700224 case appSet:
225 as, ok := fi.module.(*java.AndroidAppSet)
226 if !ok {
227 panic(fmt.Sprintf("Expected %s to be AndroidAppSet", fi.module))
228 }
Colin Crossffbcd1d2021-11-12 12:19:42 -0800229 fmt.Fprintln(w, "LOCAL_APK_SET_INSTALL_FILE :=", as.PackedAdditionalOutputs().String())
Colin Cross4fb652d2020-07-09 19:05:35 -0700230 fmt.Fprintln(w, "LOCAL_APKCERTS_FILE :=", as.APKCertsFile().String())
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700231 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_android_app_set.mk")
232 case nativeSharedLib, nativeExecutable, nativeTest:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900233 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.stem())
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700234 if ccMod, ok := fi.module.(*cc.Module); ok {
235 if ccMod.UnstrippedOutputFile() != nil {
236 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", ccMod.UnstrippedOutputFile().String())
Jiyong Park09d77522019-11-18 11:16:27 +0900237 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700238 ccMod.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
239 if ccMod.CoverageOutputFile().Valid() {
240 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", ccMod.CoverageOutputFile().String())
Jiyong Park09d77522019-11-18 11:16:27 +0900241 }
Jiyong Parkc7a46882023-02-02 11:33:39 +0900242 } else if rustMod, ok := fi.module.(*rust.Module); ok {
243 if rustMod.UnstrippedOutputFile() != nil {
244 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", rustMod.UnstrippedOutputFile().String())
245 }
Jiyong Park09d77522019-11-18 11:16:27 +0900246 }
Ivan Lozanod06cc742021-11-12 13:27:58 -0500247 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk")
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700248 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900249 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.stem())
Jiyong Park7aa3f762020-01-28 16:51:34 +0900250 if fi.builtFile == a.manifestPbOut && apexType == flattenedApex {
Jooyung Han75de2612020-01-24 02:02:45 +0900251 if a.primaryApexType {
Jooyung Han07931c72020-09-11 17:19:20 +0900252 // To install companion files (init_rc, vintf_fragments)
253 // Copy some common properties of apexBundle to apex_manifest
254 commonProperties := []string{
Liz Kammer7b3dc8a2021-04-16 16:41:59 -0400255 "LOCAL_FULL_INIT_RC", "LOCAL_FULL_VINTF_FRAGMENTS",
Jooyung Han07931c72020-09-11 17:19:20 +0900256 }
257 for _, name := range commonProperties {
258 if value, ok := apexAndroidMkData.Entries.EntryMap[name]; ok {
Sasha Smundakdcb61292022-12-08 10:41:33 -0800259 android.AndroidMkEmitAssignList(w, name, value)
Jooyung Han07931c72020-09-11 17:19:20 +0900260 }
261 }
262
Jooyung Han75de2612020-01-24 02:02:45 +0900263 // Make apex_manifest.pb module for this APEX to override all other
264 // modules in the APEXes being overridden by this APEX
265 var patterns []string
266 for _, o := range a.overridableProperties.Overrides {
267 patterns = append(patterns, "%."+o+a.suffix)
268 }
Sasha Smundakdcb61292022-12-08 10:41:33 -0800269 android.AndroidMkEmitAssignList(w, "LOCAL_OVERRIDES_MODULES", patterns)
Jooyung Han75de2612020-01-24 02:02:45 +0900270 }
Jooyung Han7f146c02020-09-23 19:15:55 +0900271
272 // File_contexts of flattened APEXes should be merged into file_contexts.bin
273 fmt.Fprintln(w, "LOCAL_FILE_CONTEXTS :=", a.fileContexts)
Jiyong Park09d77522019-11-18 11:16:27 +0900274 }
275 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
276 }
Jiyong Park31af2672020-02-11 09:36:25 +0900277
278 // m <module_name> will build <module_name>.<apex_name> as well.
Yo Chiange8128052020-07-23 20:09:18 +0800279 if fi.androidMkModuleName != moduleName && a.primaryApexType {
280 fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName)
281 fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName)
Jiyong Park31af2672020-02-11 09:36:25 +0900282 }
Jiyong Park09d77522019-11-18 11:16:27 +0900283 }
284 return moduleNames
285}
286
Jiakai Zhangd70dff72022-02-24 15:06:05 +0000287func (a *apexBundle) writeRequiredModules(w io.Writer, moduleNames []string) {
Jiyong Park7afd1072019-12-30 16:56:33 +0900288 var required []string
289 var targetRequired []string
290 var hostRequired []string
Jiyong Parkcacc4f32021-10-28 14:26:03 +0900291 required = append(required, a.RequiredModuleNames()...)
292 targetRequired = append(targetRequired, a.TargetRequiredModuleNames()...)
293 hostRequired = append(hostRequired, a.HostRequiredModuleNames()...)
Jiyong Park7afd1072019-12-30 16:56:33 +0900294 for _, fi := range a.filesInfo {
295 required = append(required, fi.requiredModuleNames...)
296 targetRequired = append(targetRequired, fi.targetRequiredModuleNames...)
297 hostRequired = append(hostRequired, fi.hostRequiredModuleNames...)
298 }
Jingwen Chen29743c82023-01-25 17:49:46 +0000299 android.AndroidMkEmitAssignList(w, "LOCAL_REQUIRED_MODULES", moduleNames, a.makeModulesToInstall, required)
Sasha Smundakdcb61292022-12-08 10:41:33 -0800300 android.AndroidMkEmitAssignList(w, "LOCAL_TARGET_REQUIRED_MODULES", targetRequired)
301 android.AndroidMkEmitAssignList(w, "LOCAL_HOST_REQUIRED_MODULES", hostRequired)
Jiyong Park7afd1072019-12-30 16:56:33 +0900302}
303
Jiyong Park09d77522019-11-18 11:16:27 +0900304func (a *apexBundle) androidMkForType() android.AndroidMkData {
305 return android.AndroidMkData{
306 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
Diwas Sharmabb9202e2023-01-26 18:42:21 +0000307 moduleNames := []string{}
Jiyong Park09d77522019-11-18 11:16:27 +0900308 apexType := a.properties.ApexType
Diwas Sharmabb9202e2023-01-26 18:42:21 +0000309 if a.installable() {
Jooyung Han63dff462023-02-09 00:11:27 +0000310 moduleNames = a.androidMkForFiles(w, name, moduleDir, data)
Diwas Sharmabb9202e2023-01-26 18:42:21 +0000311 }
Jiyong Park09d77522019-11-18 11:16:27 +0900312
313 if apexType == flattenedApex {
314 // Only image APEXes can be flattened.
Sasha Smundak5c4729d2022-12-01 10:49:23 -0800315 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS) # apex.apexBundle.flat")
Jiyong Park09d77522019-11-18 11:16:27 +0900316 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
317 fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix)
Bob Badourb4999222021-01-07 03:34:31 +0000318 data.Entries.WriteLicenseVariables(w)
Jiakai Zhangd70dff72022-02-24 15:06:05 +0000319 a.writeRequiredModules(w, moduleNames)
Jiyong Park09d77522019-11-18 11:16:27 +0900320 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Jiyong Park09d77522019-11-18 11:16:27 +0900321
322 } else {
Sasha Smundak5c4729d2022-12-01 10:49:23 -0800323 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS) # apex.apexBundle")
Jiyong Park09d77522019-11-18 11:16:27 +0900324 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
325 fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix)
Bob Badourb4999222021-01-07 03:34:31 +0000326 data.Entries.WriteLicenseVariables(w)
Jiyong Park09d77522019-11-18 11:16:27 +0900327 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
328 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFile.String())
Colin Crossc68db4b2021-11-11 18:59:15 -0800329 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.String())
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000330 stemSuffix := apexType.suffix()
331 if a.isCompressed {
Samiul Islam7c02e262021-09-08 17:48:28 +0100332 stemSuffix = imageCapexSuffix
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000333 }
334 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+stemSuffix)
Jiyong Park09d77522019-11-18 11:16:27 +0900335 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Colin Crossd9ccb6a2022-03-07 18:38:34 -0800336 if a.installable() {
337 fmt.Fprintln(w, "LOCAL_SOONG_INSTALLED_MODULE :=", a.installedFile.String())
338 fmt.Fprintln(w, "LOCAL_SOONG_INSTALL_PAIRS :=", a.outputFile.String()+":"+a.installedFile.String())
339 }
Jooyung Han2ed99d02020-06-24 23:26:26 +0900340
341 // Because apex writes .mk with Custom(), we need to write manually some common properties
342 // which are available via data.Entries
343 commonProperties := []string{
Liz Kammer7b3dc8a2021-04-16 16:41:59 -0400344 "LOCAL_FULL_INIT_RC", "LOCAL_FULL_VINTF_FRAGMENTS",
Jooyung Han2ed99d02020-06-24 23:26:26 +0900345 "LOCAL_PROPRIETARY_MODULE", "LOCAL_VENDOR_MODULE", "LOCAL_ODM_MODULE", "LOCAL_PRODUCT_MODULE", "LOCAL_SYSTEM_EXT_MODULE",
346 "LOCAL_MODULE_OWNER",
347 }
348 for _, name := range commonProperties {
349 if value, ok := data.Entries.EntryMap[name]; ok {
Sasha Smundakdcb61292022-12-08 10:41:33 -0800350 android.AndroidMkEmitAssignList(w, name, value)
Jooyung Han2ed99d02020-06-24 23:26:26 +0900351 }
352 }
353
Sasha Smundakdcb61292022-12-08 10:41:33 -0800354 android.AndroidMkEmitAssignList(w, "LOCAL_OVERRIDES_MODULES", a.overridableProperties.Overrides)
Diwas Sharmabb9202e2023-01-26 18:42:21 +0000355 a.writeRequiredModules(w, moduleNames)
Jiyong Park19972c72020-01-28 20:05:29 +0900356
Jiyong Park09d77522019-11-18 11:16:27 +0900357 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
358
359 if apexType == imageApex {
Yo Chiangef2d4892020-05-08 15:38:40 +0800360 fmt.Fprintln(w, "ALL_MODULES.$(my_register_name).BUNDLE :=", a.bundleModuleFile.String())
Jiyong Park09d77522019-11-18 11:16:27 +0900361 }
Sasha Smundakdcb61292022-12-08 10:41:33 -0800362 android.AndroidMkEmitAssignList(w, "ALL_MODULES.$(my_register_name).LINT_REPORTS", a.lintReports.Strings())
Jiyong Park3a1602e2020-01-14 14:39:19 +0900363
364 if a.installedFilesFile != nil {
Colin Cross1c85e8e2020-02-26 16:55:51 -0800365 goal := "checkbuild"
Jiyong Park3a1602e2020-01-14 14:39:19 +0900366 distFile := name + "-installed-files.txt"
367 fmt.Fprintln(w, ".PHONY:", goal)
368 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n",
369 goal, a.installedFilesFile.String(), distFile)
Bob Badour51804382022-04-13 11:27:19 -0700370 fmt.Fprintf(w, "$(call declare-0p-target,%s)\n", a.installedFilesFile.String())
Jiyong Park3a1602e2020-01-14 14:39:19 +0900371 }
Anton Hansson82d502a2020-11-11 12:33:14 +0000372 for _, dist := range data.Entries.GetDistForGoals(a) {
373 fmt.Fprintf(w, dist)
374 }
sophiez55e88152020-12-03 23:53:15 +0000375
sophiez02347372021-11-02 17:58:02 -0700376 distCoverageFiles(w, "ndk_apis_usedby_apex", a.nativeApisUsedByModuleFile.String())
sophiez36910972021-11-22 11:49:41 -0800377 distCoverageFiles(w, "ndk_apis_backedby_apex", a.nativeApisBackedByModuleFile.String())
sophiez02347372021-11-02 17:58:02 -0700378 distCoverageFiles(w, "java_apis_used_by_apex", a.javaApisUsedByModuleFile.String())
Jiyong Park09d77522019-11-18 11:16:27 +0900379 }
380 }}
381}
sophiez02347372021-11-02 17:58:02 -0700382
383func distCoverageFiles(w io.Writer, dir string, distfile string) {
384 if distfile != "" {
385 goal := "apps_only"
386 fmt.Fprintf(w, "ifneq (,$(filter $(my_register_name),$(TARGET_BUILD_APPS)))\n"+
387 " $(call dist-for-goals,%s,%s:%s/$(notdir %s))\n"+
388 "endif\n", goal, distfile, dir, distfile)
389 }
390}