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 ( |
| 24 | vndkSuffix = ".vndk." |
| 25 | ) |
| 26 | |
| 27 | // Creates vndk prebuilts that include the VNDK version. |
| 28 | // |
| 29 | // Example: |
| 30 | // |
| 31 | // vndk_prebuilt_shared { |
| 32 | // name: "libfoo", |
| 33 | // version: "27.1.0", |
| 34 | // vendor_available: true, |
| 35 | // vndk: { |
| 36 | // enabled: true, |
| 37 | // }, |
| 38 | // export_include_dirs: ["include/external/libfoo/vndk_include"], |
| 39 | // arch: { |
| 40 | // arm64: { |
| 41 | // srcs: ["arm/lib64/libfoo.so"], |
| 42 | // }, |
| 43 | // arm: { |
| 44 | // srcs: ["arm/lib/libfoo.so"], |
| 45 | // }, |
| 46 | // }, |
| 47 | // } |
| 48 | // |
| 49 | type vndkPrebuiltProperties struct { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame^] | 50 | // VNDK snapshot version. |
| 51 | Version *string |
| 52 | |
| 53 | // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64_ab') |
| 54 | Target_arch *string |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 55 | |
| 56 | // Prebuilt files for each arch. |
| 57 | Srcs []string `android:"arch_variant"` |
| 58 | } |
| 59 | |
| 60 | type vndkPrebuiltLibraryDecorator struct { |
| 61 | *libraryDecorator |
| 62 | properties vndkPrebuiltProperties |
| 63 | } |
| 64 | |
| 65 | func (p *vndkPrebuiltLibraryDecorator) Name(name string) string { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame^] | 66 | return name + p.NameSuffix() |
| 67 | } |
| 68 | |
| 69 | func (p *vndkPrebuiltLibraryDecorator) NameSuffix() string { |
| 70 | if p.arch() != "" { |
| 71 | return vndkSuffix + p.version() + "." + p.arch() |
| 72 | } |
| 73 | return vndkSuffix + p.version() |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | func (p *vndkPrebuiltLibraryDecorator) version() string { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame^] | 77 | return String(p.properties.Version) |
| 78 | } |
| 79 | |
| 80 | func (p *vndkPrebuiltLibraryDecorator) arch() string { |
| 81 | return String(p.properties.Target_arch) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | func (p *vndkPrebuiltLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame^] | 85 | p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix()) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 86 | return p.libraryDecorator.linkerFlags(ctx, flags) |
| 87 | } |
| 88 | |
| 89 | func (p *vndkPrebuiltLibraryDecorator) singleSourcePath(ctx ModuleContext) android.Path { |
| 90 | if len(p.properties.Srcs) == 0 { |
| 91 | ctx.PropertyErrorf("srcs", "missing prebuilt source file") |
| 92 | return nil |
| 93 | } |
| 94 | |
| 95 | if len(p.properties.Srcs) > 1 { |
| 96 | ctx.PropertyErrorf("srcs", "multiple prebuilt source files") |
| 97 | return nil |
| 98 | } |
| 99 | |
| 100 | return android.PathForModuleSrc(ctx, p.properties.Srcs[0]) |
| 101 | } |
| 102 | |
| 103 | func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext, |
| 104 | flags Flags, deps PathDeps, objs Objects) android.Path { |
| 105 | if len(p.properties.Srcs) > 0 && p.shared() { |
| 106 | // current VNDK prebuilts are only shared libs. |
| 107 | return p.singleSourcePath(ctx) |
| 108 | } |
| 109 | return nil |
| 110 | } |
| 111 | |
| 112 | func (p *vndkPrebuiltLibraryDecorator) install(ctx ModuleContext, file android.Path) { |
| 113 | if p.shared() { |
| 114 | if ctx.Device() && ctx.useVndk() { |
| 115 | if ctx.isVndkSp() { |
| 116 | p.baseInstaller.subDir = "vndk-sp-" + p.version() |
| 117 | } else if ctx.isVndk() { |
| 118 | p.baseInstaller.subDir = "vndk-" + p.version() |
| 119 | } |
| 120 | } |
| 121 | p.baseInstaller.install(ctx, file) |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | func vndkPrebuiltSharedLibrary() *Module { |
| 126 | module, library := NewLibrary(android.DeviceSupported) |
| 127 | library.BuildOnlyShared() |
| 128 | module.stl = nil |
| 129 | module.sanitize = nil |
| 130 | library.StripProperties.Strip.None = BoolPtr(true) |
| 131 | |
| 132 | prebuilt := &vndkPrebuiltLibraryDecorator{ |
| 133 | libraryDecorator: library, |
| 134 | } |
| 135 | |
| 136 | module.compiler = nil |
| 137 | module.linker = prebuilt |
| 138 | module.installer = prebuilt |
| 139 | |
| 140 | module.AddProperties( |
| 141 | &prebuilt.properties, |
| 142 | ) |
| 143 | |
| 144 | return module |
| 145 | } |
| 146 | |
| 147 | func vndkPrebuiltSharedFactory() android.Module { |
| 148 | module := vndkPrebuiltSharedLibrary() |
| 149 | return module.Init() |
| 150 | } |
| 151 | |
| 152 | func init() { |
| 153 | android.RegisterModuleType("vndk_prebuilt_shared", vndkPrebuiltSharedFactory) |
Colin Cross | 7a6fcbe | 2017-12-06 13:08:00 -0800 | [diff] [blame] | 154 | } |