blob: 9c9545d8152abfd136bad99826247abef87e3960 [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) {
Justin Yun312ccb92018-01-23 12:07:46 +0900113 arches := ctx.DeviceConfig().Arches()
114 if len(arches) == 0 || arches[0].ArchType.String() != p.arch() {
115 return
116 }
Justin Yun71549282017-11-17 12:10:28 +0900117 if p.shared() {
Justin Yun3e15b962018-01-10 18:28:48 +0900118 if ctx.isVndkSp() {
119 p.baseInstaller.subDir = "vndk-sp-" + p.version()
120 } else if ctx.isVndk() {
121 p.baseInstaller.subDir = "vndk-" + p.version()
Justin Yun71549282017-11-17 12:10:28 +0900122 }
123 p.baseInstaller.install(ctx, file)
124 }
125}
126
127func vndkPrebuiltSharedLibrary() *Module {
128 module, library := NewLibrary(android.DeviceSupported)
129 library.BuildOnlyShared()
130 module.stl = nil
131 module.sanitize = nil
132 library.StripProperties.Strip.None = BoolPtr(true)
133
134 prebuilt := &vndkPrebuiltLibraryDecorator{
135 libraryDecorator: library,
136 }
137
138 module.compiler = nil
139 module.linker = prebuilt
140 module.installer = prebuilt
141
142 module.AddProperties(
143 &prebuilt.properties,
144 )
145
146 return module
147}
148
149func vndkPrebuiltSharedFactory() android.Module {
150 module := vndkPrebuiltSharedLibrary()
151 return module.Init()
152}
153
154func init() {
155 android.RegisterModuleType("vndk_prebuilt_shared", vndkPrebuiltSharedFactory)
Colin Cross7a6fcbe2017-12-06 13:08:00 -0800156}