blob: ae9da98515143b53472fbffd0c86f315c543495b [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) {
124 ctx.VisitAllModules(func(m android.Module) {
125 if c, ok := m.(*Module); ok && c.VendorProperties.IsLLNDK && !c.Header() && !c.IsVndkPrebuiltLibrary() {
126 filename, err := getVndkFileName(c)
127 if err != nil {
128 ctx.ModuleErrorf(m, "%s", err)
129 }
130
131 if !strings.HasPrefix(ctx.ModuleName(m), "libclang_rt.hwasan") {
132 txt.moduleNames = append(txt.moduleNames, ctx.ModuleName(m))
133 }
134 txt.fileNames = append(txt.fileNames, filename)
135 }
136 })
137 txt.moduleNames = android.SortedUniqueStrings(txt.moduleNames)
138 txt.fileNames = android.SortedUniqueStrings(txt.fileNames)
139
140 android.WriteFileRule(ctx, txt.outputFile, strings.Join(txt.fileNames, "\n"))
141}
142
143func (txt *llndkLibrariesTxtModule) AndroidMkEntries() []android.AndroidMkEntries {
144 return []android.AndroidMkEntries{{
145 Class: "ETC",
146 OutputFile: android.OptionalPathForPath(txt.outputFile),
147 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
148 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
149 entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base())
150 },
151 },
152 }}
153}
154
155func (txt *llndkLibrariesTxtModule) MakeVars(ctx android.MakeVarsContext) {
156 ctx.Strict("LLNDK_LIBRARIES", strings.Join(txt.moduleNames, " "))
157}
158
159// PrebuiltEtcModule interface
160func (txt *llndkLibrariesTxtModule) OutputFile() android.OutputPath {
161 return txt.outputFile
162}
163
164// PrebuiltEtcModule interface
165func (txt *llndkLibrariesTxtModule) BaseDir() string {
166 return "etc"
167}
168
169// PrebuiltEtcModule interface
170func (txt *llndkLibrariesTxtModule) SubDir() string {
171 return ""
172}
173
174func (txt *llndkLibrariesTxtModule) OutputFiles(tag string) (android.Paths, error) {
175 return android.Paths{txt.outputFile}, nil
176}
177
178func llndkMutator(mctx android.BottomUpMutatorContext) {
179 m, ok := mctx.Module().(*Module)
180 if !ok {
181 return
182 }
183
184 if shouldSkipLlndkMutator(m) {
185 return
186 }
187
188 lib, isLib := m.linker.(*libraryDecorator)
189 prebuiltLib, isPrebuiltLib := m.linker.(*prebuiltLibraryLinker)
190
191 if m.InVendorOrProduct() && isLib && lib.hasLLNDKStubs() {
192 m.VendorProperties.IsLLNDK = true
193 }
194 if m.InVendorOrProduct() && isPrebuiltLib && prebuiltLib.hasLLNDKStubs() {
195 m.VendorProperties.IsLLNDK = true
196 }
197
198 if m.IsVndkPrebuiltLibrary() && !m.IsVndk() {
199 m.VendorProperties.IsLLNDK = true
200 }
201}
202
203// Check for modules that mustn't be LLNDK
204func shouldSkipLlndkMutator(m *Module) bool {
205 if !m.Enabled() {
206 return true
207 }
208 if !m.Device() {
209 return true
210 }
211 if m.Target().NativeBridge == android.NativeBridgeEnabled {
212 return true
213 }
214 return false
215}