Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generation of SPM packages when some resources are missing #6027

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion Sources/TuistGenerator/Mappers/ResourcesProjectMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ public class ResourcesProjectMapper: ProjectMapping { // swiftlint:disable:this
additionalTargets.append(resourcesTarget)
}

if target.supportsSources, target.sources.contains(where: { $0.path.extension == "swift" }) {
if target.supportsSources,
target.sources.contains(where: { $0.path.extension == "swift" }),
!target.sources.contains(where: { $0.path.basename == "\(target.name)Resources.swift" })
{
let (filePath, data) = synthesizedSwiftFile(bundleName: bundleName, target: target, project: project)

let hash = try data.map(contentHasher.hash)
Expand Down
12 changes: 12 additions & 0 deletions Sources/TuistLoader/SwiftPackageManager/PackageInfoMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,18 @@ extension ResourceFileElements {
return try handleProcessResource(resourceAbsolutePath: resourceAbsolutePath)
}
}
.filter {
switch $0 {
case let .glob(pattern: pattern, excluding: _, tags: _, inclusionCondition: _):
// We will automatically skip including globs of non-existing directories for packages
if !FileHandler.shared.exists(try AbsolutePath(validating: String(pattern.pathString)).parentDirectory) {
return false
}
return true
case .folderReference:
return true
}
}

// Add default resources path if necessary
// They are handled like a `.process` rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ final class PackageInfoMapperTests: TuistUnitTestCase {
.init(rule: .copy, path: "Resource/Folder"),
.init(rule: .process, path: "Another/Resource/Folder"),
.init(rule: .process, path: "AnotherOne/Resource/Folder"),
.init(rule: .process, path: "AnotherOne/Resource/Folder/NonExisting"),
],
exclude: [
"AnotherOne/Resource",
Expand All @@ -907,7 +908,7 @@ final class PackageInfoMapperTests: TuistUnitTestCase {
]
)

XCTAssertEqual(
XCTAssertBetterEqual(
project,
.testWithDefaultConfigs(
name: "Package",
Expand Down
1 change: 1 addition & 0 deletions fixtures/app_with_spm_dependencies/App/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let project = Project(
.external(name: "libzstd"),
.external(name: "NYTPhotoViewer"),
.external(name: "SVProgressHUD"),
.external(name: "AirshipPreferenceCenter"),
],
settings: .targetSettings
),
Expand Down
9 changes: 9 additions & 0 deletions fixtures/app_with_spm_dependencies/Tuist/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@
"version" : "2.0.0"
}
},
{
"identity" : "ios-library",
"kind" : "remoteSourceControl",
"location" : "https://github.com/urbanairship/ios-library.git",
"state" : {
"revision" : "53040c77617a2acc5d9a7b69cf5bbbf36f94ad4b",
"version" : "17.7.3"
}
},
{
"identity" : "nimble",
"kind" : "remoteSourceControl",
Expand Down
2 changes: 2 additions & 0 deletions fixtures/app_with_spm_dependencies/Tuist/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ let package = Package(
.package(url: "https://github.com/Quick/Quick", exact: "7.4.0"),
.package(url: "https://github.com/Quick/Nimble", exact: "13.2.0"),
.package(url: "https://github.com/SVProgressHUD/SVProgressHUD", exact: "2.3.1"),
// Has missing resources and its own resource bundle accessors
.package(url: "https://github.com/urbanairship/ios-library.git", .exact("17.7.3")),
.package(path: "../LocalSwiftPackage"),
.package(path: "../StringifyMacro"),
]
Expand Down