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 | |
| 64 | // Check the prebuilt ELF files (e.g. DT_SONAME, DT_NEEDED, resolution of undefined symbols, |
| 65 | // etc). |
| 66 | Check_elf_files *bool |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | type vndkPrebuiltLibraryDecorator struct { |
| 70 | *libraryDecorator |
| 71 | properties vndkPrebuiltProperties |
| 72 | } |
| 73 | |
| 74 | func (p *vndkPrebuiltLibraryDecorator) Name(name string) string { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 75 | return name + p.NameSuffix() |
| 76 | } |
| 77 | |
| 78 | func (p *vndkPrebuiltLibraryDecorator) NameSuffix() string { |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 79 | suffix := p.version() |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 80 | if p.arch() != "" { |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 81 | suffix += "." + p.arch() |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 82 | } |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 83 | if Bool(p.properties.Binder32bit) { |
| 84 | suffix += binder32Suffix |
| 85 | } |
| 86 | return vndkSuffix + suffix |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | func (p *vndkPrebuiltLibraryDecorator) version() string { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 90 | return String(p.properties.Version) |
| 91 | } |
| 92 | |
| 93 | func (p *vndkPrebuiltLibraryDecorator) arch() string { |
| 94 | return String(p.properties.Target_arch) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 95 | } |
| 96 | |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 97 | func (p *vndkPrebuiltLibraryDecorator) binderBit() string { |
| 98 | if Bool(p.properties.Binder32bit) { |
| 99 | return "32" |
| 100 | } |
| 101 | return "64" |
| 102 | } |
| 103 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 104 | func (p *vndkPrebuiltLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 105 | p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix()) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 106 | return p.libraryDecorator.linkerFlags(ctx, flags) |
| 107 | } |
| 108 | |
| 109 | func (p *vndkPrebuiltLibraryDecorator) singleSourcePath(ctx ModuleContext) android.Path { |
| 110 | if len(p.properties.Srcs) == 0 { |
| 111 | ctx.PropertyErrorf("srcs", "missing prebuilt source file") |
| 112 | return nil |
| 113 | } |
| 114 | |
| 115 | if len(p.properties.Srcs) > 1 { |
| 116 | ctx.PropertyErrorf("srcs", "multiple prebuilt source files") |
| 117 | return nil |
| 118 | } |
| 119 | |
| 120 | return android.PathForModuleSrc(ctx, p.properties.Srcs[0]) |
| 121 | } |
| 122 | |
| 123 | func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext, |
| 124 | flags Flags, deps PathDeps, objs Objects) android.Path { |
| 125 | if len(p.properties.Srcs) > 0 && p.shared() { |
| 126 | // current VNDK prebuilts are only shared libs. |
| 127 | return p.singleSourcePath(ctx) |
| 128 | } |
| 129 | return nil |
| 130 | } |
| 131 | |
| 132 | func (p *vndkPrebuiltLibraryDecorator) install(ctx ModuleContext, file android.Path) { |
Justin Yun | 312ccb9 | 2018-01-23 12:07:46 +0900 | [diff] [blame] | 133 | arches := ctx.DeviceConfig().Arches() |
| 134 | if len(arches) == 0 || arches[0].ArchType.String() != p.arch() { |
| 135 | return |
| 136 | } |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 137 | if ctx.DeviceConfig().BinderBitness() != p.binderBit() { |
| 138 | return |
| 139 | } |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 140 | if p.shared() { |
Justin Yun | 3e15b96 | 2018-01-10 18:28:48 +0900 | [diff] [blame] | 141 | if ctx.isVndkSp() { |
| 142 | p.baseInstaller.subDir = "vndk-sp-" + p.version() |
| 143 | } else if ctx.isVndk() { |
| 144 | p.baseInstaller.subDir = "vndk-" + p.version() |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 145 | } |
| 146 | p.baseInstaller.install(ctx, file) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | func vndkPrebuiltSharedLibrary() *Module { |
| 151 | module, library := NewLibrary(android.DeviceSupported) |
| 152 | library.BuildOnlyShared() |
| 153 | module.stl = nil |
| 154 | module.sanitize = nil |
| 155 | library.StripProperties.Strip.None = BoolPtr(true) |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 156 | module.Properties.UseVndk = true |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 157 | |
| 158 | prebuilt := &vndkPrebuiltLibraryDecorator{ |
| 159 | libraryDecorator: library, |
| 160 | } |
| 161 | |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 162 | prebuilt.properties.Check_elf_files = BoolPtr(false) |
| 163 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 164 | module.compiler = nil |
| 165 | module.linker = prebuilt |
| 166 | module.installer = prebuilt |
| 167 | |
| 168 | module.AddProperties( |
| 169 | &prebuilt.properties, |
| 170 | ) |
| 171 | |
| 172 | return module |
| 173 | } |
| 174 | |
| 175 | func vndkPrebuiltSharedFactory() android.Module { |
| 176 | module := vndkPrebuiltSharedLibrary() |
| 177 | return module.Init() |
| 178 | } |
| 179 | |
| 180 | func init() { |
| 181 | android.RegisterModuleType("vndk_prebuilt_shared", vndkPrebuiltSharedFactory) |
Colin Cross | 7a6fcbe | 2017-12-06 13:08:00 -0800 | [diff] [blame] | 182 | } |