blob: 75c0fb01b2fcaa459be10d4b26cc76ec27b79de4 [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 (
18 "path/filepath"
19 "strings"
Jiyong Park09d77522019-11-18 11:16:27 +090020
21 "android/soong/android"
22 "android/soong/cc"
23
24 "github.com/google/blueprint/proptools"
25)
26
27const (
Jooyung Han27151d92019-12-16 17:45:32 +090028 vndkApexName = "com.android.vndk"
29 vndkApexNamePrefix = vndkApexName + ".v"
Jiyong Park09d77522019-11-18 11:16:27 +090030)
31
32// apex_vndk creates a special variant of apex modules which contains only VNDK libraries.
33// If `vndk_version` is specified, the VNDK libraries of the specified VNDK version are gathered automatically.
34// If not specified, then the "current" versions are gathered.
35func vndkApexBundleFactory() android.Module {
36 bundle := newApexBundle()
37 bundle.vndkApex = true
38 bundle.AddProperties(&bundle.vndkProperties)
39 android.AddLoadHook(bundle, func(ctx android.LoadHookContext) {
40 ctx.AppendProperties(&struct {
41 Compile_multilib *string
42 }{
43 proptools.StringPtr("both"),
44 })
45 })
46 return bundle
47}
48
49func (a *apexBundle) vndkVersion(config android.DeviceConfig) string {
50 vndkVersion := proptools.StringDefault(a.vndkProperties.Vndk_version, "current")
51 if vndkVersion == "current" {
52 vndkVersion = config.PlatformVndkVersion()
53 }
54 return vndkVersion
55}
56
57type apexVndkProperties struct {
58 // Indicates VNDK version of which this VNDK APEX bundles VNDK libs. Default is Platform VNDK Version.
59 Vndk_version *string
60}
61
Jiyong Park09d77522019-11-18 11:16:27 +090062func apexVndkMutator(mctx android.TopDownMutatorContext) {
63 if ab, ok := mctx.Module().(*apexBundle); ok && ab.vndkApex {
64 if ab.IsNativeBridgeSupported() {
65 mctx.PropertyErrorf("native_bridge_supported", "%q doesn't support native bridge binary.", mctx.ModuleType())
66 }
67
68 vndkVersion := ab.vndkVersion(mctx.DeviceConfig())
69 // Ensure VNDK APEX mount point is formatted as com.android.vndk.v###
70 ab.properties.Apex_name = proptools.StringPtr(vndkApexNamePrefix + vndkVersion)
Jiyong Park09d77522019-11-18 11:16:27 +090071 }
72}
73
74func apexVndkDepsMutator(mctx android.BottomUpMutatorContext) {
75 if m, ok := mctx.Module().(*cc.Module); ok && cc.IsForVndkApex(mctx, m) {
76 vndkVersion := m.VndkVersion()
Jooyung Han73d20d02020-03-27 16:06:55 +090077 // For VNDK-Lite device, we gather core-variants of VNDK-Sp libraries, which doesn't have VNDK version defined
78 if vndkVersion == "" {
79 vndkVersion = mctx.DeviceConfig().PlatformVndkVersion()
80 }
Colin Cross2807f002021-03-02 10:15:29 -080081 if vndkVersion == mctx.DeviceConfig().PlatformVndkVersion() {
82 vndkVersion = "current"
83 } else {
84 vndkVersion = "v" + vndkVersion
85 }
86
87 vndkApexName := "com.android.vndk." + vndkVersion
88
89 if mctx.OtherModuleExists(vndkApexName) {
90 mctx.AddReverseDependency(mctx.Module(), sharedLibTag, vndkApexName)
Jiyong Park09d77522019-11-18 11:16:27 +090091 }
92 } else if a, ok := mctx.Module().(*apexBundle); ok && a.vndkApex {
93 vndkVersion := proptools.StringDefault(a.vndkProperties.Vndk_version, "current")
94 mctx.AddDependency(mctx.Module(), prebuiltTag, cc.VndkLibrariesTxtModules(vndkVersion)...)
95 }
96}
97
Jooyung Han002ab682020-01-08 01:57:58 +090098// name is module.BaseModuleName() which is used as LOCAL_MODULE_NAME and also LOCAL_OVERRIDES_*
99func makeCompatSymlinks(name string, ctx android.ModuleContext) (symlinks []string) {
Jiyong Park09d77522019-11-18 11:16:27 +0900100 // small helper to add symlink commands
101 addSymlink := func(target, dir, linkName string) {
Jooyung Han4791cb52019-10-25 18:17:23 +0900102 link := filepath.Join(dir, linkName)
103 symlinks = append(symlinks, "mkdir -p "+dir+" && rm -rf "+link+" && ln -sf "+target+" "+link)
Jiyong Park09d77522019-11-18 11:16:27 +0900104 }
105
106 // TODO(b/142911355): [VNDK APEX] Fix hard-coded references to /system/lib/vndk
107 // When all hard-coded references are fixed, remove symbolic links
108 // Note that we should keep following symlinks for older VNDKs (<=29)
109 // Since prebuilt vndk libs still depend on system/lib/vndk path
Jooyung Han055418a2020-04-14 14:22:31 +0900110 if strings.HasPrefix(name, vndkApexNamePrefix) {
111 vndkVersion := strings.TrimPrefix(name, vndkApexNamePrefix)
Dan Albertc8060532020-07-22 22:32:17 -0700112 if ver, err := android.ApiLevelFromUser(ctx, vndkVersion); err != nil {
Jooyung Han055418a2020-04-14 14:22:31 +0900113 ctx.ModuleErrorf("apex_vndk should be named as %v<ver:number>: %s", vndkApexNamePrefix, name)
114 return
Dan Albertc8060532020-07-22 22:32:17 -0700115 } else if ver.GreaterThan(android.SdkVersion_Android10) {
Jooyung Han055418a2020-04-14 14:22:31 +0900116 return
Jooyung Han002ab682020-01-08 01:57:58 +0900117 }
Jiyong Park09d77522019-11-18 11:16:27 +0900118 // the name of vndk apex is formatted "com.android.vndk.v" + version
Jooyung Han002ab682020-01-08 01:57:58 +0900119 apexName := vndkApexNamePrefix + vndkVersion
Jiyong Park09d77522019-11-18 11:16:27 +0900120 if ctx.Config().Android64() {
Jooyung Han4791cb52019-10-25 18:17:23 +0900121 addSymlink("/apex/"+apexName+"/lib64", "$(TARGET_OUT)/lib64", "vndk-sp-"+vndkVersion)
122 addSymlink("/apex/"+apexName+"/lib64", "$(TARGET_OUT)/lib64", "vndk-"+vndkVersion)
Jiyong Park09d77522019-11-18 11:16:27 +0900123 }
124 if !ctx.Config().Android64() || ctx.DeviceConfig().DeviceSecondaryArch() != "" {
Jooyung Han4791cb52019-10-25 18:17:23 +0900125 addSymlink("/apex/"+apexName+"/lib", "$(TARGET_OUT)/lib", "vndk-sp-"+vndkVersion)
126 addSymlink("/apex/"+apexName+"/lib", "$(TARGET_OUT)/lib", "vndk-"+vndkVersion)
127 }
Jooyung Han002ab682020-01-08 01:57:58 +0900128 return
Jooyung Han4791cb52019-10-25 18:17:23 +0900129 }
130
131 // http://b/121248172 - create a link from /system/usr/icu to
132 // /apex/com.android.i18n/etc/icu so that apps can find the ICU .dat file.
133 // A symlink can't overwrite a directory and the /system/usr/icu directory once
134 // existed so the required structure must be created whatever we find.
Jooyung Han002ab682020-01-08 01:57:58 +0900135 if name == "com.android.i18n" {
136 addSymlink("/apex/com.android.i18n/etc/icu", "$(TARGET_OUT)/usr", "icu")
137 return
Jooyung Han4791cb52019-10-25 18:17:23 +0900138 }
139
140 // TODO(b/124106384): Clean up compat symlinks for ART binaries.
Martin Stjernholm7f511072020-10-12 15:10:36 +0100141 if name == "com.android.art" || strings.HasPrefix(name, "com.android.art.") {
Nicolas Geoffrayd2a61c82020-04-29 12:00:41 +0100142 addSymlink("/apex/com.android.art/bin/dalvikvm", "$(TARGET_OUT)/bin", "dalvikvm")
143 dex2oat := "dex2oat32"
144 if ctx.Config().Android64() {
145 dex2oat = "dex2oat64"
Jiyong Park09d77522019-11-18 11:16:27 +0900146 }
Nicolas Geoffrayd2a61c82020-04-29 12:00:41 +0100147 addSymlink("/apex/com.android.art/bin/"+dex2oat, "$(TARGET_OUT)/bin", "dex2oat")
Jooyung Han002ab682020-01-08 01:57:58 +0900148 return
Jiyong Park09d77522019-11-18 11:16:27 +0900149 }
150 return
151}