blob: a1a164f3fe42fcac8484f1ab7277ce11fb508e7a [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 {
50 // VNDK snapshot version that is formated as {SDK_ver}.{Major}.{Minor}.
51 Version string
52
53 // Prebuilt files for each arch.
54 Srcs []string `android:"arch_variant"`
55}
56
57type vndkPrebuiltLibraryDecorator struct {
58 *libraryDecorator
59 properties vndkPrebuiltProperties
60}
61
62func (p *vndkPrebuiltLibraryDecorator) Name(name string) string {
63 return name + vndkSuffix + p.version()
64}
65
66func (p *vndkPrebuiltLibraryDecorator) version() string {
67 return p.properties.Version
68}
69
70func (p *vndkPrebuiltLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
71 p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), vndkSuffix+p.version())
72 return p.libraryDecorator.linkerFlags(ctx, flags)
73}
74
75func (p *vndkPrebuiltLibraryDecorator) singleSourcePath(ctx ModuleContext) android.Path {
76 if len(p.properties.Srcs) == 0 {
77 ctx.PropertyErrorf("srcs", "missing prebuilt source file")
78 return nil
79 }
80
81 if len(p.properties.Srcs) > 1 {
82 ctx.PropertyErrorf("srcs", "multiple prebuilt source files")
83 return nil
84 }
85
86 return android.PathForModuleSrc(ctx, p.properties.Srcs[0])
87}
88
89func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext,
90 flags Flags, deps PathDeps, objs Objects) android.Path {
91 if len(p.properties.Srcs) > 0 && p.shared() {
92 // current VNDK prebuilts are only shared libs.
93 return p.singleSourcePath(ctx)
94 }
95 return nil
96}
97
98func (p *vndkPrebuiltLibraryDecorator) install(ctx ModuleContext, file android.Path) {
99 if p.shared() {
100 if ctx.Device() && ctx.useVndk() {
101 if ctx.isVndkSp() {
102 p.baseInstaller.subDir = "vndk-sp-" + p.version()
103 } else if ctx.isVndk() {
104 p.baseInstaller.subDir = "vndk-" + p.version()
105 }
106 }
107 p.baseInstaller.install(ctx, file)
108 }
109}
110
111func vndkPrebuiltSharedLibrary() *Module {
112 module, library := NewLibrary(android.DeviceSupported)
113 library.BuildOnlyShared()
114 module.stl = nil
115 module.sanitize = nil
116 library.StripProperties.Strip.None = BoolPtr(true)
117
118 prebuilt := &vndkPrebuiltLibraryDecorator{
119 libraryDecorator: library,
120 }
121
122 module.compiler = nil
123 module.linker = prebuilt
124 module.installer = prebuilt
125
126 module.AddProperties(
127 &prebuilt.properties,
128 )
129
130 return module
131}
132
133func vndkPrebuiltSharedFactory() android.Module {
134 module := vndkPrebuiltSharedLibrary()
135 return module.Init()
136}
137
138func init() {
139 android.RegisterModuleType("vndk_prebuilt_shared", vndkPrebuiltSharedFactory)
140}