Files
XcodeGen/Sources/ProjectSpec/XCProjExtensions.swift
T
Jierong Li d1dd93aac4 Rebase #177 - Shared breakpoints support (#693)
* Resolves #173 - Shared breakpoints support

* Added breakpoints full documentation

* Invalid breakpoint just throw JSONUtilities decoding error.

* Use enumeration types instead of String for extensionIDs

* Remove a necessary line

* Remove unnecessary custom Equatable implementation

* Update CHANGELOG.md

* Ignore empty breakpoints

* Update Docs/ProjectSpec.md

Fix a typo

Co-Authored-By: Yonas Kolb <yonaskolb@users.noreply.github.com>

* Change some properties that should be Int to Int

* Create 2 typealiases

* Use BreakpointType where it is missing

* Remove unused Location

* Change some names

* Add Breakpoint.Scope

* Add Breakpoint.StopOnStyle

* Change the type of the raw value to String

* Remove some properties that may cause confusing

* Require filePah and line when the type is .file

* Add tests about decoding breakpoints

* Add Breakpoint.Action.ConveyanceType

* Add default value for waitUntilDone

* Add Breakpoint.Action.SoundName

* Add tests about decoding breakpoint actions

* Fix some issues in ProjectSpec.md

* Improve ProjectSpec.md

* Add missing condition

* Add breakpoints to project.yml

* Use unwarp

* Remove the Breakpoint suffix

* Refactor BreakpointType

* Refactor Breakpoint.Action

* Remove unnecessary properties

* Adjust the line wrapping style for BreakpointGenerator

* Support column breakpoints

---------

Co-authored-by: Alex Rupérez <alejandro.ruperez@intelygenz.com>
Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com>
2023-02-28 22:00:39 +11:00

136 lines
4.0 KiB
Swift

import Foundation
import PathKit
import XcodeProj
extension PBXProductType {
init?(string: String) {
if let type = PBXProductType(rawValue: string) {
self = type
} else if let type = PBXProductType(rawValue: "com.apple.product-type.\(string)") {
self = type
} else {
return nil
}
}
public var isFramework: Bool {
self == .framework || self == .staticFramework
}
public var isLibrary: Bool {
self == .staticLibrary || self == .dynamicLibrary
}
public var isExtension: Bool {
fileExtension == "appex"
}
public var isSystemExtension: Bool {
fileExtension == "dext" || fileExtension == "systemextension"
}
public var isApp: Bool {
fileExtension == "app"
}
public var isTest: Bool {
fileExtension == "xctest"
}
public var isExecutable: Bool {
isApp || isExtension || isSystemExtension || isTest || self == .commandLineTool
}
public var name: String {
rawValue.replacingOccurrences(of: "com.apple.product-type.", with: "")
}
public var canSkipCompileSourcesBuildPhase: Bool {
switch self {
case .bundle, .watch2App, .stickerPack, .messagesApplication:
// Bundles, watch apps, sticker packs and simple messages applications without sources should not include a
// compile sources build phase. Doing so can cause Xcode to produce an error on build.
return true
default:
return false
}
}
/// Function to determine when a dependendency should be embedded into the target
public func shouldEmbed(_ dependencyTarget: Target) -> Bool {
switch dependencyTarget.defaultLinkage {
case .static:
// Static dependencies should never embed
return false
case .dynamic, .none:
if isApp {
// If target is an app, all dependencies should be embed (unless they're static)
return true
} else if isTest, [.framework, .bundle].contains(dependencyTarget.type) {
// If target is test, some dependencies should be embed (depending on their type)
return true
} else {
// If none of the above, do not embed the dependency
return false
}
}
}
}
extension Platform {
public var emoji: String {
switch self {
case .iOS: return "📱"
case .watchOS: return "⌚️"
case .tvOS: return "📺"
case .macOS: return "🖥"
}
}
}
extension ProjectTarget {
public var shouldExecuteOnLaunch: Bool {
// This is different from `type.isExecutable`, because we don't want to "run" a test
type.isApp || type.isExtension || type.isSystemExtension || type == .commandLineTool
}
}
extension XCScheme.CommandLineArguments {
// Dictionary is a mapping from argument name and if it is enabled by default
public convenience init(_ dict: [String: Bool]) {
let args = dict.map { tuple in
XCScheme.CommandLineArguments.CommandLineArgument(name: tuple.key, enabled: tuple.value)
}.sorted { $0.name < $1.name }
self.init(arguments: args)
}
}
extension BreakpointExtensionID {
init(string: String) throws {
if let id = BreakpointExtensionID(rawValue: "Xcode.Breakpoint.\(string)Breakpoint") {
self = id
} else if let id = BreakpointExtensionID(rawValue: string) {
self = id
} else {
throw SpecParsingError.unknownBreakpointType(string)
}
}
}
extension BreakpointActionExtensionID {
init(string: String) throws {
if let type = BreakpointActionExtensionID(rawValue: "Xcode.BreakpointAction.\(string)") {
self = type
} else if let type = BreakpointActionExtensionID(rawValue: string) {
self = type
} else {
throw SpecParsingError.unknownBreakpointActionType(string)
}
}
}