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 | // |
| 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 | package cc |
| 15 | |
| 16 | import ( |
| 17 | "encoding/json" |
| 18 | "path/filepath" |
| 19 | "sort" |
| 20 | "strings" |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 21 | "sync" |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 22 | |
| 23 | "github.com/google/blueprint/proptools" |
| 24 | |
| 25 | "android/soong/android" |
| 26 | ) |
| 27 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 28 | const ( |
| 29 | vendorSnapshotHeaderSuffix = ".vendor_header." |
| 30 | vendorSnapshotSharedSuffix = ".vendor_shared." |
| 31 | vendorSnapshotStaticSuffix = ".vendor_static." |
| 32 | vendorSnapshotBinarySuffix = ".vendor_binary." |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 33 | vendorSnapshotObjectSuffix = ".vendor_object." |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 34 | ) |
| 35 | |
| 36 | var ( |
| 37 | vendorSnapshotsLock sync.Mutex |
| 38 | vendorSuffixModulesKey = android.NewOnceKey("vendorSuffixModules") |
| 39 | vendorSnapshotHeaderLibsKey = android.NewOnceKey("vendorSnapshotHeaderLibs") |
| 40 | vendorSnapshotStaticLibsKey = android.NewOnceKey("vendorSnapshotStaticLibs") |
| 41 | vendorSnapshotSharedLibsKey = android.NewOnceKey("vendorSnapshotSharedLibs") |
| 42 | vendorSnapshotBinariesKey = android.NewOnceKey("vendorSnapshotBinaries") |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 43 | vendorSnapshotObjectsKey = android.NewOnceKey("vendorSnapshotObjects") |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 44 | ) |
| 45 | |
Inseob Kim | 5f64aec | 2020-02-18 17:27:19 +0900 | [diff] [blame] | 46 | // vendor snapshot maps hold names of vendor snapshot modules per arch |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 47 | func vendorSuffixModules(config android.Config) map[string]bool { |
| 48 | return config.Once(vendorSuffixModulesKey, func() interface{} { |
| 49 | return make(map[string]bool) |
| 50 | }).(map[string]bool) |
| 51 | } |
| 52 | |
| 53 | func vendorSnapshotHeaderLibs(config android.Config) *snapshotMap { |
| 54 | return config.Once(vendorSnapshotHeaderLibsKey, func() interface{} { |
| 55 | return newSnapshotMap() |
| 56 | }).(*snapshotMap) |
| 57 | } |
| 58 | |
| 59 | func vendorSnapshotSharedLibs(config android.Config) *snapshotMap { |
| 60 | return config.Once(vendorSnapshotSharedLibsKey, func() interface{} { |
| 61 | return newSnapshotMap() |
| 62 | }).(*snapshotMap) |
| 63 | } |
| 64 | |
| 65 | func vendorSnapshotStaticLibs(config android.Config) *snapshotMap { |
| 66 | return config.Once(vendorSnapshotStaticLibsKey, func() interface{} { |
| 67 | return newSnapshotMap() |
| 68 | }).(*snapshotMap) |
| 69 | } |
| 70 | |
| 71 | func vendorSnapshotBinaries(config android.Config) *snapshotMap { |
| 72 | return config.Once(vendorSnapshotBinariesKey, func() interface{} { |
| 73 | return newSnapshotMap() |
| 74 | }).(*snapshotMap) |
| 75 | } |
| 76 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 77 | func vendorSnapshotObjects(config android.Config) *snapshotMap { |
| 78 | return config.Once(vendorSnapshotObjectsKey, func() interface{} { |
| 79 | return newSnapshotMap() |
| 80 | }).(*snapshotMap) |
| 81 | } |
| 82 | |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 83 | type vendorSnapshotBaseProperties struct { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 84 | // snapshot version. |
| 85 | Version string |
| 86 | |
| 87 | // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64') |
| 88 | Target_arch string |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 89 | } |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 90 | |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 91 | // vendorSnapshotModuleBase provides common basic functions for all snapshot modules. |
| 92 | type vendorSnapshotModuleBase struct { |
| 93 | baseProperties vendorSnapshotBaseProperties |
| 94 | moduleSuffix string |
| 95 | } |
| 96 | |
| 97 | func (p *vendorSnapshotModuleBase) Name(name string) string { |
| 98 | return name + p.NameSuffix() |
| 99 | } |
| 100 | |
| 101 | func (p *vendorSnapshotModuleBase) NameSuffix() string { |
| 102 | versionSuffix := p.version() |
| 103 | if p.arch() != "" { |
| 104 | versionSuffix += "." + p.arch() |
| 105 | } |
| 106 | |
| 107 | return p.moduleSuffix + versionSuffix |
| 108 | } |
| 109 | |
| 110 | func (p *vendorSnapshotModuleBase) version() string { |
| 111 | return p.baseProperties.Version |
| 112 | } |
| 113 | |
| 114 | func (p *vendorSnapshotModuleBase) arch() string { |
| 115 | return p.baseProperties.Target_arch |
| 116 | } |
| 117 | |
| 118 | func (p *vendorSnapshotModuleBase) isSnapshotPrebuilt() bool { |
| 119 | return true |
| 120 | } |
| 121 | |
| 122 | // Call this after creating a snapshot module with module suffix |
| 123 | // such as vendorSnapshotSharedSuffix |
| 124 | func (p *vendorSnapshotModuleBase) init(m *Module, suffix string) { |
| 125 | p.moduleSuffix = suffix |
| 126 | m.AddProperties(&p.baseProperties) |
| 127 | android.AddLoadHook(m, func(ctx android.LoadHookContext) { |
| 128 | vendorSnapshotLoadHook(ctx, p) |
| 129 | }) |
| 130 | } |
| 131 | |
| 132 | func vendorSnapshotLoadHook(ctx android.LoadHookContext, p *vendorSnapshotModuleBase) { |
| 133 | if p.version() != ctx.DeviceConfig().VndkVersion() { |
| 134 | ctx.Module().Disable() |
| 135 | return |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | type vendorSnapshotLibraryProperties struct { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 140 | // Prebuilt file for each arch. |
| 141 | Src *string `android:"arch_variant"` |
| 142 | |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 143 | // list of directories that will be added to the include path (using -I). |
| 144 | Export_include_dirs []string `android:"arch_variant"` |
| 145 | |
| 146 | // list of directories that will be added to the system path (using -isystem). |
| 147 | Export_system_include_dirs []string `android:"arch_variant"` |
| 148 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 149 | // list of flags that will be used for any module that links against this module. |
| 150 | Export_flags []string `android:"arch_variant"` |
| 151 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 152 | // Whether this prebuilt needs to depend on sanitize ubsan runtime or not. |
| 153 | Sanitize_ubsan_dep *bool `android:"arch_variant"` |
| 154 | |
| 155 | // Whether this prebuilt needs to depend on sanitize minimal runtime or not. |
| 156 | Sanitize_minimal_dep *bool `android:"arch_variant"` |
| 157 | } |
| 158 | |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 159 | type snapshotSanitizer interface { |
| 160 | isSanitizerEnabled(t sanitizerType) bool |
| 161 | setSanitizerVariation(t sanitizerType, enabled bool) |
| 162 | } |
| 163 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 164 | type vendorSnapshotLibraryDecorator struct { |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 165 | vendorSnapshotModuleBase |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 166 | *libraryDecorator |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 167 | properties vendorSnapshotLibraryProperties |
| 168 | sanitizerProperties struct { |
| 169 | CfiEnabled bool `blueprint:"mutated"` |
| 170 | |
| 171 | // Library flags for cfi variant. |
| 172 | Cfi vendorSnapshotLibraryProperties `android:"arch_variant"` |
| 173 | } |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 174 | androidMkVendorSuffix bool |
| 175 | } |
| 176 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 177 | func (p *vendorSnapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
| 178 | p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix()) |
| 179 | return p.libraryDecorator.linkerFlags(ctx, flags) |
| 180 | } |
| 181 | |
| 182 | func (p *vendorSnapshotLibraryDecorator) matchesWithDevice(config android.DeviceConfig) bool { |
| 183 | arches := config.Arches() |
| 184 | if len(arches) == 0 || arches[0].ArchType.String() != p.arch() { |
| 185 | return false |
| 186 | } |
| 187 | if !p.header() && p.properties.Src == nil { |
| 188 | return false |
| 189 | } |
| 190 | return true |
| 191 | } |
| 192 | |
| 193 | func (p *vendorSnapshotLibraryDecorator) link(ctx ModuleContext, |
| 194 | flags Flags, deps PathDeps, objs Objects) android.Path { |
| 195 | m := ctx.Module().(*Module) |
| 196 | p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()] |
| 197 | |
| 198 | if p.header() { |
| 199 | return p.libraryDecorator.link(ctx, flags, deps, objs) |
| 200 | } |
| 201 | |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 202 | if p.sanitizerProperties.CfiEnabled { |
| 203 | p.properties = p.sanitizerProperties.Cfi |
| 204 | } |
| 205 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 206 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 207 | return nil |
| 208 | } |
| 209 | |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 210 | p.libraryDecorator.reexportDirs(android.PathsForModuleSrc(ctx, p.properties.Export_include_dirs)...) |
| 211 | p.libraryDecorator.reexportSystemDirs(android.PathsForModuleSrc(ctx, p.properties.Export_system_include_dirs)...) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 212 | p.libraryDecorator.reexportFlags(p.properties.Export_flags...) |
| 213 | |
| 214 | in := android.PathForModuleSrc(ctx, *p.properties.Src) |
| 215 | p.unstrippedOutputFile = in |
| 216 | |
| 217 | if p.shared() { |
| 218 | libName := in.Base() |
| 219 | builderFlags := flagsToBuilderFlags(flags) |
| 220 | |
| 221 | // Optimize out relinking against shared libraries whose interface hasn't changed by |
| 222 | // depending on a table of contents file instead of the library itself. |
| 223 | tocFile := android.PathForModuleOut(ctx, libName+".toc") |
| 224 | p.tocFile = android.OptionalPathForPath(tocFile) |
| 225 | TransformSharedObjectToToc(ctx, in, tocFile, builderFlags) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame^] | 226 | |
| 227 | ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ |
| 228 | SharedLibrary: in, |
| 229 | UnstrippedSharedLibrary: p.unstrippedOutputFile, |
| 230 | |
| 231 | TableOfContents: p.tocFile, |
| 232 | }) |
| 233 | } |
| 234 | |
| 235 | if p.static() { |
| 236 | depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build() |
| 237 | ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{ |
| 238 | StaticLibrary: in, |
| 239 | |
| 240 | TransitiveStaticLibrariesForOrdering: depSet, |
| 241 | }) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | return in |
| 245 | } |
| 246 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 247 | func (p *vendorSnapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) { |
| 248 | if p.matchesWithDevice(ctx.DeviceConfig()) && (p.shared() || p.static()) { |
| 249 | p.baseInstaller.install(ctx, file) |
| 250 | } |
| 251 | } |
| 252 | |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 253 | func (p *vendorSnapshotLibraryDecorator) nativeCoverage() bool { |
| 254 | return false |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 255 | } |
| 256 | |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 257 | func (p *vendorSnapshotLibraryDecorator) isSanitizerEnabled(t sanitizerType) bool { |
| 258 | switch t { |
| 259 | case cfi: |
| 260 | return p.sanitizerProperties.Cfi.Src != nil |
| 261 | default: |
| 262 | return false |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | func (p *vendorSnapshotLibraryDecorator) setSanitizerVariation(t sanitizerType, enabled bool) { |
| 267 | if !enabled { |
| 268 | return |
| 269 | } |
| 270 | switch t { |
| 271 | case cfi: |
| 272 | p.sanitizerProperties.CfiEnabled = true |
| 273 | default: |
| 274 | return |
| 275 | } |
| 276 | } |
| 277 | |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 278 | func vendorSnapshotLibrary(suffix string) (*Module, *vendorSnapshotLibraryDecorator) { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 279 | module, library := NewLibrary(android.DeviceSupported) |
| 280 | |
| 281 | module.stl = nil |
| 282 | module.sanitize = nil |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 283 | library.disableStripping() |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 284 | |
| 285 | prebuilt := &vendorSnapshotLibraryDecorator{ |
| 286 | libraryDecorator: library, |
| 287 | } |
| 288 | |
| 289 | prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true) |
| 290 | prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true) |
| 291 | |
| 292 | // Prevent default system libs (libc, libm, and libdl) from being linked |
| 293 | if prebuilt.baseLinker.Properties.System_shared_libs == nil { |
| 294 | prebuilt.baseLinker.Properties.System_shared_libs = []string{} |
| 295 | } |
| 296 | |
| 297 | module.compiler = nil |
| 298 | module.linker = prebuilt |
| 299 | module.installer = prebuilt |
| 300 | |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 301 | prebuilt.init(module, suffix) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 302 | module.AddProperties( |
| 303 | &prebuilt.properties, |
| 304 | &prebuilt.sanitizerProperties, |
| 305 | ) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 306 | |
| 307 | return module, prebuilt |
| 308 | } |
| 309 | |
| 310 | func VendorSnapshotSharedFactory() android.Module { |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 311 | module, prebuilt := vendorSnapshotLibrary(vendorSnapshotSharedSuffix) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 312 | prebuilt.libraryDecorator.BuildOnlyShared() |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 313 | return module.Init() |
| 314 | } |
| 315 | |
| 316 | func VendorSnapshotStaticFactory() android.Module { |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 317 | module, prebuilt := vendorSnapshotLibrary(vendorSnapshotStaticSuffix) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 318 | prebuilt.libraryDecorator.BuildOnlyStatic() |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 319 | return module.Init() |
| 320 | } |
| 321 | |
| 322 | func VendorSnapshotHeaderFactory() android.Module { |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 323 | module, prebuilt := vendorSnapshotLibrary(vendorSnapshotHeaderSuffix) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 324 | prebuilt.libraryDecorator.HeaderOnly() |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 325 | return module.Init() |
| 326 | } |
| 327 | |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 328 | var _ snapshotSanitizer = (*vendorSnapshotLibraryDecorator)(nil) |
| 329 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 330 | type vendorSnapshotBinaryProperties struct { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 331 | // Prebuilt file for each arch. |
| 332 | Src *string `android:"arch_variant"` |
| 333 | } |
| 334 | |
| 335 | type vendorSnapshotBinaryDecorator struct { |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 336 | vendorSnapshotModuleBase |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 337 | *binaryDecorator |
| 338 | properties vendorSnapshotBinaryProperties |
| 339 | androidMkVendorSuffix bool |
| 340 | } |
| 341 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 342 | func (p *vendorSnapshotBinaryDecorator) matchesWithDevice(config android.DeviceConfig) bool { |
| 343 | if config.DeviceArch() != p.arch() { |
| 344 | return false |
| 345 | } |
| 346 | if p.properties.Src == nil { |
| 347 | return false |
| 348 | } |
| 349 | return true |
| 350 | } |
| 351 | |
| 352 | func (p *vendorSnapshotBinaryDecorator) link(ctx ModuleContext, |
| 353 | flags Flags, deps PathDeps, objs Objects) android.Path { |
| 354 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 355 | return nil |
| 356 | } |
| 357 | |
| 358 | in := android.PathForModuleSrc(ctx, *p.properties.Src) |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 359 | stripFlags := flagsToStripFlags(flags) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 360 | p.unstrippedOutputFile = in |
| 361 | binName := in.Base() |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 362 | if p.stripper.NeedsStrip(ctx) { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 363 | stripped := android.PathForModuleOut(ctx, "stripped", binName) |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 364 | p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 365 | in = stripped |
| 366 | } |
| 367 | |
| 368 | m := ctx.Module().(*Module) |
| 369 | p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()] |
| 370 | |
| 371 | // use cpExecutable to make it executable |
| 372 | outputFile := android.PathForModuleOut(ctx, binName) |
| 373 | ctx.Build(pctx, android.BuildParams{ |
| 374 | Rule: android.CpExecutable, |
| 375 | Description: "prebuilt", |
| 376 | Output: outputFile, |
| 377 | Input: in, |
| 378 | }) |
| 379 | |
| 380 | return outputFile |
| 381 | } |
| 382 | |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 383 | func (p *vendorSnapshotBinaryDecorator) nativeCoverage() bool { |
| 384 | return false |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 385 | } |
| 386 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 387 | func VendorSnapshotBinaryFactory() android.Module { |
| 388 | module, binary := NewBinary(android.DeviceSupported) |
| 389 | binary.baseLinker.Properties.No_libcrt = BoolPtr(true) |
| 390 | binary.baseLinker.Properties.Nocrt = BoolPtr(true) |
| 391 | |
| 392 | // Prevent default system libs (libc, libm, and libdl) from being linked |
| 393 | if binary.baseLinker.Properties.System_shared_libs == nil { |
| 394 | binary.baseLinker.Properties.System_shared_libs = []string{} |
| 395 | } |
| 396 | |
| 397 | prebuilt := &vendorSnapshotBinaryDecorator{ |
| 398 | binaryDecorator: binary, |
| 399 | } |
| 400 | |
| 401 | module.compiler = nil |
| 402 | module.sanitize = nil |
| 403 | module.stl = nil |
| 404 | module.linker = prebuilt |
| 405 | |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 406 | prebuilt.init(module, vendorSnapshotBinarySuffix) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 407 | module.AddProperties(&prebuilt.properties) |
| 408 | return module.Init() |
| 409 | } |
| 410 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 411 | type vendorSnapshotObjectProperties struct { |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 412 | // Prebuilt file for each arch. |
| 413 | Src *string `android:"arch_variant"` |
| 414 | } |
| 415 | |
| 416 | type vendorSnapshotObjectLinker struct { |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 417 | vendorSnapshotModuleBase |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 418 | objectLinker |
| 419 | properties vendorSnapshotObjectProperties |
| 420 | androidMkVendorSuffix bool |
| 421 | } |
| 422 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 423 | func (p *vendorSnapshotObjectLinker) matchesWithDevice(config android.DeviceConfig) bool { |
| 424 | if config.DeviceArch() != p.arch() { |
| 425 | return false |
| 426 | } |
| 427 | if p.properties.Src == nil { |
| 428 | return false |
| 429 | } |
| 430 | return true |
| 431 | } |
| 432 | |
| 433 | func (p *vendorSnapshotObjectLinker) link(ctx ModuleContext, |
| 434 | flags Flags, deps PathDeps, objs Objects) android.Path { |
| 435 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 436 | return nil |
| 437 | } |
| 438 | |
| 439 | m := ctx.Module().(*Module) |
| 440 | p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()] |
| 441 | |
| 442 | return android.PathForModuleSrc(ctx, *p.properties.Src) |
| 443 | } |
| 444 | |
| 445 | func (p *vendorSnapshotObjectLinker) nativeCoverage() bool { |
| 446 | return false |
| 447 | } |
| 448 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 449 | func VendorSnapshotObjectFactory() android.Module { |
| 450 | module := newObject() |
| 451 | |
| 452 | prebuilt := &vendorSnapshotObjectLinker{ |
| 453 | objectLinker: objectLinker{ |
| 454 | baseLinker: NewBaseLinker(nil), |
| 455 | }, |
| 456 | } |
| 457 | module.linker = prebuilt |
| 458 | |
Inseob Kim | 2d34ad9 | 2020-07-30 21:04:09 +0900 | [diff] [blame] | 459 | prebuilt.init(module, vendorSnapshotObjectSuffix) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 460 | module.AddProperties(&prebuilt.properties) |
| 461 | return module.Init() |
| 462 | } |
| 463 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 464 | func init() { |
| 465 | android.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 466 | android.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory) |
| 467 | android.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory) |
| 468 | android.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory) |
| 469 | android.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 470 | android.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | func VendorSnapshotSingleton() android.Singleton { |
| 474 | return &vendorSnapshotSingleton{} |
| 475 | } |
| 476 | |
| 477 | type vendorSnapshotSingleton struct { |
| 478 | vendorSnapshotZipFile android.OptionalPath |
| 479 | } |
| 480 | |
| 481 | var ( |
| 482 | // Modules under following directories are ignored. They are OEM's and vendor's |
Daniel Norman | 713387d | 2020-07-28 16:04:38 -0700 | [diff] [blame] | 483 | // proprietary modules(device/, kernel/, vendor/, and hardware/). |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 484 | // TODO(b/65377115): Clean up these with more maintainable way |
| 485 | vendorProprietaryDirs = []string{ |
| 486 | "device", |
Daniel Norman | 713387d | 2020-07-28 16:04:38 -0700 | [diff] [blame] | 487 | "kernel", |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 488 | "vendor", |
| 489 | "hardware", |
| 490 | } |
| 491 | |
| 492 | // Modules under following directories are included as they are in AOSP, |
Daniel Norman | 713387d | 2020-07-28 16:04:38 -0700 | [diff] [blame] | 493 | // although hardware/ and kernel/ are normally for vendor's own. |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 494 | // TODO(b/65377115): Clean up these with more maintainable way |
| 495 | aospDirsUnderProprietary = []string{ |
Daniel Norman | 713387d | 2020-07-28 16:04:38 -0700 | [diff] [blame] | 496 | "kernel/configs", |
| 497 | "kernel/prebuilts", |
| 498 | "kernel/tests", |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 499 | "hardware/interfaces", |
| 500 | "hardware/libhardware", |
| 501 | "hardware/libhardware_legacy", |
| 502 | "hardware/ril", |
| 503 | } |
| 504 | ) |
| 505 | |
| 506 | // Determine if a dir under source tree is an SoC-owned proprietary directory, such as |
| 507 | // device/, vendor/, etc. |
| 508 | func isVendorProprietaryPath(dir string) bool { |
| 509 | for _, p := range vendorProprietaryDirs { |
| 510 | if strings.HasPrefix(dir, p) { |
| 511 | // filter out AOSP defined directories, e.g. hardware/interfaces/ |
| 512 | aosp := false |
| 513 | for _, p := range aospDirsUnderProprietary { |
| 514 | if strings.HasPrefix(dir, p) { |
| 515 | aosp = true |
| 516 | break |
| 517 | } |
| 518 | } |
| 519 | if !aosp { |
| 520 | return true |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | return false |
| 525 | } |
| 526 | |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 527 | func isVendorProprietaryModule(ctx android.BaseModuleContext) bool { |
| 528 | |
| 529 | // Any module in a vendor proprietary path is a vendor proprietary |
| 530 | // module. |
| 531 | |
| 532 | if isVendorProprietaryPath(ctx.ModuleDir()) { |
| 533 | return true |
| 534 | } |
| 535 | |
| 536 | // However if the module is not in a vendor proprietary path, it may |
| 537 | // still be a vendor proprietary module. This happens for cc modules |
| 538 | // that are excluded from the vendor snapshot, and it means that the |
| 539 | // vendor has assumed control of the framework-provided module. |
| 540 | |
| 541 | if c, ok := ctx.Module().(*Module); ok { |
| 542 | if c.ExcludeFromVendorSnapshot() { |
| 543 | return true |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | return false |
| 548 | } |
| 549 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 550 | // Determine if a module is going to be included in vendor snapshot or not. |
| 551 | // |
| 552 | // Targets of vendor snapshot are "vendor: true" or "vendor_available: true" modules in |
| 553 | // AOSP. They are not guaranteed to be compatible with older vendor images. (e.g. might |
| 554 | // depend on newer VNDK) So they are captured as vendor snapshot To build older vendor |
| 555 | // image and newer system image altogether. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 556 | func isVendorSnapshotModule(m *Module, inVendorProprietaryPath bool, apexInfo android.ApexInfo) bool { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 557 | if !m.Enabled() || m.Properties.HideFromMake { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 558 | return false |
| 559 | } |
Martin Stjernholm | 809d518 | 2020-09-10 01:46:05 +0100 | [diff] [blame] | 560 | // When android/prebuilt.go selects between source and prebuilt, it sets |
| 561 | // SkipInstall on the other one to avoid duplicate install rules in make. |
| 562 | if m.IsSkipInstall() { |
| 563 | return false |
| 564 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 565 | // skip proprietary modules, but include all VNDK (static) |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 566 | if inVendorProprietaryPath && !m.IsVndk() { |
| 567 | return false |
| 568 | } |
| 569 | // If the module would be included based on its path, check to see if |
| 570 | // the module is marked to be excluded. If so, skip it. |
| 571 | if m.ExcludeFromVendorSnapshot() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 572 | return false |
| 573 | } |
| 574 | if m.Target().Os.Class != android.Device { |
| 575 | return false |
| 576 | } |
| 577 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
| 578 | return false |
| 579 | } |
| 580 | // the module must be installed in /vendor |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 581 | if !apexInfo.IsForPlatform() || m.isSnapshotPrebuilt() || !m.inVendor() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 582 | return false |
| 583 | } |
Inseob Kim | 65ca36a | 2020-06-11 13:55:45 +0900 | [diff] [blame] | 584 | // skip kernel_headers which always depend on vendor |
| 585 | if _, ok := m.linker.(*kernelHeadersDecorator); ok { |
| 586 | return false |
| 587 | } |
Justin Yun | f2664c6 | 2020-07-30 18:57:54 +0900 | [diff] [blame] | 588 | // skip llndk_library and llndk_headers which are backward compatible |
| 589 | if _, ok := m.linker.(*llndkStubDecorator); ok { |
| 590 | return false |
| 591 | } |
| 592 | if _, ok := m.linker.(*llndkHeadersDecorator); ok { |
| 593 | return false |
| 594 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 595 | |
| 596 | // Libraries |
| 597 | if l, ok := m.linker.(snapshotLibraryInterface); ok { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 598 | // TODO(b/65377115): add full support for sanitizer |
| 599 | if m.sanitize != nil { |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 600 | // scs and hwasan export both sanitized and unsanitized variants for static and header |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 601 | // Always use unsanitized variants of them. |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 602 | for _, t := range []sanitizerType{scs, hwasan} { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 603 | if !l.shared() && m.sanitize.isSanitizerEnabled(t) { |
| 604 | return false |
| 605 | } |
| 606 | } |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 607 | // cfi also exports both variants. But for static, we capture both. |
| 608 | if !l.static() && !l.shared() && m.sanitize.isSanitizerEnabled(cfi) { |
| 609 | return false |
| 610 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 611 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 612 | if l.static() { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 613 | return m.outputFile.Valid() && proptools.BoolDefault(m.VendorProperties.Vendor_available, true) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 614 | } |
| 615 | if l.shared() { |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 616 | if !m.outputFile.Valid() { |
| 617 | return false |
| 618 | } |
| 619 | if !m.IsVndk() { |
| 620 | return true |
| 621 | } |
| 622 | return m.isVndkExt() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 623 | } |
| 624 | return true |
| 625 | } |
| 626 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 627 | // Binaries and Objects |
| 628 | if m.binary() || m.object() { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 629 | return m.outputFile.Valid() && proptools.BoolDefault(m.VendorProperties.Vendor_available, true) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 630 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 631 | |
| 632 | return false |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 636 | // BOARD_VNDK_VERSION must be set to 'current' in order to generate a vendor snapshot. |
| 637 | if ctx.DeviceConfig().VndkVersion() != "current" { |
| 638 | return |
| 639 | } |
| 640 | |
| 641 | var snapshotOutputs android.Paths |
| 642 | |
| 643 | /* |
| 644 | Vendor snapshot zipped artifacts directory structure: |
| 645 | {SNAPSHOT_ARCH}/ |
| 646 | arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/ |
| 647 | shared/ |
| 648 | (.so shared libraries) |
| 649 | static/ |
| 650 | (.a static libraries) |
| 651 | header/ |
| 652 | (header only libraries) |
| 653 | binary/ |
| 654 | (executable binaries) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 655 | object/ |
| 656 | (.o object files) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 657 | arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/ |
| 658 | shared/ |
| 659 | (.so shared libraries) |
| 660 | static/ |
| 661 | (.a static libraries) |
| 662 | header/ |
| 663 | (header only libraries) |
| 664 | binary/ |
| 665 | (executable binaries) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 666 | object/ |
| 667 | (.o object files) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 668 | NOTICE_FILES/ |
| 669 | (notice files, e.g. libbase.txt) |
| 670 | configs/ |
| 671 | (config files, e.g. init.rc files, vintf_fragments.xml files, etc.) |
| 672 | include/ |
| 673 | (header files of same directory structure with source tree) |
| 674 | */ |
| 675 | |
| 676 | snapshotDir := "vendor-snapshot" |
| 677 | snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch()) |
| 678 | |
| 679 | includeDir := filepath.Join(snapshotArchDir, "include") |
| 680 | configsDir := filepath.Join(snapshotArchDir, "configs") |
| 681 | noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES") |
| 682 | |
| 683 | installedNotices := make(map[string]bool) |
| 684 | installedConfigs := make(map[string]bool) |
| 685 | |
| 686 | var headers android.Paths |
| 687 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 688 | installSnapshot := func(m *Module) android.Paths { |
| 689 | targetArch := "arch-" + m.Target().Arch.ArchType.String() |
| 690 | if m.Target().Arch.ArchVariant != "" { |
| 691 | targetArch += "-" + m.Target().Arch.ArchVariant |
| 692 | } |
| 693 | |
| 694 | var ret android.Paths |
| 695 | |
| 696 | prop := struct { |
| 697 | ModuleName string `json:",omitempty"` |
| 698 | RelativeInstallPath string `json:",omitempty"` |
| 699 | |
| 700 | // library flags |
| 701 | ExportedDirs []string `json:",omitempty"` |
| 702 | ExportedSystemDirs []string `json:",omitempty"` |
| 703 | ExportedFlags []string `json:",omitempty"` |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 704 | Sanitize string `json:",omitempty"` |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 705 | SanitizeMinimalDep bool `json:",omitempty"` |
| 706 | SanitizeUbsanDep bool `json:",omitempty"` |
| 707 | |
| 708 | // binary flags |
| 709 | Symlinks []string `json:",omitempty"` |
| 710 | |
| 711 | // dependencies |
| 712 | SharedLibs []string `json:",omitempty"` |
| 713 | RuntimeLibs []string `json:",omitempty"` |
| 714 | Required []string `json:",omitempty"` |
| 715 | |
| 716 | // extra config files |
| 717 | InitRc []string `json:",omitempty"` |
| 718 | VintfFragments []string `json:",omitempty"` |
| 719 | }{} |
| 720 | |
| 721 | // Common properties among snapshots. |
| 722 | prop.ModuleName = ctx.ModuleName(m) |
Bill Peckham | 7d3f096 | 2020-06-29 16:49:15 -0700 | [diff] [blame] | 723 | if m.isVndkExt() { |
| 724 | // vndk exts are installed to /vendor/lib(64)?/vndk(-sp)? |
| 725 | if m.isVndkSp() { |
| 726 | prop.RelativeInstallPath = "vndk-sp" |
| 727 | } else { |
| 728 | prop.RelativeInstallPath = "vndk" |
| 729 | } |
| 730 | } else { |
| 731 | prop.RelativeInstallPath = m.RelativeInstallPath() |
| 732 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 733 | prop.RuntimeLibs = m.Properties.SnapshotRuntimeLibs |
| 734 | prop.Required = m.RequiredModuleNames() |
| 735 | for _, path := range m.InitRc() { |
| 736 | prop.InitRc = append(prop.InitRc, filepath.Join("configs", path.Base())) |
| 737 | } |
| 738 | for _, path := range m.VintfFragments() { |
| 739 | prop.VintfFragments = append(prop.VintfFragments, filepath.Join("configs", path.Base())) |
| 740 | } |
| 741 | |
| 742 | // install config files. ignores any duplicates. |
| 743 | for _, path := range append(m.InitRc(), m.VintfFragments()...) { |
| 744 | out := filepath.Join(configsDir, path.Base()) |
| 745 | if !installedConfigs[out] { |
| 746 | installedConfigs[out] = true |
| 747 | ret = append(ret, copyFile(ctx, path, out)) |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | var propOut string |
| 752 | |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 753 | if l, ok := m.linker.(snapshotLibraryInterface); ok { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame^] | 754 | exporterInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 755 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 756 | // library flags |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame^] | 757 | prop.ExportedFlags = exporterInfo.Flags |
| 758 | for _, dir := range exporterInfo.IncludeDirs { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 759 | prop.ExportedDirs = append(prop.ExportedDirs, filepath.Join("include", dir.String())) |
| 760 | } |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame^] | 761 | for _, dir := range exporterInfo.SystemIncludeDirs { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 762 | prop.ExportedSystemDirs = append(prop.ExportedSystemDirs, filepath.Join("include", dir.String())) |
| 763 | } |
| 764 | // shared libs dependencies aren't meaningful on static or header libs |
| 765 | if l.shared() { |
| 766 | prop.SharedLibs = m.Properties.SnapshotSharedLibs |
| 767 | } |
| 768 | if l.static() && m.sanitize != nil { |
| 769 | prop.SanitizeMinimalDep = m.sanitize.Properties.MinimalRuntimeDep || enableMinimalRuntime(m.sanitize) |
| 770 | prop.SanitizeUbsanDep = m.sanitize.Properties.UbsanRuntimeDep || enableUbsanRuntime(m.sanitize) |
| 771 | } |
| 772 | |
| 773 | var libType string |
| 774 | if l.static() { |
| 775 | libType = "static" |
| 776 | } else if l.shared() { |
| 777 | libType = "shared" |
| 778 | } else { |
| 779 | libType = "header" |
| 780 | } |
| 781 | |
| 782 | var stem string |
| 783 | |
| 784 | // install .a or .so |
| 785 | if libType != "header" { |
| 786 | libPath := m.outputFile.Path() |
| 787 | stem = libPath.Base() |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 788 | if l.static() && m.sanitize != nil && m.sanitize.isSanitizerEnabled(cfi) { |
| 789 | // both cfi and non-cfi variant for static libraries can exist. |
| 790 | // attach .cfi to distinguish between cfi and non-cfi. |
| 791 | // e.g. libbase.a -> libbase.cfi.a |
| 792 | ext := filepath.Ext(stem) |
| 793 | stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext |
| 794 | prop.Sanitize = "cfi" |
| 795 | prop.ModuleName += ".cfi" |
| 796 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 797 | snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem) |
| 798 | ret = append(ret, copyFile(ctx, libPath, snapshotLibOut)) |
| 799 | } else { |
| 800 | stem = ctx.ModuleName(m) |
| 801 | } |
| 802 | |
| 803 | propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 804 | } else if m.binary() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 805 | // binary flags |
| 806 | prop.Symlinks = m.Symlinks() |
| 807 | prop.SharedLibs = m.Properties.SnapshotSharedLibs |
| 808 | |
| 809 | // install bin |
| 810 | binPath := m.outputFile.Path() |
| 811 | snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base()) |
| 812 | ret = append(ret, copyFile(ctx, binPath, snapshotBinOut)) |
| 813 | propOut = snapshotBinOut + ".json" |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 814 | } else if m.object() { |
| 815 | // object files aren't installed to the device, so their names can conflict. |
| 816 | // Use module name as stem. |
| 817 | objPath := m.outputFile.Path() |
| 818 | snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object", |
| 819 | ctx.ModuleName(m)+filepath.Ext(objPath.Base())) |
| 820 | ret = append(ret, copyFile(ctx, objPath, snapshotObjOut)) |
| 821 | propOut = snapshotObjOut + ".json" |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 822 | } else { |
| 823 | ctx.Errorf("unknown module %q in vendor snapshot", m.String()) |
| 824 | return nil |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | j, err := json.Marshal(prop) |
| 828 | if err != nil { |
| 829 | ctx.Errorf("json marshal to %q failed: %#v", propOut, err) |
| 830 | return nil |
| 831 | } |
| 832 | ret = append(ret, writeStringToFile(ctx, string(j), propOut)) |
| 833 | |
| 834 | return ret |
| 835 | } |
| 836 | |
| 837 | ctx.VisitAllModules(func(module android.Module) { |
| 838 | m, ok := module.(*Module) |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 839 | if !ok { |
| 840 | return |
| 841 | } |
| 842 | |
| 843 | moduleDir := ctx.ModuleDir(module) |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 844 | inVendorProprietaryPath := isVendorProprietaryPath(moduleDir) |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 845 | apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 846 | |
| 847 | if m.ExcludeFromVendorSnapshot() { |
| 848 | if inVendorProprietaryPath { |
| 849 | // Error: exclude_from_vendor_snapshot applies |
| 850 | // to framework-path modules only. |
| 851 | ctx.Errorf("module %q in vendor proprietary path %q may not use \"exclude_from_vendor_snapshot: true\"", m.String(), moduleDir) |
| 852 | return |
| 853 | } |
| 854 | if Bool(m.VendorProperties.Vendor_available) { |
| 855 | // Error: may not combine "vendor_available: |
| 856 | // true" with "exclude_from_vendor_snapshot: |
| 857 | // true". |
| 858 | ctx.Errorf("module %q may not use both \"vendor_available: true\" and \"exclude_from_vendor_snapshot: true\"", m.String()) |
| 859 | return |
| 860 | } |
| 861 | } |
| 862 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 863 | if !isVendorSnapshotModule(m, inVendorProprietaryPath, apexInfo) { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 864 | return |
| 865 | } |
| 866 | |
| 867 | snapshotOutputs = append(snapshotOutputs, installSnapshot(m)...) |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 868 | if l, ok := m.linker.(snapshotLibraryInterface); ok { |
| 869 | headers = append(headers, l.snapshotHeaders()...) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 870 | } |
| 871 | |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 872 | if len(m.NoticeFiles()) > 0 { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 873 | noticeName := ctx.ModuleName(m) + ".txt" |
| 874 | noticeOut := filepath.Join(noticeDir, noticeName) |
| 875 | // skip already copied notice file |
| 876 | if !installedNotices[noticeOut] { |
| 877 | installedNotices[noticeOut] = true |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 878 | snapshotOutputs = append(snapshotOutputs, combineNotices( |
| 879 | ctx, m.NoticeFiles(), noticeOut)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 880 | } |
| 881 | } |
| 882 | }) |
| 883 | |
| 884 | // install all headers after removing duplicates |
| 885 | for _, header := range android.FirstUniquePaths(headers) { |
| 886 | snapshotOutputs = append(snapshotOutputs, copyFile( |
| 887 | ctx, header, filepath.Join(includeDir, header.String()))) |
| 888 | } |
| 889 | |
| 890 | // All artifacts are ready. Sort them to normalize ninja and then zip. |
| 891 | sort.Slice(snapshotOutputs, func(i, j int) bool { |
| 892 | return snapshotOutputs[i].String() < snapshotOutputs[j].String() |
| 893 | }) |
| 894 | |
| 895 | zipPath := android.PathForOutput(ctx, snapshotDir, "vendor-"+ctx.Config().DeviceName()+".zip") |
| 896 | zipRule := android.NewRuleBuilder() |
| 897 | |
| 898 | // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr |
| 899 | snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "vendor-"+ctx.Config().DeviceName()+"_list") |
| 900 | zipRule.Command(). |
| 901 | Text("tr"). |
| 902 | FlagWithArg("-d ", "\\'"). |
| 903 | FlagWithRspFileInputList("< ", snapshotOutputs). |
| 904 | FlagWithOutput("> ", snapshotOutputList) |
| 905 | |
| 906 | zipRule.Temporary(snapshotOutputList) |
| 907 | |
| 908 | zipRule.Command(). |
| 909 | BuiltTool(ctx, "soong_zip"). |
| 910 | FlagWithOutput("-o ", zipPath). |
| 911 | FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()). |
| 912 | FlagWithInput("-l ", snapshotOutputList) |
| 913 | |
| 914 | zipRule.Build(pctx, ctx, zipPath.String(), "vendor snapshot "+zipPath.String()) |
| 915 | zipRule.DeleteTemporaryFiles() |
| 916 | c.vendorSnapshotZipFile = android.OptionalPathForPath(zipPath) |
| 917 | } |
| 918 | |
| 919 | func (c *vendorSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) { |
| 920 | ctx.Strict("SOONG_VENDOR_SNAPSHOT_ZIP", c.vendorSnapshotZipFile.String()) |
| 921 | } |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 922 | |
| 923 | type snapshotInterface interface { |
| 924 | matchesWithDevice(config android.DeviceConfig) bool |
| 925 | } |
| 926 | |
| 927 | var _ snapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil) |
| 928 | var _ snapshotInterface = (*vendorSnapshotLibraryDecorator)(nil) |
| 929 | var _ snapshotInterface = (*vendorSnapshotBinaryDecorator)(nil) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 930 | var _ snapshotInterface = (*vendorSnapshotObjectLinker)(nil) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 931 | |
| 932 | // gathers all snapshot modules for vendor, and disable unnecessary snapshots |
| 933 | // TODO(b/145966707): remove mutator and utilize android.Prebuilt to override source modules |
| 934 | func VendorSnapshotMutator(ctx android.BottomUpMutatorContext) { |
| 935 | vndkVersion := ctx.DeviceConfig().VndkVersion() |
| 936 | // don't need snapshot if current |
| 937 | if vndkVersion == "current" || vndkVersion == "" { |
| 938 | return |
| 939 | } |
| 940 | |
| 941 | module, ok := ctx.Module().(*Module) |
| 942 | if !ok || !module.Enabled() || module.VndkVersion() != vndkVersion { |
| 943 | return |
| 944 | } |
| 945 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 946 | if !module.isSnapshotPrebuilt() { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 947 | return |
| 948 | } |
| 949 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 950 | // isSnapshotPrebuilt ensures snapshotInterface |
| 951 | if !module.linker.(snapshotInterface).matchesWithDevice(ctx.DeviceConfig()) { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 952 | // Disable unnecessary snapshot module, but do not disable |
| 953 | // vndk_prebuilt_shared because they might be packed into vndk APEX |
| 954 | if !module.IsVndk() { |
| 955 | module.Disable() |
| 956 | } |
| 957 | return |
| 958 | } |
| 959 | |
| 960 | var snapshotMap *snapshotMap |
| 961 | |
| 962 | if lib, ok := module.linker.(libraryInterface); ok { |
| 963 | if lib.static() { |
| 964 | snapshotMap = vendorSnapshotStaticLibs(ctx.Config()) |
| 965 | } else if lib.shared() { |
| 966 | snapshotMap = vendorSnapshotSharedLibs(ctx.Config()) |
| 967 | } else { |
| 968 | // header |
| 969 | snapshotMap = vendorSnapshotHeaderLibs(ctx.Config()) |
| 970 | } |
| 971 | } else if _, ok := module.linker.(*vendorSnapshotBinaryDecorator); ok { |
| 972 | snapshotMap = vendorSnapshotBinaries(ctx.Config()) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 973 | } else if _, ok := module.linker.(*vendorSnapshotObjectLinker); ok { |
| 974 | snapshotMap = vendorSnapshotObjects(ctx.Config()) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 975 | } else { |
| 976 | return |
| 977 | } |
| 978 | |
| 979 | vendorSnapshotsLock.Lock() |
| 980 | defer vendorSnapshotsLock.Unlock() |
| 981 | snapshotMap.add(module.BaseModuleName(), ctx.Arch().ArchType, ctx.ModuleName()) |
| 982 | } |
| 983 | |
| 984 | // Disables source modules which have snapshots |
| 985 | func VendorSnapshotSourceMutator(ctx android.BottomUpMutatorContext) { |
Inseob Kim | 5f64aec | 2020-02-18 17:27:19 +0900 | [diff] [blame] | 986 | if !ctx.Device() { |
| 987 | return |
| 988 | } |
| 989 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 990 | vndkVersion := ctx.DeviceConfig().VndkVersion() |
| 991 | // don't need snapshot if current |
| 992 | if vndkVersion == "current" || vndkVersion == "" { |
| 993 | return |
| 994 | } |
| 995 | |
| 996 | module, ok := ctx.Module().(*Module) |
| 997 | if !ok { |
| 998 | return |
| 999 | } |
| 1000 | |
Inseob Kim | 5f64aec | 2020-02-18 17:27:19 +0900 | [diff] [blame] | 1001 | // vendor suffix should be added to snapshots if the source module isn't vendor: true. |
| 1002 | if !module.SocSpecific() { |
| 1003 | // But we can't just check SocSpecific() since we already passed the image mutator. |
| 1004 | // Check ramdisk and recovery to see if we are real "vendor: true" module. |
| 1005 | ramdisk_available := module.InRamdisk() && !module.OnlyInRamdisk() |
| 1006 | recovery_available := module.InRecovery() && !module.OnlyInRecovery() |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1007 | |
Inseob Kim | 5f64aec | 2020-02-18 17:27:19 +0900 | [diff] [blame] | 1008 | if !ramdisk_available && !recovery_available { |
| 1009 | vendorSnapshotsLock.Lock() |
| 1010 | defer vendorSnapshotsLock.Unlock() |
| 1011 | |
| 1012 | vendorSuffixModules(ctx.Config())[ctx.ModuleName()] = true |
| 1013 | } |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | if module.isSnapshotPrebuilt() || module.VndkVersion() != ctx.DeviceConfig().VndkVersion() { |
| 1017 | // only non-snapshot modules with BOARD_VNDK_VERSION |
| 1018 | return |
| 1019 | } |
| 1020 | |
Inseob Kim | 206665c | 2020-06-02 23:48:32 +0900 | [diff] [blame] | 1021 | // .. and also filter out llndk library |
| 1022 | if module.isLlndk(ctx.Config()) { |
| 1023 | return |
| 1024 | } |
| 1025 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1026 | var snapshotMap *snapshotMap |
| 1027 | |
| 1028 | if lib, ok := module.linker.(libraryInterface); ok { |
| 1029 | if lib.static() { |
| 1030 | snapshotMap = vendorSnapshotStaticLibs(ctx.Config()) |
| 1031 | } else if lib.shared() { |
| 1032 | snapshotMap = vendorSnapshotSharedLibs(ctx.Config()) |
| 1033 | } else { |
| 1034 | // header |
| 1035 | snapshotMap = vendorSnapshotHeaderLibs(ctx.Config()) |
| 1036 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1037 | } else if module.binary() { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1038 | snapshotMap = vendorSnapshotBinaries(ctx.Config()) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 1039 | } else if module.object() { |
| 1040 | snapshotMap = vendorSnapshotObjects(ctx.Config()) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1041 | } else { |
| 1042 | return |
| 1043 | } |
| 1044 | |
| 1045 | if _, ok := snapshotMap.get(ctx.ModuleName(), ctx.Arch().ArchType); !ok { |
| 1046 | // Corresponding snapshot doesn't exist |
| 1047 | return |
| 1048 | } |
| 1049 | |
| 1050 | // Disables source modules if corresponding snapshot exists. |
| 1051 | if lib, ok := module.linker.(libraryInterface); ok && lib.buildStatic() && lib.buildShared() { |
| 1052 | // But do not disable because the shared variant depends on the static variant. |
| 1053 | module.SkipInstall() |
| 1054 | module.Properties.HideFromMake = true |
| 1055 | } else { |
| 1056 | module.Disable() |
| 1057 | } |
| 1058 | } |