blob: 204842992bbad005fe43cc2de7e2f695e7fa9c1f [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 Park09d77522019-11-18 11:16:27 +090026
27 "github.com/google/blueprint/proptools"
28)
29
30func (a *apexBundle) AndroidMk() android.AndroidMkData {
31 if a.properties.HideFromMake {
32 return android.AndroidMkData{
33 Disabled: true,
34 }
35 }
Jooyung Han2ed99d02020-06-24 23:26:26 +090036 return a.androidMkForType()
Jiyong Park09d77522019-11-18 11:16:27 +090037}
38
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090039// nameInMake converts apexFileClass into the corresponding class name in Make.
40func (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
Bob Badourb4999222021-01-07 03:34:31 +000066// Return the full module name for a dependency module, which appends the apex module name unless re-using a system lib.
67func (a *apexBundle) fullModuleName(apexBundleName string, fi *apexFile) string {
68 linkToSystemLib := a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform()
69
70 if linkToSystemLib {
71 return fi.androidMkModuleName
72 }
73 return fi.androidMkModuleName + "." + apexBundleName + a.suffix
74}
75
Jooyung Han07931c72020-09-11 17:19:20 +090076func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, moduleDir string,
77 apexAndroidMkData android.AndroidMkData) []string {
78
Jiyong Parkdb334862020-02-05 17:19:28 +090079 // apexBundleName comes from the 'name' property; apexName comes from 'apex_name' property.
80 // 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.
82
Jiyong Park09d77522019-11-18 11:16:27 +090083 moduleNames := []string{}
84 apexType := a.properties.ApexType
85 // To avoid creating duplicate build rules, run this function only when primaryApexType is true
86 // to install symbol files in $(PRODUCT_OUT}/apex.
87 // And if apexType is flattened, run this function to install files in $(PRODUCT_OUT}/system/apex.
88 if !a.primaryApexType && apexType != flattenedApex {
89 return moduleNames
90 }
91
Yifan Hong93a90db2020-07-28 17:24:44 -070092 // b/162366062. Prevent GKI APEXes to emit make rules to avoid conflicts.
93 if strings.HasPrefix(apexName, "com.android.gki.") && apexType != flattenedApex {
94 return moduleNames
95 }
96
Jiyong Parkdb334862020-02-05 17:19:28 +090097 // b/140136207. When there are overriding APEXes for a VNDK APEX, the symbols file for the overridden
98 // APEX and the overriding APEX will have the same installation paths at /apex/com.android.vndk.v<ver>
99 // as their apexName will be the same. To avoid the path conflicts, skip installing the symbol files
100 // for the overriding VNDK APEXes.
101 symbolFilesNotNeeded := a.vndkApex && len(a.overridableProperties.Overrides) > 0
102 if symbolFilesNotNeeded && apexType != flattenedApex {
103 return moduleNames
104 }
105
Daniel Norman6cfb37af2021-11-16 20:28:29 +0000106 // Avoid creating duplicate build rules for multi-installed APEXes.
107 if proptools.BoolDefault(a.properties.Multi_install_skip_symbol_files, false) {
108 return moduleNames
109 }
110
Colin Crossccba23d2021-11-12 19:01:29 +0000111 var postInstallCommands []string
112 for _, fi := range a.filesInfo {
113 if a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform() {
114 // TODO(jiyong): pathOnDevice should come from fi.module, not being calculated here
115 linkTarget := filepath.Join("/system", fi.path())
116 linkPath := filepath.Join(a.installDir.ToMakePath().String(), apexBundleName, fi.path())
117 mkdirCmd := "mkdir -p " + filepath.Dir(linkPath)
118 linkCmd := "ln -sfn " + linkTarget + " " + linkPath
119 postInstallCommands = append(postInstallCommands, mkdirCmd, linkCmd)
120 }
121 }
122
Liz Kammer5bd365f2020-05-27 15:15:11 -0700123 seenDataOutPaths := make(map[string]bool)
124
Jiyong Park09d77522019-11-18 11:16:27 +0900125 for _, fi := range a.filesInfo {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900126 linkToSystemLib := a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform()
Jiyong Park7cd10e32020-01-14 09:22:18 +0900127
Bob Badourb4999222021-01-07 03:34:31 +0000128 moduleName := a.fullModuleName(apexBundleName, &fi)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900129
Jiyong Park57621b22021-01-20 20:33:11 +0900130 // This name will be added to LOCAL_REQUIRED_MODULES of the APEX. We need to be
131 // arch-specific otherwise we will end up installing both ABIs even when only
132 // either of the ABI is requested.
133 aName := moduleName
134 switch fi.multilib {
135 case "lib32":
136 aName = aName + ":32"
137 case "lib64":
138 aName = aName + ":64"
139 }
140 if !android.InList(aName, moduleNames) {
141 moduleNames = append(moduleNames, aName)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900142 }
143
144 if linkToSystemLib {
145 // No need to copy the file since it's linked to the system file
146 continue
Jiyong Park09d77522019-11-18 11:16:27 +0900147 }
148
149 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
Jiyong Park1833cef2019-12-13 13:28:36 +0900150 if fi.moduleDir != "" {
151 fmt.Fprintln(w, "LOCAL_PATH :=", fi.moduleDir)
152 } else {
153 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
154 }
Jiyong Park7cd10e32020-01-14 09:22:18 +0900155 fmt.Fprintln(w, "LOCAL_MODULE :=", moduleName)
Anton Hansson1ee62c02020-06-30 11:51:53 +0100156 if fi.module != nil && fi.module.Owner() != "" {
157 fmt.Fprintln(w, "LOCAL_MODULE_OWNER :=", fi.module.Owner())
158 }
Jiyong Park09d77522019-11-18 11:16:27 +0900159 // /apex/<apex_name>/{lib|framework|...}
160 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", apexName, fi.installDir)
Colin Cross403cc152020-07-06 14:15:24 -0700161 var modulePath string
Jiyong Park09d77522019-11-18 11:16:27 +0900162 if apexType == flattenedApex {
163 // /system/apex/<name>/{lib|framework|...}
Colin Cross403cc152020-07-06 14:15:24 -0700164 modulePath = filepath.Join(a.installDir.ToMakePath().String(), apexBundleName, fi.installDir)
Liz Kammer5bd365f2020-05-27 15:15:11 -0700165 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", modulePath)
Jiyong Parkdb334862020-02-05 17:19:28 +0900166 if a.primaryApexType && !symbolFilesNotNeeded {
Jiyong Park09d77522019-11-18 11:16:27 +0900167 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
168 }
169 if len(fi.symlinks) > 0 {
170 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
171 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400172 newDataPaths := []android.DataPath{}
Liz Kammer5bd365f2020-05-27 15:15:11 -0700173 for _, path := range fi.dataPaths {
Chris Parsons216e10a2020-07-09 17:12:52 -0400174 dataOutPath := modulePath + ":" + path.SrcPath.Rel()
Liz Kammer5bd365f2020-05-27 15:15:11 -0700175 if ok := seenDataOutPaths[dataOutPath]; !ok {
176 newDataPaths = append(newDataPaths, path)
177 seenDataOutPaths[dataOutPath] = true
178 }
179 }
180 if len(newDataPaths) > 0 {
Dan Shi31949122020-09-21 12:11:02 -0700181 fmt.Fprintln(w, "LOCAL_TEST_DATA :=", strings.Join(android.AndroidMkDataPaths(newDataPaths), " "))
Liz Kammer1c14a212020-05-12 15:26:55 -0700182 }
Jiyong Park09d77522019-11-18 11:16:27 +0900183
Bob Badoura75b0572020-02-18 20:21:55 -0800184 if fi.module != nil && len(fi.module.NoticeFiles()) > 0 {
185 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", strings.Join(fi.module.NoticeFiles().Strings(), " "))
Jiyong Park09d77522019-11-18 11:16:27 +0900186 }
187 } else {
Colin Cross403cc152020-07-06 14:15:24 -0700188 modulePath = pathWhenActivated
Jiyong Park09d77522019-11-18 11:16:27 +0900189 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park19972c72020-01-28 20:05:29 +0900190
191 // For non-flattend APEXes, the merged notice file is attached to the APEX itself.
192 // We don't need to have notice file for the individual modules in it. Otherwise,
193 // we will have duplicated notice entries.
194 fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
Jiyong Park09d77522019-11-18 11:16:27 +0900195 }
196 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900197 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.nameInMake())
Jiyong Park09d77522019-11-18 11:16:27 +0900198 if fi.module != nil {
199 archStr := fi.module.Target().Arch.ArchType.String()
200 host := false
201 switch fi.module.Target().Os.Class {
202 case android.Host:
Jiyong Park1613e552020-09-14 19:43:17 +0900203 if fi.module.Target().HostCross {
204 if fi.module.Target().Arch.ArchType != android.Common {
205 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
206 }
207 } else {
208 if fi.module.Target().Arch.ArchType != android.Common {
209 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
210 }
Jiyong Park09d77522019-11-18 11:16:27 +0900211 }
212 host = true
213 case android.Device:
214 if fi.module.Target().Arch.ArchType != android.Common {
215 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
216 }
217 }
218 if host {
219 makeOs := fi.module.Target().Os.String()
Colin Crossc74ea4b2021-08-16 14:46:46 -0700220 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 +0900221 makeOs = "linux"
222 }
223 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
224 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
225 }
226 }
Jiyong Park618922e2020-01-08 13:35:43 +0900227 if fi.jacocoReportClassesFile != nil {
228 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", fi.jacocoReportClassesFile.String())
229 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700230 switch fi.class {
231 case javaSharedLib:
Jiyong Park09d77522019-11-18 11:16:27 +0900232 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
233 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
234 // we will have foo.jar.jar
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900235 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.stem(), ".jar"))
Paul Duffin44b481b2020-06-17 16:59:43 +0100236 if javaModule, ok := fi.module.(java.ApexDependency); ok {
Jiyong Park9e83f0b2020-06-11 00:35:03 +0900237 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
238 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
239 } else {
240 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", fi.builtFile.String())
241 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", fi.builtFile.String())
242 }
Jiyong Park09d77522019-11-18 11:16:27 +0900243 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
244 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
245 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700246 case app:
Colin Cross503c1d02020-01-28 14:00:53 -0800247 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", fi.certificate.AndroidMkString())
Jiyong Park618922e2020-01-08 13:35:43 +0900248 // soong_app_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .apk Therefore
249 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
250 // we will have foo.apk.apk
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900251 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.stem(), ".apk"))
Colin Cross403cc152020-07-06 14:15:24 -0700252 if app, ok := fi.module.(*java.AndroidApp); ok {
253 if jniCoverageOutputs := app.JniCoverageOutputs(); len(jniCoverageOutputs) > 0 {
254 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", strings.Join(jniCoverageOutputs.Strings(), " "))
255 }
256 if jniLibSymbols := app.JNISymbolsInstalls(modulePath); len(jniLibSymbols) > 0 {
257 fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_SYMBOLS :=", jniLibSymbols.String())
258 }
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700259 }
Jiyong Park618922e2020-01-08 13:35:43 +0900260 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_app_prebuilt.mk")
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700261 case appSet:
262 as, ok := fi.module.(*java.AndroidAppSet)
263 if !ok {
264 panic(fmt.Sprintf("Expected %s to be AndroidAppSet", fi.module))
265 }
Colin Crossffbcd1d2021-11-12 12:19:42 -0800266 fmt.Fprintln(w, "LOCAL_APK_SET_INSTALL_FILE :=", as.PackedAdditionalOutputs().String())
Colin Cross4fb652d2020-07-09 19:05:35 -0700267 fmt.Fprintln(w, "LOCAL_APKCERTS_FILE :=", as.APKCertsFile().String())
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700268 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_android_app_set.mk")
269 case nativeSharedLib, nativeExecutable, nativeTest:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900270 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.stem())
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700271 if ccMod, ok := fi.module.(*cc.Module); ok {
272 if ccMod.UnstrippedOutputFile() != nil {
273 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", ccMod.UnstrippedOutputFile().String())
Jiyong Park09d77522019-11-18 11:16:27 +0900274 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700275 ccMod.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
276 if ccMod.CoverageOutputFile().Valid() {
277 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", ccMod.CoverageOutputFile().String())
Jiyong Park09d77522019-11-18 11:16:27 +0900278 }
279 }
Ivan Lozanod06cc742021-11-12 13:27:58 -0500280 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk")
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700281 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900282 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.stem())
Jiyong Park7aa3f762020-01-28 16:51:34 +0900283 if fi.builtFile == a.manifestPbOut && apexType == flattenedApex {
Jooyung Han75de2612020-01-24 02:02:45 +0900284 if a.primaryApexType {
Jooyung Han07931c72020-09-11 17:19:20 +0900285 // To install companion files (init_rc, vintf_fragments)
286 // Copy some common properties of apexBundle to apex_manifest
287 commonProperties := []string{
Liz Kammer7b3dc8a2021-04-16 16:41:59 -0400288 "LOCAL_FULL_INIT_RC", "LOCAL_FULL_VINTF_FRAGMENTS",
Jooyung Han07931c72020-09-11 17:19:20 +0900289 }
290 for _, name := range commonProperties {
291 if value, ok := apexAndroidMkData.Entries.EntryMap[name]; ok {
292 fmt.Fprintln(w, name+" := "+strings.Join(value, " "))
293 }
294 }
295
Jooyung Han75de2612020-01-24 02:02:45 +0900296 // Make apex_manifest.pb module for this APEX to override all other
297 // modules in the APEXes being overridden by this APEX
298 var patterns []string
299 for _, o := range a.overridableProperties.Overrides {
300 patterns = append(patterns, "%."+o+a.suffix)
301 }
Yo Chiang12d9f7a2020-06-16 17:32:19 +0800302 if len(patterns) > 0 {
303 fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES :=", strings.Join(patterns, " "))
304 }
Colin Crossccba23d2021-11-12 19:01:29 +0000305 if len(a.compatSymlinks) > 0 {
306 // For flattened apexes, compat symlinks are attached to apex_manifest.json which is guaranteed for every apex
307 postInstallCommands = append(postInstallCommands, a.compatSymlinks...)
308 }
Jooyung Han75de2612020-01-24 02:02:45 +0900309 }
Jooyung Han7f146c02020-09-23 19:15:55 +0900310
311 // File_contexts of flattened APEXes should be merged into file_contexts.bin
312 fmt.Fprintln(w, "LOCAL_FILE_CONTEXTS :=", a.fileContexts)
Colin Crossccba23d2021-11-12 19:01:29 +0000313
314 if len(postInstallCommands) > 0 {
315 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", strings.Join(postInstallCommands, " && "))
316 }
Jiyong Park09d77522019-11-18 11:16:27 +0900317 }
318 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
319 }
Jiyong Park31af2672020-02-11 09:36:25 +0900320
321 // m <module_name> will build <module_name>.<apex_name> as well.
Yo Chiange8128052020-07-23 20:09:18 +0800322 if fi.androidMkModuleName != moduleName && a.primaryApexType {
323 fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName)
324 fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName)
Jiyong Park31af2672020-02-11 09:36:25 +0900325 }
Jiyong Park09d77522019-11-18 11:16:27 +0900326 }
327 return moduleNames
328}
329
Bob Badourb4999222021-01-07 03:34:31 +0000330func (a *apexBundle) writeRequiredModules(w io.Writer, apexBundleName string) {
Jiyong Park7afd1072019-12-30 16:56:33 +0900331 var required []string
332 var targetRequired []string
333 var hostRequired []string
Jiyong Parkcacc4f32021-10-28 14:26:03 +0900334 required = append(required, a.RequiredModuleNames()...)
335 targetRequired = append(targetRequired, a.TargetRequiredModuleNames()...)
336 hostRequired = append(hostRequired, a.HostRequiredModuleNames()...)
Bob Badourb4999222021-01-07 03:34:31 +0000337 installMapSet := make(map[string]bool) // set of dependency module:location mappings
Jiyong Park7afd1072019-12-30 16:56:33 +0900338 for _, fi := range a.filesInfo {
339 required = append(required, fi.requiredModuleNames...)
340 targetRequired = append(targetRequired, fi.targetRequiredModuleNames...)
341 hostRequired = append(hostRequired, fi.hostRequiredModuleNames...)
Bob Badourb4999222021-01-07 03:34:31 +0000342 installMapSet[a.fullModuleName(apexBundleName, &fi)+":"+fi.installDir+"/"+fi.builtFile.Base()] = true
Jiyong Park7afd1072019-12-30 16:56:33 +0900343 }
344
345 if len(required) > 0 {
346 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(required, " "))
347 }
348 if len(targetRequired) > 0 {
349 fmt.Fprintln(w, "LOCAL_TARGET_REQUIRED_MODULES +=", strings.Join(targetRequired, " "))
350 }
351 if len(hostRequired) > 0 {
352 fmt.Fprintln(w, "LOCAL_HOST_REQUIRED_MODULES +=", strings.Join(hostRequired, " "))
353 }
Bob Badourb4999222021-01-07 03:34:31 +0000354 if len(installMapSet) > 0 {
355 var installs []string
356 installs = append(installs, android.SortedStringKeys(installMapSet)...)
357 fmt.Fprintln(w, "LOCAL_LICENSE_INSTALL_MAP +=", strings.Join(installs, " "))
358 }
Jiyong Park7afd1072019-12-30 16:56:33 +0900359}
360
Jiyong Park09d77522019-11-18 11:16:27 +0900361func (a *apexBundle) androidMkForType() android.AndroidMkData {
362 return android.AndroidMkData{
363 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
364 moduleNames := []string{}
365 apexType := a.properties.ApexType
366 if a.installable() {
367 apexName := proptools.StringDefault(a.properties.Apex_name, name)
Jooyung Han07931c72020-09-11 17:19:20 +0900368 moduleNames = a.androidMkForFiles(w, name, apexName, moduleDir, data)
Jiyong Park09d77522019-11-18 11:16:27 +0900369 }
370
371 if apexType == flattenedApex {
372 // Only image APEXes can be flattened.
373 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
374 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
375 fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix)
Bob Badourb4999222021-01-07 03:34:31 +0000376 data.Entries.WriteLicenseVariables(w)
Jiyong Park09d77522019-11-18 11:16:27 +0900377 if len(moduleNames) > 0 {
378 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
379 }
Bob Badourb4999222021-01-07 03:34:31 +0000380 a.writeRequiredModules(w, name)
Jiyong Park09d77522019-11-18 11:16:27 +0900381 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Jiyong Park09d77522019-11-18 11:16:27 +0900382
383 } else {
384 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
385 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
386 fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix)
Bob Badourb4999222021-01-07 03:34:31 +0000387 data.Entries.WriteLicenseVariables(w)
Jiyong Park09d77522019-11-18 11:16:27 +0900388 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
389 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFile.String())
390 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String())
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000391 stemSuffix := apexType.suffix()
392 if a.isCompressed {
Samiul Islam7c02e262021-09-08 17:48:28 +0100393 stemSuffix = imageCapexSuffix
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000394 }
395 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+stemSuffix)
Jiyong Park09d77522019-11-18 11:16:27 +0900396 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jooyung Han2ed99d02020-06-24 23:26:26 +0900397
398 // Because apex writes .mk with Custom(), we need to write manually some common properties
399 // which are available via data.Entries
400 commonProperties := []string{
Liz Kammer7b3dc8a2021-04-16 16:41:59 -0400401 "LOCAL_FULL_INIT_RC", "LOCAL_FULL_VINTF_FRAGMENTS",
Jooyung Han2ed99d02020-06-24 23:26:26 +0900402 "LOCAL_PROPRIETARY_MODULE", "LOCAL_VENDOR_MODULE", "LOCAL_ODM_MODULE", "LOCAL_PRODUCT_MODULE", "LOCAL_SYSTEM_EXT_MODULE",
403 "LOCAL_MODULE_OWNER",
404 }
405 for _, name := range commonProperties {
406 if value, ok := data.Entries.EntryMap[name]; ok {
407 fmt.Fprintln(w, name+" := "+strings.Join(value, " "))
408 }
409 }
410
Yo Chiang12d9f7a2020-06-16 17:32:19 +0800411 if len(a.overridableProperties.Overrides) > 0 {
412 fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES :=", strings.Join(a.overridableProperties.Overrides, " "))
413 }
Jiyong Park09d77522019-11-18 11:16:27 +0900414 if len(moduleNames) > 0 {
415 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
416 }
Jiyong Park956305c2020-01-09 12:32:06 +0900417 if len(a.requiredDeps) > 0 {
418 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.requiredDeps, " "))
Jiyong Park09d77522019-11-18 11:16:27 +0900419 }
Bob Badourb4999222021-01-07 03:34:31 +0000420 a.writeRequiredModules(w, name)
Colin Crossccba23d2021-11-12 19:01:29 +0000421 var postInstallCommands []string
422 if a.prebuiltFileToDelete != "" {
423 postInstallCommands = append(postInstallCommands, "rm -rf "+
424 filepath.Join(a.installDir.ToMakePath().String(), a.prebuiltFileToDelete))
425 }
426 // For unflattened apexes, compat symlinks are attached to apex package itself as LOCAL_POST_INSTALL_CMD
427 postInstallCommands = append(postInstallCommands, a.compatSymlinks...)
428 if len(postInstallCommands) > 0 {
429 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", strings.Join(postInstallCommands, " && "))
430 }
Jiyong Park19972c72020-01-28 20:05:29 +0900431
432 if a.mergedNotices.Merged.Valid() {
433 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", a.mergedNotices.Merged.Path().String())
434 }
435
Jiyong Park09d77522019-11-18 11:16:27 +0900436 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
437
438 if apexType == imageApex {
Yo Chiangef2d4892020-05-08 15:38:40 +0800439 fmt.Fprintln(w, "ALL_MODULES.$(my_register_name).BUNDLE :=", a.bundleModuleFile.String())
Jiyong Park09d77522019-11-18 11:16:27 +0900440 }
Colin Cross08dca382020-07-21 20:31:17 -0700441 if len(a.lintReports) > 0 {
442 fmt.Fprintln(w, "ALL_MODULES.$(my_register_name).LINT_REPORTS :=",
443 strings.Join(a.lintReports.Strings(), " "))
444 }
Jiyong Park3a1602e2020-01-14 14:39:19 +0900445
446 if a.installedFilesFile != nil {
Colin Cross1c85e8e2020-02-26 16:55:51 -0800447 goal := "checkbuild"
Jiyong Park3a1602e2020-01-14 14:39:19 +0900448 distFile := name + "-installed-files.txt"
449 fmt.Fprintln(w, ".PHONY:", goal)
450 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n",
451 goal, a.installedFilesFile.String(), distFile)
452 }
Anton Hansson82d502a2020-11-11 12:33:14 +0000453 for _, dist := range data.Entries.GetDistForGoals(a) {
454 fmt.Fprintf(w, dist)
455 }
sophiez55e88152020-12-03 23:53:15 +0000456
sophiez02347372021-11-02 17:58:02 -0700457 distCoverageFiles(w, "ndk_apis_usedby_apex", a.nativeApisUsedByModuleFile.String())
458 distCoverageFiles(w, "ndk_apis_usedby_apex", a.nativeApisBackedByModuleFile.String())
459 distCoverageFiles(w, "java_apis_used_by_apex", a.javaApisUsedByModuleFile.String())
Jiyong Park09d77522019-11-18 11:16:27 +0900460 }
461 }}
462}
sophiez02347372021-11-02 17:58:02 -0700463
464func distCoverageFiles(w io.Writer, dir string, distfile string) {
465 if distfile != "" {
466 goal := "apps_only"
467 fmt.Fprintf(w, "ifneq (,$(filter $(my_register_name),$(TARGET_BUILD_APPS)))\n"+
468 " $(call dist-for-goals,%s,%s:%s/$(notdir %s))\n"+
469 "endif\n", goal, distfile, dir, distfile)
470 }
471}