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