Skip to content

Commit

Permalink
Extract Tuist-specific models from XcodeGraph (tuist#6401)
Browse files Browse the repository at this point in the history
* Remove no-longer needed models

* Introduce TuistModels

* Fix compilation

* Fix Package.swift

* Fix some linting issues

* Remove TuistModels and merge models into TuistCore
  • Loading branch information
pepicrft authored Jun 12, 2024
1 parent 72e7657 commit cdb9197
Show file tree
Hide file tree
Showing 203 changed files with 540 additions and 4,719 deletions.
6 changes: 3 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "026755a035a6925da2ead11d61025383dd47d8db6b0c23d6a14cb94e12523887",
"originHash" : "be656e1285b67cd89206d2e44ae693ca74086bd97ce1788a21d0533b6a6b6f62",
"pins" : [
{
"identity" : "aexml",
Expand Down Expand Up @@ -240,8 +240,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/tuist/XcodeGraph.git",
"state" : {
"revision" : "634fd424d7d7c43aca6598f223c01b2ecf353502",
"version" : "0.2.0"
"revision" : "0e44220403553ce7f20a79e49873b492302b4650",
"version" : "0.5.0"
}
},
{
Expand Down
4 changes: 1 addition & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ var targets: [Target] = [
dependencies: [
"TuistCore",
"TuistSupportTesting",
.product(name: "XcodeGraphTesting", package: "XcodeGraph"),
pathDependency,
],
linkerSettings: [.linkedFramework("XCTest")]
Expand Down Expand Up @@ -249,7 +248,6 @@ var targets: [Target] = [
"TuistLoader",
pathDependency,
"TuistCore",
.product(name: "XcodeGraphTesting", package: "XcodeGraph"),
"ProjectDescription",
"TuistSupportTesting",
],
Expand Down Expand Up @@ -418,7 +416,7 @@ let package = Package(
.package(url: "https://github.com/tuist/swift-openapi-runtime", branch: "swift-tools-version"),
.package(url: "https://github.com/tuist/swift-openapi-urlsession", branch: "swift-tools-version"),
.package(url: "https://github.com/tuist/Path", .upToNextMajor(from: "0.3.0")),
.package(url: "https://github.com/tuist/XcodeGraph.git", exact: "0.2.0"),
.package(url: "https://github.com/tuist/XcodeGraph.git", .upToNextMajor(from: "0.5.0")),
],
targets: targets
)
41 changes: 41 additions & 0 deletions Sources/TuistCore/Models/Cloud.swift
Original file line number Diff line number Diff line change
@@ -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://test.tuist.io")!,
projectId: String = "123",
options: [Cloud.Option] = []
) -> Cloud {
Cloud(url: url, projectId: projectId, options: options)
}
}
#endif
72 changes: 72 additions & 0 deletions Sources/TuistCore/Models/CompatibleXcodeVersions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import Foundation
import XcodeGraph

/// Enum that represents all the Xcode versions that a project or set of projects is compatible with.
public enum CompatibleXcodeVersions: Equatable, Hashable, ExpressibleByArrayLiteral, ExpressibleByStringInterpolation,
CustomStringConvertible
{
/// The project supports all Xcode versions.
case all

/// The project supports only a specific Xcode version.
case exact(Version)

/// The project supports all Xcode versions from the specified version up to but not including the next major version.
case upToNextMajor(Version)

/// The project supports all Xcode versions from the specified version up to but not including the next minor version.
case upToNextMinor(Version)

/// List of versions that are supported by the project.
case list([CompatibleXcodeVersions])

public func isCompatible(versionString: String) -> Bool {
let xCodeVersion: Version = "\(versionString)"

switch self {
case .all:
return true
case let .exact(version):
return version == xCodeVersion
case let .upToNextMajor(version):
return xCodeVersion.major == version.major && xCodeVersion >= version
case let .upToNextMinor(version):
return version.major == xCodeVersion.major && version.minor == xCodeVersion.minor && xCodeVersion >= version
case let .list(versions):
return versions.contains { $0.isCompatible(versionString: versionString) }
}
}

// MARK: - ExpressibleByStringInterpolation

public init(stringLiteral value: String) {
self = .exact(Version(stringLiteral: value))
}

// MARK: - ExpressibleByArrayLiteral

public init(arrayLiteral elements: [CompatibleXcodeVersions]) {
self = .list(elements)
}

public init(arrayLiteral elements: CompatibleXcodeVersions...) {
self = .list(elements)
}

// MARK: - CustomStringConvertible

public var description: String {
switch self {
case .all:
return "all"
case let .exact(version):
return "\(version)"
case let .upToNextMajor(version):
return "\(version)..<\(version.major + 1).0.0"
case let .upToNextMinor(version):
return "\(version)..<\(version.major).\(version.minor + 1).0"
case let .list(versions):
return "\(versions.map(\.description).joined(separator: " or "))"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import Path
import TSCUtility
import XcodeGraph

/// This model allows to configure Tuist.
public struct Config: Equatable, Hashable {
Expand Down Expand Up @@ -73,3 +73,45 @@ public struct Config: Equatable, Hashable {
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: TuistCore.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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Path
import TSCUtility

extension Config {
public struct GenerationOptions: Codable, Hashable {
Expand Down
67 changes: 67 additions & 0 deletions Sources/TuistCore/Models/PackageSettings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import Foundation
import XcodeGraph

/// 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 = Settings.default,
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
File renamed without changes.
41 changes: 41 additions & 0 deletions Sources/TuistCore/Models/PluginLocation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Foundation

/// The location to a directory containing a `Plugin` manifest.
public enum PluginLocation: Hashable, Equatable {
public enum GitReference: Hashable, Equatable {
case sha(String)
case tag(String)
}

/// An absolute path `String` to a directory a `Plugin` manifest.
///
/// Example:
/// ```
/// .local(path: "/User/local/bin")
/// ```
case local(path: String)

/// A `URL` to a `git` repository pointing at a `GitReference` (either sha or tag), and optionally a directory
///
/// Examples:
/// ```
/// .git(url: "https://git/helpers.git", gitReference: .tag("1.0.0"))
/// .git(url: "https://git/helpers.git", gitReference: .sha("1.0.0"))
/// ```
case git(url: String, gitReference: GitReference, directory: String?, releaseUrl: String?)
}

// MARK: - description

extension PluginLocation: CustomStringConvertible {
public var description: String {
switch self {
case let .local(path):
return "local path: \(path)"
case let .git(url, .tag(tag), directory, releaseUrl):
return "git url: \(url), tag: \(tag), directory: \(directory ?? "nil"), releaseUrl: \(releaseUrl ?? "nil")"
case let .git(url, .sha(sha), directory, releaseUrl):
return "git url: \(url), sha: \(sha), directory: \(directory ?? "nil"), releaseUrl: \(releaseUrl ?? "nil")"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,19 @@ public struct Plugins: Equatable {
resourceSynthesizers: []
)
}

#if DEBUG
extension Plugins {
public static func test(
projectDescriptionHelpers: [ProjectDescriptionHelpersPlugin] = [],
templatePaths: [AbsolutePath] = [],
resourceSynthesizers: [PluginResourceSynthesizer] = []
) -> Plugins {
Plugins(
projectDescriptionHelpers: projectDescriptionHelpers,
templatePaths: templatePaths,
resourceSynthesizers: resourceSynthesizers
)
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,31 @@ extension Template.Attribute.Value: RawRepresentable {
}
}
}

#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
Loading

0 comments on commit cdb9197

Please sign in to comment.