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