blob: cd931f634ad5ab7de5509a7f3f8dced94f9c4b43 [file] [log] [blame]
Dan Willemsenb916b802017-03-19 13:44:32 -07001// Copyright 2017 Google Inc. All rights reserved.
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 cc
16
Kiyoung Kim37693d02024-04-04 09:56:15 +090017import (
18 "android/soong/android"
Kiyoung Kim973cb6f2024-04-29 14:14:53 +090019 "android/soong/etc"
Kiyoung Kim37693d02024-04-04 09:56:15 +090020 "strings"
21)
22
Dan Willemsenb916b802017-03-19 13:44:32 -070023var (
24 llndkLibrarySuffix = ".llndk"
25)
26
Colin Cross127bb8b2020-12-16 16:46:01 -080027// Holds properties to describe a stub shared library based on the provided version file.
Dan Willemsenb916b802017-03-19 13:44:32 -070028type llndkLibraryProperties struct {
29 // Relative path to the symbol map.
30 // An example file can be seen here: TODO(danalbert): Make an example.
Nan Zhang0007d812017-11-07 10:57:05 -080031 Symbol_file *string
Dan Willemsenb916b802017-03-19 13:44:32 -070032
33 // Whether to export any headers as -isystem instead of -I. Mainly for use by
34 // bionic/libc.
Nan Zhang0007d812017-11-07 10:57:05 -080035 Export_headers_as_system *bool
Dan Willemsenb916b802017-03-19 13:44:32 -070036
37 // Which headers to process with versioner. This really only handles
38 // bionic/libc/include right now.
39 Export_preprocessed_headers []string
40
41 // Whether the system library uses symbol versions.
Nan Zhang0007d812017-11-07 10:57:05 -080042 Unversioned *bool
Jiyong Park82e2bf32017-08-16 14:05:54 +090043
Jiyong Park2a454122017-10-19 15:59:33 +090044 // list of llndk headers to re-export include directories from.
Colin Cross0fb7fcd2021-03-02 11:00:07 -080045 Export_llndk_headers []string
46
47 // list of directories relative to the Blueprints file that willbe added to the include path
48 // (using -I) for any module that links against the LLNDK variant of this module, replacing
49 // any that were listed outside the llndk clause.
50 Override_export_include_dirs []string
Colin Cross127bb8b2020-12-16 16:46:01 -080051
52 // whether this module can be directly depended upon by libs that are installed
53 // to /vendor and /product.
54 // When set to true, this module can only be depended on by VNDK libraries, not
55 // vendor nor product libraries. This effectively hides this module from
56 // non-system modules. Default value is false.
57 Private *bool
Colin Cross1f3f1302021-04-26 18:37:44 -070058
59 // if true, make this module available to provide headers to other modules that set
60 // llndk.symbol_file.
61 Llndk_headers *bool
Dan Willemsenb916b802017-03-19 13:44:32 -070062}
Kiyoung Kim37693d02024-04-04 09:56:15 +090063
64func makeLlndkVars(ctx android.MakeVarsContext) {
65 // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
66 // they been moved to an apex.
67 movedToApexLlndkLibraries := make(map[string]bool)
68 ctx.VisitAllModules(func(module android.Module) {
69 if library := moduleLibraryInterface(module); library != nil && library.hasLLNDKStubs() {
70 // Skip bionic libs, they are handled in different manner
71 name := library.implementationModuleName(module.(*Module).BaseModuleName())
72 if module.(android.ApexModule).DirectlyInAnyApex() && !isBionic(name) {
73 movedToApexLlndkLibraries[name] = true
74 }
75 }
76 })
77
78 ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES",
79 strings.Join(android.SortedKeys(movedToApexLlndkLibraries), " "))
80}
Kiyoung Kim973cb6f2024-04-29 14:14:53 +090081
82func init() {
83 RegisterLlndkLibraryTxtType(android.InitRegistrationContext)
84}
85
86func RegisterLlndkLibraryTxtType(ctx android.RegistrationContext) {
87 ctx.RegisterParallelSingletonModuleType("llndk_libraries_txt", llndkLibrariesTxtFactory)
88}
89
90type llndkLibrariesTxtModule struct {
91 android.SingletonModuleBase
92
93 outputFile android.OutputPath
94 moduleNames []string
95 fileNames []string
96}
97
98var _ etc.PrebuiltEtcModule = &llndkLibrariesTxtModule{}
99var _ android.OutputFileProducer = &llndkLibrariesTxtModule{}
100
101// llndk_libraries_txt is a singleton module whose content is a list of LLNDK libraries
102// generated by Soong but can be referenced by other modules.
103// For example, apex_vndk can depend on these files as prebuilt.
104// Make uses LLNDK_LIBRARIES to determine which libraries to install.
105// HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
106// Therefore, by removing the library here, we cause it to only be installed if libc
107// depends on it.
108func llndkLibrariesTxtFactory() android.SingletonModule {
109 m := &llndkLibrariesTxtModule{}
110 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
111 return m
112}
113
114func (txt *llndkLibrariesTxtModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
115 filename := txt.Name()
116
117 txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
118
119 installPath := android.PathForModuleInstall(ctx, "etc")
120 ctx.InstallFile(installPath, filename, txt.outputFile)
121}
122
123func (txt *llndkLibrariesTxtModule) GenerateSingletonBuildActions(ctx android.SingletonContext) {
Kiyoung Kim0d4a9ca2024-05-07 16:11:41 +0900124 if txt.outputFile.String() == "" {
125 // Skip if target file path is empty
126 return
127 }
128
Kiyoung Kim973cb6f2024-04-29 14:14:53 +0900129 ctx.VisitAllModules(func(m android.Module) {
130 if c, ok := m.(*Module); ok && c.VendorProperties.IsLLNDK && !c.Header() && !c.IsVndkPrebuiltLibrary() {
131 filename, err := getVndkFileName(c)
132 if err != nil {
133 ctx.ModuleErrorf(m, "%s", err)
134 }
135
136 if !strings.HasPrefix(ctx.ModuleName(m), "libclang_rt.hwasan") {
137 txt.moduleNames = append(txt.moduleNames, ctx.ModuleName(m))
138 }
139 txt.fileNames = append(txt.fileNames, filename)
140 }
141 })
142 txt.moduleNames = android.SortedUniqueStrings(txt.moduleNames)
143 txt.fileNames = android.SortedUniqueStrings(txt.fileNames)
144
145 android.WriteFileRule(ctx, txt.outputFile, strings.Join(txt.fileNames, "\n"))
146}
147
148func (txt *llndkLibrariesTxtModule) AndroidMkEntries() []android.AndroidMkEntries {
149 return []android.AndroidMkEntries{{
150 Class: "ETC",
151 OutputFile: android.OptionalPathForPath(txt.outputFile),
152 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
153 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
154 entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base())
155 },
156 },
157 }}
158}
159
160func (txt *llndkLibrariesTxtModule) MakeVars(ctx android.MakeVarsContext) {
161 ctx.Strict("LLNDK_LIBRARIES", strings.Join(txt.moduleNames, " "))
162}
163
164// PrebuiltEtcModule interface
165func (txt *llndkLibrariesTxtModule) OutputFile() android.OutputPath {
166 return txt.outputFile
167}
168
169// PrebuiltEtcModule interface
170func (txt *llndkLibrariesTxtModule) BaseDir() string {
171 return "etc"
172}
173
174// PrebuiltEtcModule interface
175func (txt *llndkLibrariesTxtModule) SubDir() string {
176 return ""
177}
178
179func (txt *llndkLibrariesTxtModule) OutputFiles(tag string) (android.Paths, error) {
180 return android.Paths{txt.outputFile}, nil
181}
182
183func llndkMutator(mctx android.BottomUpMutatorContext) {
184 m, ok := mctx.Module().(*Module)
185 if !ok {
186 return
187 }
188
189 if shouldSkipLlndkMutator(m) {
190 return
191 }
192
193 lib, isLib := m.linker.(*libraryDecorator)
194 prebuiltLib, isPrebuiltLib := m.linker.(*prebuiltLibraryLinker)
195
196 if m.InVendorOrProduct() && isLib && lib.hasLLNDKStubs() {
197 m.VendorProperties.IsLLNDK = true
198 }
199 if m.InVendorOrProduct() && isPrebuiltLib && prebuiltLib.hasLLNDKStubs() {
200 m.VendorProperties.IsLLNDK = true
201 }
202
203 if m.IsVndkPrebuiltLibrary() && !m.IsVndk() {
204 m.VendorProperties.IsLLNDK = true
205 }
206}
207
208// Check for modules that mustn't be LLNDK
209func shouldSkipLlndkMutator(m *Module) bool {
210 if !m.Enabled() {
211 return true
212 }
213 if !m.Device() {
214 return true
215 }
216 if m.Target().NativeBridge == android.NativeBridgeEnabled {
217 return true
218 }
219 return false
220}