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 generating project with custom configurations (other than Debug and Release) via SPM packages #4259

Merged
merged 6 commits into from Mar 27, 2022

Conversation

mstfy
Copy link
Collaborator

@mstfy mstfy commented Mar 19, 2022

Short description 📝

This PR attempts to fix that generated project doesn't have correct configurations when custom config specified via Dependencies.swift

Long description

Xcode fails to compiling generated project with 'Framework not found' error when importing spm dependency via Dependencies.swift to a project that have configurations other than Debug and Release. This pr adds custom config to generated xcode project from spm dependency.

@@ -1026,7 +1027,21 @@ extension PackageInfo {
settingsDictionary["SWIFT_VERSION"] = .string(swiftLanguageVersion)
}

return settingsDictionary.isEmpty ? nil : .settings(base: settingsDictionary)
let hasCustomConfig = buildConfigs.firstIndex(where: { !["Debug", "Release"].contains($0.name) }) != nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would probably be better to make this field optional. If user populates it then it has a value, otherwise it's nil and we use defaults.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the logic should be that we always use what we got. If the user wants to use the defaults it' already handled by the init AFAIR

Copy link
Collaborator

@luispadron luispadron left a comment

Choose a reason for hiding this comment

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

It looks like this is still WIP so i'm converting the PR to draft. Thanks again for contributing this would be great to fix.

Copy link
Collaborator

@danieleformichelli danieleformichelli left a comment

Choose a reason for hiding this comment

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

Thanks, could you please also add a custom config to the SPM fixture in projects/tuist/fixtures/app_with_spm_dependencies so we can verify it works (and continues to work) in an acceptance test? 🙏

@@ -1026,7 +1027,21 @@ extension PackageInfo {
settingsDictionary["SWIFT_VERSION"] = .string(swiftLanguageVersion)
}

return settingsDictionary.isEmpty ? nil : .settings(base: settingsDictionary)
let hasCustomConfig = buildConfigs.firstIndex(where: { !["Debug", "Release"].contains($0.name) }) != nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the logic should be that we always use what we got. If the user wants to use the defaults it' already handled by the init AFAIR

@danieleformichelli
Copy link
Collaborator

Also, remember to add a changelog entry 🙏

@danieleformichelli danieleformichelli linked an issue Mar 26, 2022 that may be closed by this pull request
mstfy added a commit that referenced this pull request Mar 26, 2022
@mstfy mstfy force-pushed the fix/spm-dependencies-with-custom-config branch from 8886215 to 24735be Compare March 26, 2022 19:01
@@ -1026,7 +1027,20 @@ extension PackageInfo {
settingsDictionary["SWIFT_VERSION"] = .string(swiftLanguageVersion)
}

return settingsDictionary.isEmpty ? nil : .settings(base: settingsDictionary)
if let buildConfigs = buildConfigs,
buildConfigs.firstIndex(where: { !["Debug", "Release"].contains($0.name) }) != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need this condition? If a custom config is passed we should take it, regardless of its name, isn't it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Debug and Release wil always be in the generated project by default. Adding them here also breaks almost all tests here. So I choose to add settings if custom config specified by the user.

Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't add this change if it's only for the tests. Will it be so hard to fix them without including this line?

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.

Hey @mstfy 👋

The changes look good, however, I think we need to bump the version here to 2.0.0 since the SPM dependencies now have additional configurations that they did not have previously.

That should fix this issue - I have tried it locally and was getting Framework ProjectDescription not found. @danyf90 since you were the one who introduced it here, does bumping the cache version make sense to you? Or is it a bug inside the caching functionality instead?

@mstfy, you will also need to fix the lint issues.

@danieleformichelli
Copy link
Collaborator

No, that should be bumped only if something cache related changes, if the change is before (e.g. in the mapping to TuistGraph), then it shouldn't be needed.
So in this case it shouldn't 🤔

@danieleformichelli danieleformichelli merged commit c17de84 into main Mar 27, 2022
@danieleformichelli danieleformichelli deleted the fix/spm-dependencies-with-custom-config branch March 27, 2022 20:15
@adellibovi adellibovi changed the title fix project generation from spm dependency with custom configs Fix generating project with custom configurations (other than Debug and Release) via SPM packages Mar 28, 2022
@adellibovi adellibovi added the changelog:fixed PR will be listed in the Fixed section of CHANGELOG label Mar 28, 2022
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.

Can't add local SPM packages using Dependencies.swift
5 participants