blob: c42b3484e36481a9a7d3b3e08bb6f3409648e097 [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"
Jiyong Park09d77522019-11-18 11:16:27 +090025
26 "github.com/google/blueprint/proptools"
27)
28
29func (a *apexBundle) AndroidMk() android.AndroidMkData {
30 if a.properties.HideFromMake {
31 return android.AndroidMkData{
32 Disabled: true,
33 }
34 }
35 writers := []android.AndroidMkData{}
36 writers = append(writers, a.androidMkForType())
37 return android.AndroidMkData{
38 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
39 for _, data := range writers {
40 data.Custom(w, name, prefix, moduleDir, data)
41 }
42 }}
43}
44
45func (a *apexBundle) androidMkForFiles(w io.Writer, apexName, moduleDir string) []string {
46 moduleNames := []string{}
47 apexType := a.properties.ApexType
48 // To avoid creating duplicate build rules, run this function only when primaryApexType is true
49 // to install symbol files in $(PRODUCT_OUT}/apex.
50 // And if apexType is flattened, run this function to install files in $(PRODUCT_OUT}/system/apex.
51 if !a.primaryApexType && apexType != flattenedApex {
52 return moduleNames
53 }
54
55 for _, fi := range a.filesInfo {
56 if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
57 continue
58 }
59
60 if !android.InList(fi.moduleName, moduleNames) {
61 moduleNames = append(moduleNames, fi.moduleName)
62 }
63
64 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
Jiyong Park1833cef2019-12-13 13:28:36 +090065 if fi.moduleDir != "" {
66 fmt.Fprintln(w, "LOCAL_PATH :=", fi.moduleDir)
67 } else {
68 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
69 }
Jiyong Park09d77522019-11-18 11:16:27 +090070 fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName)
71 // /apex/<apex_name>/{lib|framework|...}
72 pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", apexName, fi.installDir)
73 if apexType == flattenedApex {
74 // /system/apex/<name>/{lib|framework|...}
75 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join(a.installDir.ToMakePath().String(),
76 apexName, fi.installDir))
77 if a.primaryApexType {
78 fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
79 }
80 if len(fi.symlinks) > 0 {
81 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
82 }
83
84 if fi.module != nil && fi.module.NoticeFile().Valid() {
85 fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
86 }
87 } else {
88 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
89 }
90 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
91 fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
92 if fi.module != nil {
93 archStr := fi.module.Target().Arch.ArchType.String()
94 host := false
95 switch fi.module.Target().Os.Class {
96 case android.Host:
97 if fi.module.Target().Arch.ArchType != android.Common {
98 fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
99 }
100 host = true
101 case android.HostCross:
102 if fi.module.Target().Arch.ArchType != android.Common {
103 fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
104 }
105 host = true
106 case android.Device:
107 if fi.module.Target().Arch.ArchType != android.Common {
108 fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
109 }
110 }
111 if host {
112 makeOs := fi.module.Target().Os.String()
113 if fi.module.Target().Os == android.Linux || fi.module.Target().Os == android.LinuxBionic {
114 makeOs = "linux"
115 }
116 fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
117 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
118 }
119 }
120 if fi.class == javaSharedLib {
Jooyung Han58f26ab2019-12-18 15:34:32 +0900121 javaModule := fi.module.(javaLibrary)
Jiyong Park09d77522019-11-18 11:16:27 +0900122 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
123 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
124 // we will have foo.jar.jar
125 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.builtFile.Base(), ".jar"))
126 fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String())
127 fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String())
128 fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", fi.builtFile.String())
129 fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
130 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
131 } else if fi.class == nativeSharedLib || fi.class == nativeExecutable || fi.class == nativeTest {
132 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
133 if cc, ok := fi.module.(*cc.Module); ok {
134 if cc.UnstrippedOutputFile() != nil {
135 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", cc.UnstrippedOutputFile().String())
136 }
137 cc.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
138 if cc.CoverageOutputFile().Valid() {
139 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", cc.CoverageOutputFile().String())
140 }
141 }
142 fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_prebuilt.mk")
143 } else {
144 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
145 // For flattened apexes, compat symlinks are attached to apex_manifest.json which is guaranteed for every apex
146 if a.primaryApexType && fi.builtFile == a.manifestPbOut && len(a.compatSymlinks) > 0 {
147 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", strings.Join(a.compatSymlinks, " && "))
148 }
149 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
150 }
151 }
152 return moduleNames
153}
154
155func (a *apexBundle) androidMkForType() android.AndroidMkData {
156 return android.AndroidMkData{
157 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
158 moduleNames := []string{}
159 apexType := a.properties.ApexType
160 if a.installable() {
161 apexName := proptools.StringDefault(a.properties.Apex_name, name)
162 moduleNames = a.androidMkForFiles(w, apexName, moduleDir)
163 }
164
165 if apexType == flattenedApex {
166 // Only image APEXes can be flattened.
167 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
168 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
169 fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix)
170 if len(moduleNames) > 0 {
171 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
172 }
173 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Jiyong Park09d77522019-11-18 11:16:27 +0900174
175 } else {
176 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
177 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
178 fmt.Fprintln(w, "LOCAL_MODULE :=", name+a.suffix)
179 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
180 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFile.String())
181 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String())
182 fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
183 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -0800184 fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES :=", strings.Join(a.overridableProperties.Overrides, " "))
Jiyong Park09d77522019-11-18 11:16:27 +0900185 if len(moduleNames) > 0 {
186 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
187 }
188 if len(a.externalDeps) > 0 {
189 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " "))
190 }
191 var postInstallCommands []string
192 if a.prebuiltFileToDelete != "" {
193 postInstallCommands = append(postInstallCommands, "rm -rf "+
194 filepath.Join(a.installDir.ToMakePath().String(), a.prebuiltFileToDelete))
195 }
196 // For unflattened apexes, compat symlinks are attached to apex package itself as LOCAL_POST_INSTALL_CMD
197 postInstallCommands = append(postInstallCommands, a.compatSymlinks...)
198 if len(postInstallCommands) > 0 {
199 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", strings.Join(postInstallCommands, " && "))
200 }
201 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
202
203 if apexType == imageApex {
204 fmt.Fprintln(w, "ALL_MODULES.$(LOCAL_MODULE).BUNDLE :=", a.bundleModuleFile.String())
205 }
206 }
207 }}
208}