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