blob: 74f7f270cb1f05e6913113147fd54e882df47402 [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"`
Logan Chien4fcea3d2018-11-20 11:59:08 +080063
64 // Check the prebuilt ELF files (e.g. DT_SONAME, DT_NEEDED, resolution of undefined symbols,
65 // etc).
66 Check_elf_files *bool
Justin Yun71549282017-11-17 12:10:28 +090067}
68
69type vndkPrebuiltLibraryDecorator struct {
70 *libraryDecorator
71 properties vndkPrebuiltProperties
72}
73
74func (p *vndkPrebuiltLibraryDecorator) Name(name string) string {
Jae Shin43ef2642017-12-29 16:20:21 +090075 return name + p.NameSuffix()
76}
77
78func (p *vndkPrebuiltLibraryDecorator) NameSuffix() string {
Justin Yun3e2323d2018-06-08 15:08:40 +090079 suffix := p.version()
Jae Shin43ef2642017-12-29 16:20:21 +090080 if p.arch() != "" {
Justin Yun3e2323d2018-06-08 15:08:40 +090081 suffix += "." + p.arch()
Jae Shin43ef2642017-12-29 16:20:21 +090082 }
Justin Yun3e2323d2018-06-08 15:08:40 +090083 if Bool(p.properties.Binder32bit) {
84 suffix += binder32Suffix
85 }
86 return vndkSuffix + suffix
Justin Yun71549282017-11-17 12:10:28 +090087}
88
89func (p *vndkPrebuiltLibraryDecorator) version() string {
Jae Shin43ef2642017-12-29 16:20:21 +090090 return String(p.properties.Version)
91}
92
93func (p *vndkPrebuiltLibraryDecorator) arch() string {
94 return String(p.properties.Target_arch)
Justin Yun71549282017-11-17 12:10:28 +090095}
96
Justin Yun3e2323d2018-06-08 15:08:40 +090097func (p *vndkPrebuiltLibraryDecorator) binderBit() string {
98 if Bool(p.properties.Binder32bit) {
99 return "32"
100 }
101 return "64"
102}
103
Justin Yun71549282017-11-17 12:10:28 +0900104func (p *vndkPrebuiltLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Jae Shin43ef2642017-12-29 16:20:21 +0900105 p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix())
Justin Yun71549282017-11-17 12:10:28 +0900106 return p.libraryDecorator.linkerFlags(ctx, flags)
107}
108
109func (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
123func (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
132func (p *vndkPrebuiltLibraryDecorator) install(ctx ModuleContext, file android.Path) {
Justin Yun312ccb92018-01-23 12:07:46 +0900133 arches := ctx.DeviceConfig().Arches()
134 if len(arches) == 0 || arches[0].ArchType.String() != p.arch() {
135 return
136 }
Justin Yun3e2323d2018-06-08 15:08:40 +0900137 if ctx.DeviceConfig().BinderBitness() != p.binderBit() {
138 return
139 }
Justin Yun71549282017-11-17 12:10:28 +0900140 if p.shared() {
Justin Yun3e15b962018-01-10 18:28:48 +0900141 if ctx.isVndkSp() {
142 p.baseInstaller.subDir = "vndk-sp-" + p.version()
143 } else if ctx.isVndk() {
144 p.baseInstaller.subDir = "vndk-" + p.version()
Justin Yun71549282017-11-17 12:10:28 +0900145 }
146 p.baseInstaller.install(ctx, file)
147 }
148}
149
150func 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 Crossb60190a2018-09-04 16:28:17 -0700156 module.Properties.UseVndk = true
Justin Yun71549282017-11-17 12:10:28 +0900157
158 prebuilt := &vndkPrebuiltLibraryDecorator{
159 libraryDecorator: library,
160 }
161
Logan Chien4fcea3d2018-11-20 11:59:08 +0800162 prebuilt.properties.Check_elf_files = BoolPtr(false)
163
Justin Yun71549282017-11-17 12:10:28 +0900164 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
175func vndkPrebuiltSharedFactory() android.Module {
176 module := vndkPrebuiltSharedLibrary()
177 return module.Init()
178}
179
180func init() {
181 android.RegisterModuleType("vndk_prebuilt_shared", vndkPrebuiltSharedFactory)
Colin Cross7a6fcbe2017-12-06 13:08:00 -0800182}