Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package apex |
| 16 | |
| 17 | import ( |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 18 | "strings" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 19 | |
| 20 | "android/soong/android" |
| 21 | "android/soong/cc" |
| 22 | |
| 23 | "github.com/google/blueprint/proptools" |
| 24 | ) |
| 25 | |
| 26 | const ( |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 27 | vndkApexName = "com.android.vndk" |
| 28 | vndkApexNamePrefix = vndkApexName + ".v" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 29 | ) |
| 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. |
| 34 | func 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 | |
| 48 | func (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 | |
| 56 | type 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 Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 61 | func 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()) |
Kiyoung Kim | 8487c0b | 2024-01-11 16:03:13 +0900 | [diff] [blame^] | 68 | if vndkVersion != "" { |
| 69 | apiLevel, err := android.ApiLevelFromUser(mctx, vndkVersion) |
| 70 | if err != nil { |
| 71 | mctx.PropertyErrorf("vndk_version", "%s", err.Error()) |
| 72 | return |
| 73 | } |
Colin Cross | bb137a3 | 2023-01-26 09:54:42 -0800 | [diff] [blame] | 74 | |
Kiyoung Kim | 8487c0b | 2024-01-11 16:03:13 +0900 | [diff] [blame^] | 75 | targets := mctx.MultiTargets() |
| 76 | if len(targets) > 0 && apiLevel.LessThan(cc.MinApiForArch(mctx, targets[0].Arch.ArchType)) && |
| 77 | vndkVersion != mctx.DeviceConfig().PlatformVndkVersion() { |
| 78 | // Disable VNDK APEXes for VNDK versions less than the minimum supported API |
| 79 | // level for the primary architecture. This validation is skipped if the VNDK |
| 80 | // version matches the platform VNDK version, which can occur when the device |
| 81 | // config targets the 'current' VNDK (see `vndkVersion`). |
| 82 | ab.Disable() |
| 83 | } |
| 84 | if proptools.String(ab.vndkProperties.Vndk_version) != "" && |
| 85 | mctx.DeviceConfig().PlatformVndkVersion() != "" && |
| 86 | apiLevel.GreaterThanOrEqualTo(android.ApiLevelOrPanic(mctx, mctx.DeviceConfig().PlatformVndkVersion())) { |
| 87 | ab.Disable() |
| 88 | } |
Justin Yun | f14beaf | 2023-08-18 17:51:14 +0900 | [diff] [blame] | 89 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
| 93 | func apexVndkDepsMutator(mctx android.BottomUpMutatorContext) { |
| 94 | if m, ok := mctx.Module().(*cc.Module); ok && cc.IsForVndkApex(mctx, m) { |
| 95 | vndkVersion := m.VndkVersion() |
Jooyung Han | 73d20d0 | 2020-03-27 16:06:55 +0900 | [diff] [blame] | 96 | // For VNDK-Lite device, we gather core-variants of VNDK-Sp libraries, which doesn't have VNDK version defined |
| 97 | if vndkVersion == "" { |
| 98 | vndkVersion = mctx.DeviceConfig().PlatformVndkVersion() |
| 99 | } |
Kiyoung Kim | 8487c0b | 2024-01-11 16:03:13 +0900 | [diff] [blame^] | 100 | |
| 101 | if vndkVersion == "" { |
| 102 | return |
| 103 | } |
| 104 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 105 | if vndkVersion == mctx.DeviceConfig().PlatformVndkVersion() { |
| 106 | vndkVersion = "current" |
| 107 | } else { |
| 108 | vndkVersion = "v" + vndkVersion |
| 109 | } |
| 110 | |
| 111 | vndkApexName := "com.android.vndk." + vndkVersion |
| 112 | |
| 113 | if mctx.OtherModuleExists(vndkApexName) { |
| 114 | mctx.AddReverseDependency(mctx.Module(), sharedLibTag, vndkApexName) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 115 | } |
| 116 | } else if a, ok := mctx.Module().(*apexBundle); ok && a.vndkApex { |
| 117 | vndkVersion := proptools.StringDefault(a.vndkProperties.Vndk_version, "current") |
Kiyoung Kim | a2d6dee | 2023-08-11 10:14:43 +0900 | [diff] [blame] | 118 | mctx.AddDependency(mctx.Module(), prebuiltTag, cc.VndkLibrariesTxtModules(vndkVersion, mctx)...) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 122 | // name is module.BaseModuleName() which is used as LOCAL_MODULE_NAME and also LOCAL_OVERRIDES_* |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 123 | func makeCompatSymlinks(name string, ctx android.ModuleContext) (symlinks android.InstallPaths) { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 124 | // small helper to add symlink commands |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 125 | addSymlink := func(target string, dir android.InstallPath, linkName string) { |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 126 | symlinks = append(symlinks, ctx.InstallAbsoluteSymlink(dir, linkName, target)) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | // TODO(b/142911355): [VNDK APEX] Fix hard-coded references to /system/lib/vndk |
| 130 | // When all hard-coded references are fixed, remove symbolic links |
| 131 | // Note that we should keep following symlinks for older VNDKs (<=29) |
| 132 | // Since prebuilt vndk libs still depend on system/lib/vndk path |
Jooyung Han | 055418a | 2020-04-14 14:22:31 +0900 | [diff] [blame] | 133 | if strings.HasPrefix(name, vndkApexNamePrefix) { |
| 134 | vndkVersion := strings.TrimPrefix(name, vndkApexNamePrefix) |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 135 | if ver, err := android.ApiLevelFromUser(ctx, vndkVersion); err != nil { |
Jooyung Han | 055418a | 2020-04-14 14:22:31 +0900 | [diff] [blame] | 136 | ctx.ModuleErrorf("apex_vndk should be named as %v<ver:number>: %s", vndkApexNamePrefix, name) |
| 137 | return |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 138 | } else if ver.GreaterThan(android.SdkVersion_Android10) { |
Jooyung Han | 055418a | 2020-04-14 14:22:31 +0900 | [diff] [blame] | 139 | return |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 140 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 141 | // the name of vndk apex is formatted "com.android.vndk.v" + version |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 142 | apexName := vndkApexNamePrefix + vndkVersion |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 143 | if ctx.Config().Android64() { |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 144 | dir := android.PathForModuleInPartitionInstall(ctx, "system", "lib64") |
| 145 | addSymlink("/apex/"+apexName+"/lib64", dir, "vndk-sp-"+vndkVersion) |
| 146 | addSymlink("/apex/"+apexName+"/lib64", dir, "vndk-"+vndkVersion) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 147 | } |
| 148 | if !ctx.Config().Android64() || ctx.DeviceConfig().DeviceSecondaryArch() != "" { |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 149 | dir := android.PathForModuleInPartitionInstall(ctx, "system", "lib") |
| 150 | addSymlink("/apex/"+apexName+"/lib", dir, "vndk-sp-"+vndkVersion) |
| 151 | addSymlink("/apex/"+apexName+"/lib", dir, "vndk-"+vndkVersion) |
Jooyung Han | 4791cb5 | 2019-10-25 18:17:23 +0900 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
| 155 | // http://b/121248172 - create a link from /system/usr/icu to |
| 156 | // /apex/com.android.i18n/etc/icu so that apps can find the ICU .dat file. |
| 157 | // A symlink can't overwrite a directory and the /system/usr/icu directory once |
| 158 | // existed so the required structure must be created whatever we find. |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 159 | if name == "com.android.i18n" { |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 160 | dir := android.PathForModuleInPartitionInstall(ctx, "system", "usr") |
| 161 | addSymlink("/apex/com.android.i18n/etc/icu", dir, "icu") |
Jooyung Han | 4791cb5 | 2019-10-25 18:17:23 +0900 | [diff] [blame] | 162 | } |
| 163 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 164 | return symlinks |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 165 | } |