blob: b4fcb57aa5cc9edd612587dabfc95f6256524b18 [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 (
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//
49type vndkPrebuiltProperties struct {
Jae Shin43ef2642017-12-29 16:20:21 +090050 // 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 Yun71549282017-11-17 12:10:28 +090055
56 // Prebuilt files for each arch.
57 Srcs []string `android:"arch_variant"`
58}
59
60type vndkPrebuiltLibraryDecorator struct {
61 *libraryDecorator
62 properties vndkPrebuiltProperties
63}
64
65func (p *vndkPrebuiltLibraryDecorator) Name(name string) string {
Jae Shin43ef2642017-12-29 16:20:21 +090066 return name + p.NameSuffix()
67}
68
69func (p *vndkPrebuiltLibraryDecorator) NameSuffix() string {
70 if p.arch() != "" {
71 return vndkSuffix + p.version() + "." + p.arch()
72 }
73 return vndkSuffix + p.version()
Justin Yun71549282017-11-17 12:10:28 +090074}
75
76func (p *vndkPrebuiltLibraryDecorator) version() string {
Jae Shin43ef2642017-12-29 16:20:21 +090077 return String(p.properties.Version)
78}
79
80func (p *vndkPrebuiltLibraryDecorator) arch() string {
81 return String(p.properties.Target_arch)
Justin Yun71549282017-11-17 12:10:28 +090082}
83
84func (p *vndkPrebuiltLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Jae Shin43ef2642017-12-29 16:20:21 +090085 p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix())
Justin Yun71549282017-11-17 12:10:28 +090086 return p.libraryDecorator.linkerFlags(ctx, flags)
87}
88
89func (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
103func (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
112func (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
125func 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
147func vndkPrebuiltSharedFactory() android.Module {
148 module := vndkPrebuiltSharedLibrary()
149 return module.Init()
150}
151
152func init() {
153 android.RegisterModuleType("vndk_prebuilt_shared", vndkPrebuiltSharedFactory)
Colin Cross7a6fcbe2017-12-06 13:08:00 -0800154}