|
2 | 2 | // |
3 | 3 | // This source file contains derivative work from the Swift Open Source Project |
4 | 4 | // |
5 | | -// Copyright (c) 2014-2020 Apple Inc. and the Swift project authors |
| 5 | +// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors |
6 | 6 | // Licensed under Apache License v2.0 with Runtime Library Exception |
7 | 7 | // |
8 | 8 | // See http://swift.org/LICENSE.txt for license information |
@@ -483,35 +483,59 @@ public enum PIF { |
483 | 483 | /// An Xcode target, representing a single entity to build. |
484 | 484 | public final class Target: BaseTarget { |
485 | 485 | public enum ProductType: String, Decodable { |
486 | | - case appExtension = "com.apple.product-type.app-extension" |
487 | | - case appExtensionMessages = "com.apple.product-type.app-extension.messages" |
488 | | - case stickerPackExtension = "com.apple.product-type.app-extension.messages-sticker-pack" |
489 | | - case application = "com.apple.product-type.application" |
490 | | - case applicationMessages = "com.apple.product-type.application.messages" |
491 | | - case appClip = "com.apple.product-type.application.on-demand-install-capable" |
492 | | - case bundle = "com.apple.product-type.bundle" |
493 | | - case externalTest = "com.apple.product-type.bundle.external-test" |
494 | | - case ocUnitTest = "com.apple.product-type.bundle.ocunit-test" |
495 | | - case uiTesting = "com.apple.product-type.bundle.ui-testing" |
496 | | - case unitTest = "com.apple.product-type.bundle.unit-test" |
497 | | - case extensionKitExtension = "com.apple.product-type.extensionkit-extension" |
498 | | - case framework = "com.apple.product-type.framework" |
499 | | - case staticFramework = "com.apple.product-type.framework.static" |
500 | | - case instrumentsPackage = "com.apple.product-type.instruments-package" |
501 | | - case kernelExtension = "com.apple.product-type.kernel-extension" |
502 | | - case ioKitKernelExtension = "com.apple.product-type.kernel-extension.iokit" |
503 | | - case dynamicLibrary = "com.apple.product-type.library.dynamic" |
504 | | - case staticLibrary = "com.apple.product-type.library.static" |
505 | | - case objectFile = "com.apple.product-type.objfile" |
506 | | - case pluginKitPlugin = "com.apple.product-type.pluginkit-plugin" |
| 486 | + case appExtension = "product-type.app-extension" |
| 487 | + case appExtensionMessages = "product-type.app-extension.messages" |
| 488 | + case stickerPackExtension = "product-type.app-extension.messages-sticker-pack" |
| 489 | + case application = "product-type.application" |
| 490 | + case applicationMessages = "product-type.application.messages" |
| 491 | + case appClip = "product-type.application.on-demand-install-capable" |
| 492 | + case bundle = "product-type.bundle" |
| 493 | + case externalTest = "product-type.bundle.external-test" |
| 494 | + case ocUnitTest = "product-type.bundle.ocunit-test" |
| 495 | + case uiTesting = "product-type.bundle.ui-testing" |
| 496 | + case unitTest = "product-type.bundle.unit-test" |
| 497 | + case extensionKitExtension = "product-type.extensionkit-extension" |
| 498 | + case framework = "product-type.framework" |
| 499 | + case staticFramework = "product-type.framework.static" |
| 500 | + case instrumentsPackage = "product-type.instruments-package" |
| 501 | + case kernelExtension = "product-type.kernel-extension" |
| 502 | + case ioKitKernelExtension = "product-type.kernel-extension.iokit" |
| 503 | + case dynamicLibrary = "product-type.library.dynamic" |
| 504 | + case staticLibrary = "product-type.library.static" |
| 505 | + case objectFile = "product-type.objfile" |
| 506 | + case pluginKitPlugin = "product-type.pluginkit-plugin" |
507 | 507 | case packageProduct = "packageProduct" |
508 | | - case systemExtension = "com.apple.product-type.system-extension" |
509 | | - case tool = "com.apple.product-type.tool" |
510 | | - case hostBuild = "com.apple.product-type.tool.host-build" |
511 | | - case xpcService = "com.apple.product-type.xpc-service" |
512 | | - case watchApp2 = "com.apple.product-type.application.watchapp2" |
513 | | - case watchApp2Container = "com.apple.product-type.application.watchapp2-container" |
514 | | - case watchKit2Extension = "com.apple.product-type.watchkit2-extension" |
| 508 | + case systemExtension = "product-type.system-extension" |
| 509 | + case tool = "product-type.tool" |
| 510 | + case hostBuild = "product-type.tool.host-build" |
| 511 | + case xpcService = "product-type.xpc-service" |
| 512 | + case watchApp2 = "product-type.application.watchapp2" |
| 513 | + case watchApp2Container = "product-type.application.watchapp2-container" |
| 514 | + case watchKit2Extension = "product-type.watchkit2-extension" |
| 515 | + |
| 516 | + public init(from decoder: Decoder) throws { |
| 517 | + let container = try decoder.singleValueContainer() |
| 518 | + let fullValue = try container.decode(String.self) |
| 519 | + |
| 520 | + let normalizedValue: String |
| 521 | + if fullValue.hasPrefix("com.apple.") { |
| 522 | + normalizedValue = String(fullValue.dropFirst("com.apple.".count)) |
| 523 | + } else if fullValue.hasPrefix("org.swift.") { |
| 524 | + normalizedValue = String(fullValue.dropFirst("org.swift.".count)) |
| 525 | + } else { |
| 526 | + normalizedValue = fullValue |
| 527 | + } |
| 528 | + |
| 529 | + guard let decodedCase = ProductType(rawValue: normalizedValue) else { |
| 530 | + throw DecodingError.dataCorrupted( |
| 531 | + DecodingError.Context( |
| 532 | + codingPath: decoder.codingPath, |
| 533 | + debugDescription: "Cannot initialize ProductType from invalid String value \(fullValue)" |
| 534 | + ) |
| 535 | + ) |
| 536 | + } |
| 537 | + self = decodedCase |
| 538 | + } |
515 | 539 | } |
516 | 540 |
|
517 | 541 | public let productName: String |
|
0 commit comments