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