blob: 0fc971bb06ec5bd407a689f0d5fa2971e38ba17d [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
Liz Kammer5bd365f2020-05-27 15:15:11 -0700111 seenDataOutPaths := make(map[string]bool)
112
Jiyong Park09d77522019-11-18 11:16:27 +0900113 for _, fi := range a.filesInfo {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900114 linkToSystemLib := a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform()
Jiyong Park7cd10e32020-01-14 09:22:18 +0900115
Bob Badourb4999222021-01-07 03:34:31 +0000116 moduleName := a.fullModuleName(apexBundleName, &fi)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900117
Jiyong Park57621b22021-01-20 20:33:11 +0900118 // This name will be added to LOCAL_REQUIRED_MODULES of the APEX. We need to be
119 // arch-specific otherwise we will end up installing both ABIs even when only
120 // either of the ABI is requested.
121 aName := moduleName
122 switch fi.multilib {
123 case "lib32":
124 aName = aName + ":32"
125 case "lib64":
126 aName = aName + ":64"
127 }
128 if !android.InList(aName, moduleNames) {
129 moduleNames = append(moduleNames, aName)
Jiyong Park7cd10e32020-01-14 09:22:18 +0900130 }
131
132 if linkToSystemLib {
133 // No need to copy the file since it's linked to the system file
134 continue
Jiyong Park09d77522019-11-18 11:16:27 +0900135 }
136
Sasha Smundak5c4729d2022-12-01 10:49:23 -0800137 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS) # apex.apexBundle.files")
Jiyong Park1833cef2019-12-13 13:28:36 +0900138 if fi.moduleDir != "" {
139 fmt.Fprintln(w, "LOCAL_PATH :=", fi.moduleDir)
140 } else {
141 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
142 }
Jiyong Park7cd10e32020-01-14 09:22:18 +0900143 fmt.Fprintln(w, "LOCAL_MODULE :=", moduleName)
Anton Hansson1ee62c02020-06-30 11:51:53 +0100144 if fi.module != nil && fi.module.Owner() != "" {
145 fmt.Fprintln(w, "LOCAL_MODULE_OWNER :=", fi.module.Owner())
146 }
Jiyong Park09d77522019-11-18 11:16:27 +0900147 // /apex/<apex_name>/{lib|framework|...}
148 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", apexName, fi.installDir)
Colin Cross403cc152020-07-06 14:15:24 -0700149 var modulePath string
Jiyong Park09d77522019-11-18 11:16:27 +0900150 if apexType == flattenedApex {
151 // /system/apex/<name>/{lib|framework|...}
Colin Crossc68db4b2021-11-11 18:59:15 -0800152 modulePath = filepath.Join(a.installDir.String(), apexBundleName, fi.installDir)
Liz Kammer5bd365f2020-05-27 15:15:11 -0700153 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", modulePath)
Jiyong Parkdb334862020-02-05 17:19:28 +0900154 if a.primaryApexType && !symbolFilesNotNeeded {
Jiyong Park09d77522019-11-18 11:16:27 +0900155 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
156 }
157 if len(fi.symlinks) > 0 {
158 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
159 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400160 newDataPaths := []android.DataPath{}
Liz Kammer5bd365f2020-05-27 15:15:11 -0700161 for _, path := range fi.dataPaths {
Chris Parsons216e10a2020-07-09 17:12:52 -0400162 dataOutPath := modulePath + ":" + path.SrcPath.Rel()
Liz Kammer5bd365f2020-05-27 15:15:11 -0700163 if ok := seenDataOutPaths[dataOutPath]; !ok {
164 newDataPaths = append(newDataPaths, path)
165 seenDataOutPaths[dataOutPath] = true
166 }
167 }
168 if len(newDataPaths) > 0 {
Dan Shi31949122020-09-21 12:11:02 -0700169 fmt.Fprintln(w, "LOCAL_TEST_DATA :=", strings.Join(android.AndroidMkDataPaths(newDataPaths), " "))
Liz Kammer1c14a212020-05-12 15:26:55 -0700170 }
Jiyong Park09d77522019-11-18 11:16:27 +0900171 } else {
Colin Cross403cc152020-07-06 14:15:24 -0700172 modulePath = pathWhenActivated
Jiyong Park09d77522019-11-18 11:16:27 +0900173 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
Jiyong Park19972c72020-01-28 20:05:29 +0900174
175 // For non-flattend APEXes, the merged notice file is attached to the APEX itself.
176 // We don't need to have notice file for the individual modules in it. Otherwise,
177 // we will have duplicated notice entries.
178 fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
Jiyong Park09d77522019-11-18 11:16:27 +0900179 }
Colin Cross6340ea52021-11-04 12:01:18 -0700180 fmt.Fprintln(w, "LOCAL_SOONG_INSTALLED_MODULE :=", filepath.Join(modulePath, fi.stem()))
181 fmt.Fprintln(w, "LOCAL_SOONG_INSTALL_PAIRS :=", fi.builtFile.String()+":"+filepath.Join(modulePath, fi.stem()))
Jiyong Park09d77522019-11-18 11:16:27 +0900182 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900183 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.nameInMake())
Jiyong Park09d77522019-11-18 11:16:27 +0900184 if fi.module != nil {
185 archStr := fi.module.Target().Arch.ArchType.String()
186 host := false
187 switch fi.module.Target().Os.Class {
188 case android.Host:
Jiyong Park1613e552020-09-14 19:43:17 +0900189 if fi.module.Target().HostCross {
190 if fi.module.Target().Arch.ArchType != android.Common {
191 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
192 }
193 } else {
194 if fi.module.Target().Arch.ArchType != android.Common {
195 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
196 }
Jiyong Park09d77522019-11-18 11:16:27 +0900197 }
198 host = true
199 case android.Device:
200 if fi.module.Target().Arch.ArchType != android.Common {
201 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
202 }
203 }
204 if host {
205 makeOs := fi.module.Target().Os.String()
Colin Crossc74ea4b2021-08-16 14:46:46 -0700206 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 +0900207 makeOs = "linux"
208 }
209 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
210 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
211 }
212 }
Jiyong Park618922e2020-01-08 13:35:43 +0900213 if fi.jacocoReportClassesFile != nil {
214 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", fi.jacocoReportClassesFile.String())
215 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700216 switch fi.class {
217 case javaSharedLib:
Jiyong Park09d77522019-11-18 11:16:27 +0900218 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
219 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
220 // we will have foo.jar.jar
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900221 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.stem(), ".jar"))
Paul Duffin44b481b2020-06-17 16:59:43 +0100222 if javaModule, ok := fi.module.(java.ApexDependency); ok {
Jiyong Park9e83f0b2020-06-11 00:35:03 +0900223 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
224 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
225 } else {
226 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", fi.builtFile.String())
227 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", fi.builtFile.String())
228 }
Jiyong Park09d77522019-11-18 11:16:27 +0900229 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
230 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
231 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700232 case app:
Colin Cross503c1d02020-01-28 14:00:53 -0800233 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", fi.certificate.AndroidMkString())
Jiyong Park618922e2020-01-08 13:35:43 +0900234 // soong_app_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .apk Therefore
235 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
236 // we will have foo.apk.apk
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900237 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.stem(), ".apk"))
Colin Cross403cc152020-07-06 14:15:24 -0700238 if app, ok := fi.module.(*java.AndroidApp); ok {
239 if jniCoverageOutputs := app.JniCoverageOutputs(); len(jniCoverageOutputs) > 0 {
240 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", strings.Join(jniCoverageOutputs.Strings(), " "))
241 }
242 if jniLibSymbols := app.JNISymbolsInstalls(modulePath); len(jniLibSymbols) > 0 {
243 fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_SYMBOLS :=", jniLibSymbols.String())
244 }
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700245 }
Jiyong Park618922e2020-01-08 13:35:43 +0900246 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_app_prebuilt.mk")
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700247 case appSet:
248 as, ok := fi.module.(*java.AndroidAppSet)
249 if !ok {
250 panic(fmt.Sprintf("Expected %s to be AndroidAppSet", fi.module))
251 }
Colin Crossffbcd1d2021-11-12 12:19:42 -0800252 fmt.Fprintln(w, "LOCAL_APK_SET_INSTALL_FILE :=", as.PackedAdditionalOutputs().String())
Colin Cross4fb652d2020-07-09 19:05:35 -0700253 fmt.Fprintln(w, "LOCAL_APKCERTS_FILE :=", as.APKCertsFile().String())
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700254 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_android_app_set.mk")
255 case nativeSharedLib, nativeExecutable, nativeTest:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900256 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.stem())
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700257 if ccMod, ok := fi.module.(*cc.Module); ok {
258 if ccMod.UnstrippedOutputFile() != nil {
259 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", ccMod.UnstrippedOutputFile().String())
Jiyong Park09d77522019-11-18 11:16:27 +0900260 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700261 ccMod.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
262 if ccMod.CoverageOutputFile().Valid() {
263 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", ccMod.CoverageOutputFile().String())
Jiyong Park09d77522019-11-18 11:16:27 +0900264 }
265 }
Ivan Lozanod06cc742021-11-12 13:27:58 -0500266 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk")
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700267 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900268 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.stem())
Jiyong Park7aa3f762020-01-28 16:51:34 +0900269 if fi.builtFile == a.manifestPbOut && apexType == flattenedApex {
Jooyung Han75de2612020-01-24 02:02:45 +0900270 if a.primaryApexType {
Jooyung Han07931c72020-09-11 17:19:20 +0900271 // To install companion files (init_rc, vintf_fragments)
272 // Copy some common properties of apexBundle to apex_manifest
273 commonProperties := []string{
Liz Kammer7b3dc8a2021-04-16 16:41:59 -0400274 "LOCAL_FULL_INIT_RC", "LOCAL_FULL_VINTF_FRAGMENTS",
Jooyung Han07931c72020-09-11 17:19:20 +0900275 }
276 for _, name := range commonProperties {
277 if value, ok := apexAndroidMkData.Entries.EntryMap[name]; ok {
278 fmt.Fprintln(w, name+" := "+strings.Join(value, " "))
279 }
280 }
281
Jooyung Han75de2612020-01-24 02:02:45 +0900282 // Make apex_manifest.pb module for this APEX to override all other
283 // modules in the APEXes being overridden by this APEX
284 var patterns []string
285 for _, o := range a.overridableProperties.Overrides {
286 patterns = append(patterns, "%."+o+a.suffix)
287 }
Yo Chiang12d9f7a2020-06-16 17:32:19 +0800288 if len(patterns) > 0 {
289 fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES :=", strings.Join(patterns, " "))
290 }
Jooyung Han75de2612020-01-24 02:02:45 +0900291 }
Jooyung Han7f146c02020-09-23 19:15:55 +0900292
293 // File_contexts of flattened APEXes should be merged into file_contexts.bin
294 fmt.Fprintln(w, "LOCAL_FILE_CONTEXTS :=", a.fileContexts)
Jiyong Park09d77522019-11-18 11:16:27 +0900295 }
296 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
297 }
Jiyong Park31af2672020-02-11 09:36:25 +0900298
299 // m <module_name> will build <module_name>.<apex_name> as well.
Yo Chiange8128052020-07-23 20:09:18 +0800300 if fi.androidMkModuleName != moduleName && a.primaryApexType {
301 fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName)
302 fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName)
Jiyong Park31af2672020-02-11 09:36:25 +0900303 }
Jiyong Park09d77522019-11-18 11:16:27 +0900304 }
305 return moduleNames
306}
307
Jiakai Zhangd70dff72022-02-24 15:06:05 +0000308func (a *apexBundle) writeRequiredModules(w io.Writer, moduleNames []string) {
309 if len(moduleNames) > 0 {
310 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
311 }
312 if len(a.requiredDeps) > 0 {
313 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.requiredDeps, " "))
314 }
315
Jiyong Park7afd1072019-12-30 16:56:33 +0900316 var required []string
317 var targetRequired []string
318 var hostRequired []string
Jiyong Parkcacc4f32021-10-28 14:26:03 +0900319 required = append(required, a.RequiredModuleNames()...)
320 targetRequired = append(targetRequired, a.TargetRequiredModuleNames()...)
321 hostRequired = append(hostRequired, a.HostRequiredModuleNames()...)
Jiyong Park7afd1072019-12-30 16:56:33 +0900322 for _, fi := range a.filesInfo {
323 required = append(required, fi.requiredModuleNames...)
324 targetRequired = append(targetRequired, fi.targetRequiredModuleNames...)
325 hostRequired = append(hostRequired, fi.hostRequiredModuleNames...)
326 }
327
328 if len(required) > 0 {
329 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(required, " "))
330 }
331 if len(targetRequired) > 0 {
332 fmt.Fprintln(w, "LOCAL_TARGET_REQUIRED_MODULES +=", strings.Join(targetRequired, " "))
333 }
334 if len(hostRequired) > 0 {
335 fmt.Fprintln(w, "LOCAL_HOST_REQUIRED_MODULES +=", strings.Join(hostRequired, " "))
336 }
337}
338
Jiyong Park09d77522019-11-18 11:16:27 +0900339func (a *apexBundle) androidMkForType() android.AndroidMkData {
340 return android.AndroidMkData{
341 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
Prerana Patilb1896c82022-11-09 18:14:34 +0000342 moduleNames := []string{}
Jiyong Park09d77522019-11-18 11:16:27 +0900343 apexType := a.properties.ApexType
Prerana Patilb1896c82022-11-09 18:14:34 +0000344 if a.installable() {
345 apexName := proptools.StringDefault(a.properties.Apex_name, name)
346 moduleNames = a.androidMkForFiles(w, name, apexName, moduleDir, data)
347 }
Jiyong Park09d77522019-11-18 11:16:27 +0900348
349 if apexType == flattenedApex {
350 // Only image APEXes can be flattened.
Sasha Smundak5c4729d2022-12-01 10:49:23 -0800351 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS) # apex.apexBundle.flat")
Jiyong Park09d77522019-11-18 11:16:27 +0900352 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
353 fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix)
Bob Badourb4999222021-01-07 03:34:31 +0000354 data.Entries.WriteLicenseVariables(w)
Jiakai Zhangd70dff72022-02-24 15:06:05 +0000355 a.writeRequiredModules(w, moduleNames)
Jiyong Park09d77522019-11-18 11:16:27 +0900356 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Jiyong Park09d77522019-11-18 11:16:27 +0900357
358 } else {
Sasha Smundak5c4729d2022-12-01 10:49:23 -0800359 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS) # apex.apexBundle")
Jiyong Park09d77522019-11-18 11:16:27 +0900360 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
361 fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix)
Bob Badourb4999222021-01-07 03:34:31 +0000362 data.Entries.WriteLicenseVariables(w)
Jiyong Park09d77522019-11-18 11:16:27 +0900363 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
364 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFile.String())
Colin Crossc68db4b2021-11-11 18:59:15 -0800365 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.String())
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000366 stemSuffix := apexType.suffix()
367 if a.isCompressed {
Samiul Islam7c02e262021-09-08 17:48:28 +0100368 stemSuffix = imageCapexSuffix
Mohammad Samiul Islam3cd005d2020-11-26 13:32:26 +0000369 }
370 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+stemSuffix)
Jiyong Park09d77522019-11-18 11:16:27 +0900371 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Colin Crossd9ccb6a2022-03-07 18:38:34 -0800372 if a.installable() {
373 fmt.Fprintln(w, "LOCAL_SOONG_INSTALLED_MODULE :=", a.installedFile.String())
374 fmt.Fprintln(w, "LOCAL_SOONG_INSTALL_PAIRS :=", a.outputFile.String()+":"+a.installedFile.String())
375 }
Jooyung Han2ed99d02020-06-24 23:26:26 +0900376
377 // Because apex writes .mk with Custom(), we need to write manually some common properties
378 // which are available via data.Entries
379 commonProperties := []string{
Liz Kammer7b3dc8a2021-04-16 16:41:59 -0400380 "LOCAL_FULL_INIT_RC", "LOCAL_FULL_VINTF_FRAGMENTS",
Jooyung Han2ed99d02020-06-24 23:26:26 +0900381 "LOCAL_PROPRIETARY_MODULE", "LOCAL_VENDOR_MODULE", "LOCAL_ODM_MODULE", "LOCAL_PRODUCT_MODULE", "LOCAL_SYSTEM_EXT_MODULE",
382 "LOCAL_MODULE_OWNER",
383 }
384 for _, name := range commonProperties {
385 if value, ok := data.Entries.EntryMap[name]; ok {
386 fmt.Fprintln(w, name+" := "+strings.Join(value, " "))
387 }
388 }
389
Yo Chiang12d9f7a2020-06-16 17:32:19 +0800390 if len(a.overridableProperties.Overrides) > 0 {
391 fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES :=", strings.Join(a.overridableProperties.Overrides, " "))
392 }
Prerana Patilb1896c82022-11-09 18:14:34 +0000393 a.writeRequiredModules(w, moduleNames)
Jiyong Park19972c72020-01-28 20:05:29 +0900394
Jiyong Park09d77522019-11-18 11:16:27 +0900395 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
396
397 if apexType == imageApex {
Yo Chiangef2d4892020-05-08 15:38:40 +0800398 fmt.Fprintln(w, "ALL_MODULES.$(my_register_name).BUNDLE :=", a.bundleModuleFile.String())
Jiyong Park09d77522019-11-18 11:16:27 +0900399 }
Colin Cross08dca382020-07-21 20:31:17 -0700400 if len(a.lintReports) > 0 {
401 fmt.Fprintln(w, "ALL_MODULES.$(my_register_name).LINT_REPORTS :=",
402 strings.Join(a.lintReports.Strings(), " "))
403 }
Jiyong Park3a1602e2020-01-14 14:39:19 +0900404
405 if a.installedFilesFile != nil {
Colin Cross1c85e8e2020-02-26 16:55:51 -0800406 goal := "checkbuild"
Jiyong Park3a1602e2020-01-14 14:39:19 +0900407 distFile := name + "-installed-files.txt"
408 fmt.Fprintln(w, ".PHONY:", goal)
409 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n",
410 goal, a.installedFilesFile.String(), distFile)
Bob Badour51804382022-04-13 11:27:19 -0700411 fmt.Fprintf(w, "$(call declare-0p-target,%s)\n", a.installedFilesFile.String())
Jiyong Park3a1602e2020-01-14 14:39:19 +0900412 }
Anton Hansson82d502a2020-11-11 12:33:14 +0000413 for _, dist := range data.Entries.GetDistForGoals(a) {
414 fmt.Fprintf(w, dist)
415 }
sophiez55e88152020-12-03 23:53:15 +0000416
sophiez02347372021-11-02 17:58:02 -0700417 distCoverageFiles(w, "ndk_apis_usedby_apex", a.nativeApisUsedByModuleFile.String())
sophiez36910972021-11-22 11:49:41 -0800418 distCoverageFiles(w, "ndk_apis_backedby_apex", a.nativeApisBackedByModuleFile.String())
sophiez02347372021-11-02 17:58:02 -0700419 distCoverageFiles(w, "java_apis_used_by_apex", a.javaApisUsedByModuleFile.String())
Jiyong Park09d77522019-11-18 11:16:27 +0900420 }
421 }}
422}
sophiez02347372021-11-02 17:58:02 -0700423
424func distCoverageFiles(w io.Writer, dir string, distfile string) {
425 if distfile != "" {
426 goal := "apps_only"
427 fmt.Fprintf(w, "ifneq (,$(filter $(my_register_name),$(TARGET_BUILD_APPS)))\n"+
428 " $(call dist-for-goals,%s,%s:%s/$(notdir %s))\n"+
429 "endif\n", goal, distfile, dir, distfile)
430 }
431}