blob: 849bb3fb53046be1d2aaf8a5b49687e6b1f5026e [file] [log] [blame]
Justin Yun71549282017-11-17 12:10:28 +09001// 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
15package cc
16
17import (
18 "strings"
19
20 "android/soong/android"
21)
22
23var (
Justin Yun3e2323d2018-06-08 15:08:40 +090024 vndkSuffix = ".vndk."
25 binder32Suffix = ".binder32"
Justin Yun71549282017-11-17 12:10:28 +090026)
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//
50type vndkPrebuiltProperties struct {
Jae Shin43ef2642017-12-29 16:20:21 +090051 // 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 Yun71549282017-11-17 12:10:28 +090056
Justin Yun3e2323d2018-06-08 15:08:40 +090057 // 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 Yun71549282017-11-17 12:10:28 +090061 // Prebuilt files for each arch.
62 Srcs []string `android:"arch_variant"`
63}
64
65type vndkPrebuiltLibraryDecorator struct {
66 *libraryDecorator
67 properties vndkPrebuiltProperties
68}
69
70func (p *vndkPrebuiltLibraryDecorator) Name(name string) string {
Jae Shin43ef2642017-12-29 16:20:21 +090071 return name + p.NameSuffix()
72}
73
74func (p *vndkPrebuiltLibraryDecorator) NameSuffix() string {
Justin Yun3e2323d2018-06-08 15:08:40 +090075 suffix := p.version()
Jae Shin43ef2642017-12-29 16:20:21 +090076 if p.arch() != "" {
Justin Yun3e2323d2018-06-08 15:08:40 +090077 suffix += "." + p.arch()
Jae Shin43ef2642017-12-29 16:20:21 +090078 }
Justin Yun3e2323d2018-06-08 15:08:40 +090079 if Bool(p.properties.Binder32bit) {
80 suffix += binder32Suffix
81 }
82 return vndkSuffix + suffix
Justin Yun71549282017-11-17 12:10:28 +090083}
84
85func (p *vndkPrebuiltLibraryDecorator) version() string {
Jae Shin43ef2642017-12-29 16:20:21 +090086 return String(p.properties.Version)
87}
88
89func (p *vndkPrebuiltLibraryDecorator) arch() string {
90 return String(p.properties.Target_arch)
Justin Yun71549282017-11-17 12:10:28 +090091}
92
Justin Yun3e2323d2018-06-08 15:08:40 +090093func (p *vndkPrebuiltLibraryDecorator) binderBit() string {
94 if Bool(p.properties.Binder32bit) {
95 return "32"
96 }
97 return "64"
98}
99
Justin Yun71549282017-11-17 12:10:28 +0900100func (p *vndkPrebuiltLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Jae Shin43ef2642017-12-29 16:20:21 +0900101 p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix())
Justin Yun71549282017-11-17 12:10:28 +0900102 return p.libraryDecorator.linkerFlags(ctx, flags)
103}
104
105func (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
119func (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
128func (p *vndkPrebuiltLibraryDecorator) install(ctx ModuleContext, file android.Path) {
Justin Yun312ccb92018-01-23 12:07:46 +0900129 arches := ctx.DeviceConfig().Arches()
130 if len(arches) == 0 || arches[0].ArchType.String() != p.arch() {
131 return
132 }
Justin Yun3e2323d2018-06-08 15:08:40 +0900133 if ctx.DeviceConfig().BinderBitness() != p.binderBit() {
134 return
135 }
Justin Yun71549282017-11-17 12:10:28 +0900136 if p.shared() {
Justin Yun3e15b962018-01-10 18:28:48 +0900137 if ctx.isVndkSp() {
138 p.baseInstaller.subDir = "vndk-sp-" + p.version()
139 } else if ctx.isVndk() {
140 p.baseInstaller.subDir = "vndk-" + p.version()
Justin Yun71549282017-11-17 12:10:28 +0900141 }
142 p.baseInstaller.install(ctx, file)
143 }
144}
145
146func 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
168func vndkPrebuiltSharedFactory() android.Module {
169 module := vndkPrebuiltSharedLibrary()
170 return module.Init()
171}
172
173func init() {
174 android.RegisterModuleType("vndk_prebuilt_shared", vndkPrebuiltSharedFactory)
Colin Cross7a6fcbe2017-12-06 13:08:00 -0800175}