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