Skip to content

Commit

Permalink
Skip targets with unsupported platforms instead of throwing an error
Browse files Browse the repository at this point in the history
  • Loading branch information
fortmarek committed Mar 8, 2024
1 parent fc18623 commit 0290b7a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 28 deletions.
44 changes: 18 additions & 26 deletions Sources/TuistLoader/SwiftPackageManager/PackageInfoMapper.swift
Expand Up @@ -483,22 +483,23 @@ public final class PackageInfoMapper: PackageInfoMapping {

if target.type.supportsDependencies {
let linkerDependencies: [ProjectDescription.TargetDependency] = target.settings.compactMap { setting in
do {
let condition = try ProjectDescription.PlatformCondition.from(setting.condition)

switch (setting.tool, setting.name) {
case (.linker, .linkedFramework):
return .sdk(name: setting.value[0], type: .framework, status: .required, condition: condition)
case (.linker, .linkedLibrary):
return .sdk(name: setting.value[0], type: .library, status: .required, condition: condition)
case (.c, _), (.cxx, _), (_, .enableUpcomingFeature), (.swift, _), (.linker, .headerSearchPath), (
.linker,
.define
),
(.linker, .unsafeFlags), (_, .enableExperimentalFeature):
return nil
}
} catch {
let condition = ProjectDescription.PlatformCondition.from(setting.condition)

// The condition returned only unsupported platforms
if condition == nil, setting.condition != nil {
return nil
}

switch (setting.tool, setting.name) {
case (.linker, .linkedFramework):
return .sdk(name: setting.value[0], type: .framework, status: .required, condition: condition)
case (.linker, .linkedLibrary):
return .sdk(name: setting.value[0], type: .library, status: .required, condition: condition)
case (.c, _), (.cxx, _), (_, .enableUpcomingFeature), (.swift, _), (.linker, .headerSearchPath), (
.linker,
.define
),
(.linker, .unsafeFlags), (_, .enableExperimentalFeature):
return nil
}
}
Expand Down Expand Up @@ -1216,14 +1217,10 @@ extension PackageInfoMapper {
}

extension ProjectDescription.PlatformCondition {
struct OnlyConditionsWithUnsupportedPlatforms: Error {}

/// Map from a package condition to ProjectDescription.PlatformCondition
/// - Parameter condition: condition representing platforms that a given dependency applies to
/// - Returns: set of PlatformFilters to be used with `GraphDependencyRefrence`
/// throws `OnlyConditionsWithUnsupportedPlatforms` if the condition only contains platforms not supported by Tuist (e.g
/// `windows`)
fileprivate static func from(_ condition: PackageInfo.PackageConditionDescription?) throws -> Self? {
fileprivate static func from(_ condition: PackageInfo.PackageConditionDescription?) -> Self? {
guard let condition else { return nil }
let filters: [ProjectDescription.PlatformFilter] = condition.platformNames.compactMap { name in
switch name {
Expand All @@ -1244,11 +1241,6 @@ extension ProjectDescription.PlatformCondition {
}
}

// If empty, we know there are no supported platforms and this dependency should not be included in the graph
if filters.isEmpty {
throw OnlyConditionsWithUnsupportedPlatforms()
}

return .when(Set(filters))
}
}
Expand Down
67 changes: 65 additions & 2 deletions fixtures/app_with_spm_dependencies/Tuist/Package.resolved
Expand Up @@ -36,6 +36,15 @@
"version" : "3.8.4"
}
},
{
"identity" : "collectionconcurrencykit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/JohnSundell/CollectionConcurrencyKit.git",
"state" : {
"revision" : "b4f23e24b5a1bff301efc5e70871083ca029ff95",
"version" : "0.2.0"
}
},
{
"identity" : "combine-schedulers",
"kind" : "remoteSourceControl",
Expand All @@ -45,6 +54,15 @@
"version" : "1.0.0"
}
},
{
"identity" : "cryptoswift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/krzyzanowskim/CryptoSwift.git",
"state" : {
"revision" : "7892a123f7e8d0fe62f9f03728b17bbd4f94df5c",
"version" : "1.8.1"
}
},
{
"identity" : "cwlcatchexception",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -171,6 +189,15 @@
"version" : "8.20.0"
}
},
{
"identity" : "sourcekitten",
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/SourceKitten.git",
"state" : {
"revision" : "b6dc09ee51dfb0c66e042d2328c017483a1a5d56",
"version" : "0.34.1"
}
},
{
"identity" : "svprogresshud",
"kind" : "remoteSourceControl",
Expand All @@ -180,6 +207,15 @@
"version" : "2.3.1"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531",
"version" : "1.2.3"
}
},
{
"identity" : "swift-case-paths",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -275,8 +311,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d",
"version" : "509.1.1"
"revision" : "6ad4ea24b01559dde0773e3d091f1b9e36175036",
"version" : "509.0.2"
}
},
{
"identity" : "swiftlint",
"kind" : "remoteSourceControl",
"location" : "https://github.com/realm/SwiftLint",
"state" : {
"revision" : "f17a4f9dfb6a6afb0408426354e4180daaf49cee",
"version" : "0.54.0"
}
},
{
Expand All @@ -288,6 +333,24 @@
"version" : "1.2.1"
}
},
{
"identity" : "swiftytexttable",
"kind" : "remoteSourceControl",
"location" : "https://github.com/scottrhoyt/SwiftyTextTable.git",
"state" : {
"revision" : "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3",
"version" : "0.9.0"
}
},
{
"identity" : "swxmlhash",
"kind" : "remoteSourceControl",
"location" : "https://github.com/drmohundro/SWXMLHash.git",
"state" : {
"revision" : "a853604c9e9a83ad9954c7e3d2a565273982471f",
"version" : "7.0.2"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
Expand Down
1 change: 1 addition & 0 deletions fixtures/app_with_spm_dependencies/Tuist/Package.swift
Expand Up @@ -24,6 +24,7 @@ let package = Package(
.package(url: "https://github.com/google/GoogleSignIn-iOS", .upToNextMajor(from: "7.0.0")),
.package(url: "https://github.com/getsentry/sentry-cocoa", .upToNextMajor(from: "8.20.0")),
.package(url: "https://github.com/realm/realm-swift", .upToNextMajor(from: "10.46.0")),
.package(url: "https://github.com/realm/SwiftLint", exact: "0.54.0"),
.package(url: "https://github.com/CocoaLumberjack/CocoaLumberjack", .upToNextMajor(from: "3.8.4")),
.package(url: "https://github.com/facebook/zstd", exact: "1.5.5"),
.package(url: "https://github.com/microsoft/appcenter-sdk-apple", .upToNextMajor(from: "5.0.4")),
Expand Down

0 comments on commit 0290b7a

Please sign in to comment.