blob: fe89b73cc010e9d0c830fe7af31bd407aa7a753e [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
Jooyung Han07931c72020-09-11 17:19:20 +090066func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, moduleDir string,
67 apexAndroidMkData android.AndroidMkData) []string {
68
Jiyong Parkdb334862020-02-05 17:19:28 +090069 // apexBundleName comes from the 'name' property; apexName comes from 'apex_name' property.
70 // An apex is installed to /system/apex/<apexBundleName> and is activated at /apex/<apexName>
71 // In many cases, the two names are the same, but could be different in general.
72
Jiyong Park09d77522019-11-18 11:16:27 +090073 moduleNames := []string{}
74 apexType := a.properties.ApexType
75 // To avoid creating duplicate build rules, run this function only when primaryApexType is true
76 // to install symbol files in $(PRODUCT_OUT}/apex.
77 // And if apexType is flattened, run this function to install files in $(PRODUCT_OUT}/system/apex.
78 if !a.primaryApexType && apexType != flattenedApex {
79 return moduleNames
80 }
81
Yifan Hong93a90db2020-07-28 17:24:44 -070082 // b/162366062. Prevent GKI APEXes to emit make rules to avoid conflicts.
83 if strings.HasPrefix(apexName, "com.android.gki.") && apexType != flattenedApex {
84 return moduleNames
85 }
86
Jiyong Parkdb334862020-02-05 17:19:28 +090087 // b/140136207. When there are overriding APEXes for a VNDK APEX, the symbols file for the overridden
88 // APEX and the overriding APEX will have the same installation paths at /apex/com.android.vndk.v<ver>
89 // as their apexName will be the same. To avoid the path conflicts, skip installing the symbol files
90 // for the overriding VNDK APEXes.
91 symbolFilesNotNeeded := a.vndkApex && len(a.overridableProperties.Overrides) > 0
92 if symbolFilesNotNeeded && apexType != flattenedApex {
93 return moduleNames
94 }
95
Jiyong Park7cd10e32020-01-14 09:22:18 +090096 var postInstallCommands []string
97 for _, fi := range a.filesInfo {
Jiyong Parkc0ec6f92020-11-19 23:00:52 +090098 if a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform() {
Jiyong Park7cd10e32020-01-14 09:22:18 +090099 // TODO(jiyong): pathOnDevice should come from fi.module, not being calculated here
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900100 linkTarget := filepath.Join("/system", fi.path())
101 linkPath := filepath.Join(a.installDir.ToMakePath().String(), apexBundleName, fi.path())
Jiyong Park7cd10e32020-01-14 09:22:18 +0900102 mkdirCmd := "mkdir -p " + filepath.Dir(linkPath)
103 linkCmd := "ln -sfn " + linkTarget + " " + linkPath
104 postInstallCommands = append(postInstallCommands, mkdirCmd, linkCmd)
105 }
106 }
Jiyong Park7cd10e32020-01-14 09:22:18 +0900107
Liz Kammer5bd365f2020-05-27 15:15:11 -0700108 seenDataOutPaths := make(map[string]bool)
109
Jiyong Park09d77522019-11-18 11:16:27 +0900110 for _, fi := range a.filesInfo {
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700111 if ccMod, ok := fi.module.(*cc.Module); ok && ccMod.Properties.HideFromMake {
Jiyong Park09d77522019-11-18 11:16:27 +0900112 continue
113 }
114
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900115 linkToSystemLib := a.linkToSystemLib && fi.transitiveDep && fi.availableToPlatform()
Jiyong Park7cd10e32020-01-14 09:22:18 +0900116
117 var moduleName string
118 if linkToSystemLib {
Yo Chiange8128052020-07-23 20:09:18 +0800119 moduleName = fi.androidMkModuleName
Jiyong Park7cd10e32020-01-14 09:22:18 +0900120 } else {
Yo Chiange8128052020-07-23 20:09:18 +0800121 moduleName = fi.androidMkModuleName + "." + apexBundleName + a.suffix
Jiyong Park7cd10e32020-01-14 09:22:18 +0900122 }
123
124 if !android.InList(moduleName, moduleNames) {
125 moduleNames = append(moduleNames, moduleName)
126 }
127
128 if linkToSystemLib {
129 // No need to copy the file since it's linked to the system file
130 continue
Jiyong Park09d77522019-11-18 11:16:27 +0900131 }
132
133 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
Jiyong Park1833cef2019-12-13 13:28:36 +0900134 if fi.moduleDir != "" {
135 fmt.Fprintln(w, "LOCAL_PATH :=", fi.moduleDir)
136 } else {
137 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
138 }
Jiyong Park7cd10e32020-01-14 09:22:18 +0900139 fmt.Fprintln(w, "LOCAL_MODULE :=", moduleName)
Anton Hansson1ee62c02020-06-30 11:51:53 +0100140 if fi.module != nil && fi.module.Owner() != "" {
141 fmt.Fprintln(w, "LOCAL_MODULE_OWNER :=", fi.module.Owner())
142 }
Jiyong Park09d77522019-11-18 11:16:27 +0900143 // /apex/<apex_name>/{lib|framework|...}
144 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", apexName, fi.installDir)
Colin Cross403cc152020-07-06 14:15:24 -0700145 var modulePath string
Jiyong Park09d77522019-11-18 11:16:27 +0900146 if apexType == flattenedApex {
147 // /system/apex/<name>/{lib|framework|...}
Colin Cross403cc152020-07-06 14:15:24 -0700148 modulePath = filepath.Join(a.installDir.ToMakePath().String(), apexBundleName, fi.installDir)
Liz Kammer5bd365f2020-05-27 15:15:11 -0700149 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", modulePath)
Jiyong Parkdb334862020-02-05 17:19:28 +0900150 if a.primaryApexType && !symbolFilesNotNeeded {
Jiyong Park09d77522019-11-18 11:16:27 +0900151 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
152 }
153 if len(fi.symlinks) > 0 {
154 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
155 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400156 newDataPaths := []android.DataPath{}
Liz Kammer5bd365f2020-05-27 15:15:11 -0700157 for _, path := range fi.dataPaths {
Chris Parsons216e10a2020-07-09 17:12:52 -0400158 dataOutPath := modulePath + ":" + path.SrcPath.Rel()
Liz Kammer5bd365f2020-05-27 15:15:11 -0700159 if ok := seenDataOutPaths[dataOutPath]; !ok {
160 newDataPaths = append(newDataPaths, path)
161 seenDataOutPaths[dataOutPath] = true
162 }
163 }
164 if len(newDataPaths) > 0 {
Dan Shi31949122020-09-21 12:11:02 -0700165 fmt.Fprintln(w, "LOCAL_TEST_DATA :=", strings.Join(android.AndroidMkDataPaths(newDataPaths), " "))
Liz Kammer1c14a212020-05-12 15:26:55 -0700166 }
Jiyong Park09d77522019-11-18 11:16:27 +0900167
Bob Badoura75b0572020-02-18 20:21:55 -0800168 if fi.module != nil && len(fi.module.NoticeFiles()) > 0 {
169 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", strings.Join(fi.module.NoticeFiles().Strings(), " "))
Jiyong Park09d77522019-11-18 11:16:27 +0900170 }
171 } 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 }
180 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900181 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.nameInMake())
Jiyong Park09d77522019-11-18 11:16:27 +0900182 if fi.module != nil {
183 archStr := fi.module.Target().Arch.ArchType.String()
184 host := false
185 switch fi.module.Target().Os.Class {
186 case android.Host:
Jiyong Park1613e552020-09-14 19:43:17 +0900187 if fi.module.Target().HostCross {
188 if fi.module.Target().Arch.ArchType != android.Common {
189 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
190 }
191 } else {
192 if fi.module.Target().Arch.ArchType != android.Common {
193 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
194 }
Jiyong Park09d77522019-11-18 11:16:27 +0900195 }
196 host = true
197 case android.Device:
198 if fi.module.Target().Arch.ArchType != android.Common {
199 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
200 }
201 }
202 if host {
203 makeOs := fi.module.Target().Os.String()
204 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
205 makeOs = "linux"
206 }
207 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
208 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
209 }
210 }
Jiyong Park618922e2020-01-08 13:35:43 +0900211 if fi.jacocoReportClassesFile != nil {
212 fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", fi.jacocoReportClassesFile.String())
213 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700214 switch fi.class {
215 case javaSharedLib:
Jiyong Park09d77522019-11-18 11:16:27 +0900216 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
217 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
218 // we will have foo.jar.jar
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900219 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.stem(), ".jar"))
Paul Duffin44b481b2020-06-17 16:59:43 +0100220 if javaModule, ok := fi.module.(java.ApexDependency); ok {
Jiyong Park9e83f0b2020-06-11 00:35:03 +0900221 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
222 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
223 } else {
224 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", fi.builtFile.String())
225 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", fi.builtFile.String())
226 }
Jiyong Park09d77522019-11-18 11:16:27 +0900227 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
228 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
229 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700230 case app:
Colin Cross503c1d02020-01-28 14:00:53 -0800231 fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", fi.certificate.AndroidMkString())
Jiyong Park618922e2020-01-08 13:35:43 +0900232 // soong_app_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .apk Therefore
233 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
234 // we will have foo.apk.apk
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900235 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.stem(), ".apk"))
Colin Cross403cc152020-07-06 14:15:24 -0700236 if app, ok := fi.module.(*java.AndroidApp); ok {
237 if jniCoverageOutputs := app.JniCoverageOutputs(); len(jniCoverageOutputs) > 0 {
238 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", strings.Join(jniCoverageOutputs.Strings(), " "))
239 }
240 if jniLibSymbols := app.JNISymbolsInstalls(modulePath); len(jniLibSymbols) > 0 {
241 fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_SYMBOLS :=", jniLibSymbols.String())
242 }
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700243 }
Jiyong Park618922e2020-01-08 13:35:43 +0900244 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_app_prebuilt.mk")
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700245 case appSet:
246 as, ok := fi.module.(*java.AndroidAppSet)
247 if !ok {
248 panic(fmt.Sprintf("Expected %s to be AndroidAppSet", fi.module))
249 }
Liz Kammercada8072020-07-28 15:47:38 -0700250 fmt.Fprintln(w, "LOCAL_APK_SET_INSTALL_FILE :=", as.InstallFile())
Colin Cross4fb652d2020-07-09 19:05:35 -0700251 fmt.Fprintln(w, "LOCAL_APKCERTS_FILE :=", as.APKCertsFile().String())
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700252 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_android_app_set.mk")
253 case nativeSharedLib, nativeExecutable, nativeTest:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900254 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.stem())
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700255 if ccMod, ok := fi.module.(*cc.Module); ok {
256 if ccMod.UnstrippedOutputFile() != nil {
257 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", ccMod.UnstrippedOutputFile().String())
Jiyong Park09d77522019-11-18 11:16:27 +0900258 }
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700259 ccMod.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
260 if ccMod.CoverageOutputFile().Valid() {
261 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", ccMod.CoverageOutputFile().String())
Jiyong Park09d77522019-11-18 11:16:27 +0900262 }
263 }
264 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
Sasha Smundak18d98bc2020-05-27 16:36:07 -0700265 default:
Jiyong Parkc0ec6f92020-11-19 23:00:52 +0900266 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.stem())
Jiyong Park7aa3f762020-01-28 16:51:34 +0900267 if fi.builtFile == a.manifestPbOut && apexType == flattenedApex {
Jooyung Han75de2612020-01-24 02:02:45 +0900268 if a.primaryApexType {
Jooyung Han07931c72020-09-11 17:19:20 +0900269 // To install companion files (init_rc, vintf_fragments)
270 // Copy some common properties of apexBundle to apex_manifest
271 commonProperties := []string{
272 "LOCAL_INIT_RC", "LOCAL_VINTF_FRAGMENTS",
273 }
274 for _, name := range commonProperties {
275 if value, ok := apexAndroidMkData.Entries.EntryMap[name]; ok {
276 fmt.Fprintln(w, name+" := "+strings.Join(value, " "))
277 }
278 }
279
Jooyung Han75de2612020-01-24 02:02:45 +0900280 // Make apex_manifest.pb module for this APEX to override all other
281 // modules in the APEXes being overridden by this APEX
282 var patterns []string
283 for _, o := range a.overridableProperties.Overrides {
284 patterns = append(patterns, "%."+o+a.suffix)
285 }
Yo Chiang12d9f7a2020-06-16 17:32:19 +0800286 if len(patterns) > 0 {
287 fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES :=", strings.Join(patterns, " "))
288 }
Jiyong Park7aa3f762020-01-28 16:51:34 +0900289 if len(a.compatSymlinks) > 0 {
Jooyung Han75de2612020-01-24 02:02:45 +0900290 // For flattened apexes, compat symlinks are attached to apex_manifest.json which is guaranteed for every apex
291 postInstallCommands = append(postInstallCommands, a.compatSymlinks...)
292 }
293 }
Jooyung Han7f146c02020-09-23 19:15:55 +0900294
295 // File_contexts of flattened APEXes should be merged into file_contexts.bin
296 fmt.Fprintln(w, "LOCAL_FILE_CONTEXTS :=", a.fileContexts)
297
Jooyung Han75de2612020-01-24 02:02:45 +0900298 if len(postInstallCommands) > 0 {
Jiyong Park7cd10e32020-01-14 09:22:18 +0900299 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", strings.Join(postInstallCommands, " && "))
Jiyong Park0abc1b42020-01-09 17:43:39 +0900300 }
Jiyong Park09d77522019-11-18 11:16:27 +0900301 }
302 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
303 }
Jiyong Park31af2672020-02-11 09:36:25 +0900304
305 // m <module_name> will build <module_name>.<apex_name> as well.
Yo Chiange8128052020-07-23 20:09:18 +0800306 if fi.androidMkModuleName != moduleName && a.primaryApexType {
307 fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName)
308 fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName)
Jiyong Park31af2672020-02-11 09:36:25 +0900309 }
Jiyong Park09d77522019-11-18 11:16:27 +0900310 }
311 return moduleNames
312}
313
Jiyong Park7afd1072019-12-30 16:56:33 +0900314func (a *apexBundle) writeRequiredModules(w io.Writer) {
315 var required []string
316 var targetRequired []string
317 var hostRequired []string
318 for _, fi := range a.filesInfo {
319 required = append(required, fi.requiredModuleNames...)
320 targetRequired = append(targetRequired, fi.targetRequiredModuleNames...)
321 hostRequired = append(hostRequired, fi.hostRequiredModuleNames...)
322 }
323
324 if len(required) > 0 {
325 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(required, " "))
326 }
327 if len(targetRequired) > 0 {
328 fmt.Fprintln(w, "LOCAL_TARGET_REQUIRED_MODULES +=", strings.Join(targetRequired, " "))
329 }
330 if len(hostRequired) > 0 {
331 fmt.Fprintln(w, "LOCAL_HOST_REQUIRED_MODULES +=", strings.Join(hostRequired, " "))
332 }
333}
334
Jiyong Park09d77522019-11-18 11:16:27 +0900335func (a *apexBundle) androidMkForType() android.AndroidMkData {
336 return android.AndroidMkData{
Anton Hansson82d502a2020-11-11 12:33:14 +0000337 DistFiles: a.distFiles,
Jiyong Park09d77522019-11-18 11:16:27 +0900338 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
339 moduleNames := []string{}
340 apexType := a.properties.ApexType
341 if a.installable() {
342 apexName := proptools.StringDefault(a.properties.Apex_name, name)
Jooyung Han07931c72020-09-11 17:19:20 +0900343 moduleNames = a.androidMkForFiles(w, name, apexName, moduleDir, data)
Jiyong Park09d77522019-11-18 11:16:27 +0900344 }
345
346 if apexType == flattenedApex {
347 // Only image APEXes can be flattened.
348 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
349 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
350 fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix)
351 if len(moduleNames) > 0 {
352 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
353 }
Jiyong Park7afd1072019-12-30 16:56:33 +0900354 a.writeRequiredModules(w)
Jiyong Park09d77522019-11-18 11:16:27 +0900355 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Jiyong Park09d77522019-11-18 11:16:27 +0900356
357 } else {
358 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
359 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
360 fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix)
361 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
362 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFile.String())
363 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String())
364 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
365 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jooyung Han2ed99d02020-06-24 23:26:26 +0900366
367 // Because apex writes .mk with Custom(), we need to write manually some common properties
368 // which are available via data.Entries
369 commonProperties := []string{
370 "LOCAL_INIT_RC", "LOCAL_VINTF_FRAGMENTS",
371 "LOCAL_PROPRIETARY_MODULE", "LOCAL_VENDOR_MODULE", "LOCAL_ODM_MODULE", "LOCAL_PRODUCT_MODULE", "LOCAL_SYSTEM_EXT_MODULE",
372 "LOCAL_MODULE_OWNER",
373 }
374 for _, name := range commonProperties {
375 if value, ok := data.Entries.EntryMap[name]; ok {
376 fmt.Fprintln(w, name+" := "+strings.Join(value, " "))
377 }
378 }
379
Yo Chiang12d9f7a2020-06-16 17:32:19 +0800380 if len(a.overridableProperties.Overrides) > 0 {
381 fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES :=", strings.Join(a.overridableProperties.Overrides, " "))
382 }
Jiyong Park09d77522019-11-18 11:16:27 +0900383 if len(moduleNames) > 0 {
384 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
385 }
Jiyong Park956305c2020-01-09 12:32:06 +0900386 if len(a.requiredDeps) > 0 {
387 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.requiredDeps, " "))
Jiyong Park09d77522019-11-18 11:16:27 +0900388 }
Jiyong Park7afd1072019-12-30 16:56:33 +0900389 a.writeRequiredModules(w)
Jiyong Park09d77522019-11-18 11:16:27 +0900390 var postInstallCommands []string
391 if a.prebuiltFileToDelete != "" {
392 postInstallCommands = append(postInstallCommands, "rm -rf "+
393 filepath.Join(a.installDir.ToMakePath().String(), a.prebuiltFileToDelete))
394 }
395 // For unflattened apexes, compat symlinks are attached to apex package itself as LOCAL_POST_INSTALL_CMD
396 postInstallCommands = append(postInstallCommands, a.compatSymlinks...)
397 if len(postInstallCommands) > 0 {
398 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", strings.Join(postInstallCommands, " && "))
399 }
Jiyong Park19972c72020-01-28 20:05:29 +0900400
401 if a.mergedNotices.Merged.Valid() {
402 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", a.mergedNotices.Merged.Path().String())
403 }
404
Jiyong Park09d77522019-11-18 11:16:27 +0900405 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
406
407 if apexType == imageApex {
Yo Chiangef2d4892020-05-08 15:38:40 +0800408 fmt.Fprintln(w, "ALL_MODULES.$(my_register_name).BUNDLE :=", a.bundleModuleFile.String())
Jiyong Park09d77522019-11-18 11:16:27 +0900409 }
Colin Cross08dca382020-07-21 20:31:17 -0700410 if len(a.lintReports) > 0 {
411 fmt.Fprintln(w, "ALL_MODULES.$(my_register_name).LINT_REPORTS :=",
412 strings.Join(a.lintReports.Strings(), " "))
413 }
Jiyong Park3a1602e2020-01-14 14:39:19 +0900414
415 if a.installedFilesFile != nil {
Colin Cross1c85e8e2020-02-26 16:55:51 -0800416 goal := "checkbuild"
Jiyong Park3a1602e2020-01-14 14:39:19 +0900417 distFile := name + "-installed-files.txt"
418 fmt.Fprintln(w, ".PHONY:", goal)
419 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n",
420 goal, a.installedFilesFile.String(), distFile)
421 }
Anton Hansson82d502a2020-11-11 12:33:14 +0000422 for _, dist := range data.Entries.GetDistForGoals(a) {
423 fmt.Fprintf(w, dist)
424 }
Jiyong Park09d77522019-11-18 11:16:27 +0900425 }
426 }}
427}