Skip to content

feat(cli): Add SE-0162 support for custom SPM target layouts#8191

Merged
fortmarek merged 12 commits intotuist:mainfrom
devyhan:se-0162-custom-target-layouts
Sep 18, 2025
Merged

feat(cli): Add SE-0162 support for custom SPM target layouts#8191
fortmarek merged 12 commits intotuist:mainfrom
devyhan:se-0162-custom-target-layouts

Conversation

@devyhan
Copy link
Copy Markdown
Contributor

@devyhan devyhan commented Sep 13, 2025

Resolves #8185, xcodebuild-nvim-preview/#3

Fixes the "Default source path not found" error when using SPM packages that have source files directly in the Sources/ directory instead of Sources/TargetName/.

This implements support for SPM's flexible source discovery mechanism which allows packages like xcodebuild-nvim-preview to place source files directly in Sources/.

The fix modifies PackageInfoMapper.basePath(packageFolder:) to first check for the standard Sources/TargetName/ layout, then fall back to checking for source files directly in Sources/ as per SPM's auto-discovery rules.

How to test locally

  1. Add wojciech-kulik/xcodebuild-nvim-preview package (version 1.0.10) to your Tuist project
  2. Run tuist install
  3. Run tuist generate
  4. Verify the project generates successfully without "Default source path not found for target XcodebuildNvimPreview" error

- Add test for Test targets with custom layout
- Add test for alternative source directories (Source/, src/)
- Add test for empty Sources directory fallback to standard layout
- Add reference to SPM's SupportedLanguageExtension.swift
- Add TODO for potential assembly extensions support
@dosubot dosubot Bot added size:L For issues that take up to a day to implement domain:dependencies For issues and PRs related to integrating third-party dependencies type:enhancement New feature or request labels Sep 13, 2025
@devyhan devyhan force-pushed the se-0162-custom-target-layouts branch from 042385a to a6ca7e0 Compare September 13, 2025 03:33
@devyhan devyhan force-pushed the se-0162-custom-target-layouts branch from a6ca7e0 to 3d83784 Compare September 13, 2025 03:34
Copy link
Copy Markdown
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 couple of minor comments 🙂

Comment thread cli/Sources/TuistLoader/SwiftPackageManager/PackageInfoMapper.swift Outdated
Comment thread cli/Sources/TuistLoader/SwiftPackageManager/PackageInfoMapper.swift Outdated
Comment thread cli/Sources/TuistLoader/SwiftPackageManager/PackageInfoMapper.swift Outdated
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Sep 15, 2025
 - Support packages with sources directly in Sources/ without subdirectories.
 - Refactor basePath to use single-loop verification with early return.
  - Extract hasSourceFiles as private method
  - Consolidate layout detection into single loop with early returns
  - Simplify directory selection with ternary operator
  - Consolidate SE-0162 tests into PackageInfoMapperTests
  - Remove redundant PackageInfoMapperCustomLayoutTests file
  - Eliminate duplicate test coverage already handled by existing tests
@devyhan devyhan requested a review from fortmarek September 15, 2025 17:35
@devyhan
Copy link
Copy Markdown
Contributor Author

devyhan commented Sep 15, 2025

Thank you for the review @fortmarek 👍
Based on your suggestions, I analyzed the surrounding code and discovered a more fundamental improvement opportunity.

I refactored the layout validation logic that previously checked standard layout and SE-0162 separately (traversing directories twice) into a single loop that validates all layouts. Additionally, I replaced the unnecessary Task creation overhead from concurrentFilter (creating a Task for each element and waiting for all Tasks to complete) with sequential processing and early termination, resulting in improved performance.

Copy link
Copy Markdown
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.

We can make the globbing slightly more performant. Also, don't forget to run mise run lint --fix when you push, so the lint check can pass 😌

Comment thread cli/Sources/TuistLoader/SwiftPackageManager/PackageInfoMapper.swift Outdated
Comment thread cli/Sources/TuistLoader/SwiftPackageManager/PackageInfoMapper.swift Outdated
  - Rename 'dir' to 'directory' for better readability
  - Use backticks for 'extension' to avoid Swift keyword conflict
@devyhan devyhan force-pushed the se-0162-custom-target-layouts branch from 1b34d35 to a1b87f3 Compare September 17, 2025 05:23
  - Replace 7 individual glob operations with one using brace expansion
  - Follows existing pattern used in line 901 for consistency
  - Improves performance for SE-0162 source file detection

https://github.com/tuist/tuist/blob/main/cli/Sources/TuistLoader/SwiftPackageManager/PackageInfoMapper.swift#L901
@devyhan devyhan force-pushed the se-0162-custom-target-layouts branch from a1b87f3 to a1a2ef9 Compare September 17, 2025 08:38
@devyhan
Copy link
Copy Markdown
Contributor Author

devyhan commented Sep 17, 2025

Thank you for your time @fortmarek 😄

We can make the globbing slightly more performant. Also, don't forget to run mise run lint --fix when you push, so the lint check can pass 😌

Regarding the lint error

I ran mise run lint.sh --fix locally, and it finished without any issues. However, I'm still not sure what's causing the lint error, so I'd really appreciate any guidance. For reference, here's the CLI command I used

mise run lint.sh --fix
[lint.sh] $ ~/Desktop/tuist/mise/tasks/lint.sh --fix
[cli:lint] $ ~/Desktop/tuist/mise/tasks/cli/lint.sh --fix
Running SwiftFormat...
Reading config file at /Users/devyhan93/Desktop/tuist/.swiftformat
SwiftFormat completed in 0.76s.
0/2239 files formatted, 30 files skipped.

CI-Lint Job Error:

/Users/runner/work/tuist/tuist/cli/Sources/TuistServer/Client/ServerAuthenticationController.swift:175:8: error: Type Body Length Violation: Type body should span 350 lines or less excluding comments and whitespace: currently spans 362 lines (type_body_length)

About Test Failures

I noticed that the CI tests are failing specifically for registry-based packages while Git-based SPM packages pass
After investigating deeply, I believe this might be unrelated to the glob pattern changes since:

  1. The FileSystem's glob properly expands brace patterns via expandBraces function
  2. Both the old approach (7 individual globs) and new approach (single brace pattern) generate the same file patterns
  3. The failures occur specifically with registry packages, which might indicate an issue with registry package installation or authentication in CI

Could this be related to registry package handling or CI environment configuration? I'd appreciate your insights on whether these test failures are expected or if there's something I should address.

@devyhan devyhan requested a review from fortmarek September 17, 2025 15:08
@fortmarek
Copy link
Copy Markdown
Member

The lint job error was failing on main, too. Updated this branch with latest changes which should make the lint job pass 🤞

@fortmarek
Copy link
Copy Markdown
Member

Thanks again for your contribution!

@fortmarek fortmarek merged commit b003a33 into tuist:main Sep 18, 2025
13 of 14 checks passed
pepicrft pushed a commit that referenced this pull request Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain:dependencies For issues and PRs related to integrating third-party dependencies lgtm This PR has been approved by a maintainer size:L For issues that take up to a day to implement type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tuist Fails to Generate SPM Dependency Due to Non-standard Directory Layout

3 participants