Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [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 | "strings" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | var ( |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 24 | vndkSuffix = ".vndk." |
| 25 | binder32Suffix = ".binder32" |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | // Creates vndk prebuilts that include the VNDK version. |
| 29 | // |
| 30 | // Example: |
| 31 | // |
| 32 | // vndk_prebuilt_shared { |
| 33 | // name: "libfoo", |
| 34 | // version: "27.1.0", |
| 35 | // vendor_available: true, |
| 36 | // vndk: { |
| 37 | // enabled: true, |
| 38 | // }, |
| 39 | // export_include_dirs: ["include/external/libfoo/vndk_include"], |
| 40 | // arch: { |
| 41 | // arm64: { |
| 42 | // srcs: ["arm/lib64/libfoo.so"], |
| 43 | // }, |
| 44 | // arm: { |
| 45 | // srcs: ["arm/lib/libfoo.so"], |
| 46 | // }, |
| 47 | // }, |
| 48 | // } |
| 49 | // |
| 50 | type vndkPrebuiltProperties struct { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 51 | // VNDK snapshot version. |
| 52 | Version *string |
| 53 | |
| 54 | // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64_ab') |
| 55 | Target_arch *string |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 56 | |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 57 | // If the prebuilt snapshot lib is built with 32 bit binder, this must be set to true. |
| 58 | // The lib with 64 bit binder does not need to set this property. |
| 59 | Binder32bit *bool |
| 60 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 61 | // Prebuilt files for each arch. |
| 62 | Srcs []string `android:"arch_variant"` |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 63 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 64 | // list of directories relative to the Blueprints file that will be added to the include |
| 65 | // path (using -isystem) for any module that links against this module. |
| 66 | Export_system_include_dirs []string `android:"arch_variant"` |
| 67 | |
| 68 | // list of flags that will be used for any module that links against this module. |
| 69 | Export_flags []string `android:"arch_variant"` |
| 70 | |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 71 | // Check the prebuilt ELF files (e.g. DT_SONAME, DT_NEEDED, resolution of undefined symbols, |
| 72 | // etc). |
| 73 | Check_elf_files *bool |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | type vndkPrebuiltLibraryDecorator struct { |
| 77 | *libraryDecorator |
| 78 | properties vndkPrebuiltProperties |
| 79 | } |
| 80 | |
| 81 | func (p *vndkPrebuiltLibraryDecorator) Name(name string) string { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 82 | return name + p.NameSuffix() |
| 83 | } |
| 84 | |
| 85 | func (p *vndkPrebuiltLibraryDecorator) NameSuffix() string { |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 86 | suffix := p.version() |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 87 | if p.arch() != "" { |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 88 | suffix += "." + p.arch() |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 89 | } |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 90 | if Bool(p.properties.Binder32bit) { |
| 91 | suffix += binder32Suffix |
| 92 | } |
| 93 | return vndkSuffix + suffix |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | func (p *vndkPrebuiltLibraryDecorator) version() string { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 97 | return String(p.properties.Version) |
| 98 | } |
| 99 | |
| 100 | func (p *vndkPrebuiltLibraryDecorator) arch() string { |
| 101 | return String(p.properties.Target_arch) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 102 | } |
| 103 | |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 104 | func (p *vndkPrebuiltLibraryDecorator) binderBit() string { |
| 105 | if Bool(p.properties.Binder32bit) { |
| 106 | return "32" |
| 107 | } |
| 108 | return "64" |
| 109 | } |
| 110 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 111 | func (p *vndkPrebuiltLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 112 | p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix()) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 113 | return p.libraryDecorator.linkerFlags(ctx, flags) |
| 114 | } |
| 115 | |
| 116 | func (p *vndkPrebuiltLibraryDecorator) singleSourcePath(ctx ModuleContext) android.Path { |
| 117 | if len(p.properties.Srcs) == 0 { |
| 118 | ctx.PropertyErrorf("srcs", "missing prebuilt source file") |
| 119 | return nil |
| 120 | } |
| 121 | |
| 122 | if len(p.properties.Srcs) > 1 { |
| 123 | ctx.PropertyErrorf("srcs", "multiple prebuilt source files") |
| 124 | return nil |
| 125 | } |
| 126 | |
| 127 | return android.PathForModuleSrc(ctx, p.properties.Srcs[0]) |
| 128 | } |
| 129 | |
| 130 | func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext, |
| 131 | flags Flags, deps PathDeps, objs Objects) android.Path { |
| 132 | if len(p.properties.Srcs) > 0 && p.shared() { |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 133 | p.libraryDecorator.exportIncludes(ctx) |
| 134 | p.libraryDecorator.reexportSystemDirs(p.properties.Export_system_include_dirs...) |
| 135 | p.libraryDecorator.reexportFlags(p.properties.Export_flags...) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 136 | // current VNDK prebuilts are only shared libs. |
| 137 | return p.singleSourcePath(ctx) |
| 138 | } |
| 139 | return nil |
| 140 | } |
| 141 | |
| 142 | func (p *vndkPrebuiltLibraryDecorator) install(ctx ModuleContext, file android.Path) { |
Justin Yun | 312ccb9 | 2018-01-23 12:07:46 +0900 | [diff] [blame] | 143 | arches := ctx.DeviceConfig().Arches() |
| 144 | if len(arches) == 0 || arches[0].ArchType.String() != p.arch() { |
| 145 | return |
| 146 | } |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 147 | if ctx.DeviceConfig().BinderBitness() != p.binderBit() { |
| 148 | return |
| 149 | } |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 150 | if p.shared() { |
Justin Yun | 3e15b96 | 2018-01-10 18:28:48 +0900 | [diff] [blame] | 151 | if ctx.isVndkSp() { |
| 152 | p.baseInstaller.subDir = "vndk-sp-" + p.version() |
| 153 | } else if ctx.isVndk() { |
| 154 | p.baseInstaller.subDir = "vndk-" + p.version() |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 155 | } |
| 156 | p.baseInstaller.install(ctx, file) |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | func vndkPrebuiltSharedLibrary() *Module { |
| 161 | module, library := NewLibrary(android.DeviceSupported) |
| 162 | library.BuildOnlyShared() |
| 163 | module.stl = nil |
| 164 | module.sanitize = nil |
| 165 | library.StripProperties.Strip.None = BoolPtr(true) |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 166 | module.Properties.UseVndk = true |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 167 | |
| 168 | prebuilt := &vndkPrebuiltLibraryDecorator{ |
| 169 | libraryDecorator: library, |
| 170 | } |
| 171 | |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 172 | prebuilt.properties.Check_elf_files = BoolPtr(false) |
| 173 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 174 | module.compiler = nil |
| 175 | module.linker = prebuilt |
| 176 | module.installer = prebuilt |
| 177 | |
| 178 | module.AddProperties( |
| 179 | &prebuilt.properties, |
| 180 | ) |
| 181 | |
| 182 | return module |
| 183 | } |
| 184 | |
Patrice Arruda | ad03150 | 2019-04-01 10:56:49 -0700 | [diff] [blame] | 185 | // vndk_prebuilt_shared installs Vendor Native Development kit (VNDK) snapshot |
| 186 | // shared libraries for system build. Example: |
| 187 | // |
| 188 | // vndk_prebuilt_shared { |
| 189 | // name: "libfoo", |
| 190 | // version: "27.1.0", |
| 191 | // vendor_available: true, |
| 192 | // vndk: { |
| 193 | // enabled: true, |
| 194 | // }, |
| 195 | // export_include_dirs: ["include/external/libfoo/vndk_include"], |
| 196 | // arch: { |
| 197 | // arm64: { |
| 198 | // srcs: ["arm/lib64/libfoo.so"], |
| 199 | // }, |
| 200 | // arm: { |
| 201 | // srcs: ["arm/lib/libfoo.so"], |
| 202 | // }, |
| 203 | // }, |
| 204 | // } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame^] | 205 | func VndkPrebuiltSharedFactory() android.Module { |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 206 | module := vndkPrebuiltSharedLibrary() |
| 207 | return module.Init() |
| 208 | } |
| 209 | |
| 210 | func init() { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame^] | 211 | android.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory) |
Colin Cross | 7a6fcbe | 2017-12-06 13:08:00 -0800 | [diff] [blame] | 212 | } |