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 ( |
| 18 | "path/filepath" |
Jooyung Han | 055418a | 2020-04-14 14:22:31 +0900 | [diff] [blame] | 19 | "strconv" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 20 | "strings" |
| 21 | "sync" |
| 22 | |
| 23 | "android/soong/android" |
| 24 | "android/soong/cc" |
| 25 | |
| 26 | "github.com/google/blueprint/proptools" |
| 27 | ) |
| 28 | |
| 29 | const ( |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 30 | vndkApexName = "com.android.vndk" |
| 31 | vndkApexNamePrefix = vndkApexName + ".v" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 32 | ) |
| 33 | |
| 34 | // apex_vndk creates a special variant of apex modules which contains only VNDK libraries. |
| 35 | // If `vndk_version` is specified, the VNDK libraries of the specified VNDK version are gathered automatically. |
| 36 | // If not specified, then the "current" versions are gathered. |
| 37 | func vndkApexBundleFactory() android.Module { |
| 38 | bundle := newApexBundle() |
| 39 | bundle.vndkApex = true |
| 40 | bundle.AddProperties(&bundle.vndkProperties) |
| 41 | android.AddLoadHook(bundle, func(ctx android.LoadHookContext) { |
| 42 | ctx.AppendProperties(&struct { |
| 43 | Compile_multilib *string |
| 44 | }{ |
| 45 | proptools.StringPtr("both"), |
| 46 | }) |
| 47 | }) |
| 48 | return bundle |
| 49 | } |
| 50 | |
| 51 | func (a *apexBundle) vndkVersion(config android.DeviceConfig) string { |
| 52 | vndkVersion := proptools.StringDefault(a.vndkProperties.Vndk_version, "current") |
| 53 | if vndkVersion == "current" { |
| 54 | vndkVersion = config.PlatformVndkVersion() |
| 55 | } |
| 56 | return vndkVersion |
| 57 | } |
| 58 | |
| 59 | type apexVndkProperties struct { |
| 60 | // Indicates VNDK version of which this VNDK APEX bundles VNDK libs. Default is Platform VNDK Version. |
| 61 | Vndk_version *string |
| 62 | } |
| 63 | |
| 64 | var ( |
| 65 | vndkApexListKey = android.NewOnceKey("vndkApexList") |
| 66 | vndkApexListMutex sync.Mutex |
| 67 | ) |
| 68 | |
| 69 | func vndkApexList(config android.Config) map[string]string { |
| 70 | return config.Once(vndkApexListKey, func() interface{} { |
| 71 | return map[string]string{} |
| 72 | }).(map[string]string) |
| 73 | } |
| 74 | |
| 75 | func apexVndkMutator(mctx android.TopDownMutatorContext) { |
| 76 | if ab, ok := mctx.Module().(*apexBundle); ok && ab.vndkApex { |
| 77 | if ab.IsNativeBridgeSupported() { |
| 78 | mctx.PropertyErrorf("native_bridge_supported", "%q doesn't support native bridge binary.", mctx.ModuleType()) |
| 79 | } |
| 80 | |
| 81 | vndkVersion := ab.vndkVersion(mctx.DeviceConfig()) |
| 82 | // Ensure VNDK APEX mount point is formatted as com.android.vndk.v### |
| 83 | ab.properties.Apex_name = proptools.StringPtr(vndkApexNamePrefix + vndkVersion) |
| 84 | |
| 85 | // vndk_version should be unique |
| 86 | vndkApexListMutex.Lock() |
| 87 | defer vndkApexListMutex.Unlock() |
| 88 | vndkApexList := vndkApexList(mctx.Config()) |
| 89 | if other, ok := vndkApexList[vndkVersion]; ok { |
| 90 | mctx.PropertyErrorf("vndk_version", "%v is already defined in %q", vndkVersion, other) |
| 91 | } |
| 92 | vndkApexList[vndkVersion] = mctx.ModuleName() |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | func apexVndkDepsMutator(mctx android.BottomUpMutatorContext) { |
| 97 | if m, ok := mctx.Module().(*cc.Module); ok && cc.IsForVndkApex(mctx, m) { |
| 98 | vndkVersion := m.VndkVersion() |
Jooyung Han | 73d20d0 | 2020-03-27 16:06:55 +0900 | [diff] [blame] | 99 | // For VNDK-Lite device, we gather core-variants of VNDK-Sp libraries, which doesn't have VNDK version defined |
| 100 | if vndkVersion == "" { |
| 101 | vndkVersion = mctx.DeviceConfig().PlatformVndkVersion() |
| 102 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 103 | vndkApexList := vndkApexList(mctx.Config()) |
| 104 | if vndkApex, ok := vndkApexList[vndkVersion]; ok { |
| 105 | mctx.AddReverseDependency(mctx.Module(), sharedLibTag, vndkApex) |
| 106 | } |
| 107 | } else if a, ok := mctx.Module().(*apexBundle); ok && a.vndkApex { |
| 108 | vndkVersion := proptools.StringDefault(a.vndkProperties.Vndk_version, "current") |
| 109 | mctx.AddDependency(mctx.Module(), prebuiltTag, cc.VndkLibrariesTxtModules(vndkVersion)...) |
| 110 | } |
| 111 | } |
| 112 | |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 113 | // name is module.BaseModuleName() which is used as LOCAL_MODULE_NAME and also LOCAL_OVERRIDES_* |
| 114 | func makeCompatSymlinks(name string, ctx android.ModuleContext) (symlinks []string) { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 115 | // small helper to add symlink commands |
| 116 | addSymlink := func(target, dir, linkName string) { |
Jooyung Han | 4791cb5 | 2019-10-25 18:17:23 +0900 | [diff] [blame] | 117 | link := filepath.Join(dir, linkName) |
| 118 | symlinks = append(symlinks, "mkdir -p "+dir+" && rm -rf "+link+" && ln -sf "+target+" "+link) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | // TODO(b/142911355): [VNDK APEX] Fix hard-coded references to /system/lib/vndk |
| 122 | // When all hard-coded references are fixed, remove symbolic links |
| 123 | // Note that we should keep following symlinks for older VNDKs (<=29) |
| 124 | // Since prebuilt vndk libs still depend on system/lib/vndk path |
Jooyung Han | 055418a | 2020-04-14 14:22:31 +0900 | [diff] [blame] | 125 | if strings.HasPrefix(name, vndkApexNamePrefix) { |
| 126 | vndkVersion := strings.TrimPrefix(name, vndkApexNamePrefix) |
| 127 | if numVer, err := strconv.Atoi(vndkVersion); err != nil { |
| 128 | ctx.ModuleErrorf("apex_vndk should be named as %v<ver:number>: %s", vndkApexNamePrefix, name) |
| 129 | return |
| 130 | } else if numVer > android.SdkVersion_Android10 { |
| 131 | return |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 132 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 133 | // the name of vndk apex is formatted "com.android.vndk.v" + version |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 134 | apexName := vndkApexNamePrefix + vndkVersion |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 135 | if ctx.Config().Android64() { |
Jooyung Han | 4791cb5 | 2019-10-25 18:17:23 +0900 | [diff] [blame] | 136 | addSymlink("/apex/"+apexName+"/lib64", "$(TARGET_OUT)/lib64", "vndk-sp-"+vndkVersion) |
| 137 | addSymlink("/apex/"+apexName+"/lib64", "$(TARGET_OUT)/lib64", "vndk-"+vndkVersion) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 138 | } |
| 139 | if !ctx.Config().Android64() || ctx.DeviceConfig().DeviceSecondaryArch() != "" { |
Jooyung Han | 4791cb5 | 2019-10-25 18:17:23 +0900 | [diff] [blame] | 140 | addSymlink("/apex/"+apexName+"/lib", "$(TARGET_OUT)/lib", "vndk-sp-"+vndkVersion) |
| 141 | addSymlink("/apex/"+apexName+"/lib", "$(TARGET_OUT)/lib", "vndk-"+vndkVersion) |
| 142 | } |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 143 | return |
Jooyung Han | 4791cb5 | 2019-10-25 18:17:23 +0900 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | // http://b/121248172 - create a link from /system/usr/icu to |
| 147 | // /apex/com.android.i18n/etc/icu so that apps can find the ICU .dat file. |
| 148 | // A symlink can't overwrite a directory and the /system/usr/icu directory once |
| 149 | // existed so the required structure must be created whatever we find. |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 150 | if name == "com.android.i18n" { |
| 151 | addSymlink("/apex/com.android.i18n/etc/icu", "$(TARGET_OUT)/usr", "icu") |
| 152 | return |
Jooyung Han | 4791cb5 | 2019-10-25 18:17:23 +0900 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | // TODO(b/124106384): Clean up compat symlinks for ART binaries. |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 156 | if strings.HasPrefix(name, "com.android.art.") { |
Nicolas Geoffray | d2a61c8 | 2020-04-29 12:00:41 +0100 | [diff] [blame] | 157 | addSymlink("/apex/com.android.art/bin/dalvikvm", "$(TARGET_OUT)/bin", "dalvikvm") |
| 158 | dex2oat := "dex2oat32" |
| 159 | if ctx.Config().Android64() { |
| 160 | dex2oat = "dex2oat64" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 161 | } |
Nicolas Geoffray | d2a61c8 | 2020-04-29 12:00:41 +0100 | [diff] [blame] | 162 | addSymlink("/apex/com.android.art/bin/"+dex2oat, "$(TARGET_OUT)/bin", "dex2oat") |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 163 | return |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 164 | } |
| 165 | return |
| 166 | } |