From 87a16756c8cf82101ff6daec3bc5380811b6f424 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 10 Jun 2024 16:07:57 +0200 Subject: [PATCH 1/7] Delete XcodeGraphTesting --- Package.resolved | 22 +-- Package.swift | 10 +- .../DependenciesGraph/DependenciesGraph.swift | 175 +++++++++++++++++ Sources/XcodeGraph/Graph/Graph.swift | 24 +++ .../XcodeGraph/Graph/GraphDependency.swift | 111 +++++++++++ Sources/XcodeGraph/Graph/GraphTarget.swift | 16 ++ Sources/XcodeGraph/Models/AnalyzeAction.swift | 8 + Sources/XcodeGraph/Models/ArchiveAction.swift | 20 ++ Sources/XcodeGraph/Models/Arguments.swift | 14 ++ Sources/XcodeGraph/Models/BuildAction.swift | 13 ++ Sources/XcodeGraph/Models/Cloud.swift | 41 ++++ Sources/XcodeGraph/Models/Config.swift | 116 +++++++++++ .../Models/Dependencies/PackageSettings.swift | 66 +++++++ Sources/XcodeGraph/Models/Headers.swift | 16 ++ .../XcodeGraph/Models/IDETemplateMacros.swift | 8 + .../Models/Metadata/FrameworkMetadata.swift | 26 +++ .../Models/Metadata/LibraryMetadata.swift | 23 +++ .../Models/Metadata/XCFrameworkMetadata.swift | 27 +++ .../XcodeGraph/Models/PlatformCondition.swift | 8 + .../Models/PluginResourceSynthesizer.swift | 14 ++ Sources/XcodeGraph/Models/Plugins.swift | 53 +++++ Sources/XcodeGraph/Models/ProfileAction.swift | 22 +++ Sources/XcodeGraph/Models/Project.swift | 132 +++++++++++++ .../Models/RawScriptBuildPhase.swift | 13 ++ .../Models/ResourceSynthesizer.swift | 13 ++ Sources/XcodeGraph/Models/RunAction.swift | 38 ++++ Sources/XcodeGraph/Models/Scheme.swift | 26 +++ Sources/XcodeGraph/Models/Settings.swift | 47 +++++ Sources/XcodeGraph/Models/Target.swift | 183 +++++++++++++++++ Sources/XcodeGraph/Models/Template.swift | 179 +++++++++++++++++ Sources/XcodeGraph/Models/TestAction.swift | 44 +++++ .../XcodeGraph/Models/TestableTarget.swift | 22 +++ Sources/XcodeGraph/Models/Workspace.swift | 47 +++++ .../Models/XCFrameworkInfoPlist.swift | 25 +++ .../DependenciesGraph+TestData.swift | 176 ----------------- .../Graph/Graph+TestData.swift | 25 --- .../Graph/GraphDependency+TestData.swift | 113 ----------- .../Graph/GraphTarget+TestData.swift | 18 -- .../Models/AnalyzeAction+TestData.swift | 9 - .../Models/ArchiveAction+TestData.swift | 21 -- .../Models/Arguments+TestData.swift | 15 -- .../Models/BuildAction+TestData.swift | 14 -- .../Models/Condition+TestData.swift | 9 - .../Models/Headers+TestData.swift | 17 -- .../Models/IDETemplateMacros+TestData.swift | 8 - .../Metadata/FrameworkMetadata+TestData.swift | 27 --- .../Metadata/LibraryMetadata+TestData.swift | 24 --- .../XCFrameworkMetadata+TestData.swift | 28 --- .../Models/ProfileAction+TestData.swift | 22 --- .../Models/Project+TestData.swift | 90 --------- .../Models/ProjectOptions+TestData.swift | 44 ----- .../Models/RawScriptBuildPhase+TestData.swift | 14 -- .../ResourceSynthesizerPlugin+TestData.swift | 15 -- .../ResourceSynthesizers+TestData.swift | 13 -- .../Models/RunAction+TestData.swift | 39 ---- .../Models/Scheme+TestData.swift | 27 --- .../Models/Settings+TestData.swift | 48 ----- .../Models/Target+TestData.swift | 184 ------------------ .../Models/TestAction+TestData.swift | 45 ----- .../Models/TestableTarget+TestData.swift | 21 -- .../Models/Workspace+TestData.swift | 48 ----- .../XCFrameworkInfoPlist+TestData.swift | 27 --- .../XcodeGraphTests/Models/ProjectTests.swift | 1 - .../XcodeGraphTests/Models/TargetTests.swift | 1 - 64 files changed, 1573 insertions(+), 1172 deletions(-) create mode 100644 Sources/XcodeGraph/Models/Cloud.swift create mode 100644 Sources/XcodeGraph/Models/Config.swift create mode 100644 Sources/XcodeGraph/Models/Dependencies/PackageSettings.swift create mode 100644 Sources/XcodeGraph/Models/Plugins.swift create mode 100644 Sources/XcodeGraph/Models/Template.swift delete mode 100644 Sources/XcodeGraphTesting/DependenciesGraph/DependenciesGraph+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Graph/Graph+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Graph/GraphDependency+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Graph/GraphTarget+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/AnalyzeAction+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/ArchiveAction+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/Arguments+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/BuildAction+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/Condition+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/Headers+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/IDETemplateMacros+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/Metadata/FrameworkMetadata+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/Metadata/LibraryMetadata+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/Metadata/XCFrameworkMetadata+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/ProfileAction+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/Project+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/ProjectOptions+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/RawScriptBuildPhase+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/ResourceSynthesizerPlugin+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/ResourceSynthesizers+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/RunAction+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/Scheme+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/Settings+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/Target+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/TestAction+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/TestableTarget+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/Workspace+TestData.swift delete mode 100644 Sources/XcodeGraphTesting/Models/XCFrameworkInfoPlist+TestData.swift diff --git a/Package.resolved b/Package.resolved index 58b23de0..5d7f2870 100644 --- a/Package.resolved +++ b/Package.resolved @@ -9,31 +9,13 @@ "version" : "0.6.7" } }, - { - "identity" : "mockable", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Kolos65/Mockable.git", - "state" : { - "revision" : "f931faaae32a0ef21a0dcc731e5fc8bdc7d704f9", - "version" : "0.0.8" - } - }, { "identity" : "path", "kind" : "remoteSourceControl", "location" : "https://github.com/tuist/Path.git", "state" : { - "revision" : "61e3fa3b2fd56e0bd2496afd62a35c2cb98a6fca", - "version" : "0.2.0" - } - }, - { - "identity" : "swift-syntax", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-syntax.git", - "state" : { - "revision" : "64889f0c732f210a935a0ad7cda38f77f876262d", - "version" : "509.1.1" + "revision" : "4490da629937fc3994f72dd787dcc3f50d6973fe", + "version" : "0.3.0" } } ], diff --git a/Package.swift b/Package.swift index dbc132e6..21f0e9b8 100644 --- a/Package.swift +++ b/Package.swift @@ -9,15 +9,7 @@ var targets: [Target] = [ "AnyCodable", "Path", ] - ), - .target( - name: "XcodeGraphTesting", - dependencies: [ - "XcodeGraph", - "AnyCodable", - ], - linkerSettings: [.linkedFramework("XCTest")] - ), + ) ] let package = Package( diff --git a/Sources/XcodeGraph/DependenciesGraph/DependenciesGraph.swift b/Sources/XcodeGraph/DependenciesGraph/DependenciesGraph.swift index 371d773f..ad29684b 100644 --- a/Sources/XcodeGraph/DependenciesGraph/DependenciesGraph.swift +++ b/Sources/XcodeGraph/DependenciesGraph/DependenciesGraph.swift @@ -19,3 +19,178 @@ public struct DependenciesGraph: Equatable, Codable { /// An empty `DependenciesGraph`. public static let none: DependenciesGraph = .init(externalDependencies: [:], externalProjects: [:]) } + +#if DEBUG + extension DependenciesGraph { + public static func test( + externalDependencies: [String: [TargetDependency]] = [:], + externalProjects: [AbsolutePath: Project] = [:] + ) -> Self { + .init(externalDependencies: externalDependencies, externalProjects: externalProjects) + } + + public static func testXCFramework( + name: String = "Test", + // swiftlint:disable:next force_try + path: AbsolutePath = AbsolutePath.root.appending(try! RelativePath(validating: "Test.xcframework")), + status: FrameworkStatus = .required + ) -> DependenciesGraph { + let externalDependencies = [name: [TargetDependency.xcframework(path: path, status: status)]] + + return .init( + externalDependencies: externalDependencies, + externalProjects: [:] + ) + } + + public static func test( + packageFolder: AbsolutePath + ) -> Self { + let externalDependencies = [ + "Tuist": [ + TargetDependency.project( + target: "Tuist", + path: packageFolder + ), + ], + ] + + return .init( + externalDependencies: externalDependencies, + externalProjects: [:] + ) + } + + public static func aDependency( + packageFolder: AbsolutePath + ) -> Self { + let externalDependencies = [ + "ALibrary": [ + TargetDependency.project( + target: "ALibrary", + path: packageFolder + ), + ], + ] + + return .init( + externalDependencies: externalDependencies, + externalProjects: [:] + ) + } + + public static func anotherDependency( + packageFolder: AbsolutePath + ) -> Self { + let externalDependencies = [ + "AnotherLibrary": [ + TargetDependency.project( + target: "AnotherLibrary", + path: packageFolder + ), + ], + ] + + return .init( + externalDependencies: externalDependencies, + externalProjects: [:] + ) + } + + public static func alamofire( + packageFolder: AbsolutePath + ) -> Self { + let externalDependencies = [ + "Alamofire": [ + TargetDependency.project( + target: "Alamofire", + path: packageFolder + ), + ], + ] + + return .init( + externalDependencies: externalDependencies, + externalProjects: [:] + ) + } + + public static func googleAppMeasurement( + packageFolder: AbsolutePath + ) -> Self { + let externalDependencies = [ + "GoogleAppMeasurement": [ + TargetDependency.project( + target: "GoogleAppMeasurementTarget", + path: packageFolder + ), + ], + "GoogleAppMeasurementWithoutAdIdSupport": [ + TargetDependency.project( + target: "GoogleAppMeasurementWithoutAdIdSupportTarget", + path: packageFolder + ), + ], + ] + + return .init( + externalDependencies: externalDependencies, + externalProjects: [:] + ) + } + + public static func googleUtilities( + packageFolder: AbsolutePath + ) -> Self { + let externalDependencies = [ + "GULAppDelegateSwizzler": [ + TargetDependency.project( + target: "GULAppDelegateSwizzler", + path: packageFolder + ), + ], + "GULMethodSwizzler": [ + TargetDependency.project( + target: "GULMethodSwizzler", + path: packageFolder + ), + ], + "GULNSData": [ + TargetDependency.project( + target: "GULNSData", + path: packageFolder + ), + ], + "GULNetwork": [ + TargetDependency.project( + target: "GULNetwork", + path: packageFolder + ), + ], + ] + + return .init( + externalDependencies: externalDependencies, + externalProjects: [:] + ) + } + + public static func nanopb( + packageFolder: AbsolutePath + ) -> Self { + let externalDependencies = [ + "nanopb": [ + TargetDependency.project( + target: "nanopb", + path: packageFolder + ), + ], + ] + + return .init( + externalDependencies: externalDependencies, + externalProjects: [:] + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Graph/Graph.swift b/Sources/XcodeGraph/Graph/Graph.swift index 033b95ab..8cdf72d7 100644 --- a/Sources/XcodeGraph/Graph/Graph.swift +++ b/Sources/XcodeGraph/Graph/Graph.swift @@ -65,3 +65,27 @@ extension [GraphEdge: PlatformCondition] { } } } + +#if DEBUG + extension Graph { + public static func test( + name: String = "graph", + path: AbsolutePath = .root, + workspace: Workspace = .test(), + projects: [AbsolutePath: Project] = [:], + packages: [AbsolutePath: [String: Package]] = [:], + dependencies: [GraphDependency: Set] = [:], + dependencyConditions: [GraphEdge: PlatformCondition] = [:] + ) -> Graph { + Graph( + name: name, + path: path, + workspace: workspace, + projects: projects, + packages: packages, + dependencies: dependencies, + dependencyConditions: dependencyConditions + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Graph/GraphDependency.swift b/Sources/XcodeGraph/Graph/GraphDependency.swift index 870b73c4..9d99134c 100644 --- a/Sources/XcodeGraph/Graph/GraphDependency.swift +++ b/Sources/XcodeGraph/Graph/GraphDependency.swift @@ -282,3 +282,114 @@ public enum GraphDependency: Hashable, CustomStringConvertible, Comparable, Coda lhs.description < rhs.description } } + +#if DEBUG + // swiftlint:disable force_try + + extension GraphDependency { + public static func testFramework( + path: AbsolutePath = AbsolutePath.root.appending(component: "Test.framework"), + binaryPath: AbsolutePath = AbsolutePath.root.appending(try! RelativePath(validating: "Test.framework/Test")), + dsymPath: AbsolutePath? = nil, + bcsymbolmapPaths: [AbsolutePath] = [], + linking: BinaryLinking = .dynamic, + architectures: [BinaryArchitecture] = [.armv7], + status: FrameworkStatus = .required + ) -> GraphDependency { + GraphDependency.framework( + path: path, + binaryPath: binaryPath, + dsymPath: dsymPath, + bcsymbolmapPaths: bcsymbolmapPaths, + linking: linking, + architectures: architectures, + status: status + ) + } + + public static func testMacro( + path: AbsolutePath = AbsolutePath.root.appending(try! RelativePath(validating: "macro")) + ) -> GraphDependency { + .macro(path: path) + } + + public static func testXCFramework( + path: AbsolutePath = AbsolutePath.root.appending(try! RelativePath(validating: "Test.xcframework")), + infoPlist: XCFrameworkInfoPlist = .test(), + primaryBinaryPath: AbsolutePath = AbsolutePath.root + .appending(try! RelativePath(validating: "Test.xcframework/Test")), + linking: BinaryLinking = .dynamic, + status: FrameworkStatus = .required, + macroPath: AbsolutePath? = nil + ) -> GraphDependency { + .xcframework( + GraphDependency.XCFramework( + path: path, + infoPlist: infoPlist, + primaryBinaryPath: primaryBinaryPath, + linking: linking, + mergeable: false, + status: status, + macroPath: macroPath + ) + ) + } + + public static func testTarget( + name: String = "Test", + path: AbsolutePath = .root + ) -> GraphDependency { + .target( + name: name, + path: path + ) + } + + public static func testSDK( + name: String = "XCTest.framework", + path: AbsolutePath = AbsolutePath.root.appending(try! RelativePath(validating: "XCTest.framework")), + status: SDKStatus = .required, + source: SDKSource = .system + ) -> GraphDependency { + .sdk( + name: name, + path: path, + status: status, + source: source + ) + } + + public static func testLibrary( + path: AbsolutePath = AbsolutePath.root.appending(try! RelativePath(validating: "libTuist.a")), + publicHeaders: AbsolutePath = AbsolutePath.root.appending(try! RelativePath(validating: "headers")), + linking: BinaryLinking = .dynamic, + architectures: [BinaryArchitecture] = [.armv7], + swiftModuleMap: AbsolutePath? = nil + ) -> GraphDependency { + .library( + path: path, + publicHeaders: publicHeaders, + linking: linking, + architectures: architectures, + swiftModuleMap: swiftModuleMap + ) + } + + public static func testBundle(path: AbsolutePath = .root.appending(component: "test.bundle")) -> GraphDependency { + .bundle(path: path) + } + + public static func testPackageProduct( + path: AbsolutePath = .root, + product: String = "Tuist" + ) -> GraphDependency { + .packageProduct( + path: path, + product: product, + type: .runtime + ) + } + } + + // swiftlint:enable force_try +#endif diff --git a/Sources/XcodeGraph/Graph/GraphTarget.swift b/Sources/XcodeGraph/Graph/GraphTarget.swift index a2126db3..71d25639 100644 --- a/Sources/XcodeGraph/Graph/GraphTarget.swift +++ b/Sources/XcodeGraph/Graph/GraphTarget.swift @@ -31,3 +31,19 @@ public struct GraphTarget: Equatable, Hashable, Comparable, CustomDebugStringCon "Target '\(target.name)' at path '\(project.path)'" } } + +#if DEBUG + extension GraphTarget { + public static func test( + path: AbsolutePath = .root, + target: Target = .test(), + project: Project = .test() + ) -> GraphTarget { + GraphTarget( + path: path, + target: target, + project: project + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/AnalyzeAction.swift b/Sources/XcodeGraph/Models/AnalyzeAction.swift index 7f80868e..eb63012b 100644 --- a/Sources/XcodeGraph/Models/AnalyzeAction.swift +++ b/Sources/XcodeGraph/Models/AnalyzeAction.swift @@ -11,3 +11,11 @@ public struct AnalyzeAction: Equatable, Codable { self.configurationName = configurationName } } + +#if DEBUG + extension AnalyzeAction { + public static func test(configurationName: String = "Beta Release") -> AnalyzeAction { + AnalyzeAction(configurationName: configurationName) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/ArchiveAction.swift b/Sources/XcodeGraph/Models/ArchiveAction.swift index da727bb9..a7e1ba65 100644 --- a/Sources/XcodeGraph/Models/ArchiveAction.swift +++ b/Sources/XcodeGraph/Models/ArchiveAction.swift @@ -26,3 +26,23 @@ public struct ArchiveAction: Equatable, Codable { self.postActions = postActions } } + +#if DEBUG + extension ArchiveAction { + public static func test( + configurationName: String = "Beta Release", + revealArchiveInOrganizer: Bool = true, + customArchiveName: String? = nil, + preActions: [ExecutionAction] = [], + postActions: [ExecutionAction] = [] + ) -> ArchiveAction { + ArchiveAction( + configurationName: configurationName, + revealArchiveInOrganizer: revealArchiveInOrganizer, + customArchiveName: customArchiveName, + preActions: preActions, + postActions: postActions + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Arguments.swift b/Sources/XcodeGraph/Models/Arguments.swift index 8f43b1d7..c9aac9e2 100644 --- a/Sources/XcodeGraph/Models/Arguments.swift +++ b/Sources/XcodeGraph/Models/Arguments.swift @@ -28,3 +28,17 @@ extension Arguments: Equatable { == rhs.launchArguments.sorted { $0.name == $1.name } } } + +#if DEBUG + extension Arguments { + public static func test( + environmentVariables: [String: EnvironmentVariable] = [:], + launchArguments: [LaunchArgument] = [] + ) -> Arguments { + Arguments( + environmentVariables: environmentVariables, + launchArguments: launchArguments + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/BuildAction.swift b/Sources/XcodeGraph/Models/BuildAction.swift index e539571e..161e0d2e 100644 --- a/Sources/XcodeGraph/Models/BuildAction.swift +++ b/Sources/XcodeGraph/Models/BuildAction.swift @@ -23,3 +23,16 @@ public struct BuildAction: Equatable, Codable { self.runPostActionsOnFailure = runPostActionsOnFailure } } + +#if DEBUG + extension BuildAction { + public static func test( + // swiftlint:disable:next force_try + targets: [TargetReference] = [TargetReference(projectPath: try! AbsolutePath(validating: "/Project"), name: "App")], + preActions: [ExecutionAction] = [], + postActions: [ExecutionAction] = [] + ) -> BuildAction { + BuildAction(targets: targets, preActions: preActions, postActions: postActions) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Cloud.swift b/Sources/XcodeGraph/Models/Cloud.swift new file mode 100644 index 00000000..2cd8c07a --- /dev/null +++ b/Sources/XcodeGraph/Models/Cloud.swift @@ -0,0 +1,41 @@ +import Foundation + +/// Cloud represents the configuration to connect to the server. +public struct Cloud: Equatable, Hashable { + /// Cloud option. + public enum Option: String, Codable, Equatable { + case optional + } + + /// The base URL that points to the cloud server + public let url: URL + + /// The project unique identifier. + public let projectId: String + + /// Cloud options. + public let options: [Option] + + /// Initializes an instance of Cloud. + /// - Parameters: + /// - url: Cloud server base URL. + /// - projectId: Project unique identifier. + /// - options: Cloud options. + public init(url: URL, projectId: String, options: [Option]) { + self.url = url + self.projectId = projectId + self.options = options + } +} + +#if DEBUG + extension Cloud { + public static func test( + url: URL = URL(string: "https://cloud.tuist.io")!, + projectId: String = "123", + options: [Cloud.Option] = [] + ) -> Cloud { + Cloud(url: url, projectId: projectId, options: options) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Config.swift b/Sources/XcodeGraph/Models/Config.swift new file mode 100644 index 00000000..ab556fb3 --- /dev/null +++ b/Sources/XcodeGraph/Models/Config.swift @@ -0,0 +1,116 @@ +import Foundation +import Path + +/// This model allows to configure Tuist. +public struct Config: Equatable, Hashable { + /// List of `Plugin`s used to extend Tuist. + public let plugins: [PluginLocation] + + /// Generation options. + public let generationOptions: GenerationOptions + + /// List of Xcode versions the project or set of projects is compatible with. + public let compatibleXcodeVersions: CompatibleXcodeVersions + + /// Cloud configuration. + public let cloud: Cloud? + + /// The version of Swift that will be used by Tuist. + /// If `nil` is passed then Tuist will use the environment’s version. + public let swiftVersion: Version? + + /// The path of the config file. + public let path: AbsolutePath? + + /// Returns the default Tuist configuration. + public static var `default`: Config { + Config( + compatibleXcodeVersions: .all, + cloud: nil, + swiftVersion: nil, + plugins: [], + generationOptions: .init( + resolveDependenciesWithSystemScm: false, + disablePackageVersionLocking: false, + staticSideEffectsWarningTargets: .all + ), + path: nil + ) + } + + /// Initializes the tuist cofiguration. + /// + /// - Parameters: + /// - compatibleXcodeVersions: List of Xcode versions the project or set of projects is compatible with. + /// - cloud: Cloud configuration. + /// - swiftVersion: The version of Swift that will be used by Tuist. + /// - plugins: List of locations to a `Plugin` manifest. + /// - generationOptions: Generation options. + /// - path: The path of the config file. + public init( + compatibleXcodeVersions: CompatibleXcodeVersions, + cloud: Cloud?, + swiftVersion: Version?, + plugins: [PluginLocation], + generationOptions: GenerationOptions, + path: AbsolutePath? + ) { + self.compatibleXcodeVersions = compatibleXcodeVersions + self.cloud = cloud + self.swiftVersion = swiftVersion + self.plugins = plugins + self.generationOptions = generationOptions + self.path = path + } + + // MARK: - Hashable + + public func hash(into hasher: inout Hasher) { + hasher.combine(generationOptions) + hasher.combine(cloud) + hasher.combine(swiftVersion) + hasher.combine(compatibleXcodeVersions) + } +} + +#if DEBUG + extension Config { + public static func test( + compatibleXcodeVersions: CompatibleXcodeVersions = .all, + cloud: Cloud? = Cloud.test(), + swiftVersion: Version? = nil, + plugins: [PluginLocation] = [], + generationOptions: GenerationOptions = Config.default.generationOptions, + path: AbsolutePath? = nil + ) -> Config { + .init( + compatibleXcodeVersions: compatibleXcodeVersions, + cloud: cloud, + swiftVersion: swiftVersion, + plugins: plugins, + generationOptions: generationOptions, + path: path + ) + } + } + + extension Config.GenerationOptions { + public static func test( + resolveDependenciesWithSystemScm: Bool = false, + disablePackageVersionLocking: Bool = false, + clonedSourcePackagesDirPath: AbsolutePath? = nil, + staticSideEffectsWarningTargets: XcodeGraph.Config.GenerationOptions.StaticSideEffectsWarningTargets = .all, + enforceExplicitDependencies: Bool = false, + defaultConfiguration: String? = nil + ) -> Self { + .init( + resolveDependenciesWithSystemScm: resolveDependenciesWithSystemScm, + disablePackageVersionLocking: disablePackageVersionLocking, + clonedSourcePackagesDirPath: clonedSourcePackagesDirPath, + staticSideEffectsWarningTargets: staticSideEffectsWarningTargets, + enforceExplicitDependencies: enforceExplicitDependencies, + defaultConfiguration: defaultConfiguration + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Dependencies/PackageSettings.swift b/Sources/XcodeGraph/Models/Dependencies/PackageSettings.swift new file mode 100644 index 00000000..56732b68 --- /dev/null +++ b/Sources/XcodeGraph/Models/Dependencies/PackageSettings.swift @@ -0,0 +1,66 @@ +import Foundation + +/// Contains the description of custom SPM settings +public struct PackageSettings: Equatable, Codable { + /// The custom `Product` types to be used for SPM targets. + public let productTypes: [String: Product] + + /// Custom destinations to be used for SPM products. + public let productDestinations: [String: Destinations] + + // The base settings to be used for targets generated from SwiftPackageManager + public let baseSettings: Settings + + /// The custom `Settings` to be applied to SPM targets + public let targetSettings: [String: SettingsDictionary] + + /// The custom project options for each project generated from a swift package + public let projectOptions: [String: XcodeGraph.Project.Options] + + /// Swift tools version of the parsed `Package.swift` + public let swiftToolsVersion: Version + + /// Initializes a new `PackageSettings` instance. + /// - Parameters: + /// - productTypes: The custom `Product` types to be used for SPM targets. + /// - baseSettings: The base settings to be used for targets generated from SwiftPackageManager + /// - targetSettings: The custom `SettingsDictionary` to be applied to denoted targets + /// - projectOptions: The custom project options for each project generated from a swift package + public init( + productTypes: [String: Product], + productDestinations: [String: Destinations], + baseSettings: Settings, + targetSettings: [String: SettingsDictionary], + projectOptions: [String: XcodeGraph.Project.Options] = [:], + swiftToolsVersion: Version + ) { + self.productTypes = productTypes + self.productDestinations = productDestinations + self.baseSettings = baseSettings + self.targetSettings = targetSettings + self.projectOptions = projectOptions + self.swiftToolsVersion = swiftToolsVersion + } +} + +#if DEBUG + extension PackageSettings { + public static func test( + productTypes: [String: Product] = [:], + productDestinations: [String: Destinations] = [:], + baseSettings: Settings = .test(), + targetSettings: [String: SettingsDictionary] = [:], + projectOptions: [String: XcodeGraph.Project.Options] = [:], + swiftToolsVersion: Version = Version("5.4.9") + ) -> PackageSettings { + PackageSettings( + productTypes: productTypes, + productDestinations: productDestinations, + baseSettings: baseSettings, + targetSettings: targetSettings, + projectOptions: projectOptions, + swiftToolsVersion: swiftToolsVersion + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Headers.swift b/Sources/XcodeGraph/Models/Headers.swift index 85e76eac..1a4c4dac 100644 --- a/Sources/XcodeGraph/Models/Headers.swift +++ b/Sources/XcodeGraph/Models/Headers.swift @@ -21,3 +21,19 @@ public struct Headers: Equatable, Codable { self.project = project } } + +#if DEBUG + extension Headers { + public static func test( + public: [AbsolutePath] = [], + private: [AbsolutePath] = [], + project: [AbsolutePath] = [] + ) -> Headers { + Headers( + public: `public`, + private: `private`, + project: project + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/IDETemplateMacros.swift b/Sources/XcodeGraph/Models/IDETemplateMacros.swift index 59490b2a..3c4df637 100644 --- a/Sources/XcodeGraph/Models/IDETemplateMacros.swift +++ b/Sources/XcodeGraph/Models/IDETemplateMacros.swift @@ -36,3 +36,11 @@ public struct IDETemplateMacros: Codable, Hashable { return fileHeader } } + +#if DEBUG + extension IDETemplateMacros { + public static func test(fileHeader: String? = "Header template") -> IDETemplateMacros { + IDETemplateMacros(fileHeader: fileHeader) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Metadata/FrameworkMetadata.swift b/Sources/XcodeGraph/Models/Metadata/FrameworkMetadata.swift index d1bf70b6..46943cfa 100644 --- a/Sources/XcodeGraph/Models/Metadata/FrameworkMetadata.swift +++ b/Sources/XcodeGraph/Models/Metadata/FrameworkMetadata.swift @@ -29,3 +29,29 @@ public struct FrameworkMetadata: Equatable { self.status = status } } + +#if DEBUG + extension FrameworkMetadata { + public static func test( + // swiftlint:disable:next force_try + path: AbsolutePath = try! AbsolutePath(validating: "/Frameworks/TestFramework.xframework"), + // swiftlint:disable:next force_try + binaryPath: AbsolutePath = try! AbsolutePath(validating: "/Frameworks/TestFramework.xframework/TestFramework"), + dsymPath: AbsolutePath? = nil, + bcsymbolmapPaths: [AbsolutePath] = [], + linking: BinaryLinking = .dynamic, + architectures: [BinaryArchitecture] = [.arm64], + status: FrameworkStatus = .required + ) -> FrameworkMetadata { + FrameworkMetadata( + path: path, + binaryPath: binaryPath, + dsymPath: dsymPath, + bcsymbolmapPaths: bcsymbolmapPaths, + linking: linking, + architectures: architectures, + status: status + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Metadata/LibraryMetadata.swift b/Sources/XcodeGraph/Models/Metadata/LibraryMetadata.swift index c8aad5cc..5861b6b1 100644 --- a/Sources/XcodeGraph/Models/Metadata/LibraryMetadata.swift +++ b/Sources/XcodeGraph/Models/Metadata/LibraryMetadata.swift @@ -23,3 +23,26 @@ public struct LibraryMetadata: Equatable { self.linking = linking } } + +#if DEBUG + extension LibraryMetadata { + public static func test( + // swiftlint:disable:next force_try + path: AbsolutePath = try! AbsolutePath(validating: "/Libraries/libTest/libTest.a"), + // swiftlint:disable:next force_try + publicHeaders: AbsolutePath = try! AbsolutePath(validating: "/Libraries/libTest/include"), + // swiftlint:disable:next force_try + swiftModuleMap: AbsolutePath? = try! AbsolutePath(validating: "/Libraries/libTest/libTest.swiftmodule"), + architectures: [BinaryArchitecture] = [.arm64], + linking: BinaryLinking = .static + ) -> LibraryMetadata { + LibraryMetadata( + path: path, + publicHeaders: publicHeaders, + swiftModuleMap: swiftModuleMap, + architectures: architectures, + linking: linking + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Metadata/XCFrameworkMetadata.swift b/Sources/XcodeGraph/Models/Metadata/XCFrameworkMetadata.swift index 707bfa74..4e80a582 100644 --- a/Sources/XcodeGraph/Models/Metadata/XCFrameworkMetadata.swift +++ b/Sources/XcodeGraph/Models/Metadata/XCFrameworkMetadata.swift @@ -29,3 +29,30 @@ public struct XCFrameworkMetadata: Equatable { self.macroPath = macroPath } } + +#if DEBUG + extension XCFrameworkMetadata { + public static func test( + // swiftlint:disable:next force_try + path: AbsolutePath = try! AbsolutePath(validating: "/XCFrameworks/XCFramework.xcframework"), + infoPlist: XCFrameworkInfoPlist = .test(), + primaryBinaryPath: AbsolutePath = + // swiftlint:disable:next force_try + try! AbsolutePath(validating: "/XCFrameworks/XCFramework.xcframework/ios-arm64/XCFramework"), + linking: BinaryLinking = .dynamic, + mergeable: Bool = false, + status: FrameworkStatus = .required, + macroPath: AbsolutePath? = nil + ) -> XCFrameworkMetadata { + XCFrameworkMetadata( + path: path, + infoPlist: infoPlist, + primaryBinaryPath: primaryBinaryPath, + linking: linking, + mergeable: mergeable, + status: status, + macroPath: macroPath + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/PlatformCondition.swift b/Sources/XcodeGraph/Models/PlatformCondition.swift index 9709766f..9bfecc0f 100644 --- a/Sources/XcodeGraph/Models/PlatformCondition.swift +++ b/Sources/XcodeGraph/Models/PlatformCondition.swift @@ -62,3 +62,11 @@ public struct PlatformCondition: Codable, Hashable, Equatable, Comparable { } } } + +#if DEBUG + extension PlatformCondition { + static func test(_ platformFilters: PlatformFilters) throws -> PlatformCondition? { + .when(platformFilters) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/PluginResourceSynthesizer.swift b/Sources/XcodeGraph/Models/PluginResourceSynthesizer.swift index 65409941..47048e00 100644 --- a/Sources/XcodeGraph/Models/PluginResourceSynthesizer.swift +++ b/Sources/XcodeGraph/Models/PluginResourceSynthesizer.swift @@ -16,3 +16,17 @@ public struct PluginResourceSynthesizer: Equatable { self.path = path } } + +#if DEBUG + extension PluginResourceSynthesizer { + public static func test( + name: String = "Plugin", + path: AbsolutePath = try! AbsolutePath(validating: "/test") // swiftlint:disable:this force_try + ) -> Self { + .init( + name: name, + path: path + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Plugins.swift b/Sources/XcodeGraph/Models/Plugins.swift new file mode 100644 index 00000000..81e1e75b --- /dev/null +++ b/Sources/XcodeGraph/Models/Plugins.swift @@ -0,0 +1,53 @@ +import Foundation +import Path + +/// A model which contains all loaded plugin representations. +public struct Plugins: Equatable { + /// List of the loaded custom helper plugins. + public let projectDescriptionHelpers: [ProjectDescriptionHelpersPlugin] + + /// List of paths to template definitions. + public let templateDirectories: [AbsolutePath] + + /// List of paths pointing to resource templates + public let resourceSynthesizers: [PluginResourceSynthesizer] + + /// Creates a `Plugins`. + /// + /// - Parameters: + /// - projectDescriptionHelpers: List of the loaded helper plugins. + /// - templatePaths: List of paths to the `Templates/` directory for the loaded plugins. + /// - resourceSynthesizers: List of the loaded resource synthesizer plugins + public init( + projectDescriptionHelpers: [ProjectDescriptionHelpersPlugin], + templatePaths: [AbsolutePath], + resourceSynthesizers: [PluginResourceSynthesizer] + ) { + self.projectDescriptionHelpers = projectDescriptionHelpers + templateDirectories = templatePaths + self.resourceSynthesizers = resourceSynthesizers + } + + /// An empty `Plugins`. + public static let none: Plugins = .init( + projectDescriptionHelpers: [], + templatePaths: [], + resourceSynthesizers: [] + ) +} + +#if DEBUG + extension Plugins { + public static func test( + projectDescriptionHelpers: [ProjectDescriptionHelpersPlugin] = [], + templatePaths: [AbsolutePath] = [], + resourceSynthesizers: [PluginResourceSynthesizer] = [] + ) -> Plugins { + Plugins( + projectDescriptionHelpers: projectDescriptionHelpers, + templatePaths: templatePaths, + resourceSynthesizers: resourceSynthesizers + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/ProfileAction.swift b/Sources/XcodeGraph/Models/ProfileAction.swift index 10694329..d06c1435 100644 --- a/Sources/XcodeGraph/Models/ProfileAction.swift +++ b/Sources/XcodeGraph/Models/ProfileAction.swift @@ -1,4 +1,5 @@ import Foundation +import Path public struct ProfileAction: Equatable, Codable { // MARK: - Attributes @@ -25,3 +26,24 @@ public struct ProfileAction: Equatable, Codable { self.arguments = arguments } } + +#if DEBUG + extension ProfileAction { + public static func test( + configurationName: String = "Beta Release", + preActions: [ExecutionAction] = [], + postActions: [ExecutionAction] = [], + // swiftlint:disable:next force_try + executable: TargetReference? = TargetReference(projectPath: try! AbsolutePath(validating: "/Project"), name: "App"), + arguments: Arguments? = Arguments.test() + ) -> ProfileAction { + ProfileAction( + configurationName: configurationName, + preActions: preActions, + postActions: postActions, + executable: executable, + arguments: arguments + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Project.swift b/Sources/XcodeGraph/Models/Project.swift index 57f95a89..b62969ab 100644 --- a/Sources/XcodeGraph/Models/Project.swift +++ b/Sources/XcodeGraph/Models/Project.swift @@ -149,3 +149,135 @@ public struct Project: Hashable, Equatable, CustomStringConvertible, CustomDebug return buildConfiguration?.name ?? BuildConfiguration.debug.name } } + +#if DEBUG + extension Project { + public static func test( + path: AbsolutePath = try! AbsolutePath(validating: "/Project"), // swiftlint:disable:this force_try + sourceRootPath: AbsolutePath = try! AbsolutePath(validating: "/Project"), // swiftlint:disable:this force_try + // swiftlint:disable:next force_try + xcodeProjPath: AbsolutePath = try! AbsolutePath(validating: "/Project/Project.xcodeproj"), + name: String = "Project", + organizationName: String? = nil, + defaultKnownRegions: [String]? = nil, + developmentRegion: String? = nil, + options: Options = .test(automaticSchemesOptions: .disabled), + settings: Settings = Settings.test(), + filesGroup: ProjectGroup = .group(name: "Project"), + targets: [Target] = [Target.test()], + packages: [Package] = [], + schemes: [Scheme] = [], + ideTemplateMacros: IDETemplateMacros? = nil, + additionalFiles: [FileElement] = [], + resourceSynthesizers: [ResourceSynthesizer] = [], + lastUpgradeCheck: Version? = nil, + isExternal: Bool = false + ) -> Project { + Project( + path: path, + sourceRootPath: sourceRootPath, + xcodeProjPath: xcodeProjPath, + name: name, + organizationName: organizationName, + defaultKnownRegions: defaultKnownRegions, + developmentRegion: developmentRegion, + options: options, + settings: settings, + filesGroup: filesGroup, + targets: targets, + packages: packages, + schemes: schemes, + ideTemplateMacros: ideTemplateMacros, + additionalFiles: additionalFiles, + resourceSynthesizers: resourceSynthesizers, + lastUpgradeCheck: lastUpgradeCheck, + isExternal: isExternal + ) + } + + public static func empty( + path: AbsolutePath = try! AbsolutePath(validating: "/test/"), // swiftlint:disable:this force_try + sourceRootPath: AbsolutePath = try! AbsolutePath(validating: "/test/"), // swiftlint:disable:this force_try + xcodeProjPath: AbsolutePath = try! AbsolutePath(validating: "/test/text.xcodeproj"), + // swiftlint:disable:this force_try + name: String = "Project", + organizationName: String? = nil, + defaultKnownRegions: [String]? = nil, + developmentRegion: String? = nil, + options: Options = .test(automaticSchemesOptions: .disabled), + settings: Settings = .default, + filesGroup: ProjectGroup = .group(name: "Project"), + targets: [Target] = [], + packages: [Package] = [], + schemes: [Scheme] = [], + ideTemplateMacros: IDETemplateMacros? = nil, + additionalFiles: [FileElement] = [], + resourceSynthesizers: [ResourceSynthesizer] = [], + lastUpgradeCheck: Version? = nil, + isExternal: Bool = false + ) -> Project { + Project( + path: path, + sourceRootPath: sourceRootPath, + xcodeProjPath: xcodeProjPath, + name: name, + organizationName: organizationName, + defaultKnownRegions: defaultKnownRegions, + developmentRegion: developmentRegion, + options: options, + settings: settings, + filesGroup: filesGroup, + targets: targets, + packages: packages, + schemes: schemes, + ideTemplateMacros: ideTemplateMacros, + additionalFiles: additionalFiles, + resourceSynthesizers: resourceSynthesizers, + lastUpgradeCheck: lastUpgradeCheck, + isExternal: isExternal + ) + } + } + + extension Project.Options { + public static func test( + automaticSchemesOptions: AutomaticSchemesOptions = .enabled( + targetSchemesGrouping: .byNameSuffix( + build: ["Implementation", "Interface", "Mocks", "Testing"], + test: ["Tests", "IntegrationTests", "UITests", "SnapshotTests"], + run: ["App", "Demo"] + ), + codeCoverageEnabled: false, + testingOptions: [] + ), + disableBundleAccessors: Bool = false, + disableShowEnvironmentVarsInScriptPhases: Bool = false, + disableSynthesizedResourceAccessors: Bool = false, + textSettings: TextSettings = .init(usesTabs: nil, indentWidth: nil, tabWidth: nil, wrapsLines: nil) + ) -> Self { + .init( + automaticSchemesOptions: automaticSchemesOptions, + disableBundleAccessors: disableBundleAccessors, + disableShowEnvironmentVarsInScriptPhases: disableShowEnvironmentVarsInScriptPhases, + disableSynthesizedResourceAccessors: disableSynthesizedResourceAccessors, + textSettings: textSettings + ) + } + } + + extension Project.Options.TextSettings { + public static func test( + usesTabs: Bool? = true, + indentWidth: UInt? = 2, + tabWidth: UInt? = 2, + wrapsLines: Bool? = true + ) -> Self { + .init( + usesTabs: usesTabs, + indentWidth: indentWidth, + tabWidth: tabWidth, + wrapsLines: wrapsLines + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/RawScriptBuildPhase.swift b/Sources/XcodeGraph/Models/RawScriptBuildPhase.swift index a1588453..808748f8 100644 --- a/Sources/XcodeGraph/Models/RawScriptBuildPhase.swift +++ b/Sources/XcodeGraph/Models/RawScriptBuildPhase.swift @@ -38,3 +38,16 @@ public struct RawScriptBuildPhase: Equatable, Codable { self.shellPath = shellPath } } + +#if DEBUG + extension RawScriptBuildPhase { + public static func test( + name: String = "Test", + script: String = "", + showEnvVarsInLog: Bool = false, + hashable: Bool = false + ) -> RawScriptBuildPhase { + RawScriptBuildPhase(name: name, script: script, showEnvVarsInLog: showEnvVarsInLog, hashable: hashable) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/ResourceSynthesizer.swift b/Sources/XcodeGraph/Models/ResourceSynthesizer.swift index 67a5e5ac..f1ce4edd 100644 --- a/Sources/XcodeGraph/Models/ResourceSynthesizer.swift +++ b/Sources/XcodeGraph/Models/ResourceSynthesizer.swift @@ -94,3 +94,16 @@ extension ResourceSynthesizer.Parser.Option: ExpressibleByArrayLiteral { self = .init(value: elements) } } + +#if DEBUG + extension XcodeGraph.ResourceSynthesizer { + public static func test( + parser: Parser = .assets, + parserOptions: [String: Parser.Option] = [:], + extensions: Set = ["xcassets"], + template: Template = .defaultTemplate("Assets") + ) -> Self { + ResourceSynthesizer(parser: parser, parserOptions: parserOptions, extensions: extensions, template: template) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/RunAction.swift b/Sources/XcodeGraph/Models/RunAction.swift index a7ac3aa9..e6774dd1 100644 --- a/Sources/XcodeGraph/Models/RunAction.swift +++ b/Sources/XcodeGraph/Models/RunAction.swift @@ -47,3 +47,41 @@ public struct RunAction: Equatable, Codable { self.launchStyle = launchStyle } } + +#if DEBUG + extension RunAction { + public static func test( + configurationName: String = BuildConfiguration.debug.name, + attachDebugger: Bool = true, + customLLDBInitFile: AbsolutePath? = nil, + preActions: [ExecutionAction] = [], + postActions: [ExecutionAction] = [], + // swiftlint:disable:next force_try + executable: TargetReference? = TargetReference(projectPath: try! AbsolutePath(validating: "/Project"), name: "App"), + filePath: AbsolutePath? = nil, + arguments: Arguments? = Arguments.test(), + options: RunActionOptions = .init(), + diagnosticsOptions: SchemeDiagnosticsOptions = XcodeGraph.SchemeDiagnosticsOptions( + mainThreadCheckerEnabled: true, + performanceAntipatternCheckerEnabled: true + ), + expandVariableFromTarget: TargetReference? = nil, + launchStyle: LaunchStyle = .automatically + ) -> RunAction { + RunAction( + configurationName: configurationName, + attachDebugger: attachDebugger, + customLLDBInitFile: customLLDBInitFile, + preActions: preActions, + postActions: postActions, + executable: executable, + filePath: filePath, + arguments: arguments, + options: options, + diagnosticsOptions: diagnosticsOptions, + expandVariableFromTarget: expandVariableFromTarget, + launchStyle: launchStyle + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Scheme.swift b/Sources/XcodeGraph/Models/Scheme.swift index 8440cd14..fb40a136 100644 --- a/Sources/XcodeGraph/Models/Scheme.swift +++ b/Sources/XcodeGraph/Models/Scheme.swift @@ -38,3 +38,29 @@ public struct Scheme: Equatable, Codable { self.analyzeAction = analyzeAction } } + +#if DEBUG + extension Scheme { + public static func test( + name: String = "Test", + shared: Bool = false, + buildAction: BuildAction? = BuildAction.test(), + testAction: TestAction? = TestAction.test(), + runAction: RunAction? = RunAction.test(), + archiveAction: ArchiveAction? = ArchiveAction.test(), + profileAction: ProfileAction? = ProfileAction.test(), + analyzeAction: AnalyzeAction? = AnalyzeAction.test() + ) -> Scheme { + Scheme( + name: name, + shared: shared, + buildAction: buildAction, + testAction: testAction, + runAction: runAction, + archiveAction: archiveAction, + profileAction: profileAction, + analyzeAction: analyzeAction + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Settings.swift b/Sources/XcodeGraph/Models/Settings.swift index 8e103c3d..a89d1ede 100644 --- a/Sources/XcodeGraph/Models/Settings.swift +++ b/Sources/XcodeGraph/Models/Settings.swift @@ -199,3 +199,50 @@ extension [String: SettingValue] { } } } + +#if DEBUG + extension Configuration { + public static func test( + settings: SettingsDictionary = [:], + xcconfig: AbsolutePath? = try! AbsolutePath(validating: "/Config.xcconfig") // swiftlint:disable:this force_try + ) -> Configuration { + Configuration(settings: settings, xcconfig: xcconfig) + } + } + + extension Settings { + public static func test( + base: SettingsDictionary, + debug: Configuration, + release: Configuration + ) -> Settings { + Settings( + base: base, + configurations: [.debug: debug, .release: release] + ) + } + + public static func test( + base: SettingsDictionary = [:], + baseDebug: SettingsDictionary = [:], + configurations: [BuildConfiguration: Configuration?] = [:] + ) -> Settings { + Settings( + base: base, + baseDebug: baseDebug, + configurations: configurations + ) + } + + public static func test(defaultSettings: DefaultSettings) -> Settings { + Settings( + base: [:], + configurations: [ + .debug: Configuration(settings: [:]), + .release: Configuration(settings: [:]), + ], + defaultSettings: defaultSettings + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Target.swift b/Sources/XcodeGraph/Models/Target.swift index ad5ab358..29fd5b96 100644 --- a/Sources/XcodeGraph/Models/Target.swift +++ b/Sources/XcodeGraph/Models/Target.swift @@ -371,3 +371,186 @@ extension Sequence { filter { $0.product == .app || $0.product == .appClip } } } + +#if DEBUG + extension Target { + /// Creates a Target with test data + /// Note: Referenced paths may not exist + public static func test( + name: String = "Target", + destinations: Destinations = [.iPhone, .iPad], + product: Product = .app, + productName: String? = nil, + bundleId: String? = nil, + deploymentTargets: DeploymentTargets = .iOS("13.1"), + infoPlist: InfoPlist? = nil, + entitlements: Entitlements? = nil, + settings: Settings? = Settings.test(), + sources: [SourceFile] = [], + resources: ResourceFileElements = .init([]), + copyFiles: [CopyFilesAction] = [], + coreDataModels: [CoreDataModel] = [], + headers: Headers? = nil, + scripts: [TargetScript] = [], + environmentVariables: [String: EnvironmentVariable] = [:], + filesGroup: ProjectGroup = .group(name: "Project"), + dependencies: [TargetDependency] = [], + rawScriptBuildPhases: [RawScriptBuildPhase] = [], + launchArguments: [LaunchArgument] = [], + playgrounds: [AbsolutePath] = [], + additionalFiles: [FileElement] = [], + prune: Bool = false, + mergedBinaryType: MergedBinaryType = .disabled, + mergeable: Bool = false + ) -> Target { + Target( + name: name, + destinations: destinations, + product: product, + productName: productName, + bundleId: bundleId ?? "io.tuist.\(name)", + deploymentTargets: deploymentTargets, + infoPlist: infoPlist, + entitlements: entitlements, + settings: settings, + sources: sources, + resources: resources, + copyFiles: copyFiles, + headers: headers, + coreDataModels: coreDataModels, + scripts: scripts, + environmentVariables: environmentVariables, + launchArguments: launchArguments, + filesGroup: filesGroup, + dependencies: dependencies, + rawScriptBuildPhases: rawScriptBuildPhases, + playgrounds: playgrounds, + additionalFiles: additionalFiles, + prune: prune, + mergedBinaryType: mergedBinaryType, + mergeable: mergeable + ) + } + + /// Creates a Target with test data + /// Note: Referenced paths may not exist + public static func test( + name: String = "Target", + platform: Platform, + product: Product = .app, + productName: String? = nil, + bundleId: String? = nil, + deploymentTarget: DeploymentTargets = .iOS("13.1"), + infoPlist: InfoPlist? = nil, + entitlements: Entitlements? = nil, + settings: Settings? = Settings.test(), + sources: [SourceFile] = [], + resources: ResourceFileElements = .init([]), + copyFiles: [CopyFilesAction] = [], + coreDataModels: [CoreDataModel] = [], + headers: Headers? = nil, + scripts: [TargetScript] = [], + environmentVariables: [String: EnvironmentVariable] = [:], + filesGroup: ProjectGroup = .group(name: "Project"), + dependencies: [TargetDependency] = [], + rawScriptBuildPhases: [RawScriptBuildPhase] = [], + launchArguments: [LaunchArgument] = [], + playgrounds: [AbsolutePath] = [], + additionalFiles: [FileElement] = [], + prune: Bool = false, + mergedBinaryType: MergedBinaryType = .disabled, + mergeable: Bool = false + ) -> Target { + Target( + name: name, + destinations: destinationsFrom(platform), + product: product, + productName: productName, + bundleId: bundleId ?? "io.tuist.\(name)", + deploymentTargets: deploymentTarget, + infoPlist: infoPlist, + entitlements: entitlements, + settings: settings, + sources: sources, + resources: resources, + copyFiles: copyFiles, + headers: headers, + coreDataModels: coreDataModels, + scripts: scripts, + environmentVariables: environmentVariables, + launchArguments: launchArguments, + filesGroup: filesGroup, + dependencies: dependencies, + rawScriptBuildPhases: rawScriptBuildPhases, + playgrounds: playgrounds, + additionalFiles: additionalFiles, + prune: prune, + mergedBinaryType: mergedBinaryType, + mergeable: mergeable + ) + } + + /// Creates a bare bones Target with as little data as possible + public static func empty( + name: String = "Target", + destinations: Destinations = [.iPhone, .iPad], + product: Product = .app, + productName: String? = nil, + bundleId: String? = nil, + deploymentTargets: DeploymentTargets = .init(), + infoPlist: InfoPlist? = nil, + entitlements: Entitlements? = nil, + settings: Settings? = nil, + sources: [SourceFile] = [], + resources: ResourceFileElements = .init([]), + copyFiles: [CopyFilesAction] = [], + coreDataModels: [CoreDataModel] = [], + headers: Headers? = nil, + scripts: [TargetScript] = [], + environmentVariables: [String: EnvironmentVariable] = [:], + filesGroup: ProjectGroup = .group(name: "Project"), + dependencies: [TargetDependency] = [], + rawScriptBuildPhases: [RawScriptBuildPhase] = [], + onDemandResourcesTags: OnDemandResourcesTags? = nil + ) -> Target { + Target( + name: name, + destinations: destinations, + product: product, + productName: productName, + bundleId: bundleId ?? "io.tuist.\(name)", + deploymentTargets: deploymentTargets, + infoPlist: infoPlist, + entitlements: entitlements, + settings: settings, + sources: sources, + resources: resources, + copyFiles: copyFiles, + headers: headers, + coreDataModels: coreDataModels, + scripts: scripts, + environmentVariables: environmentVariables, + filesGroup: filesGroup, + dependencies: dependencies, + rawScriptBuildPhases: rawScriptBuildPhases, + onDemandResourcesTags: onDemandResourcesTags + ) + } + + // Maps a platform to a set of Destinations. For migration purposes + private static func destinationsFrom(_ platform: Platform) -> Destinations { + switch platform { + case .iOS: + return .iOS + case .macOS: + return .macOS + case .tvOS: + return .tvOS + case .watchOS: + return .watchOS + case .visionOS: + return .visionOS + } + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Template.swift b/Sources/XcodeGraph/Models/Template.swift new file mode 100644 index 00000000..98b6a642 --- /dev/null +++ b/Sources/XcodeGraph/Models/Template.swift @@ -0,0 +1,179 @@ +import Path + +public struct Template: Equatable { + public let description: String + public let attributes: [Attribute] + public let items: [Item] + + public init( + description: String, + attributes: [Attribute] = [], + items: [Item] = [] + ) { + self.description = description + self.attributes = attributes + self.items = items + } + + public enum Attribute: Equatable { + case required(String) + case optional(String, default: Value) + + public var isOptional: Bool { + switch self { + case .required: + return false + case .optional: + return true + } + } + + public var name: String { + switch self { + case let .required(name): + return name + case let .optional(name, default: _): + return name + } + } + } + + public enum Contents: Equatable { + case string(String) + case file(AbsolutePath) + case directory(AbsolutePath) + } + + public struct Item: Equatable { + public let path: RelativePath + public let contents: Contents + + public init( + path: RelativePath, + contents: Contents + ) { + self.path = path + self.contents = contents + } + } +} + +extension Template.Attribute { + /// This represents the default value type of Attribute + public indirect enum Value: Equatable { + /// It represents a string value. + case string(String) + /// It represents an integer value. + case integer(Int) + /// It represents a floating value. + case real(Double) + /// It represents a boolean value. + case boolean(Bool) + /// It represents a dictionary value. + case dictionary([String: Value]) + /// It represents an array value. + case array([Value]) + } +} + +extension Template.Attribute.Value: RawRepresentable { + public typealias RawValue = Any + + public init?(rawValue: RawValue) { + switch rawValue { + case is String: + if let string = rawValue as? String { + self = .string(string) + } else { + return nil + } + case is Int: + if let integer = rawValue as? Int { + self = .integer(integer) + } else { + return nil + } + case is Double: + if let real = rawValue as? Double { + self = .real(real) + } else { + return nil + } + case is Bool: + if let boolean = rawValue as? Bool { + self = .boolean(boolean) + } else { + return nil + } + case is [String: Any]: + if let dictionary = rawValue as? [String: Any] { + var newDictionary: [String: Self] = [:] + for (key, value) in dictionary { + newDictionary[key] = .init(rawValue: value) + } + self = .dictionary(newDictionary) + } else { + return nil + } + case is [Any]: + if let array = rawValue as? [Any] { + let newArray: [Self] = array.map { .init(rawValue: $0) }.compactMap { $0 } + self = .array(newArray) + } else { + return nil + } + default: + return nil + } + } + + public var rawValue: RawValue { + switch self { + case let .string(string): + return string + case let .integer(integer): + return integer + case let .real(real): + return real + case let .boolean(boolean): + return boolean + case let .dictionary(dictionary): + var newDictionary: [String: Any] = [:] + for (key, value) in dictionary { + newDictionary[key] = value.rawValue + } + return newDictionary + case let .array(array): + let newArray: [Any] = array.map(\.rawValue) + return newArray + } + } +} + +#if DEBUG + extension Template { + public static func test( + description: String = "Template", + attributes: [Attribute] = [], + items: [Template.Item] = [] + ) -> Template { + Template( + description: description, + attributes: attributes, + items: items + ) + } + } + + extension Template.Item { + public static func test( + path: RelativePath, + contents: Template.Contents = .string("test content") + ) -> Template.Item { + Template.Item( + path: path, + contents: contents + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/TestAction.swift b/Sources/XcodeGraph/Models/TestAction.swift index 501251af..8575a4fb 100644 --- a/Sources/XcodeGraph/Models/TestAction.swift +++ b/Sources/XcodeGraph/Models/TestAction.swift @@ -56,3 +56,47 @@ public struct TestAction: Equatable, Codable { self.skippedTests = skippedTests } } + +#if DEBUG + extension TestAction { + public static func test( + targets: [TestableTarget] = [TestableTarget(target: TargetReference( + // swiftlint:disable:next force_try + projectPath: try! AbsolutePath(validating: "/Project"), + name: "AppTests" + ))], + arguments: Arguments? = Arguments.test(), + configurationName: String = BuildConfiguration.debug.name, + attachDebugger: Bool = true, + coverage: Bool = false, + codeCoverageTargets: [TargetReference] = [], + expandVariableFromTarget: TargetReference? = nil, + preActions: [ExecutionAction] = [], + postActions: [ExecutionAction] = [], + diagnosticsOptions: SchemeDiagnosticsOptions = SchemeDiagnosticsOptions(mainThreadCheckerEnabled: true), + language: String? = nil, + region: String? = nil, + preferredScreenCaptureFormat: ScreenCaptureFormat? = nil, + testPlans: [TestPlan]? = nil, + skippedTests: [String]? = nil + ) -> TestAction { + TestAction( + targets: targets, + arguments: arguments, + configurationName: configurationName, + attachDebugger: attachDebugger, + coverage: coverage, + codeCoverageTargets: codeCoverageTargets, + expandVariableFromTarget: expandVariableFromTarget, + preActions: preActions, + postActions: postActions, + diagnosticsOptions: diagnosticsOptions, + language: language, + region: region, + preferredScreenCaptureFormat: preferredScreenCaptureFormat, + testPlans: testPlans, + skippedTests: skippedTests + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/TestableTarget.swift b/Sources/XcodeGraph/Models/TestableTarget.swift index b53e6099..c6522ab5 100644 --- a/Sources/XcodeGraph/Models/TestableTarget.swift +++ b/Sources/XcodeGraph/Models/TestableTarget.swift @@ -1,4 +1,5 @@ import Foundation +import Path /// Testable target describe target and tests information. public struct TestableTarget: Equatable, Hashable, Codable { @@ -27,3 +28,24 @@ public struct TestableTarget: Equatable, Hashable, Codable { self.simulatedLocation = simulatedLocation } } + +#if DEBUG + extension TestableTarget { + public static func test( + // swiftlint:disable:next force_try + target: TargetReference = TargetReference(projectPath: try! AbsolutePath(validating: "/Project"), name: "App"), + skipped: Bool = false, + parallelizable: Bool = false, + randomExecutionOrdering: Bool = false, + simulatedLocation: SimulatedLocation? = nil + ) -> TestableTarget { + TestableTarget( + target: target, + skipped: skipped, + parallelizable: parallelizable, + randomExecutionOrdering: randomExecutionOrdering, + simulatedLocation: simulatedLocation + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/Workspace.swift b/Sources/XcodeGraph/Models/Workspace.swift index e66ea8c1..4fc7f6fa 100644 --- a/Sources/XcodeGraph/Models/Workspace.swift +++ b/Sources/XcodeGraph/Models/Workspace.swift @@ -147,3 +147,50 @@ extension Workspace { } } } + +#if DEBUG + extension Workspace { + public static func test( + path: AbsolutePath = try! AbsolutePath(validating: "/"), // swiftlint:disable:this force_try + xcWorkspacePath: AbsolutePath = try! AbsolutePath(validating: "/"), // swiftlint:disable:this force_try + name: String = "test", + projects: [AbsolutePath] = [], + schemes: [Scheme] = [], + ideTemplateMacros: IDETemplateMacros? = nil, + additionalFiles: [FileElement] = [], + generationOptions: GenerationOptions = .test() + ) -> Workspace { + Workspace( + path: path, + xcWorkspacePath: xcWorkspacePath, + name: name, + projects: projects, + schemes: schemes, + generationOptions: generationOptions, + ideTemplateMacros: ideTemplateMacros, + additionalFiles: additionalFiles + ) + } + } + + extension Workspace.GenerationOptions { + public static func test( + enableAutomaticXcodeSchemes: Bool? = false, + autogeneratedWorkspaceSchemes: AutogeneratedWorkspaceSchemes = .enabled( + codeCoverageMode: .disabled, + testingOptions: [], + testLanguage: nil, + testRegion: nil, + testScreenCaptureFormat: nil + ), + lastXcodeUpgradeCheck: Version? = nil + ) -> Self { + .init( + enableAutomaticXcodeSchemes: enableAutomaticXcodeSchemes, + autogeneratedWorkspaceSchemes: autogeneratedWorkspaceSchemes, + lastXcodeUpgradeCheck: lastXcodeUpgradeCheck, + renderMarkdownReadme: false + ) + } + } +#endif diff --git a/Sources/XcodeGraph/Models/XCFrameworkInfoPlist.swift b/Sources/XcodeGraph/Models/XCFrameworkInfoPlist.swift index 27b56a1f..41767bbf 100644 --- a/Sources/XcodeGraph/Models/XCFrameworkInfoPlist.swift +++ b/Sources/XcodeGraph/Models/XCFrameworkInfoPlist.swift @@ -70,3 +70,28 @@ public struct XCFrameworkInfoPlist: Codable, Hashable, Equatable { /// List of libraries that are part of the .xcframework. public let libraries: [Library] } + +#if DEBUG + extension XCFrameworkInfoPlist { + public static func test(libraries: [XCFrameworkInfoPlist.Library] = [.test()]) -> XCFrameworkInfoPlist { + XCFrameworkInfoPlist(libraries: libraries) + } + } + + extension XCFrameworkInfoPlist.Library { + public static func test( + identifier: String = "test", + // swiftlint:disable:next force_try + path: RelativePath = try! RelativePath(validating: "relative/to/library"), + mergeable: Bool = false, + architectures: [BinaryArchitecture] = [.i386] + ) -> XCFrameworkInfoPlist.Library { + XCFrameworkInfoPlist.Library( + identifier: identifier, + path: path, + mergeable: mergeable, + architectures: architectures + ) + } + } +#endif diff --git a/Sources/XcodeGraphTesting/DependenciesGraph/DependenciesGraph+TestData.swift b/Sources/XcodeGraphTesting/DependenciesGraph/DependenciesGraph+TestData.swift deleted file mode 100644 index fe51b9b2..00000000 --- a/Sources/XcodeGraphTesting/DependenciesGraph/DependenciesGraph+TestData.swift +++ /dev/null @@ -1,176 +0,0 @@ -import Foundation -import Path -import XcodeGraph - -extension DependenciesGraph { - public static func test( - externalDependencies: [String: [TargetDependency]] = [:], - externalProjects: [AbsolutePath: Project] = [:] - ) -> Self { - .init(externalDependencies: externalDependencies, externalProjects: externalProjects) - } - - public static func testXCFramework( - name: String = "Test", - // swiftlint:disable:next force_try - path: AbsolutePath = AbsolutePath.root.appending(try! RelativePath(validating: "Test.xcframework")), - status: FrameworkStatus = .required - ) -> DependenciesGraph { - let externalDependencies = [name: [TargetDependency.xcframework(path: path, status: status)]] - - return .init( - externalDependencies: externalDependencies, - externalProjects: [:] - ) - } - - public static func test( - packageFolder: AbsolutePath - ) -> Self { - let externalDependencies = [ - "Tuist": [ - TargetDependency.project( - target: "Tuist", - path: packageFolder - ), - ], - ] - - return .init( - externalDependencies: externalDependencies, - externalProjects: [:] - ) - } - - public static func aDependency( - packageFolder: AbsolutePath - ) -> Self { - let externalDependencies = [ - "ALibrary": [ - TargetDependency.project( - target: "ALibrary", - path: packageFolder - ), - ], - ] - - return .init( - externalDependencies: externalDependencies, - externalProjects: [:] - ) - } - - public static func anotherDependency( - packageFolder: AbsolutePath - ) -> Self { - let externalDependencies = [ - "AnotherLibrary": [ - TargetDependency.project( - target: "AnotherLibrary", - path: packageFolder - ), - ], - ] - - return .init( - externalDependencies: externalDependencies, - externalProjects: [:] - ) - } - - public static func alamofire( - packageFolder: AbsolutePath - ) -> Self { - let externalDependencies = [ - "Alamofire": [ - TargetDependency.project( - target: "Alamofire", - path: packageFolder - ), - ], - ] - - return .init( - externalDependencies: externalDependencies, - externalProjects: [:] - ) - } - - public static func googleAppMeasurement( - packageFolder: AbsolutePath - ) -> Self { - let externalDependencies = [ - "GoogleAppMeasurement": [ - TargetDependency.project( - target: "GoogleAppMeasurementTarget", - path: packageFolder - ), - ], - "GoogleAppMeasurementWithoutAdIdSupport": [ - TargetDependency.project( - target: "GoogleAppMeasurementWithoutAdIdSupportTarget", - path: packageFolder - ), - ], - ] - - return .init( - externalDependencies: externalDependencies, - externalProjects: [:] - ) - } - - public static func googleUtilities( - packageFolder: AbsolutePath - ) -> Self { - let externalDependencies = [ - "GULAppDelegateSwizzler": [ - TargetDependency.project( - target: "GULAppDelegateSwizzler", - path: packageFolder - ), - ], - "GULMethodSwizzler": [ - TargetDependency.project( - target: "GULMethodSwizzler", - path: packageFolder - ), - ], - "GULNSData": [ - TargetDependency.project( - target: "GULNSData", - path: packageFolder - ), - ], - "GULNetwork": [ - TargetDependency.project( - target: "GULNetwork", - path: packageFolder - ), - ], - ] - - return .init( - externalDependencies: externalDependencies, - externalProjects: [:] - ) - } - - public static func nanopb( - packageFolder: AbsolutePath - ) -> Self { - let externalDependencies = [ - "nanopb": [ - TargetDependency.project( - target: "nanopb", - path: packageFolder - ), - ], - ] - - return .init( - externalDependencies: externalDependencies, - externalProjects: [:] - ) - } -} diff --git a/Sources/XcodeGraphTesting/Graph/Graph+TestData.swift b/Sources/XcodeGraphTesting/Graph/Graph+TestData.swift deleted file mode 100644 index 266b1c0c..00000000 --- a/Sources/XcodeGraphTesting/Graph/Graph+TestData.swift +++ /dev/null @@ -1,25 +0,0 @@ -import Foundation -import Path -import XcodeGraph - -extension Graph { - public static func test( - name: String = "graph", - path: AbsolutePath = .root, - workspace: Workspace = .test(), - projects: [AbsolutePath: Project] = [:], - packages: [AbsolutePath: [String: Package]] = [:], - dependencies: [GraphDependency: Set] = [:], - dependencyConditions: [GraphEdge: PlatformCondition] = [:] - ) -> Graph { - Graph( - name: name, - path: path, - workspace: workspace, - projects: projects, - packages: packages, - dependencies: dependencies, - dependencyConditions: dependencyConditions - ) - } -} diff --git a/Sources/XcodeGraphTesting/Graph/GraphDependency+TestData.swift b/Sources/XcodeGraphTesting/Graph/GraphDependency+TestData.swift deleted file mode 100644 index 8373926c..00000000 --- a/Sources/XcodeGraphTesting/Graph/GraphDependency+TestData.swift +++ /dev/null @@ -1,113 +0,0 @@ -import Foundation -import Path - -@testable import XcodeGraph - -// swiftlint:disable force_try - -extension GraphDependency { - public static func testFramework( - path: AbsolutePath = AbsolutePath.root.appending(component: "Test.framework"), - binaryPath: AbsolutePath = AbsolutePath.root.appending(try! RelativePath(validating: "Test.framework/Test")), - dsymPath: AbsolutePath? = nil, - bcsymbolmapPaths: [AbsolutePath] = [], - linking: BinaryLinking = .dynamic, - architectures: [BinaryArchitecture] = [.armv7], - status: FrameworkStatus = .required - ) -> GraphDependency { - GraphDependency.framework( - path: path, - binaryPath: binaryPath, - dsymPath: dsymPath, - bcsymbolmapPaths: bcsymbolmapPaths, - linking: linking, - architectures: architectures, - status: status - ) - } - - public static func testMacro( - path: AbsolutePath = AbsolutePath.root.appending(try! RelativePath(validating: "macro")) - ) -> GraphDependency { - .macro(path: path) - } - - public static func testXCFramework( - path: AbsolutePath = AbsolutePath.root.appending(try! RelativePath(validating: "Test.xcframework")), - infoPlist: XCFrameworkInfoPlist = .test(), - primaryBinaryPath: AbsolutePath = AbsolutePath.root - .appending(try! RelativePath(validating: "Test.xcframework/Test")), - linking: BinaryLinking = .dynamic, - status: FrameworkStatus = .required, - macroPath: AbsolutePath? = nil - ) -> GraphDependency { - .xcframework( - GraphDependency.XCFramework( - path: path, - infoPlist: infoPlist, - primaryBinaryPath: primaryBinaryPath, - linking: linking, - mergeable: false, - status: status, - macroPath: macroPath - ) - ) - } - - public static func testTarget( - name: String = "Test", - path: AbsolutePath = .root - ) -> GraphDependency { - .target( - name: name, - path: path - ) - } - - public static func testSDK( - name: String = "XCTest.framework", - path: AbsolutePath = AbsolutePath.root.appending(try! RelativePath(validating: "XCTest.framework")), - status: SDKStatus = .required, - source: SDKSource = .system - ) -> GraphDependency { - .sdk( - name: name, - path: path, - status: status, - source: source - ) - } - - public static func testLibrary( - path: AbsolutePath = AbsolutePath.root.appending(try! RelativePath(validating: "libTuist.a")), - publicHeaders: AbsolutePath = AbsolutePath.root.appending(try! RelativePath(validating: "headers")), - linking: BinaryLinking = .dynamic, - architectures: [BinaryArchitecture] = [.armv7], - swiftModuleMap: AbsolutePath? = nil - ) -> GraphDependency { - .library( - path: path, - publicHeaders: publicHeaders, - linking: linking, - architectures: architectures, - swiftModuleMap: swiftModuleMap - ) - } - - public static func testBundle(path: AbsolutePath = .root.appending(component: "test.bundle")) -> GraphDependency { - .bundle(path: path) - } - - public static func testPackageProduct( - path: AbsolutePath = .root, - product: String = "Tuist" - ) -> GraphDependency { - .packageProduct( - path: path, - product: product, - type: .runtime - ) - } -} - -// swiftlint:enable force_try diff --git a/Sources/XcodeGraphTesting/Graph/GraphTarget+TestData.swift b/Sources/XcodeGraphTesting/Graph/GraphTarget+TestData.swift deleted file mode 100644 index 5bf7fc67..00000000 --- a/Sources/XcodeGraphTesting/Graph/GraphTarget+TestData.swift +++ /dev/null @@ -1,18 +0,0 @@ -import Foundation -import Path - -@testable import XcodeGraph - -extension GraphTarget { - public static func test( - path: AbsolutePath = .root, - target: Target = .test(), - project: Project = .test() - ) -> GraphTarget { - GraphTarget( - path: path, - target: target, - project: project - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/AnalyzeAction+TestData.swift b/Sources/XcodeGraphTesting/Models/AnalyzeAction+TestData.swift deleted file mode 100644 index 28e1b7ed..00000000 --- a/Sources/XcodeGraphTesting/Models/AnalyzeAction+TestData.swift +++ /dev/null @@ -1,9 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension AnalyzeAction { - public static func test(configurationName: String = "Beta Release") -> AnalyzeAction { - AnalyzeAction(configurationName: configurationName) - } -} diff --git a/Sources/XcodeGraphTesting/Models/ArchiveAction+TestData.swift b/Sources/XcodeGraphTesting/Models/ArchiveAction+TestData.swift deleted file mode 100644 index 0e1e9156..00000000 --- a/Sources/XcodeGraphTesting/Models/ArchiveAction+TestData.swift +++ /dev/null @@ -1,21 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension ArchiveAction { - public static func test( - configurationName: String = "Beta Release", - revealArchiveInOrganizer: Bool = true, - customArchiveName: String? = nil, - preActions: [ExecutionAction] = [], - postActions: [ExecutionAction] = [] - ) -> ArchiveAction { - ArchiveAction( - configurationName: configurationName, - revealArchiveInOrganizer: revealArchiveInOrganizer, - customArchiveName: customArchiveName, - preActions: preActions, - postActions: postActions - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/Arguments+TestData.swift b/Sources/XcodeGraphTesting/Models/Arguments+TestData.swift deleted file mode 100644 index ed2d6c95..00000000 --- a/Sources/XcodeGraphTesting/Models/Arguments+TestData.swift +++ /dev/null @@ -1,15 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension Arguments { - public static func test( - environmentVariables: [String: EnvironmentVariable] = [:], - launchArguments: [LaunchArgument] = [] - ) -> Arguments { - Arguments( - environmentVariables: environmentVariables, - launchArguments: launchArguments - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/BuildAction+TestData.swift b/Sources/XcodeGraphTesting/Models/BuildAction+TestData.swift deleted file mode 100644 index 62a4b15c..00000000 --- a/Sources/XcodeGraphTesting/Models/BuildAction+TestData.swift +++ /dev/null @@ -1,14 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension BuildAction { - public static func test( - // swiftlint:disable:next force_try - targets: [TargetReference] = [TargetReference(projectPath: try! AbsolutePath(validating: "/Project"), name: "App")], - preActions: [ExecutionAction] = [], - postActions: [ExecutionAction] = [] - ) -> BuildAction { - BuildAction(targets: targets, preActions: preActions, postActions: postActions) - } -} diff --git a/Sources/XcodeGraphTesting/Models/Condition+TestData.swift b/Sources/XcodeGraphTesting/Models/Condition+TestData.swift deleted file mode 100644 index 6500e4af..00000000 --- a/Sources/XcodeGraphTesting/Models/Condition+TestData.swift +++ /dev/null @@ -1,9 +0,0 @@ -import Foundation -import XcodeGraph -import XCTest - -extension PlatformCondition { - static func test(_ platformFilters: PlatformFilters) throws -> PlatformCondition { - try XCTUnwrap(.when(platformFilters)) - } -} diff --git a/Sources/XcodeGraphTesting/Models/Headers+TestData.swift b/Sources/XcodeGraphTesting/Models/Headers+TestData.swift deleted file mode 100644 index 4a6641b5..00000000 --- a/Sources/XcodeGraphTesting/Models/Headers+TestData.swift +++ /dev/null @@ -1,17 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension Headers { - public static func test( - public: [AbsolutePath] = [], - private: [AbsolutePath] = [], - project: [AbsolutePath] = [] - ) -> Headers { - Headers( - public: `public`, - private: `private`, - project: project - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/IDETemplateMacros+TestData.swift b/Sources/XcodeGraphTesting/Models/IDETemplateMacros+TestData.swift deleted file mode 100644 index 1fb4e8c1..00000000 --- a/Sources/XcodeGraphTesting/Models/IDETemplateMacros+TestData.swift +++ /dev/null @@ -1,8 +0,0 @@ -import Foundation -import XcodeGraph - -extension IDETemplateMacros { - public static func test(fileHeader: String? = "Header template") -> IDETemplateMacros { - IDETemplateMacros(fileHeader: fileHeader) - } -} diff --git a/Sources/XcodeGraphTesting/Models/Metadata/FrameworkMetadata+TestData.swift b/Sources/XcodeGraphTesting/Models/Metadata/FrameworkMetadata+TestData.swift deleted file mode 100644 index 87e19e95..00000000 --- a/Sources/XcodeGraphTesting/Models/Metadata/FrameworkMetadata+TestData.swift +++ /dev/null @@ -1,27 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension FrameworkMetadata { - public static func test( - // swiftlint:disable:next force_try - path: AbsolutePath = try! AbsolutePath(validating: "/Frameworks/TestFramework.xframework"), - // swiftlint:disable:next force_try - binaryPath: AbsolutePath = try! AbsolutePath(validating: "/Frameworks/TestFramework.xframework/TestFramework"), - dsymPath: AbsolutePath? = nil, - bcsymbolmapPaths: [AbsolutePath] = [], - linking: BinaryLinking = .dynamic, - architectures: [BinaryArchitecture] = [.arm64], - status: FrameworkStatus = .required - ) -> FrameworkMetadata { - FrameworkMetadata( - path: path, - binaryPath: binaryPath, - dsymPath: dsymPath, - bcsymbolmapPaths: bcsymbolmapPaths, - linking: linking, - architectures: architectures, - status: status - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/Metadata/LibraryMetadata+TestData.swift b/Sources/XcodeGraphTesting/Models/Metadata/LibraryMetadata+TestData.swift deleted file mode 100644 index 4d0e2755..00000000 --- a/Sources/XcodeGraphTesting/Models/Metadata/LibraryMetadata+TestData.swift +++ /dev/null @@ -1,24 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension LibraryMetadata { - public static func test( - // swiftlint:disable:next force_try - path: AbsolutePath = try! AbsolutePath(validating: "/Libraries/libTest/libTest.a"), - // swiftlint:disable:next force_try - publicHeaders: AbsolutePath = try! AbsolutePath(validating: "/Libraries/libTest/include"), - // swiftlint:disable:next force_try - swiftModuleMap: AbsolutePath? = try! AbsolutePath(validating: "/Libraries/libTest/libTest.swiftmodule"), - architectures: [BinaryArchitecture] = [.arm64], - linking: BinaryLinking = .static - ) -> LibraryMetadata { - LibraryMetadata( - path: path, - publicHeaders: publicHeaders, - swiftModuleMap: swiftModuleMap, - architectures: architectures, - linking: linking - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/Metadata/XCFrameworkMetadata+TestData.swift b/Sources/XcodeGraphTesting/Models/Metadata/XCFrameworkMetadata+TestData.swift deleted file mode 100644 index dbff7362..00000000 --- a/Sources/XcodeGraphTesting/Models/Metadata/XCFrameworkMetadata+TestData.swift +++ /dev/null @@ -1,28 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension XCFrameworkMetadata { - public static func test( - // swiftlint:disable:next force_try - path: AbsolutePath = try! AbsolutePath(validating: "/XCFrameworks/XCFramework.xcframework"), - infoPlist: XCFrameworkInfoPlist = .test(), - primaryBinaryPath: AbsolutePath = - // swiftlint:disable:next force_try - try! AbsolutePath(validating: "/XCFrameworks/XCFramework.xcframework/ios-arm64/XCFramework"), - linking: BinaryLinking = .dynamic, - mergeable: Bool = false, - status: FrameworkStatus = .required, - macroPath: AbsolutePath? = nil - ) -> XCFrameworkMetadata { - XCFrameworkMetadata( - path: path, - infoPlist: infoPlist, - primaryBinaryPath: primaryBinaryPath, - linking: linking, - mergeable: mergeable, - status: status, - macroPath: macroPath - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/ProfileAction+TestData.swift b/Sources/XcodeGraphTesting/Models/ProfileAction+TestData.swift deleted file mode 100644 index 12332bad..00000000 --- a/Sources/XcodeGraphTesting/Models/ProfileAction+TestData.swift +++ /dev/null @@ -1,22 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension ProfileAction { - public static func test( - configurationName: String = "Beta Release", - preActions: [ExecutionAction] = [], - postActions: [ExecutionAction] = [], - // swiftlint:disable:next force_try - executable: TargetReference? = TargetReference(projectPath: try! AbsolutePath(validating: "/Project"), name: "App"), - arguments: Arguments? = Arguments.test() - ) -> ProfileAction { - ProfileAction( - configurationName: configurationName, - preActions: preActions, - postActions: postActions, - executable: executable, - arguments: arguments - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/Project+TestData.swift b/Sources/XcodeGraphTesting/Models/Project+TestData.swift deleted file mode 100644 index 2409d8e9..00000000 --- a/Sources/XcodeGraphTesting/Models/Project+TestData.swift +++ /dev/null @@ -1,90 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension Project { - public static func test( - path: AbsolutePath = try! AbsolutePath(validating: "/Project"), // swiftlint:disable:this force_try - sourceRootPath: AbsolutePath = try! AbsolutePath(validating: "/Project"), // swiftlint:disable:this force_try - // swiftlint:disable:next force_try - xcodeProjPath: AbsolutePath = try! AbsolutePath(validating: "/Project/Project.xcodeproj"), - name: String = "Project", - organizationName: String? = nil, - defaultKnownRegions: [String]? = nil, - developmentRegion: String? = nil, - options: Options = .test(automaticSchemesOptions: .disabled), - settings: Settings = Settings.test(), - filesGroup: ProjectGroup = .group(name: "Project"), - targets: [Target] = [Target.test()], - packages: [Package] = [], - schemes: [Scheme] = [], - ideTemplateMacros: IDETemplateMacros? = nil, - additionalFiles: [FileElement] = [], - resourceSynthesizers: [ResourceSynthesizer] = [], - lastUpgradeCheck: Version? = nil, - isExternal: Bool = false - ) -> Project { - Project( - path: path, - sourceRootPath: sourceRootPath, - xcodeProjPath: xcodeProjPath, - name: name, - organizationName: organizationName, - defaultKnownRegions: defaultKnownRegions, - developmentRegion: developmentRegion, - options: options, - settings: settings, - filesGroup: filesGroup, - targets: targets, - packages: packages, - schemes: schemes, - ideTemplateMacros: ideTemplateMacros, - additionalFiles: additionalFiles, - resourceSynthesizers: resourceSynthesizers, - lastUpgradeCheck: lastUpgradeCheck, - isExternal: isExternal - ) - } - - public static func empty( - path: AbsolutePath = try! AbsolutePath(validating: "/test/"), // swiftlint:disable:this force_try - sourceRootPath: AbsolutePath = try! AbsolutePath(validating: "/test/"), // swiftlint:disable:this force_try - xcodeProjPath: AbsolutePath = try! AbsolutePath(validating: "/test/text.xcodeproj"), // swiftlint:disable:this force_try - name: String = "Project", - organizationName: String? = nil, - defaultKnownRegions: [String]? = nil, - developmentRegion: String? = nil, - options: Options = .test(automaticSchemesOptions: .disabled), - settings: Settings = .default, - filesGroup: ProjectGroup = .group(name: "Project"), - targets: [Target] = [], - packages: [Package] = [], - schemes: [Scheme] = [], - ideTemplateMacros: IDETemplateMacros? = nil, - additionalFiles: [FileElement] = [], - resourceSynthesizers: [ResourceSynthesizer] = [], - lastUpgradeCheck: Version? = nil, - isExternal: Bool = false - ) -> Project { - Project( - path: path, - sourceRootPath: sourceRootPath, - xcodeProjPath: xcodeProjPath, - name: name, - organizationName: organizationName, - defaultKnownRegions: defaultKnownRegions, - developmentRegion: developmentRegion, - options: options, - settings: settings, - filesGroup: filesGroup, - targets: targets, - packages: packages, - schemes: schemes, - ideTemplateMacros: ideTemplateMacros, - additionalFiles: additionalFiles, - resourceSynthesizers: resourceSynthesizers, - lastUpgradeCheck: lastUpgradeCheck, - isExternal: isExternal - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/ProjectOptions+TestData.swift b/Sources/XcodeGraphTesting/Models/ProjectOptions+TestData.swift deleted file mode 100644 index 1c71d383..00000000 --- a/Sources/XcodeGraphTesting/Models/ProjectOptions+TestData.swift +++ /dev/null @@ -1,44 +0,0 @@ -import Foundation -@testable import XcodeGraph - -extension Project.Options { - public static func test( - automaticSchemesOptions: AutomaticSchemesOptions = .enabled( - targetSchemesGrouping: .byNameSuffix( - build: ["Implementation", "Interface", "Mocks", "Testing"], - test: ["Tests", "IntegrationTests", "UITests", "SnapshotTests"], - run: ["App", "Demo"] - ), - codeCoverageEnabled: false, - testingOptions: [] - ), - disableBundleAccessors: Bool = false, - disableShowEnvironmentVarsInScriptPhases: Bool = false, - disableSynthesizedResourceAccessors: Bool = false, - textSettings: TextSettings = .init(usesTabs: nil, indentWidth: nil, tabWidth: nil, wrapsLines: nil) - ) -> Self { - .init( - automaticSchemesOptions: automaticSchemesOptions, - disableBundleAccessors: disableBundleAccessors, - disableShowEnvironmentVarsInScriptPhases: disableShowEnvironmentVarsInScriptPhases, - disableSynthesizedResourceAccessors: disableSynthesizedResourceAccessors, - textSettings: textSettings - ) - } -} - -extension Project.Options.TextSettings { - public static func test( - usesTabs: Bool? = true, - indentWidth: UInt? = 2, - tabWidth: UInt? = 2, - wrapsLines: Bool? = true - ) -> Self { - .init( - usesTabs: usesTabs, - indentWidth: indentWidth, - tabWidth: tabWidth, - wrapsLines: wrapsLines - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/RawScriptBuildPhase+TestData.swift b/Sources/XcodeGraphTesting/Models/RawScriptBuildPhase+TestData.swift deleted file mode 100644 index 4ed99315..00000000 --- a/Sources/XcodeGraphTesting/Models/RawScriptBuildPhase+TestData.swift +++ /dev/null @@ -1,14 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension RawScriptBuildPhase { - public static func test( - name: String = "Test", - script: String = "", - showEnvVarsInLog: Bool = false, - hashable: Bool = false - ) -> RawScriptBuildPhase { - RawScriptBuildPhase(name: name, script: script, showEnvVarsInLog: showEnvVarsInLog, hashable: hashable) - } -} diff --git a/Sources/XcodeGraphTesting/Models/ResourceSynthesizerPlugin+TestData.swift b/Sources/XcodeGraphTesting/Models/ResourceSynthesizerPlugin+TestData.swift deleted file mode 100644 index a2e33ac2..00000000 --- a/Sources/XcodeGraphTesting/Models/ResourceSynthesizerPlugin+TestData.swift +++ /dev/null @@ -1,15 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension PluginResourceSynthesizer { - public static func test( - name: String = "Plugin", - path: AbsolutePath = try! AbsolutePath(validating: "/test") // swiftlint:disable:this force_try - ) -> Self { - .init( - name: name, - path: path - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/ResourceSynthesizers+TestData.swift b/Sources/XcodeGraphTesting/Models/ResourceSynthesizers+TestData.swift deleted file mode 100644 index e7f8898a..00000000 --- a/Sources/XcodeGraphTesting/Models/ResourceSynthesizers+TestData.swift +++ /dev/null @@ -1,13 +0,0 @@ -import Foundation -@testable import XcodeGraph - -extension XcodeGraph.ResourceSynthesizer { - public static func test( - parser: Parser = .assets, - parserOptions: [String: Parser.Option] = [:], - extensions: Set = ["xcassets"], - template: Template = .defaultTemplate("Assets") - ) -> Self { - ResourceSynthesizer(parser: parser, parserOptions: parserOptions, extensions: extensions, template: template) - } -} diff --git a/Sources/XcodeGraphTesting/Models/RunAction+TestData.swift b/Sources/XcodeGraphTesting/Models/RunAction+TestData.swift deleted file mode 100644 index 7212910f..00000000 --- a/Sources/XcodeGraphTesting/Models/RunAction+TestData.swift +++ /dev/null @@ -1,39 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension RunAction { - public static func test( - configurationName: String = BuildConfiguration.debug.name, - attachDebugger: Bool = true, - customLLDBInitFile: AbsolutePath? = nil, - preActions: [ExecutionAction] = [], - postActions: [ExecutionAction] = [], - // swiftlint:disable:next force_try - executable: TargetReference? = TargetReference(projectPath: try! AbsolutePath(validating: "/Project"), name: "App"), - filePath: AbsolutePath? = nil, - arguments: Arguments? = Arguments.test(), - options: RunActionOptions = .init(), - diagnosticsOptions: SchemeDiagnosticsOptions = XcodeGraph.SchemeDiagnosticsOptions( - mainThreadCheckerEnabled: true, - performanceAntipatternCheckerEnabled: true - ), - expandVariableFromTarget: TargetReference? = nil, - launchStyle: LaunchStyle = .automatically - ) -> RunAction { - RunAction( - configurationName: configurationName, - attachDebugger: attachDebugger, - customLLDBInitFile: customLLDBInitFile, - preActions: preActions, - postActions: postActions, - executable: executable, - filePath: filePath, - arguments: arguments, - options: options, - diagnosticsOptions: diagnosticsOptions, - expandVariableFromTarget: expandVariableFromTarget, - launchStyle: launchStyle - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/Scheme+TestData.swift b/Sources/XcodeGraphTesting/Models/Scheme+TestData.swift deleted file mode 100644 index 4a9b51f8..00000000 --- a/Sources/XcodeGraphTesting/Models/Scheme+TestData.swift +++ /dev/null @@ -1,27 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension Scheme { - public static func test( - name: String = "Test", - shared: Bool = false, - buildAction: BuildAction? = BuildAction.test(), - testAction: TestAction? = TestAction.test(), - runAction: RunAction? = RunAction.test(), - archiveAction: ArchiveAction? = ArchiveAction.test(), - profileAction: ProfileAction? = ProfileAction.test(), - analyzeAction: AnalyzeAction? = AnalyzeAction.test() - ) -> Scheme { - Scheme( - name: name, - shared: shared, - buildAction: buildAction, - testAction: testAction, - runAction: runAction, - archiveAction: archiveAction, - profileAction: profileAction, - analyzeAction: analyzeAction - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/Settings+TestData.swift b/Sources/XcodeGraphTesting/Models/Settings+TestData.swift deleted file mode 100644 index 950a79ad..00000000 --- a/Sources/XcodeGraphTesting/Models/Settings+TestData.swift +++ /dev/null @@ -1,48 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension Configuration { - public static func test( - settings: SettingsDictionary = [:], - xcconfig: AbsolutePath? = try! AbsolutePath(validating: "/Config.xcconfig") // swiftlint:disable:this force_try - ) -> Configuration { - Configuration(settings: settings, xcconfig: xcconfig) - } -} - -extension Settings { - public static func test( - base: SettingsDictionary, - debug: Configuration, - release: Configuration - ) -> Settings { - Settings( - base: base, - configurations: [.debug: debug, .release: release] - ) - } - - public static func test( - base: SettingsDictionary = [:], - baseDebug: SettingsDictionary = [:], - configurations: [BuildConfiguration: Configuration?] = [:] - ) -> Settings { - Settings( - base: base, - baseDebug: baseDebug, - configurations: configurations - ) - } - - public static func test(defaultSettings: DefaultSettings) -> Settings { - Settings( - base: [:], - configurations: [ - .debug: Configuration(settings: [:]), - .release: Configuration(settings: [:]), - ], - defaultSettings: defaultSettings - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/Target+TestData.swift b/Sources/XcodeGraphTesting/Models/Target+TestData.swift deleted file mode 100644 index ca648e6e..00000000 --- a/Sources/XcodeGraphTesting/Models/Target+TestData.swift +++ /dev/null @@ -1,184 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension Target { - /// Creates a Target with test data - /// Note: Referenced paths may not exist - public static func test( - name: String = "Target", - destinations: Destinations = [.iPhone, .iPad], - product: Product = .app, - productName: String? = nil, - bundleId: String? = nil, - deploymentTargets: DeploymentTargets = .iOS("13.1"), - infoPlist: InfoPlist? = nil, - entitlements: Entitlements? = nil, - settings: Settings? = Settings.test(), - sources: [SourceFile] = [], - resources: ResourceFileElements = .init([]), - copyFiles: [CopyFilesAction] = [], - coreDataModels: [CoreDataModel] = [], - headers: Headers? = nil, - scripts: [TargetScript] = [], - environmentVariables: [String: EnvironmentVariable] = [:], - filesGroup: ProjectGroup = .group(name: "Project"), - dependencies: [TargetDependency] = [], - rawScriptBuildPhases: [RawScriptBuildPhase] = [], - launchArguments: [LaunchArgument] = [], - playgrounds: [AbsolutePath] = [], - additionalFiles: [FileElement] = [], - prune: Bool = false, - mergedBinaryType: MergedBinaryType = .disabled, - mergeable: Bool = false - ) -> Target { - Target( - name: name, - destinations: destinations, - product: product, - productName: productName, - bundleId: bundleId ?? "io.tuist.\(name)", - deploymentTargets: deploymentTargets, - infoPlist: infoPlist, - entitlements: entitlements, - settings: settings, - sources: sources, - resources: resources, - copyFiles: copyFiles, - headers: headers, - coreDataModels: coreDataModels, - scripts: scripts, - environmentVariables: environmentVariables, - launchArguments: launchArguments, - filesGroup: filesGroup, - dependencies: dependencies, - rawScriptBuildPhases: rawScriptBuildPhases, - playgrounds: playgrounds, - additionalFiles: additionalFiles, - prune: prune, - mergedBinaryType: mergedBinaryType, - mergeable: mergeable - ) - } - - /// Creates a Target with test data - /// Note: Referenced paths may not exist - public static func test( - name: String = "Target", - platform: Platform, - product: Product = .app, - productName: String? = nil, - bundleId: String? = nil, - deploymentTarget: DeploymentTargets = .iOS("13.1"), - infoPlist: InfoPlist? = nil, - entitlements: Entitlements? = nil, - settings: Settings? = Settings.test(), - sources: [SourceFile] = [], - resources: ResourceFileElements = .init([]), - copyFiles: [CopyFilesAction] = [], - coreDataModels: [CoreDataModel] = [], - headers: Headers? = nil, - scripts: [TargetScript] = [], - environmentVariables: [String: EnvironmentVariable] = [:], - filesGroup: ProjectGroup = .group(name: "Project"), - dependencies: [TargetDependency] = [], - rawScriptBuildPhases: [RawScriptBuildPhase] = [], - launchArguments: [LaunchArgument] = [], - playgrounds: [AbsolutePath] = [], - additionalFiles: [FileElement] = [], - prune: Bool = false, - mergedBinaryType: MergedBinaryType = .disabled, - mergeable: Bool = false - ) -> Target { - Target( - name: name, - destinations: destinationsFrom(platform), - product: product, - productName: productName, - bundleId: bundleId ?? "io.tuist.\(name)", - deploymentTargets: deploymentTarget, - infoPlist: infoPlist, - entitlements: entitlements, - settings: settings, - sources: sources, - resources: resources, - copyFiles: copyFiles, - headers: headers, - coreDataModels: coreDataModels, - scripts: scripts, - environmentVariables: environmentVariables, - launchArguments: launchArguments, - filesGroup: filesGroup, - dependencies: dependencies, - rawScriptBuildPhases: rawScriptBuildPhases, - playgrounds: playgrounds, - additionalFiles: additionalFiles, - prune: prune, - mergedBinaryType: mergedBinaryType, - mergeable: mergeable - ) - } - - /// Creates a bare bones Target with as little data as possible - public static func empty( - name: String = "Target", - destinations: Destinations = [.iPhone, .iPad], - product: Product = .app, - productName: String? = nil, - bundleId: String? = nil, - deploymentTargets: DeploymentTargets = .init(), - infoPlist: InfoPlist? = nil, - entitlements: Entitlements? = nil, - settings: Settings? = nil, - sources: [SourceFile] = [], - resources: ResourceFileElements = .init([]), - copyFiles: [CopyFilesAction] = [], - coreDataModels: [CoreDataModel] = [], - headers: Headers? = nil, - scripts: [TargetScript] = [], - environmentVariables: [String: EnvironmentVariable] = [:], - filesGroup: ProjectGroup = .group(name: "Project"), - dependencies: [TargetDependency] = [], - rawScriptBuildPhases: [RawScriptBuildPhase] = [], - onDemandResourcesTags: OnDemandResourcesTags? = nil - ) -> Target { - Target( - name: name, - destinations: destinations, - product: product, - productName: productName, - bundleId: bundleId ?? "io.tuist.\(name)", - deploymentTargets: deploymentTargets, - infoPlist: infoPlist, - entitlements: entitlements, - settings: settings, - sources: sources, - resources: resources, - copyFiles: copyFiles, - headers: headers, - coreDataModels: coreDataModels, - scripts: scripts, - environmentVariables: environmentVariables, - filesGroup: filesGroup, - dependencies: dependencies, - rawScriptBuildPhases: rawScriptBuildPhases, - onDemandResourcesTags: onDemandResourcesTags - ) - } - - // Maps a platform to a set of Destinations. For migration purposes - private static func destinationsFrom(_ platform: Platform) -> Destinations { - switch platform { - case .iOS: - return .iOS - case .macOS: - return .macOS - case .tvOS: - return .tvOS - case .watchOS: - return .watchOS - case .visionOS: - return .visionOS - } - } -} diff --git a/Sources/XcodeGraphTesting/Models/TestAction+TestData.swift b/Sources/XcodeGraphTesting/Models/TestAction+TestData.swift deleted file mode 100644 index 46121266..00000000 --- a/Sources/XcodeGraphTesting/Models/TestAction+TestData.swift +++ /dev/null @@ -1,45 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension TestAction { - public static func test( - targets: [TestableTarget] = [TestableTarget(target: TargetReference( - // swiftlint:disable:next force_try - projectPath: try! AbsolutePath(validating: "/Project"), - name: "AppTests" - ))], - arguments: Arguments? = Arguments.test(), - configurationName: String = BuildConfiguration.debug.name, - attachDebugger: Bool = true, - coverage: Bool = false, - codeCoverageTargets: [TargetReference] = [], - expandVariableFromTarget: TargetReference? = nil, - preActions: [ExecutionAction] = [], - postActions: [ExecutionAction] = [], - diagnosticsOptions: SchemeDiagnosticsOptions = SchemeDiagnosticsOptions(mainThreadCheckerEnabled: true), - language: String? = nil, - region: String? = nil, - preferredScreenCaptureFormat: ScreenCaptureFormat? = nil, - testPlans: [TestPlan]? = nil, - skippedTests: [String]? = nil - ) -> TestAction { - TestAction( - targets: targets, - arguments: arguments, - configurationName: configurationName, - attachDebugger: attachDebugger, - coverage: coverage, - codeCoverageTargets: codeCoverageTargets, - expandVariableFromTarget: expandVariableFromTarget, - preActions: preActions, - postActions: postActions, - diagnosticsOptions: diagnosticsOptions, - language: language, - region: region, - preferredScreenCaptureFormat: preferredScreenCaptureFormat, - testPlans: testPlans, - skippedTests: skippedTests - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/TestableTarget+TestData.swift b/Sources/XcodeGraphTesting/Models/TestableTarget+TestData.swift deleted file mode 100644 index d8ca9a12..00000000 --- a/Sources/XcodeGraphTesting/Models/TestableTarget+TestData.swift +++ /dev/null @@ -1,21 +0,0 @@ -import Path -import XcodeGraph - -extension TestableTarget { - public static func test( - // swiftlint:disable:next force_try - target: TargetReference = TargetReference(projectPath: try! AbsolutePath(validating: "/Project"), name: "App"), - skipped: Bool = false, - parallelizable: Bool = false, - randomExecutionOrdering: Bool = false, - simulatedLocation: SimulatedLocation? = nil - ) -> TestableTarget { - TestableTarget( - target: target, - skipped: skipped, - parallelizable: parallelizable, - randomExecutionOrdering: randomExecutionOrdering, - simulatedLocation: simulatedLocation - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/Workspace+TestData.swift b/Sources/XcodeGraphTesting/Models/Workspace+TestData.swift deleted file mode 100644 index 6176285f..00000000 --- a/Sources/XcodeGraphTesting/Models/Workspace+TestData.swift +++ /dev/null @@ -1,48 +0,0 @@ -import Foundation -import Path -@testable import XcodeGraph - -extension Workspace { - public static func test( - path: AbsolutePath = try! AbsolutePath(validating: "/"), // swiftlint:disable:this force_try - xcWorkspacePath: AbsolutePath = try! AbsolutePath(validating: "/"), // swiftlint:disable:this force_try - name: String = "test", - projects: [AbsolutePath] = [], - schemes: [Scheme] = [], - ideTemplateMacros: IDETemplateMacros? = nil, - additionalFiles: [FileElement] = [], - generationOptions: GenerationOptions = .test() - ) -> Workspace { - Workspace( - path: path, - xcWorkspacePath: xcWorkspacePath, - name: name, - projects: projects, - schemes: schemes, - generationOptions: generationOptions, - ideTemplateMacros: ideTemplateMacros, - additionalFiles: additionalFiles - ) - } -} - -extension Workspace.GenerationOptions { - public static func test( - enableAutomaticXcodeSchemes: Bool? = false, - autogeneratedWorkspaceSchemes: AutogeneratedWorkspaceSchemes = .enabled( - codeCoverageMode: .disabled, - testingOptions: [], - testLanguage: nil, - testRegion: nil, - testScreenCaptureFormat: nil - ), - lastXcodeUpgradeCheck: Version? = nil - ) -> Self { - .init( - enableAutomaticXcodeSchemes: enableAutomaticXcodeSchemes, - autogeneratedWorkspaceSchemes: autogeneratedWorkspaceSchemes, - lastXcodeUpgradeCheck: lastXcodeUpgradeCheck, - renderMarkdownReadme: false - ) - } -} diff --git a/Sources/XcodeGraphTesting/Models/XCFrameworkInfoPlist+TestData.swift b/Sources/XcodeGraphTesting/Models/XCFrameworkInfoPlist+TestData.swift deleted file mode 100644 index 832f09e2..00000000 --- a/Sources/XcodeGraphTesting/Models/XCFrameworkInfoPlist+TestData.swift +++ /dev/null @@ -1,27 +0,0 @@ -import Foundation -import Path - -@testable import XcodeGraph - -extension XCFrameworkInfoPlist { - public static func test(libraries: [XCFrameworkInfoPlist.Library] = [.test()]) -> XCFrameworkInfoPlist { - XCFrameworkInfoPlist(libraries: libraries) - } -} - -extension XCFrameworkInfoPlist.Library { - public static func test( - identifier: String = "test", - // swiftlint:disable:next force_try - path: RelativePath = try! RelativePath(validating: "relative/to/library"), - mergeable: Bool = false, - architectures: [BinaryArchitecture] = [.i386] - ) -> XCFrameworkInfoPlist.Library { - XCFrameworkInfoPlist.Library( - identifier: identifier, - path: path, - mergeable: mergeable, - architectures: architectures - ) - } -} diff --git a/Tests/XcodeGraphTests/Models/ProjectTests.swift b/Tests/XcodeGraphTests/Models/ProjectTests.swift index a4864add..163f8314 100644 --- a/Tests/XcodeGraphTests/Models/ProjectTests.swift +++ b/Tests/XcodeGraphTests/Models/ProjectTests.swift @@ -1,6 +1,5 @@ import Foundation import Path -import XcodeGraphTesting import XCTest @testable import XcodeGraph diff --git a/Tests/XcodeGraphTests/Models/TargetTests.swift b/Tests/XcodeGraphTests/Models/TargetTests.swift index 4fdd0b3d..4b9c9d08 100644 --- a/Tests/XcodeGraphTests/Models/TargetTests.swift +++ b/Tests/XcodeGraphTests/Models/TargetTests.swift @@ -2,7 +2,6 @@ import Foundation import Path import XCTest @testable import XcodeGraph -@testable import XcodeGraphTesting final class TargetTests: XCTestCase { func test_codable() { From 44fa707b849aaff94822b34d6a41da5e60e935ec Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 10 Jun 2024 16:16:01 +0200 Subject: [PATCH 2/7] Removed XcodeGraphTesting --- Package.swift | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Package.swift b/Package.swift index 21f0e9b8..1077fde8 100644 --- a/Package.swift +++ b/Package.swift @@ -19,12 +19,7 @@ let package = Package( .library( name: "XcodeGraph", targets: ["XcodeGraph"] - ), - .library( - name: "XcodeGraphTesting", - targets: ["XcodeGraphTesting"] - ), - + ) ], dependencies: [ .package(url: "https://github.com/Flight-School/AnyCodable", .upToNextMajor(from: "0.6.7")), From 3366385bc1df9517f71c3d6a08c1a68c40f0fca0 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 10 Jun 2024 16:20:36 +0200 Subject: [PATCH 3/7] Fix the Tuist project --- Tuist/ProjectDescriptionHelpers/Module.swift | 48 +++----------------- 1 file changed, 6 insertions(+), 42 deletions(-) diff --git a/Tuist/ProjectDescriptionHelpers/Module.swift b/Tuist/ProjectDescriptionHelpers/Module.swift index 7b14d8bf..c6c1c37e 100644 --- a/Tuist/ProjectDescriptionHelpers/Module.swift +++ b/Tuist/ProjectDescriptionHelpers/Module.swift @@ -18,8 +18,7 @@ public enum Module: String, CaseIterable { targets.append(target( name: acceptanceTestsTargetName, product: .unitTests, - dependencies: acceptanceTestDependencies, - isTestingTarget: false + dependencies: acceptanceTestDependencies )) } @@ -34,8 +33,7 @@ public enum Module: String, CaseIterable { target( name: unitTestsTargetName, product: .unitTests, - dependencies: unitTestDependencies, - isTestingTarget: false + dependencies: unitTestDependencies ) ) } @@ -45,8 +43,7 @@ public enum Module: String, CaseIterable { target( name: integrationTestsTargetName, product: .unitTests, - dependencies: integrationTestsDependencies, - isTestingTarget: false + dependencies: integrationTestsDependencies ) ) } @@ -59,30 +56,15 @@ public enum Module: String, CaseIterable { } public var targets: [Target] { - var targets: [Target] = sourceTargets - - if let testingTargetName { - targets.append( - target( - name: testingTargetName, - product: product, - dependencies: testingDependencies, - isTestingTarget: true - ) - ) - } - - return targets + testTargets + return sourceTargets + testTargets } public var sourceTargets: [Target] { - let isStaticProduct = product == .staticLibrary || product == .staticFramework return [ target( name: targetName, product: product, - dependencies: dependencies, - isTestingTarget: false + dependencies: dependencies ), ] } @@ -94,13 +76,6 @@ public enum Module: String, CaseIterable { } } - public var testingTargetName: String? { - switch self { - default: - return "\(rawValue)Testing" - } - } - public var unitTestsTargetName: String? { switch self { default: @@ -159,9 +134,6 @@ public enum Module: String, CaseIterable { ] } dependencies = dependencies + [.target(name: targetName)] - if let testingTargetName { - dependencies.append(.target(name: testingTargetName)) - } return dependencies } @@ -180,17 +152,13 @@ public enum Module: String, CaseIterable { [] } dependencies.append(.target(name: targetName)) - if let testingTargetName { - dependencies.append(contentsOf: [.target(name: testingTargetName)]) - } return dependencies } fileprivate func target( name: String, product: Product, - dependencies: [TargetDependency], - isTestingTarget: Bool + dependencies: [TargetDependency] ) -> Target { let rootFolder: String switch product { @@ -201,10 +169,6 @@ public enum Module: String, CaseIterable { } var debugSettings: ProjectDescription.SettingsDictionary = ["SWIFT_ACTIVE_COMPILATION_CONDITIONS": "$(inherited) MOCKING"] var releaseSettings: ProjectDescription.SettingsDictionary = [:] - if isTestingTarget { - debugSettings["ENABLE_TESTING_SEARCH_PATHS"] = "YES" - releaseSettings["ENABLE_TESTING_SEARCH_PATHS"] = "YES" - } if let strictConcurrencySetting, product == .framework { debugSettings["SWIFT_STRICT_CONCURRENCY"] = .string(strictConcurrencySetting) From e1aec9006a4c90328e142a4122edc7750c640ea7 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 10 Jun 2024 16:25:49 +0200 Subject: [PATCH 4/7] Fix linting issues --- Package.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 1077fde8..914c97b3 100644 --- a/Package.swift +++ b/Package.swift @@ -9,7 +9,7 @@ var targets: [Target] = [ "AnyCodable", "Path", ] - ) + ), ] let package = Package( @@ -19,7 +19,7 @@ let package = Package( .library( name: "XcodeGraph", targets: ["XcodeGraph"] - ) + ), ], dependencies: [ .package(url: "https://github.com/Flight-School/AnyCodable", .upToNextMajor(from: "0.6.7")), From 5efdafc33d347e45e6b8cc48749e2c8f5cacc076 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 10 Jun 2024 16:34:36 +0200 Subject: [PATCH 5/7] Fix linting issue --- Sources/XcodeGraph/Models/Project.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/XcodeGraph/Models/Project.swift b/Sources/XcodeGraph/Models/Project.swift index b62969ab..d6cb59f5 100644 --- a/Sources/XcodeGraph/Models/Project.swift +++ b/Sources/XcodeGraph/Models/Project.swift @@ -198,8 +198,8 @@ public struct Project: Hashable, Equatable, CustomStringConvertible, CustomDebug public static func empty( path: AbsolutePath = try! AbsolutePath(validating: "/test/"), // swiftlint:disable:this force_try sourceRootPath: AbsolutePath = try! AbsolutePath(validating: "/test/"), // swiftlint:disable:this force_try + // swiftlint:disable:next force_try xcodeProjPath: AbsolutePath = try! AbsolutePath(validating: "/test/text.xcodeproj"), - // swiftlint:disable:this force_try name: String = "Project", organizationName: String? = nil, defaultKnownRegions: [String]? = nil, From f709095b5c1e21eb7e44bff4505e930fd1117598 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 10 Jun 2024 17:27:47 +0200 Subject: [PATCH 6/7] Fix some issues after rebasing --- Project.swift | 18 -- Sources/XcodeGraph/Models/Cloud.swift | 41 ---- Sources/XcodeGraph/Models/Config.swift | 116 ------------ .../Models/Dependencies/PackageSettings.swift | 66 ------- Sources/XcodeGraph/Models/Plugins.swift | 53 ------ Sources/XcodeGraph/Models/Template.swift | 179 ------------------ 6 files changed, 473 deletions(-) delete mode 100644 Sources/XcodeGraph/Models/Cloud.swift delete mode 100644 Sources/XcodeGraph/Models/Config.swift delete mode 100644 Sources/XcodeGraph/Models/Dependencies/PackageSettings.swift delete mode 100644 Sources/XcodeGraph/Models/Plugins.swift delete mode 100644 Sources/XcodeGraph/Models/Template.swift diff --git a/Project.swift b/Project.swift index 6ee7dc22..b3b6513a 100644 --- a/Project.swift +++ b/Project.swift @@ -48,24 +48,6 @@ func schemes() -> [Scheme] { ) ) ), - .scheme( - name: "TuistUnitTests", - buildAction: .buildAction( - targets: Module.allCases.flatMap(\.unitTestTargets).map(\.name).sorted() - .map { .target($0) } - ), - testAction: .targets( - Module.allCases.flatMap(\.unitTestTargets).map { .testableTarget(target: .target($0.name)) } - ), - runAction: .runAction( - arguments: .arguments( - environmentVariables: [ - "TUIST_CONFIG_SRCROOT": "$(SRCROOT)", - "TUIST_FRAMEWORK_SEARCH_PATHS": "$(FRAMEWORK_SEARCH_PATHS)", - ] - ) - ) - ), ] schemes.append(contentsOf: Module.allCases.filter(\.isRunnable).map { .scheme( diff --git a/Sources/XcodeGraph/Models/Cloud.swift b/Sources/XcodeGraph/Models/Cloud.swift deleted file mode 100644 index 2cd8c07a..00000000 --- a/Sources/XcodeGraph/Models/Cloud.swift +++ /dev/null @@ -1,41 +0,0 @@ -import Foundation - -/// Cloud represents the configuration to connect to the server. -public struct Cloud: Equatable, Hashable { - /// Cloud option. - public enum Option: String, Codable, Equatable { - case optional - } - - /// The base URL that points to the cloud server - public let url: URL - - /// The project unique identifier. - public let projectId: String - - /// Cloud options. - public let options: [Option] - - /// Initializes an instance of Cloud. - /// - Parameters: - /// - url: Cloud server base URL. - /// - projectId: Project unique identifier. - /// - options: Cloud options. - public init(url: URL, projectId: String, options: [Option]) { - self.url = url - self.projectId = projectId - self.options = options - } -} - -#if DEBUG - extension Cloud { - public static func test( - url: URL = URL(string: "https://cloud.tuist.io")!, - projectId: String = "123", - options: [Cloud.Option] = [] - ) -> Cloud { - Cloud(url: url, projectId: projectId, options: options) - } - } -#endif diff --git a/Sources/XcodeGraph/Models/Config.swift b/Sources/XcodeGraph/Models/Config.swift deleted file mode 100644 index ab556fb3..00000000 --- a/Sources/XcodeGraph/Models/Config.swift +++ /dev/null @@ -1,116 +0,0 @@ -import Foundation -import Path - -/// This model allows to configure Tuist. -public struct Config: Equatable, Hashable { - /// List of `Plugin`s used to extend Tuist. - public let plugins: [PluginLocation] - - /// Generation options. - public let generationOptions: GenerationOptions - - /// List of Xcode versions the project or set of projects is compatible with. - public let compatibleXcodeVersions: CompatibleXcodeVersions - - /// Cloud configuration. - public let cloud: Cloud? - - /// The version of Swift that will be used by Tuist. - /// If `nil` is passed then Tuist will use the environment’s version. - public let swiftVersion: Version? - - /// The path of the config file. - public let path: AbsolutePath? - - /// Returns the default Tuist configuration. - public static var `default`: Config { - Config( - compatibleXcodeVersions: .all, - cloud: nil, - swiftVersion: nil, - plugins: [], - generationOptions: .init( - resolveDependenciesWithSystemScm: false, - disablePackageVersionLocking: false, - staticSideEffectsWarningTargets: .all - ), - path: nil - ) - } - - /// Initializes the tuist cofiguration. - /// - /// - Parameters: - /// - compatibleXcodeVersions: List of Xcode versions the project or set of projects is compatible with. - /// - cloud: Cloud configuration. - /// - swiftVersion: The version of Swift that will be used by Tuist. - /// - plugins: List of locations to a `Plugin` manifest. - /// - generationOptions: Generation options. - /// - path: The path of the config file. - public init( - compatibleXcodeVersions: CompatibleXcodeVersions, - cloud: Cloud?, - swiftVersion: Version?, - plugins: [PluginLocation], - generationOptions: GenerationOptions, - path: AbsolutePath? - ) { - self.compatibleXcodeVersions = compatibleXcodeVersions - self.cloud = cloud - self.swiftVersion = swiftVersion - self.plugins = plugins - self.generationOptions = generationOptions - self.path = path - } - - // MARK: - Hashable - - public func hash(into hasher: inout Hasher) { - hasher.combine(generationOptions) - hasher.combine(cloud) - hasher.combine(swiftVersion) - hasher.combine(compatibleXcodeVersions) - } -} - -#if DEBUG - extension Config { - public static func test( - compatibleXcodeVersions: CompatibleXcodeVersions = .all, - cloud: Cloud? = Cloud.test(), - swiftVersion: Version? = nil, - plugins: [PluginLocation] = [], - generationOptions: GenerationOptions = Config.default.generationOptions, - path: AbsolutePath? = nil - ) -> Config { - .init( - compatibleXcodeVersions: compatibleXcodeVersions, - cloud: cloud, - swiftVersion: swiftVersion, - plugins: plugins, - generationOptions: generationOptions, - path: path - ) - } - } - - extension Config.GenerationOptions { - public static func test( - resolveDependenciesWithSystemScm: Bool = false, - disablePackageVersionLocking: Bool = false, - clonedSourcePackagesDirPath: AbsolutePath? = nil, - staticSideEffectsWarningTargets: XcodeGraph.Config.GenerationOptions.StaticSideEffectsWarningTargets = .all, - enforceExplicitDependencies: Bool = false, - defaultConfiguration: String? = nil - ) -> Self { - .init( - resolveDependenciesWithSystemScm: resolveDependenciesWithSystemScm, - disablePackageVersionLocking: disablePackageVersionLocking, - clonedSourcePackagesDirPath: clonedSourcePackagesDirPath, - staticSideEffectsWarningTargets: staticSideEffectsWarningTargets, - enforceExplicitDependencies: enforceExplicitDependencies, - defaultConfiguration: defaultConfiguration - ) - } - } -#endif diff --git a/Sources/XcodeGraph/Models/Dependencies/PackageSettings.swift b/Sources/XcodeGraph/Models/Dependencies/PackageSettings.swift deleted file mode 100644 index 56732b68..00000000 --- a/Sources/XcodeGraph/Models/Dependencies/PackageSettings.swift +++ /dev/null @@ -1,66 +0,0 @@ -import Foundation - -/// Contains the description of custom SPM settings -public struct PackageSettings: Equatable, Codable { - /// The custom `Product` types to be used for SPM targets. - public let productTypes: [String: Product] - - /// Custom destinations to be used for SPM products. - public let productDestinations: [String: Destinations] - - // The base settings to be used for targets generated from SwiftPackageManager - public let baseSettings: Settings - - /// The custom `Settings` to be applied to SPM targets - public let targetSettings: [String: SettingsDictionary] - - /// The custom project options for each project generated from a swift package - public let projectOptions: [String: XcodeGraph.Project.Options] - - /// Swift tools version of the parsed `Package.swift` - public let swiftToolsVersion: Version - - /// Initializes a new `PackageSettings` instance. - /// - Parameters: - /// - productTypes: The custom `Product` types to be used for SPM targets. - /// - baseSettings: The base settings to be used for targets generated from SwiftPackageManager - /// - targetSettings: The custom `SettingsDictionary` to be applied to denoted targets - /// - projectOptions: The custom project options for each project generated from a swift package - public init( - productTypes: [String: Product], - productDestinations: [String: Destinations], - baseSettings: Settings, - targetSettings: [String: SettingsDictionary], - projectOptions: [String: XcodeGraph.Project.Options] = [:], - swiftToolsVersion: Version - ) { - self.productTypes = productTypes - self.productDestinations = productDestinations - self.baseSettings = baseSettings - self.targetSettings = targetSettings - self.projectOptions = projectOptions - self.swiftToolsVersion = swiftToolsVersion - } -} - -#if DEBUG - extension PackageSettings { - public static func test( - productTypes: [String: Product] = [:], - productDestinations: [String: Destinations] = [:], - baseSettings: Settings = .test(), - targetSettings: [String: SettingsDictionary] = [:], - projectOptions: [String: XcodeGraph.Project.Options] = [:], - swiftToolsVersion: Version = Version("5.4.9") - ) -> PackageSettings { - PackageSettings( - productTypes: productTypes, - productDestinations: productDestinations, - baseSettings: baseSettings, - targetSettings: targetSettings, - projectOptions: projectOptions, - swiftToolsVersion: swiftToolsVersion - ) - } - } -#endif diff --git a/Sources/XcodeGraph/Models/Plugins.swift b/Sources/XcodeGraph/Models/Plugins.swift deleted file mode 100644 index 81e1e75b..00000000 --- a/Sources/XcodeGraph/Models/Plugins.swift +++ /dev/null @@ -1,53 +0,0 @@ -import Foundation -import Path - -/// A model which contains all loaded plugin representations. -public struct Plugins: Equatable { - /// List of the loaded custom helper plugins. - public let projectDescriptionHelpers: [ProjectDescriptionHelpersPlugin] - - /// List of paths to template definitions. - public let templateDirectories: [AbsolutePath] - - /// List of paths pointing to resource templates - public let resourceSynthesizers: [PluginResourceSynthesizer] - - /// Creates a `Plugins`. - /// - /// - Parameters: - /// - projectDescriptionHelpers: List of the loaded helper plugins. - /// - templatePaths: List of paths to the `Templates/` directory for the loaded plugins. - /// - resourceSynthesizers: List of the loaded resource synthesizer plugins - public init( - projectDescriptionHelpers: [ProjectDescriptionHelpersPlugin], - templatePaths: [AbsolutePath], - resourceSynthesizers: [PluginResourceSynthesizer] - ) { - self.projectDescriptionHelpers = projectDescriptionHelpers - templateDirectories = templatePaths - self.resourceSynthesizers = resourceSynthesizers - } - - /// An empty `Plugins`. - public static let none: Plugins = .init( - projectDescriptionHelpers: [], - templatePaths: [], - resourceSynthesizers: [] - ) -} - -#if DEBUG - extension Plugins { - public static func test( - projectDescriptionHelpers: [ProjectDescriptionHelpersPlugin] = [], - templatePaths: [AbsolutePath] = [], - resourceSynthesizers: [PluginResourceSynthesizer] = [] - ) -> Plugins { - Plugins( - projectDescriptionHelpers: projectDescriptionHelpers, - templatePaths: templatePaths, - resourceSynthesizers: resourceSynthesizers - ) - } - } -#endif diff --git a/Sources/XcodeGraph/Models/Template.swift b/Sources/XcodeGraph/Models/Template.swift deleted file mode 100644 index 98b6a642..00000000 --- a/Sources/XcodeGraph/Models/Template.swift +++ /dev/null @@ -1,179 +0,0 @@ -import Path - -public struct Template: Equatable { - public let description: String - public let attributes: [Attribute] - public let items: [Item] - - public init( - description: String, - attributes: [Attribute] = [], - items: [Item] = [] - ) { - self.description = description - self.attributes = attributes - self.items = items - } - - public enum Attribute: Equatable { - case required(String) - case optional(String, default: Value) - - public var isOptional: Bool { - switch self { - case .required: - return false - case .optional: - return true - } - } - - public var name: String { - switch self { - case let .required(name): - return name - case let .optional(name, default: _): - return name - } - } - } - - public enum Contents: Equatable { - case string(String) - case file(AbsolutePath) - case directory(AbsolutePath) - } - - public struct Item: Equatable { - public let path: RelativePath - public let contents: Contents - - public init( - path: RelativePath, - contents: Contents - ) { - self.path = path - self.contents = contents - } - } -} - -extension Template.Attribute { - /// This represents the default value type of Attribute - public indirect enum Value: Equatable { - /// It represents a string value. - case string(String) - /// It represents an integer value. - case integer(Int) - /// It represents a floating value. - case real(Double) - /// It represents a boolean value. - case boolean(Bool) - /// It represents a dictionary value. - case dictionary([String: Value]) - /// It represents an array value. - case array([Value]) - } -} - -extension Template.Attribute.Value: RawRepresentable { - public typealias RawValue = Any - - public init?(rawValue: RawValue) { - switch rawValue { - case is String: - if let string = rawValue as? String { - self = .string(string) - } else { - return nil - } - case is Int: - if let integer = rawValue as? Int { - self = .integer(integer) - } else { - return nil - } - case is Double: - if let real = rawValue as? Double { - self = .real(real) - } else { - return nil - } - case is Bool: - if let boolean = rawValue as? Bool { - self = .boolean(boolean) - } else { - return nil - } - case is [String: Any]: - if let dictionary = rawValue as? [String: Any] { - var newDictionary: [String: Self] = [:] - for (key, value) in dictionary { - newDictionary[key] = .init(rawValue: value) - } - self = .dictionary(newDictionary) - } else { - return nil - } - case is [Any]: - if let array = rawValue as? [Any] { - let newArray: [Self] = array.map { .init(rawValue: $0) }.compactMap { $0 } - self = .array(newArray) - } else { - return nil - } - default: - return nil - } - } - - public var rawValue: RawValue { - switch self { - case let .string(string): - return string - case let .integer(integer): - return integer - case let .real(real): - return real - case let .boolean(boolean): - return boolean - case let .dictionary(dictionary): - var newDictionary: [String: Any] = [:] - for (key, value) in dictionary { - newDictionary[key] = value.rawValue - } - return newDictionary - case let .array(array): - let newArray: [Any] = array.map(\.rawValue) - return newArray - } - } -} - -#if DEBUG - extension Template { - public static func test( - description: String = "Template", - attributes: [Attribute] = [], - items: [Template.Item] = [] - ) -> Template { - Template( - description: description, - attributes: attributes, - items: items - ) - } - } - - extension Template.Item { - public static func test( - path: RelativePath, - contents: Template.Contents = .string("test content") - ) -> Template.Item { - Template.Item( - path: path, - contents: contents - ) - } - } -#endif From 357e18ecdfdeca340f4141da7d572ef50e688163 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 10 Jun 2024 18:10:06 +0200 Subject: [PATCH 7/7] Remove models that shouldn't be there --- .../Models/PluginResourceSynthesizer.swift | 32 ----------------- .../ProjectDescriptionHelpersPlugin.swift | 35 ------------------- 2 files changed, 67 deletions(-) delete mode 100644 Sources/XcodeGraph/Models/PluginResourceSynthesizer.swift delete mode 100644 Sources/XcodeGraph/Models/ProjectDescriptionHelpersPlugin.swift diff --git a/Sources/XcodeGraph/Models/PluginResourceSynthesizer.swift b/Sources/XcodeGraph/Models/PluginResourceSynthesizer.swift deleted file mode 100644 index 47048e00..00000000 --- a/Sources/XcodeGraph/Models/PluginResourceSynthesizer.swift +++ /dev/null @@ -1,32 +0,0 @@ -import Foundation -import Path - -/// Resource synthesizer plugin model -public struct PluginResourceSynthesizer: Equatable { - /// Name of the plugin - public let name: String - /// Path to `ResourceSynthesizers` directory where all resource templates are located - public let path: AbsolutePath - - public init( - name: String, - path: AbsolutePath - ) { - self.name = name - self.path = path - } -} - -#if DEBUG - extension PluginResourceSynthesizer { - public static func test( - name: String = "Plugin", - path: AbsolutePath = try! AbsolutePath(validating: "/test") // swiftlint:disable:this force_try - ) -> Self { - .init( - name: name, - path: path - ) - } - } -#endif diff --git a/Sources/XcodeGraph/Models/ProjectDescriptionHelpersPlugin.swift b/Sources/XcodeGraph/Models/ProjectDescriptionHelpersPlugin.swift deleted file mode 100644 index 2301a321..00000000 --- a/Sources/XcodeGraph/Models/ProjectDescriptionHelpersPlugin.swift +++ /dev/null @@ -1,35 +0,0 @@ -import Foundation -import Path - -/// A model representing a custom `ProjectDescription` helper. -public struct ProjectDescriptionHelpersPlugin: Equatable { - /// Possible locations for a ProjectDescriptionHelpersPlugin - public enum Location: Equatable { - /// A plugin local to the current file system. - case local - /// A plugin on a remote server. - case remote - } - - /// The name of the helper module. - public let name: String - /// The path to `Plugin` manifest for this helper. - public let path: AbsolutePath - /// The type of location for the plugin. - public let location: Location - - /// Creates a `ProjectDescriptionHelpersPlugin`. - /// - Parameters: - /// - name: The name of the helper module. - /// - path: The path to `Plugin` manifest for this helper. - /// - location: The type of location for the plugin. - public init( - name: String, - path: AbsolutePath, - location: Location - ) { - self.name = name - self.path = path - self.location = location - } -}