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 ( |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 18 | "strings" |
| 19 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | var ( |
| 24 | llndkLibrarySuffix = ".llndk" |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 25 | llndkHeadersSuffix = ".llndk" |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 26 | ) |
| 27 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 28 | // Holds properties to describe a stub shared library based on the provided version file. |
| 29 | // The stub library will actually be built by the cc_library module that points to this |
| 30 | // module with the llndk_stubs property. |
| 31 | // TODO(ccross): move the properties from llndk_library modules directly into the cc_library |
| 32 | // modules and remove the llndk_library modules. |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 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 | |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 58 | // list of llndk headers to re-export include directories from. |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame^] | 59 | Export_llndk_headers []string |
| 60 | |
| 61 | // list of directories relative to the Blueprints file that willbe added to the include path |
| 62 | // (using -I) for any module that links against the LLNDK variant of this module, replacing |
| 63 | // any that were listed outside the llndk clause. |
| 64 | Override_export_include_dirs []string |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 65 | |
| 66 | // whether this module can be directly depended upon by libs that are installed |
| 67 | // to /vendor and /product. |
| 68 | // When set to true, this module can only be depended on by VNDK libraries, not |
| 69 | // vendor nor product libraries. This effectively hides this module from |
| 70 | // non-system modules. Default value is false. |
| 71 | Private *bool |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | type llndkStubDecorator struct { |
| 75 | *libraryDecorator |
| 76 | |
| 77 | Properties llndkLibraryProperties |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 80 | var _ versionedInterface = (*llndkStubDecorator)(nil) |
| 81 | |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 82 | func (stub *llndkStubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags { |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 83 | return flags |
George Burgess IV | f5310e3 | 2017-07-19 11:39:53 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 86 | func (stub *llndkStubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 87 | return Objects{} |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | func (stub *llndkStubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 91 | return deps |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 94 | func (stub *llndkStubDecorator) Name(name string) string { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 95 | if strings.HasSuffix(name, llndkLibrarySuffix) { |
| 96 | return name |
| 97 | } |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 98 | return name + llndkLibrarySuffix |
| 99 | } |
| 100 | |
Colin Cross | 4f4f8eb | 2021-01-06 14:07:27 -0800 | [diff] [blame] | 101 | func (stub *llndkStubDecorator) linkerProps() []interface{} { |
| 102 | props := stub.libraryDecorator.linkerProps() |
| 103 | return append(props, &stub.Properties) |
| 104 | } |
| 105 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 106 | func (stub *llndkStubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 107 | stub.libraryDecorator.libName = stub.implementationModuleName(ctx.ModuleName()) |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 108 | return stub.libraryDecorator.linkerFlags(ctx, flags) |
| 109 | } |
| 110 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 111 | func (stub *llndkStubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, |
| 112 | objs Objects) android.Path { |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 113 | return nil |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 116 | func (stub *llndkStubDecorator) nativeCoverage() bool { |
| 117 | return false |
| 118 | } |
| 119 | |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 120 | func (stub *llndkStubDecorator) implementationModuleName(name string) string { |
| 121 | return strings.TrimSuffix(name, llndkLibrarySuffix) |
| 122 | } |
| 123 | |
Colin Cross | c88c272 | 2020-09-28 17:32:47 -0700 | [diff] [blame] | 124 | func (stub *llndkStubDecorator) buildStubs() bool { |
| 125 | return true |
| 126 | } |
| 127 | |
Jiyong Park | 64ca4b7 | 2017-11-14 20:53:00 +0900 | [diff] [blame] | 128 | func NewLLndkStubLibrary() *Module { |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 129 | module, library := NewLibrary(android.DeviceSupported) |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 130 | module.stl = nil |
| 131 | module.sanitize = nil |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 132 | library.disableStripping() |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 133 | |
| 134 | stub := &llndkStubDecorator{ |
| 135 | libraryDecorator: library, |
| 136 | } |
| 137 | module.compiler = stub |
| 138 | module.linker = stub |
| 139 | module.installer = nil |
Colin Cross | 31076b3 | 2020-10-23 17:22:06 -0700 | [diff] [blame] | 140 | module.library = stub |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 141 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 142 | return module |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Patrice Arruda | ea3fcdf | 2019-04-03 14:37:46 -0700 | [diff] [blame] | 145 | // llndk_library creates a stub llndk shared library based on the provided |
| 146 | // version file. Example: |
| 147 | // |
| 148 | // llndk_library { |
| 149 | // name: "libfoo", |
| 150 | // symbol_file: "libfoo.map.txt", |
| 151 | // export_include_dirs: ["include_vndk"], |
| 152 | // } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 153 | func LlndkLibraryFactory() android.Module { |
Jiyong Park | 64ca4b7 | 2017-11-14 20:53:00 +0900 | [diff] [blame] | 154 | module := NewLLndkStubLibrary() |
Colin Cross | 4f4f8eb | 2021-01-06 14:07:27 -0800 | [diff] [blame] | 155 | return module.Init() |
| 156 | } |
| 157 | |
| 158 | // isVestigialLLNDKModule returns true if m is a vestigial llndk_library module used to provide |
| 159 | // properties to the LLNDK variant of a cc_library. |
| 160 | func isVestigialLLNDKModule(m *Module) bool { |
| 161 | _, ok := m.linker.(*llndkStubDecorator) |
| 162 | return ok |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 165 | type llndkHeadersDecorator struct { |
| 166 | *libraryDecorator |
| 167 | } |
| 168 | |
Colin Cross | b5f6fa6 | 2021-01-06 17:05:04 -0800 | [diff] [blame] | 169 | func (llndk *llndkHeadersDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { |
| 170 | deps.HeaderLibs = append(deps.HeaderLibs, llndk.Properties.Llndk.Export_llndk_headers...) |
| 171 | deps.ReexportHeaderLibHeaders = append(deps.ReexportHeaderLibHeaders, |
| 172 | llndk.Properties.Llndk.Export_llndk_headers...) |
| 173 | return deps |
| 174 | } |
| 175 | |
Patrice Arruda | ea3fcdf | 2019-04-03 14:37:46 -0700 | [diff] [blame] | 176 | // llndk_headers contains a set of c/c++ llndk headers files which are imported |
| 177 | // by other soongs cc modules. |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 178 | func llndkHeadersFactory() android.Module { |
| 179 | module, library := NewLibrary(android.DeviceSupported) |
| 180 | library.HeaderOnly() |
Inseob Kim | c7c6910 | 2020-07-08 07:56:02 +0900 | [diff] [blame] | 181 | module.stl = nil |
| 182 | module.sanitize = nil |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 183 | |
| 184 | decorator := &llndkHeadersDecorator{ |
| 185 | libraryDecorator: library, |
| 186 | } |
| 187 | |
| 188 | module.compiler = nil |
| 189 | module.linker = decorator |
| 190 | module.installer = nil |
Colin Cross | 31076b3 | 2020-10-23 17:22:06 -0700 | [diff] [blame] | 191 | module.library = decorator |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 192 | |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 193 | module.Init() |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 194 | |
| 195 | return module |
| 196 | } |
| 197 | |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 198 | func init() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 199 | android.RegisterModuleType("llndk_library", LlndkLibraryFactory) |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 200 | android.RegisterModuleType("llndk_headers", llndkHeadersFactory) |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 201 | } |