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 | |
Cole Faust | a0463d3 | 2024-10-03 11:26:41 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 24 | "github.com/google/blueprint/proptools" |
| 25 | ) |
| 26 | |
| 27 | const ( |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 28 | vndkApexName = "com.android.vndk" |
| 29 | vndkApexNamePrefix = vndkApexName + ".v" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 30 | ) |
| 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. |
| 35 | func 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 | |
Kiyoung Kim | fa13ff1 | 2024-03-18 16:01:19 +0900 | [diff] [blame] | 49 | func (a *apexBundle) vndkVersion() string { |
| 50 | return proptools.StringDefault(a.vndkProperties.Vndk_version, "current") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | type apexVndkProperties struct { |
Kiyoung Kim | fa13ff1 | 2024-03-18 16:01:19 +0900 | [diff] [blame] | 54 | // Indicates VNDK version of which this VNDK APEX bundles VNDK libs. |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 55 | Vndk_version *string |
| 56 | } |
| 57 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 58 | func apexVndkDepsMutator(mctx android.BottomUpMutatorContext) { |
| 59 | if m, ok := mctx.Module().(*cc.Module); ok && cc.IsForVndkApex(mctx, m) { |
| 60 | vndkVersion := m.VndkVersion() |
Kiyoung Kim | 8487c0b | 2024-01-11 16:03:13 +0900 | [diff] [blame] | 61 | |
| 62 | if vndkVersion == "" { |
| 63 | return |
| 64 | } |
Kiyoung Kim | fa13ff1 | 2024-03-18 16:01:19 +0900 | [diff] [blame] | 65 | vndkVersion = "v" + vndkVersion |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 66 | |
| 67 | vndkApexName := "com.android.vndk." + vndkVersion |
| 68 | |
| 69 | if mctx.OtherModuleExists(vndkApexName) { |
Cole Faust | a0463d3 | 2024-10-03 11:26:41 -0700 | [diff] [blame] | 70 | // Reverse dependencies must exactly specify the variant they want, starting from the |
| 71 | // current module's variant. But unlike cc modules, the vndk apex doesn't have |
| 72 | // arch/image/link variations, so we explicitly remove them here. |
| 73 | mctx.AddReverseVariationDependency([]blueprint.Variation{ |
| 74 | {Mutator: "arch", Variation: "common"}, |
| 75 | {Mutator: "image", Variation: ""}, |
| 76 | {Mutator: "link", Variation: ""}, |
| 77 | }, sharedLibTag, vndkApexName) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 78 | } |
| 79 | } else if a, ok := mctx.Module().(*apexBundle); ok && a.vndkApex { |
Colin Cross | da279cf | 2024-09-17 14:25:45 -0700 | [diff] [blame] | 80 | if a.IsNativeBridgeSupported() { |
| 81 | mctx.PropertyErrorf("native_bridge_supported", "%q doesn't support native bridge binary.", mctx.ModuleType()) |
| 82 | } |
| 83 | |
| 84 | vndkVersion := a.vndkVersion() |
| 85 | if vndkVersion != "" { |
| 86 | apiLevel, err := android.ApiLevelFromUser(mctx, vndkVersion) |
| 87 | if err != nil { |
| 88 | mctx.PropertyErrorf("vndk_version", "%s", err.Error()) |
| 89 | return |
| 90 | } |
| 91 | |
| 92 | targets := mctx.MultiTargets() |
| 93 | if len(targets) > 0 && apiLevel.LessThan(cc.MinApiForArch(mctx, targets[0].Arch.ArchType)) { |
| 94 | // Disable VNDK APEXes for VNDK versions less than the minimum supported API |
| 95 | // level for the primary architecture. |
| 96 | a.Disable() |
| 97 | } else { |
Cole Faust | 6978879 | 2024-10-10 11:00:36 -0700 | [diff] [blame] | 98 | mctx.AddVariationDependencies( |
| 99 | mctx.Config().AndroidFirstDeviceTarget.Variations(), |
| 100 | prebuiltTag, |
| 101 | cc.VndkLibrariesTxtModules(vndkVersion, mctx)..., |
| 102 | ) |
Colin Cross | da279cf | 2024-09-17 14:25:45 -0700 | [diff] [blame] | 103 | } |
| 104 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 108 | // 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] | 109 | func makeCompatSymlinks(name string, ctx android.ModuleContext) (symlinks android.InstallPaths) { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 110 | // small helper to add symlink commands |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 111 | addSymlink := func(target string, dir android.InstallPath, linkName string) { |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 112 | symlinks = append(symlinks, ctx.InstallAbsoluteSymlink(dir, linkName, target)) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | // TODO(b/142911355): [VNDK APEX] Fix hard-coded references to /system/lib/vndk |
| 116 | // When all hard-coded references are fixed, remove symbolic links |
| 117 | // Note that we should keep following symlinks for older VNDKs (<=29) |
| 118 | // Since prebuilt vndk libs still depend on system/lib/vndk path |
Jooyung Han | 055418a | 2020-04-14 14:22:31 +0900 | [diff] [blame] | 119 | if strings.HasPrefix(name, vndkApexNamePrefix) { |
| 120 | vndkVersion := strings.TrimPrefix(name, vndkApexNamePrefix) |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 121 | if ver, err := android.ApiLevelFromUser(ctx, vndkVersion); err != nil { |
Jooyung Han | 055418a | 2020-04-14 14:22:31 +0900 | [diff] [blame] | 122 | ctx.ModuleErrorf("apex_vndk should be named as %v<ver:number>: %s", vndkApexNamePrefix, name) |
| 123 | return |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 124 | } else if ver.GreaterThan(android.SdkVersion_Android10) { |
Jooyung Han | 055418a | 2020-04-14 14:22:31 +0900 | [diff] [blame] | 125 | return |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 126 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 127 | // the name of vndk apex is formatted "com.android.vndk.v" + version |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 128 | apexName := vndkApexNamePrefix + vndkVersion |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 129 | if ctx.Config().Android64() { |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 130 | dir := android.PathForModuleInPartitionInstall(ctx, "system", "lib64") |
| 131 | addSymlink("/apex/"+apexName+"/lib64", dir, "vndk-sp-"+vndkVersion) |
| 132 | addSymlink("/apex/"+apexName+"/lib64", dir, "vndk-"+vndkVersion) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 133 | } |
| 134 | if !ctx.Config().Android64() || ctx.DeviceConfig().DeviceSecondaryArch() != "" { |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 135 | dir := android.PathForModuleInPartitionInstall(ctx, "system", "lib") |
| 136 | addSymlink("/apex/"+apexName+"/lib", dir, "vndk-sp-"+vndkVersion) |
| 137 | addSymlink("/apex/"+apexName+"/lib", dir, "vndk-"+vndkVersion) |
Jooyung Han | 4791cb5 | 2019-10-25 18:17:23 +0900 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
| 141 | // http://b/121248172 - create a link from /system/usr/icu to |
| 142 | // /apex/com.android.i18n/etc/icu so that apps can find the ICU .dat file. |
| 143 | // A symlink can't overwrite a directory and the /system/usr/icu directory once |
| 144 | // existed so the required structure must be created whatever we find. |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 145 | if name == "com.android.i18n" { |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 146 | dir := android.PathForModuleInPartitionInstall(ctx, "system", "usr") |
| 147 | addSymlink("/apex/com.android.i18n/etc/icu", dir, "icu") |
Jooyung Han | 4791cb5 | 2019-10-25 18:17:23 +0900 | [diff] [blame] | 148 | } |
| 149 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 150 | return symlinks |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 151 | } |