blob: ef3e5e1c58b3971f42f41c4643c92433ced477a2 [file] [log] [blame]
Jiyong Park09d77522019-11-18 11:16:27 +09001// Copyright (C) 2019 The Android Open Source Project
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 apex
16
17import (
Jiyong Park09d77522019-11-18 11:16:27 +090018 "strings"
Jiyong Park09d77522019-11-18 11:16:27 +090019
20 "android/soong/android"
21 "android/soong/cc"
22
23 "github.com/google/blueprint/proptools"
24)
25
26const (
Jooyung Han27151d92019-12-16 17:45:32 +090027 vndkApexName = "com.android.vndk"
28 vndkApexNamePrefix = vndkApexName + ".v"
Jiyong Park09d77522019-11-18 11:16:27 +090029)
30
31// apex_vndk creates a special variant of apex modules which contains only VNDK libraries.
32// If `vndk_version` is specified, the VNDK libraries of the specified VNDK version are gathered automatically.
33// If not specified, then the "current" versions are gathered.
34func vndkApexBundleFactory() android.Module {
35 bundle := newApexBundle()
36 bundle.vndkApex = true
37 bundle.AddProperties(&bundle.vndkProperties)
38 android.AddLoadHook(bundle, func(ctx android.LoadHookContext) {
39 ctx.AppendProperties(&struct {
40 Compile_multilib *string
41 }{
42 proptools.StringPtr("both"),
43 })
44 })
45 return bundle
46}
47
48func (a *apexBundle) vndkVersion(config android.DeviceConfig) string {
49 vndkVersion := proptools.StringDefault(a.vndkProperties.Vndk_version, "current")
50 if vndkVersion == "current" {
51 vndkVersion = config.PlatformVndkVersion()
52 }
53 return vndkVersion
54}
55
56type apexVndkProperties struct {
57 // Indicates VNDK version of which this VNDK APEX bundles VNDK libs. Default is Platform VNDK Version.
58 Vndk_version *string
59}
60
Jiyong Park09d77522019-11-18 11:16:27 +090061func apexVndkMutator(mctx android.TopDownMutatorContext) {
62 if ab, ok := mctx.Module().(*apexBundle); ok && ab.vndkApex {
63 if ab.IsNativeBridgeSupported() {
64 mctx.PropertyErrorf("native_bridge_supported", "%q doesn't support native bridge binary.", mctx.ModuleType())
65 }
66
67 vndkVersion := ab.vndkVersion(mctx.DeviceConfig())
68 // Ensure VNDK APEX mount point is formatted as com.android.vndk.v###
69 ab.properties.Apex_name = proptools.StringPtr(vndkApexNamePrefix + vndkVersion)
Jiyong Park09d77522019-11-18 11:16:27 +090070 }
71}
72
73func apexVndkDepsMutator(mctx android.BottomUpMutatorContext) {
74 if m, ok := mctx.Module().(*cc.Module); ok && cc.IsForVndkApex(mctx, m) {
75 vndkVersion := m.VndkVersion()
Jooyung Han73d20d02020-03-27 16:06:55 +090076 // For VNDK-Lite device, we gather core-variants of VNDK-Sp libraries, which doesn't have VNDK version defined
77 if vndkVersion == "" {
78 vndkVersion = mctx.DeviceConfig().PlatformVndkVersion()
79 }
Colin Cross2807f002021-03-02 10:15:29 -080080 if vndkVersion == mctx.DeviceConfig().PlatformVndkVersion() {
81 vndkVersion = "current"
82 } else {
83 vndkVersion = "v" + vndkVersion
84 }
85
86 vndkApexName := "com.android.vndk." + vndkVersion
87
88 if mctx.OtherModuleExists(vndkApexName) {
89 mctx.AddReverseDependency(mctx.Module(), sharedLibTag, vndkApexName)
Jiyong Park09d77522019-11-18 11:16:27 +090090 }
91 } else if a, ok := mctx.Module().(*apexBundle); ok && a.vndkApex {
92 vndkVersion := proptools.StringDefault(a.vndkProperties.Vndk_version, "current")
93 mctx.AddDependency(mctx.Module(), prebuiltTag, cc.VndkLibrariesTxtModules(vndkVersion)...)
94 }
95}
96
Jooyung Han002ab682020-01-08 01:57:58 +090097// name is module.BaseModuleName() which is used as LOCAL_MODULE_NAME and also LOCAL_OVERRIDES_*
Colin Cross6340ea52021-11-04 12:01:18 -070098func makeCompatSymlinks(name string, ctx android.ModuleContext, primaryApex bool) (symlinks android.InstallPaths) {
Jiyong Park09d77522019-11-18 11:16:27 +090099 // small helper to add symlink commands
Colin Cross6340ea52021-11-04 12:01:18 -0700100 addSymlink := func(target string, dir android.InstallPath, linkName string) {
101 if primaryApex {
102 symlinks = append(symlinks, ctx.InstallAbsoluteSymlink(dir, linkName, target))
103 } else {
104 symlinks = append(symlinks, dir.Join(ctx, linkName))
105 }
Jiyong Park09d77522019-11-18 11:16:27 +0900106 }
107
108 // TODO(b/142911355): [VNDK APEX] Fix hard-coded references to /system/lib/vndk
109 // When all hard-coded references are fixed, remove symbolic links
110 // Note that we should keep following symlinks for older VNDKs (<=29)
111 // Since prebuilt vndk libs still depend on system/lib/vndk path
Jooyung Han055418a2020-04-14 14:22:31 +0900112 if strings.HasPrefix(name, vndkApexNamePrefix) {
113 vndkVersion := strings.TrimPrefix(name, vndkApexNamePrefix)
Dan Albertc8060532020-07-22 22:32:17 -0700114 if ver, err := android.ApiLevelFromUser(ctx, vndkVersion); err != nil {
Jooyung Han055418a2020-04-14 14:22:31 +0900115 ctx.ModuleErrorf("apex_vndk should be named as %v<ver:number>: %s", vndkApexNamePrefix, name)
116 return
Dan Albertc8060532020-07-22 22:32:17 -0700117 } else if ver.GreaterThan(android.SdkVersion_Android10) {
Jooyung Han055418a2020-04-14 14:22:31 +0900118 return
Jooyung Han002ab682020-01-08 01:57:58 +0900119 }
Jiyong Park09d77522019-11-18 11:16:27 +0900120 // the name of vndk apex is formatted "com.android.vndk.v" + version
Jooyung Han002ab682020-01-08 01:57:58 +0900121 apexName := vndkApexNamePrefix + vndkVersion
Jiyong Park09d77522019-11-18 11:16:27 +0900122 if ctx.Config().Android64() {
Colin Cross6340ea52021-11-04 12:01:18 -0700123 dir := android.PathForModuleInPartitionInstall(ctx, "system", "lib64")
124 addSymlink("/apex/"+apexName+"/lib64", dir, "vndk-sp-"+vndkVersion)
125 addSymlink("/apex/"+apexName+"/lib64", dir, "vndk-"+vndkVersion)
Jiyong Park09d77522019-11-18 11:16:27 +0900126 }
127 if !ctx.Config().Android64() || ctx.DeviceConfig().DeviceSecondaryArch() != "" {
Colin Cross6340ea52021-11-04 12:01:18 -0700128 dir := android.PathForModuleInPartitionInstall(ctx, "system", "lib")
129 addSymlink("/apex/"+apexName+"/lib", dir, "vndk-sp-"+vndkVersion)
130 addSymlink("/apex/"+apexName+"/lib", dir, "vndk-"+vndkVersion)
Jooyung Han4791cb52019-10-25 18:17:23 +0900131 }
132 }
133
134 // http://b/121248172 - create a link from /system/usr/icu to
135 // /apex/com.android.i18n/etc/icu so that apps can find the ICU .dat file.
136 // A symlink can't overwrite a directory and the /system/usr/icu directory once
137 // existed so the required structure must be created whatever we find.
Jooyung Han002ab682020-01-08 01:57:58 +0900138 if name == "com.android.i18n" {
Colin Cross6340ea52021-11-04 12:01:18 -0700139 dir := android.PathForModuleInPartitionInstall(ctx, "system", "usr")
140 addSymlink("/apex/com.android.i18n/etc/icu", dir, "icu")
Jooyung Han4791cb52019-10-25 18:17:23 +0900141 }
142
Colin Cross6340ea52021-11-04 12:01:18 -0700143 return symlinks
Jiyong Park09d77522019-11-18 11:16:27 +0900144}