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 integration of SPM packages with slashes in their targets names #6260

Merged
merged 2 commits into from May 15, 2024

Conversation

kapitoshka438
Copy link
Contributor

@kapitoshka438 kapitoshka438 commented May 7, 2024

Resolves #6145

Short description πŸ“

Although targets names and bundle identifiers have to be Uniform Type Identifiers, SPM is able to process some non-compliant targets such as those that contain a slash "/" in their name just by replacing it with an underscore "_".
This PS brings the same to enable Tuist to work with dependencies like KSCrash.

How to test the changes locally 🧐

KSCrash was added as an SPM dependency in the app_with_spm_dependencies fixture.

Contributor checklist βœ…

  • The code has been linted using run mise run lint:fix
  • The change is tested via unit testing or acceptance testing, or both
  • The title of the PR is formulated in a way that is usable as a changelog entry
  • In case the PR introduces changes that affect users, the documentation has been updated

Reviewer checklist βœ…

  • The code architecture and patterns are consistent with the rest of the codebase
  • Reviewer has checked that, if needed, the PR includes the label changelog:added, changelog:fixed, or changelog:changed, and the title is usable as a changelog entry

@kapitoshka438 kapitoshka438 force-pushed the allow-slash-in-target-name branch 3 times, most recently from 84dca6d to e27c85f Compare May 8, 2024 00:22
@kapitoshka438 kapitoshka438 marked this pull request as ready for review May 8, 2024 00:30
@danibachar
Copy link
Collaborator

I think the same happens with whitespaces - example package.
https://github.com/Shopify/mobile-buy-sdk-ios

@kapitoshka438 kapitoshka438 force-pushed the allow-slash-in-target-name branch 2 times, most recently from b83ea92 to 85f02d7 Compare May 8, 2024 21:16
Copy link
Member

@fortmarek fortmarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the PR, a couple of comments, but nothing major πŸ™‚

fixtures/ios_app_with_spm_dependencies/Project.swift Outdated Show resolved Hide resolved
let sanitizedTargetName = targetName
.replacingOccurrences(of: "-", with: "_")
.replacingOccurrences(of: "/", with: "_")
let expectedBundleName = "\(projectName)_\(sanitizedTargetName)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably hardcode this. The less business logic in tests the better.

Suggested change
let expectedBundleName = "\(projectName)_\(sanitizedTargetName)"
let expectedBundleName = "sdk_with_dash_target_with_dash"

@@ -594,9 +595,9 @@ public final class PackageInfoMapper: PackageInfoMapping {
product: product,
productName: PackageInfoMapper
.sanitize(targetName: target.name)
.replacingOccurrences(of: "-", with: "_"),
.replacingOccurrences(of: "-", with: "_").replacingOccurrences(of: "/", with: "_"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the sanitize method already do the replacement?

Comment on lines 39 to 41
let sanitizedTargetName = target.name
.replacingOccurrences(of: "-", with: "_")
.replacingOccurrences(of: "/", with: "_")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given in how many places we needed to update this, I wonder if we should extract this into a helper method such as:

extension TuistGraph.Target {
  static func sanitizedTargetName(_ targetName: String) -> String { ... }
}

@kapitoshka438 kapitoshka438 marked this pull request as draft May 13, 2024 22:26
@kapitoshka438 kapitoshka438 force-pushed the allow-slash-in-target-name branch 7 times, most recently from f60aa56 to b5a3707 Compare May 14, 2024 12:45
@kapitoshka438 kapitoshka438 marked this pull request as ready for review May 14, 2024 12:45
@kapitoshka438 kapitoshka438 changed the title Allow slash in non-uti-compliant target names Fix integration of SPM packages with slashes in their targets names May 14, 2024
@kapitoshka438
Copy link
Contributor Author

@fortmarek I've rebased and made some fixes. Still have no idea what's happening on CI tho. All tests pass fine locally.

@fortmarek
Copy link
Member

I've rebased and made some fixes. Still have no idea what's happening on CI tho. All tests pass fine locally.

main seems to be green the couple of last commits. Afaict tell from the test results, this is likely related to your PR. Both tests fail with the same crash:

The main part of the crash is TuistAutomationAcceptanceTests 0x108191590 UNIXPath.appending(component:) + 528. Is it possible that we're adding an invalid component somewhere in the test that causes things to crash?

@kapitoshka438
Copy link
Contributor Author

I've rebased and made some fixes. Still have no idea what's happening on CI tho. All tests pass fine locally.

main seems to be green the couple of last commits. Afaict tell from the test results, this is likely related to your PR. Both tests fail with the same crash:

The main part of the crash is TuistAutomationAcceptanceTests 0x108191590 UNIXPath.appending(component:) + 528. Is it possible that we're adding an invalid component somewhere in the test that causes things to crash?

Yay thank you @fortmarek this helped a lot.
I don't know why but this assertion was commented out for me locally.
I've pushed fixes, CI finally passed

@pepicrft pepicrft added the changelog:fixed PR will be listed in the Fixed section of CHANGELOG label May 15, 2024
Copy link
Member

@fortmarek fortmarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great findings @kapitoshka438 πŸ‘

@fortmarek fortmarek merged commit daa042c into tuist:main May 15, 2024
8 checks passed
@TopIvanAbramov
Copy link

TopIvanAbramov commented May 15, 2024

@fortmarek when can we expect to see this bugfix in release and which version?

@kapitoshka438 kapitoshka438 deleted the allow-slash-in-target-name branch May 15, 2024 13:54
@fortmarek
Copy link
Member

when can we expect to see this bugfix in release and which version?

We try to release weekly on Monday, i.e., there should be 4.14.0 tuist release on Monday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:fixed PR will be listed in the Fixed section of CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tuist doesn't work with KSCrash
5 participants