Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1 | // Copyright 2020 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 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 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 | package cc |
| 15 | |
| 16 | import ( |
| 17 | "encoding/json" |
| 18 | "path/filepath" |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 19 | "strings" |
| 20 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 21 | "android/soong/android" |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 22 | "android/soong/snapshot" |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 23 | ) |
| 24 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 25 | // This file defines how to capture cc modules into snapshot package. |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 26 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 27 | // Checks if the target image would contain VNDK |
| 28 | func includeVndk(image snapshot.SnapshotImage) bool { |
| 29 | if image.ImageName() == snapshot.VendorSnapshotImageName { |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 30 | return true |
| 31 | } |
| 32 | |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 33 | return false |
| 34 | } |
| 35 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 36 | // Check if the module is VNDK private |
| 37 | func isPrivate(image snapshot.SnapshotImage, m LinkableInterface) bool { |
| 38 | if image.ImageName() == snapshot.VendorSnapshotImageName && m.IsVndkPrivate() { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 39 | return true |
| 40 | } |
| 41 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 42 | return false |
| 43 | } |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 44 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 45 | // Checks if target image supports VNDK Ext |
| 46 | func supportsVndkExt(image snapshot.SnapshotImage) bool { |
| 47 | if image.ImageName() == snapshot.VendorSnapshotImageName { |
| 48 | return true |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | return false |
| 52 | } |
| 53 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 54 | // Determines if the module is a candidate for snapshot. |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 55 | func isSnapshotAware(cfg android.DeviceConfig, m LinkableInterface, inProprietaryPath bool, apexInfo android.ApexInfo, image snapshot.SnapshotImage) bool { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 56 | if !m.Enabled() || m.HiddenFromMake() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 57 | return false |
| 58 | } |
Martin Stjernholm | 809d518 | 2020-09-10 01:46:05 +0100 | [diff] [blame] | 59 | // When android/prebuilt.go selects between source and prebuilt, it sets |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 60 | // HideFromMake on the other one to avoid duplicate install rules in make. |
| 61 | if m.IsHideFromMake() { |
Martin Stjernholm | 809d518 | 2020-09-10 01:46:05 +0100 | [diff] [blame] | 62 | return false |
| 63 | } |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 64 | // skip proprietary modules, but (for the vendor snapshot only) |
| 65 | // include all VNDK (static) |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 66 | if inProprietaryPath && (!includeVndk(image) || !m.IsVndk()) { |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 67 | return false |
| 68 | } |
| 69 | // If the module would be included based on its path, check to see if |
| 70 | // the module is marked to be excluded. If so, skip it. |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 71 | if image.ExcludeFromSnapshot(m) { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 72 | return false |
| 73 | } |
| 74 | if m.Target().Os.Class != android.Device { |
| 75 | return false |
| 76 | } |
| 77 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
| 78 | return false |
| 79 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 80 | // the module must be installed in target image |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 81 | if !apexInfo.IsForPlatform() || m.IsSnapshotPrebuilt() || !image.InImage(m)() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 82 | return false |
| 83 | } |
Inseob Kim | 65ca36a | 2020-06-11 13:55:45 +0900 | [diff] [blame] | 84 | // skip kernel_headers which always depend on vendor |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 85 | if m.KernelHeadersDecorator() { |
Inseob Kim | 65ca36a | 2020-06-11 13:55:45 +0900 | [diff] [blame] | 86 | return false |
| 87 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 88 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 89 | if m.IsLlndk() { |
| 90 | return false |
| 91 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 92 | |
| 93 | // Libraries |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 94 | if sanitizable, ok := m.(PlatformSanitizeable); ok && sanitizable.IsSnapshotLibrary() { |
| 95 | if sanitizable.SanitizePropDefined() { |
Justin Yun | 8814fc5 | 2022-12-15 21:45:35 +0900 | [diff] [blame] | 96 | // scs exports both sanitized and unsanitized variants for static and header |
| 97 | // Always use unsanitized variant of it. |
Ivan Lozano | 22823ee | 2023-07-31 18:01:26 +0000 | [diff] [blame] | 98 | if !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(scs) { |
Justin Yun | 8814fc5 | 2022-12-15 21:45:35 +0900 | [diff] [blame] | 99 | return false |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 100 | } |
Justin Yun | a05a4f6 | 2023-09-25 23:07:49 +0900 | [diff] [blame] | 101 | // cfi and hwasan cannot be enabled at the same time. |
| 102 | // Skip variants that have both cfi and hwasan enabled. |
| 103 | if sanitizable.IsSanitizerEnabled(cfi) && sanitizable.IsSanitizerEnabled(Hwasan) { |
| 104 | return false |
| 105 | } |
Justin Yun | 8814fc5 | 2022-12-15 21:45:35 +0900 | [diff] [blame] | 106 | // cfi and hwasan also export both variants. But for static, we capture both. |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 107 | // This is because cfi static libraries can't be linked from non-cfi modules, |
Justin Yun | 8814fc5 | 2022-12-15 21:45:35 +0900 | [diff] [blame] | 108 | // and vice versa. |
| 109 | // hwasan is captured as well to support hwasan build. |
| 110 | if !sanitizable.Static() && |
| 111 | !sanitizable.Shared() && |
| 112 | (sanitizable.IsSanitizerEnabled(cfi) || sanitizable.IsSanitizerEnabled(Hwasan)) { |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 113 | return false |
| 114 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 115 | } |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 116 | if sanitizable.Static() || sanitizable.Rlib() { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 117 | return sanitizable.OutputFile().Valid() && !isPrivate(image, m) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 118 | } |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 119 | if sanitizable.Shared() || sanitizable.Dylib() { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 120 | if !sanitizable.OutputFile().Valid() { |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 121 | return false |
| 122 | } |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 123 | if includeVndk(image) { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 124 | if !sanitizable.IsVndk() { |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 125 | return true |
| 126 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 127 | return sanitizable.IsVndkExt() |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 128 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 129 | } |
| 130 | return true |
| 131 | } |
| 132 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 133 | // Binaries and Objects |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 134 | if m.Binary() || m.Object() { |
| 135 | return m.OutputFile().Valid() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 136 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 137 | |
| 138 | return false |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 139 | } |
| 140 | |
Rob Seymour | 925aa09 | 2021-08-10 20:42:03 +0000 | [diff] [blame] | 141 | // Extend the snapshot.SnapshotJsonFlags to include cc specific fields. |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 142 | type snapshotJsonFlags struct { |
Rob Seymour | 925aa09 | 2021-08-10 20:42:03 +0000 | [diff] [blame] | 143 | snapshot.SnapshotJsonFlags |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 144 | // library flags |
| 145 | ExportedDirs []string `json:",omitempty"` |
| 146 | ExportedSystemDirs []string `json:",omitempty"` |
| 147 | ExportedFlags []string `json:",omitempty"` |
| 148 | Sanitize string `json:",omitempty"` |
| 149 | SanitizeMinimalDep bool `json:",omitempty"` |
| 150 | SanitizeUbsanDep bool `json:",omitempty"` |
| 151 | |
| 152 | // binary flags |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 153 | Symlinks []string `json:",omitempty"` |
| 154 | StaticExecutable bool `json:",omitempty"` |
Jose Galmes | c1a56bc | 2022-03-07 14:07:59 -0800 | [diff] [blame] | 155 | InstallInRoot bool `json:",omitempty"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 156 | |
| 157 | // dependencies |
| 158 | SharedLibs []string `json:",omitempty"` |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 159 | StaticLibs []string `json:",omitempty"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 160 | RuntimeLibs []string `json:",omitempty"` |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 161 | Dylibs []string `json:",omitempty"` |
| 162 | Rlibs []string `json:",omitempty"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 163 | |
| 164 | // extra config files |
| 165 | InitRc []string `json:",omitempty"` |
| 166 | VintfFragments []string `json:",omitempty"` |
Inseob Kim | 5860f82 | 2023-04-18 11:30:22 +0900 | [diff] [blame] | 167 | MinSdkVersion string `json:",omitempty"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 168 | } |
| 169 | |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 170 | var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) snapshot.SnapshotPaths { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 171 | /* |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 172 | Vendor snapshot zipped artifacts directory structure for cc modules: |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 173 | {SNAPSHOT_ARCH}/ |
| 174 | arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/ |
| 175 | shared/ |
| 176 | (.so shared libraries) |
| 177 | static/ |
| 178 | (.a static libraries) |
| 179 | header/ |
| 180 | (header only libraries) |
| 181 | binary/ |
| 182 | (executable binaries) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 183 | object/ |
| 184 | (.o object files) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 185 | arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/ |
| 186 | shared/ |
| 187 | (.so shared libraries) |
| 188 | static/ |
| 189 | (.a static libraries) |
| 190 | header/ |
| 191 | (header only libraries) |
| 192 | binary/ |
| 193 | (executable binaries) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 194 | object/ |
| 195 | (.o object files) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 196 | NOTICE_FILES/ |
| 197 | (notice files, e.g. libbase.txt) |
| 198 | configs/ |
| 199 | (config files, e.g. init.rc files, vintf_fragments.xml files, etc.) |
| 200 | include/ |
| 201 | (header files of same directory structure with source tree) |
| 202 | */ |
| 203 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 204 | var snapshotOutputs android.Paths |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 205 | var snapshotNotices android.Paths |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 206 | |
| 207 | includeDir := filepath.Join(snapshotArchDir, "include") |
| 208 | configsDir := filepath.Join(snapshotArchDir, "configs") |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 209 | |
| 210 | installedNotices := make(map[string]bool) |
| 211 | installedConfigs := make(map[string]bool) |
| 212 | |
| 213 | var headers android.Paths |
| 214 | |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 215 | copyFile := func(ctx android.SingletonContext, path android.Path, out string, fake bool) android.OutputPath { |
| 216 | if fake { |
| 217 | // All prebuilt binaries and headers are installed by copyFile function. This makes a fake |
| 218 | // snapshot just touch prebuilts and headers, rather than installing real files. |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 219 | return snapshot.WriteStringToFileRule(ctx, "", out) |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 220 | } else { |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 221 | return snapshot.CopyFileRule(pctx, ctx, path, out) |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 225 | // installSnapshot function copies prebuilt file (.so, .a, or executable) and json flag file. |
| 226 | // For executables, init_rc and vintf_fragments files are also copied. |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 227 | installSnapshot := func(m LinkableInterface, fake bool) android.Paths { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 228 | targetArch := "arch-" + m.Target().Arch.ArchType.String() |
| 229 | if m.Target().Arch.ArchVariant != "" { |
| 230 | targetArch += "-" + m.Target().Arch.ArchVariant |
| 231 | } |
| 232 | |
| 233 | var ret android.Paths |
| 234 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 235 | prop := snapshotJsonFlags{} |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 236 | |
| 237 | // Common properties among snapshots. |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 238 | prop.InitBaseSnapshotPropsWithName(m, ctx.ModuleName(m)) |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 239 | if supportsVndkExt(s.Image) && m.IsVndkExt() { |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 240 | // vndk exts are installed to /vendor/lib(64)?/vndk(-sp)? |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 241 | if m.IsVndkSp() { |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 242 | prop.RelativeInstallPath = "vndk-sp" |
| 243 | } else { |
| 244 | prop.RelativeInstallPath = "vndk" |
| 245 | } |
| 246 | } else { |
| 247 | prop.RelativeInstallPath = m.RelativeInstallPath() |
| 248 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 249 | prop.RuntimeLibs = m.SnapshotRuntimeLibs() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 250 | prop.Required = m.RequiredModuleNames() |
Inseob Kim | a1888ce | 2022-10-04 14:42:02 +0900 | [diff] [blame] | 251 | if o, ok := m.(overridable); ok { |
| 252 | prop.Overrides = o.overriddenModules() |
| 253 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 254 | for _, path := range m.InitRc() { |
| 255 | prop.InitRc = append(prop.InitRc, filepath.Join("configs", path.Base())) |
| 256 | } |
| 257 | for _, path := range m.VintfFragments() { |
| 258 | prop.VintfFragments = append(prop.VintfFragments, filepath.Join("configs", path.Base())) |
| 259 | } |
Justin Yun | 3cc7846 | 2023-05-08 21:06:59 +0900 | [diff] [blame] | 260 | if m.IsPrebuilt() { |
| 261 | prop.MinSdkVersion = "apex_inherit" |
| 262 | } else { |
| 263 | prop.MinSdkVersion = m.MinSdkVersion() |
| 264 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 265 | |
| 266 | // install config files. ignores any duplicates. |
| 267 | for _, path := range append(m.InitRc(), m.VintfFragments()...) { |
| 268 | out := filepath.Join(configsDir, path.Base()) |
| 269 | if !installedConfigs[out] { |
| 270 | installedConfigs[out] = true |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 271 | ret = append(ret, copyFile(ctx, path, out, fake)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | |
| 275 | var propOut string |
| 276 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 277 | if m.IsSnapshotLibrary() { |
Colin Cross | 5a37718 | 2023-12-14 14:46:23 -0800 | [diff] [blame] | 278 | exporterInfo, _ := android.SingletonModuleProvider(ctx, m.Module(), FlagExporterInfoProvider) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 279 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 280 | // library flags |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 281 | prop.ExportedFlags = exporterInfo.Flags |
| 282 | for _, dir := range exporterInfo.IncludeDirs { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 283 | prop.ExportedDirs = append(prop.ExportedDirs, filepath.Join("include", dir.String())) |
| 284 | } |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 285 | for _, dir := range exporterInfo.SystemIncludeDirs { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 286 | prop.ExportedSystemDirs = append(prop.ExportedSystemDirs, filepath.Join("include", dir.String())) |
| 287 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 288 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 289 | // shared libs dependencies aren't meaningful on static or header libs |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 290 | if m.Shared() { |
| 291 | prop.SharedLibs = m.SnapshotSharedLibs() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 292 | } |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 293 | |
| 294 | // dylibs collect both shared and dylib dependencies. |
| 295 | if m.Dylib() { |
| 296 | prop.SharedLibs = m.SnapshotSharedLibs() |
| 297 | prop.Dylibs = m.SnapshotDylibs() |
| 298 | } |
| 299 | |
| 300 | // static and rlib libs dependencies are required to collect the NOTICE files. |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 301 | prop.StaticLibs = m.SnapshotStaticLibs() |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 302 | prop.Rlibs = m.SnapshotRlibs() |
| 303 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 304 | if sanitizable, ok := m.(PlatformSanitizeable); ok { |
| 305 | if sanitizable.Static() && sanitizable.SanitizePropDefined() { |
| 306 | prop.SanitizeMinimalDep = sanitizable.MinimalRuntimeDep() || sanitizable.MinimalRuntimeNeeded() |
| 307 | prop.SanitizeUbsanDep = sanitizable.UbsanRuntimeDep() || sanitizable.UbsanRuntimeNeeded() |
| 308 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | var libType string |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 312 | if m.Static() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 313 | libType = "static" |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 314 | } else if m.Shared() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 315 | libType = "shared" |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 316 | } else if m.Rlib() { |
| 317 | libType = "rlib" |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 318 | } else if m.Dylib() { |
| 319 | libType = "dylib" |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 320 | } else { |
| 321 | libType = "header" |
| 322 | } |
| 323 | |
| 324 | var stem string |
| 325 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 326 | // install .a, .rlib, .dylib.so, or .so |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 327 | if libType != "header" { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 328 | libPath := m.OutputFile().Path() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 329 | stem = libPath.Base() |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 330 | if sanitizable, ok := m.(PlatformSanitizeable); ok { |
Justin Yun | 8814fc5 | 2022-12-15 21:45:35 +0900 | [diff] [blame] | 331 | if (sanitizable.Static() || sanitizable.Rlib()) && sanitizable.SanitizePropDefined() { |
| 332 | if sanitizable.IsSanitizerEnabled(cfi) { |
| 333 | // both cfi and non-cfi variant for static libraries can exist. |
| 334 | // attach .cfi to distinguish between cfi and non-cfi. |
| 335 | // e.g. libbase.a -> libbase.cfi.a |
| 336 | ext := filepath.Ext(stem) |
| 337 | stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext |
| 338 | prop.Sanitize = "cfi" |
| 339 | prop.ModuleName += ".cfi" |
| 340 | } else if sanitizable.IsSanitizerEnabled(Hwasan) { |
| 341 | // Same for the hwasan |
| 342 | ext := filepath.Ext(stem) |
| 343 | stem = strings.TrimSuffix(stem, ext) + ".hwasan" + ext |
| 344 | prop.Sanitize = "hwasan" |
| 345 | prop.ModuleName += ".hwasan" |
| 346 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 347 | } |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 348 | } |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 349 | if m.Rlib() && m.RlibStd() { |
| 350 | // rlibs produce both rlib-std and dylib-std variants |
| 351 | ext := filepath.Ext(stem) |
| 352 | stem = strings.TrimSuffix(stem, ext) + ".rlib-std" + ext |
| 353 | prop.ModuleName += ".rlib-std" |
| 354 | } |
Justin Yun | 17d0ee2 | 2023-05-02 14:56:38 +0900 | [diff] [blame] | 355 | snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, m.RelativeInstallPath(), stem) |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 356 | ret = append(ret, copyFile(ctx, libPath, snapshotLibOut, fake)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 357 | } else { |
| 358 | stem = ctx.ModuleName(m) |
| 359 | } |
| 360 | |
Justin Yun | 17d0ee2 | 2023-05-02 14:56:38 +0900 | [diff] [blame] | 361 | propOut = filepath.Join(snapshotArchDir, targetArch, libType, m.RelativeInstallPath(), stem+".json") |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 362 | } else if m.Binary() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 363 | // binary flags |
| 364 | prop.Symlinks = m.Symlinks() |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 365 | prop.StaticExecutable = m.StaticExecutable() |
Jose Galmes | c1a56bc | 2022-03-07 14:07:59 -0800 | [diff] [blame] | 366 | prop.InstallInRoot = m.InstallInRoot() |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 367 | prop.SharedLibs = m.SnapshotSharedLibs() |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 368 | prop.Dylibs = m.SnapshotDylibs() |
| 369 | |
| 370 | // static and rlib dependencies are required to collect the NOTICE files. |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 371 | prop.StaticLibs = m.SnapshotStaticLibs() |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 372 | prop.Rlibs = m.SnapshotRlibs() |
| 373 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 374 | // install bin |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 375 | binPath := m.OutputFile().Path() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 376 | snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base()) |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 377 | ret = append(ret, copyFile(ctx, binPath, snapshotBinOut, fake)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 378 | propOut = snapshotBinOut + ".json" |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 379 | } else if m.Object() { |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 380 | // object files aren't installed to the device, so their names can conflict. |
| 381 | // Use module name as stem. |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 382 | objPath := m.OutputFile().Path() |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 383 | snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object", |
| 384 | ctx.ModuleName(m)+filepath.Ext(objPath.Base())) |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 385 | ret = append(ret, copyFile(ctx, objPath, snapshotObjOut, fake)) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 386 | propOut = snapshotObjOut + ".json" |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 387 | } else { |
| 388 | ctx.Errorf("unknown module %q in vendor snapshot", m.String()) |
| 389 | return nil |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | j, err := json.Marshal(prop) |
| 393 | if err != nil { |
| 394 | ctx.Errorf("json marshal to %q failed: %#v", propOut, err) |
| 395 | return nil |
| 396 | } |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 397 | ret = append(ret, snapshot.WriteStringToFileRule(ctx, string(j), propOut)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 398 | |
| 399 | return ret |
| 400 | } |
| 401 | |
| 402 | ctx.VisitAllModules(func(module android.Module) { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 403 | m, ok := module.(LinkableInterface) |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 404 | if !ok { |
| 405 | return |
| 406 | } |
| 407 | |
| 408 | moduleDir := ctx.ModuleDir(module) |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 409 | inProprietaryPath := s.Image.IsProprietaryPath(moduleDir, ctx.DeviceConfig()) |
Colin Cross | 5a37718 | 2023-12-14 14:46:23 -0800 | [diff] [blame] | 410 | apexInfo, _ := android.SingletonModuleProvider(ctx, module, android.ApexInfoProvider) |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 411 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 412 | if s.Image.ExcludeFromSnapshot(m) { |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 413 | if inProprietaryPath { |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 414 | // Error: exclude_from_vendor_snapshot applies |
| 415 | // to framework-path modules only. |
| 416 | ctx.Errorf("module %q in vendor proprietary path %q may not use \"exclude_from_vendor_snapshot: true\"", m.String(), moduleDir) |
| 417 | return |
| 418 | } |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 421 | if !isSnapshotAware(ctx.DeviceConfig(), m, inProprietaryPath, apexInfo, s.Image) { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 422 | return |
| 423 | } |
| 424 | |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 425 | // If we are using directed snapshot and a module is not included in the |
| 426 | // list, we will still include the module as if it was a fake module. |
| 427 | // The reason is that soong needs all the dependencies to be present, even |
| 428 | // if they are not using during the build. |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 429 | installAsFake := s.Fake |
| 430 | if s.Image.ExcludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) { |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 431 | installAsFake = true |
| 432 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 433 | |
Jose Galmes | 0a942a0 | 2021-02-03 14:23:15 -0800 | [diff] [blame] | 434 | // installSnapshot installs prebuilts and json flag files |
| 435 | snapshotOutputs = append(snapshotOutputs, installSnapshot(m, installAsFake)...) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 436 | // just gather headers and notice files here, because they are to be deduplicated |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 437 | if m.IsSnapshotLibrary() { |
| 438 | headers = append(headers, m.SnapshotHeaders()...) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 439 | } |
| 440 | |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 441 | for _, notice := range m.EffectiveLicenseFiles() { |
| 442 | if _, ok := installedNotices[notice.String()]; !ok { |
| 443 | installedNotices[notice.String()] = true |
| 444 | snapshotNotices = append(snapshotNotices, notice) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | }) |
| 448 | |
| 449 | // install all headers after removing duplicates |
| 450 | for _, header := range android.FirstUniquePaths(headers) { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 451 | snapshotOutputs = append(snapshotOutputs, copyFile(ctx, header, filepath.Join(includeDir, header.String()), s.Fake)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 452 | } |
| 453 | |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 454 | return snapshot.SnapshotPaths{OutputFiles: snapshotOutputs, NoticeFiles: snapshotNotices} |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 455 | } |
| 456 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 457 | func init() { |
| 458 | snapshot.RegisterSnapshotAction(ccSnapshotAction) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 459 | } |