Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
Colin Cross | 3572cf7 | 2020-10-01 15:58:11 -0700 | [diff] [blame] | 18 | "fmt" |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 19 | "path/filepath" |
| 20 | "strings" |
| 21 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 22 | "android/soong/android" |
| 23 | ) |
| 24 | |
Colin Cross | c88c272 | 2020-09-28 17:32:47 -0700 | [diff] [blame] | 25 | var llndkImplDep = dependencyTag{name: "llndk impl"} |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 26 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 27 | var ( |
| 28 | llndkLibrarySuffix = ".llndk" |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 29 | llndkHeadersSuffix = ".llndk" |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 30 | ) |
| 31 | |
| 32 | // Creates a stub shared library based on the provided version file. |
| 33 | // |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 34 | // Example: |
| 35 | // |
| 36 | // llndk_library { |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 37 | // name: "libfoo", |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 38 | // symbol_file: "libfoo.map.txt", |
| 39 | // export_include_dirs: ["include_vndk"], |
| 40 | // } |
| 41 | // |
| 42 | type llndkLibraryProperties struct { |
| 43 | // Relative path to the symbol map. |
| 44 | // An example file can be seen here: TODO(danalbert): Make an example. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 45 | Symbol_file *string |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 46 | |
| 47 | // Whether to export any headers as -isystem instead of -I. Mainly for use by |
| 48 | // bionic/libc. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 49 | Export_headers_as_system *bool |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 50 | |
| 51 | // Which headers to process with versioner. This really only handles |
| 52 | // bionic/libc/include right now. |
| 53 | Export_preprocessed_headers []string |
| 54 | |
| 55 | // Whether the system library uses symbol versions. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 56 | Unversioned *bool |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 57 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 58 | // whether this module can be directly depended upon by libs that are installed |
| 59 | // to /vendor and /product. |
| 60 | // When set to false, this module can only be depended on by VNDK libraries, not |
| 61 | // vendor nor product libraries. This effectively hides this module from |
| 62 | // non-system modules. Default value is true. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 63 | Vendor_available *bool |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 64 | |
| 65 | // list of llndk headers to re-export include directories from. |
| 66 | Export_llndk_headers []string `android:"arch_variant"` |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | type llndkStubDecorator struct { |
| 70 | *libraryDecorator |
| 71 | |
| 72 | Properties llndkLibraryProperties |
| 73 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 74 | movedToApex bool |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 77 | var _ versionedInterface = (*llndkStubDecorator)(nil) |
| 78 | |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 79 | func (stub *llndkStubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags { |
| 80 | flags = stub.baseCompiler.compilerFlags(ctx, flags, deps) |
George Burgess IV | f5310e3 | 2017-07-19 11:39:53 -0700 | [diff] [blame] | 81 | return addStubLibraryCompilerFlags(flags) |
| 82 | } |
| 83 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 84 | func (stub *llndkStubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 85 | vndkVer := ctx.Module().(*Module).VndkVersion() |
Jooyung Han | 03302ee | 2020-04-08 09:22:26 +0900 | [diff] [blame] | 86 | if !inList(vndkVer, ctx.Config().PlatformVersionActiveCodenames()) || vndkVer == "" { |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 87 | // For non-enforcing devices, vndkVer is empty. Use "current" in that case, too. |
| 88 | vndkVer = "current" |
Justin Yun | 732aa6a | 2018-03-23 17:43:47 +0900 | [diff] [blame] | 89 | } |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 90 | if stub.stubsVersion() != "" { |
| 91 | vndkVer = stub.stubsVersion() |
| 92 | } |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 93 | objs, versionScript := compileStubLibrary(ctx, flags, String(stub.Properties.Symbol_file), vndkVer, "--llndk") |
Colin Cross | 8e21aa5 | 2020-09-28 18:28:02 -0700 | [diff] [blame] | 94 | if !Bool(stub.Properties.Unversioned) { |
| 95 | stub.versionScriptPath = android.OptionalPathForPath(versionScript) |
| 96 | } |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 97 | return objs |
| 98 | } |
| 99 | |
| 100 | func (stub *llndkStubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 101 | headers := addSuffix(stub.Properties.Export_llndk_headers, llndkHeadersSuffix) |
| 102 | deps.HeaderLibs = append(deps.HeaderLibs, headers...) |
| 103 | deps.ReexportHeaderLibHeaders = append(deps.ReexportHeaderLibHeaders, headers...) |
| 104 | return deps |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 107 | func (stub *llndkStubDecorator) Name(name string) string { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 108 | if strings.HasSuffix(name, llndkLibrarySuffix) { |
| 109 | return name |
| 110 | } |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 111 | return name + llndkLibrarySuffix |
| 112 | } |
| 113 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 114 | func (stub *llndkStubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 115 | stub.libraryDecorator.libName = stub.implementationModuleName(ctx.ModuleName()) |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 116 | return stub.libraryDecorator.linkerFlags(ctx, flags) |
| 117 | } |
| 118 | |
| 119 | func (stub *llndkStubDecorator) processHeaders(ctx ModuleContext, srcHeaderDir string, outDir android.ModuleGenPath) android.Path { |
| 120 | srcDir := android.PathForModuleSrc(ctx, srcHeaderDir) |
Dan Willemsen | 540a78c | 2018-02-26 21:50:08 -0800 | [diff] [blame] | 121 | srcFiles := ctx.GlobFiles(filepath.Join(srcDir.String(), "**/*.h"), nil) |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 122 | |
| 123 | var installPaths []android.WritablePath |
| 124 | for _, header := range srcFiles { |
| 125 | headerDir := filepath.Dir(header.String()) |
| 126 | relHeaderDir, err := filepath.Rel(srcDir.String(), headerDir) |
| 127 | if err != nil { |
| 128 | ctx.ModuleErrorf("filepath.Rel(%q, %q) failed: %s", |
| 129 | srcDir.String(), headerDir, err) |
| 130 | continue |
| 131 | } |
| 132 | |
| 133 | installPaths = append(installPaths, outDir.Join(ctx, relHeaderDir, header.Base())) |
| 134 | } |
| 135 | |
| 136 | return processHeadersWithVersioner(ctx, srcDir, outDir, srcFiles, installPaths) |
| 137 | } |
| 138 | |
| 139 | func (stub *llndkStubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, |
| 140 | objs Objects) android.Path { |
| 141 | |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 142 | impl := ctx.GetDirectDepWithTag(stub.implementationModuleName(ctx.ModuleName()), llndkImplDep) |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 143 | if implApexModule, ok := impl.(android.ApexModule); ok { |
| 144 | stub.movedToApex = implApexModule.DirectlyInAnyApex() |
| 145 | } |
| 146 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 147 | if len(stub.Properties.Export_preprocessed_headers) > 0 { |
| 148 | genHeaderOutDir := android.PathForModuleGen(ctx, "include") |
| 149 | |
| 150 | var timestampFiles android.Paths |
| 151 | for _, dir := range stub.Properties.Export_preprocessed_headers { |
| 152 | timestampFiles = append(timestampFiles, stub.processHeaders(ctx, dir, genHeaderOutDir)) |
| 153 | } |
| 154 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 155 | if Bool(stub.Properties.Export_headers_as_system) { |
Jiyong Park | 7495504 | 2019-10-22 20:19:51 +0900 | [diff] [blame] | 156 | stub.reexportSystemDirs(genHeaderOutDir) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 157 | } else { |
Jiyong Park | 7495504 | 2019-10-22 20:19:51 +0900 | [diff] [blame] | 158 | stub.reexportDirs(genHeaderOutDir) |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 161 | stub.reexportDeps(timestampFiles...) |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 164 | if Bool(stub.Properties.Export_headers_as_system) { |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 165 | stub.exportIncludesAsSystem(ctx) |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 166 | stub.libraryDecorator.flagExporter.Properties.Export_include_dirs = []string{} |
| 167 | } |
| 168 | |
| 169 | return stub.libraryDecorator.link(ctx, flags, deps, objs) |
| 170 | } |
| 171 | |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 172 | func (stub *llndkStubDecorator) nativeCoverage() bool { |
| 173 | return false |
| 174 | } |
| 175 | |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 176 | func (stub *llndkStubDecorator) implementationModuleName(name string) string { |
| 177 | return strings.TrimSuffix(name, llndkLibrarySuffix) |
| 178 | } |
| 179 | |
Colin Cross | c88c272 | 2020-09-28 17:32:47 -0700 | [diff] [blame] | 180 | func (stub *llndkStubDecorator) buildStubs() bool { |
| 181 | return true |
| 182 | } |
| 183 | |
Colin Cross | 3572cf7 | 2020-10-01 15:58:11 -0700 | [diff] [blame] | 184 | func (stub *llndkStubDecorator) stubsVersions(ctx android.BaseMutatorContext) []string { |
| 185 | // Get the versions from the implementation module. |
| 186 | impls := ctx.GetDirectDepsWithTag(llndkImplDep) |
| 187 | if len(impls) > 1 { |
| 188 | panic(fmt.Errorf("Expected single implmenetation library, got %d", len(impls))) |
| 189 | } else if len(impls) == 1 { |
Colin Cross | 31076b3 | 2020-10-23 17:22:06 -0700 | [diff] [blame] | 190 | return moduleLibraryInterface(impls[0]).allStubsVersions() |
Colin Cross | 3572cf7 | 2020-10-01 15:58:11 -0700 | [diff] [blame] | 191 | } |
| 192 | return nil |
| 193 | } |
| 194 | |
Jiyong Park | 64ca4b7 | 2017-11-14 20:53:00 +0900 | [diff] [blame] | 195 | func NewLLndkStubLibrary() *Module { |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 196 | module, library := NewLibrary(android.DeviceSupported) |
| 197 | library.BuildOnlyShared() |
| 198 | module.stl = nil |
| 199 | module.sanitize = nil |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 200 | library.disableStripping() |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 201 | |
| 202 | stub := &llndkStubDecorator{ |
| 203 | libraryDecorator: library, |
| 204 | } |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 205 | stub.Properties.Vendor_available = BoolPtr(true) |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 206 | module.compiler = stub |
| 207 | module.linker = stub |
| 208 | module.installer = nil |
Colin Cross | 31076b3 | 2020-10-23 17:22:06 -0700 | [diff] [blame] | 209 | module.library = stub |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 210 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 211 | module.AddProperties( |
Jiyong Park | 5e676fe | 2019-04-17 13:12:10 +0900 | [diff] [blame] | 212 | &module.Properties, |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 213 | &stub.Properties, |
| 214 | &library.MutatedProperties, |
| 215 | &library.flagExporter.Properties) |
| 216 | |
| 217 | return module |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Patrice Arruda | ea3fcdf | 2019-04-03 14:37:46 -0700 | [diff] [blame] | 220 | // llndk_library creates a stub llndk shared library based on the provided |
| 221 | // version file. Example: |
| 222 | // |
| 223 | // llndk_library { |
| 224 | // name: "libfoo", |
| 225 | // symbol_file: "libfoo.map.txt", |
| 226 | // export_include_dirs: ["include_vndk"], |
| 227 | // } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 228 | func LlndkLibraryFactory() android.Module { |
Jiyong Park | 64ca4b7 | 2017-11-14 20:53:00 +0900 | [diff] [blame] | 229 | module := NewLLndkStubLibrary() |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 230 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth) |
| 231 | return module |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 234 | type llndkHeadersDecorator struct { |
| 235 | *libraryDecorator |
| 236 | } |
| 237 | |
| 238 | func (headers *llndkHeadersDecorator) Name(name string) string { |
| 239 | return name + llndkHeadersSuffix |
| 240 | } |
| 241 | |
Patrice Arruda | ea3fcdf | 2019-04-03 14:37:46 -0700 | [diff] [blame] | 242 | // llndk_headers contains a set of c/c++ llndk headers files which are imported |
| 243 | // by other soongs cc modules. |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 244 | func llndkHeadersFactory() android.Module { |
| 245 | module, library := NewLibrary(android.DeviceSupported) |
| 246 | library.HeaderOnly() |
Inseob Kim | c7c6910 | 2020-07-08 07:56:02 +0900 | [diff] [blame] | 247 | module.stl = nil |
| 248 | module.sanitize = nil |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 249 | |
| 250 | decorator := &llndkHeadersDecorator{ |
| 251 | libraryDecorator: library, |
| 252 | } |
| 253 | |
| 254 | module.compiler = nil |
| 255 | module.linker = decorator |
| 256 | module.installer = nil |
Colin Cross | 31076b3 | 2020-10-23 17:22:06 -0700 | [diff] [blame] | 257 | module.library = decorator |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 258 | |
Jiyong Park | 5e676fe | 2019-04-17 13:12:10 +0900 | [diff] [blame] | 259 | module.AddProperties( |
| 260 | &module.Properties, |
| 261 | &library.MutatedProperties, |
| 262 | &library.flagExporter.Properties) |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 263 | |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 264 | module.Init() |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 265 | |
| 266 | return module |
| 267 | } |
| 268 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 269 | func init() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 270 | android.RegisterModuleType("llndk_library", LlndkLibraryFactory) |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 271 | android.RegisterModuleType("llndk_headers", llndkHeadersFactory) |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 272 | } |