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

SPM Target Support #127

Open
agarrharr opened this issue Apr 2, 2024 · 16 comments
Open

SPM Target Support #127

agarrharr opened this issue Apr 2, 2024 · 16 comments

Comments

@agarrharr
Copy link

agarrharr commented Apr 2, 2024

I'm not sure what the difference is, but I have 2 different projects that are set up in pretty much the same way, with an spm package that has many modules. One of them correctly shows all of the schemes when I run :XcodebuildSetup and the other one does not. I can provide more information if needed.

This one is correct:
Screenshot 2024-04-02 at 3 40 10 PM

And this one only shows 2 schemes:
Screenshot 2024-04-02 at 3 41 02 PM

@wojciech-kulik
Copy link
Owner

Hmm, the plugin relies on .xcscheme files inside xcodeproj. It looks like Xcode doesn't autogenerate all schemes at once. Clicking on Edit Scheme... and switching between all schemes should generate missing schemes and it should fix the issue.

@agarrharr
Copy link
Author

Interesting. Well, for the project that works, I don't have any .xcscheme files in my .xcodeproj...

Screenshot 2024-04-02 at 5 22 54 PM

@agarrharr
Copy link
Author

And for the one that doesn't work, it DOES have an .xcscheme... I'm not sure how to click around to make it update...

Screenshot 2024-04-02 at 5 25 33 PM

@agarrharr
Copy link
Author

agarrharr commented Apr 2, 2024

I tried deleting the Countable.xcodeproj/xcshareddata folder and if can now find all of the schemes from my spm module, but of course it can't find the schemes app targets or widget extension (and neither can Xcode obviously).

Screenshot 2024-04-02 at 5 50 23 PM

@notlus
Copy link

notlus commented Apr 2, 2024

I ran into this as well. My SwiftPM schemes were in the .swiftpm/xcode/xcschemes folder for the package, with nothing in the xcodeproj folder. Moving the schemes into the xcodeproj folder and updating the project seems to work. Ideally this should not be necessary, given that Xcode seems able to find these schemes.

The other schemes were visible prior to PR 96.

@wojciech-kulik
Copy link
Owner

Ahhh, so there could be schemes also in .swiftpm/xcode/xcschemes. I didn't know about this path.

@wojciech-kulik
Copy link
Owner

I will need to investigate it, for now I'm reverting the improvement to find schemes based on generated files. Let me know if it resolves your issue.

@agarrharr
Copy link
Author

Thanks, that does fix the issue for me. They all show up now!

@agarrharr
Copy link
Author

If you need a project to test with, this is the one that had the problem: https://github.com/agarrharr/Countable

@wojciech-kulik
Copy link
Owner

I had to revert yesterday's changes because they break other things as now there is no build configuration selection.

I missed yesterday that this problem is generally about SPM packages, currently SPM targets are not supported directly. They break some assumptions of the plugin like running the target or getting build settings (which are not available for SPM packages).

Could you describe what's your use case for selecting a specific SPM module? To build it faster than when using the wrapping app?

If you benefit from using these schemes and it somehow works for you, you can still switch to the previous commit.

@wojciech-kulik wojciech-kulik changed the title Setup command is missing schemes SPM Support Apr 3, 2024
@wojciech-kulik wojciech-kulik changed the title SPM Support SPM Target Support Apr 3, 2024
@notlus
Copy link

notlus commented Apr 3, 2024

For my use-case, this change was a huge benefit. I have a large macOS project with multiple SPM packages. Working in the project involves changing schemes often, depending on what is being worked on. Building the SPM packages via the parent target is very time consuming, and it does not allow me to use the test explorer to run tests for a specific package. This increases the build/test time significantly.

@agarrharr
Copy link
Author

Ah, great questions. I don't really need to select them, I was just surprised that they were missing from this list. Technically, it would make it build faster if I was working on one small module at a time.

But if I'm working on a SwiftUI view, I have Xcode in the background and I have an AppleScript that automatically switches to that scheme in Xcode when I save a file so that I can see the SwiftUI preview.

Now that I think about it though, I would need to select one of them to run their tests, right?

@wojciech-kulik
Copy link
Owner

wojciech-kulik commented Apr 3, 2024

Currently, tests are supported only via test plans, so if you configure a test plan in your main app that runs tests from specific module you should be able to do that without selecting SPM target.

@notlus for now you can switch to specific commit if this solution worked for you. But keep in mind that build configuration detection doesn't work there, so if you use a different build configuration than "Debug" it won't work correctly.

I need to figure out if and how to support SPM packages, basically it's a different flow than for apps. I guess I would have to support two modes xcodeproj/xcworkspace and SPM module with a different set of commands and behaviors.

@agarrharr
Copy link
Author

agarrharr commented Apr 3, 2024

Yeah, so I'm running an app that includes a single module (called AppFeature) from an spm package (called Modules) under "Frameworks, Libraries, and Embedded Content". In that package, AppFeature has a dependency on other modules and an external library. I think you already understand, but I wanted to be clear and a picture is worth a thousand words.

xcode

@notlus
Copy link

notlus commented Apr 3, 2024

@wojciech-kulik The main project has multiple peer targets (there is no main app), none of which currently have test plans. I will see whether I can add test plans for them, but it seems like each test plan would need to be configured to run the SPM tests.

I also have this issue with sub-projects. The main Xcode project has some dependencies as child Xcode projects and like the SPM schemes, their schemes are not visible. In Xcode, I can select schemes across the projects.

For now, I will either stick with the commit or move the SPM schemes into the xcodeproj location. For the sub-projects, I guess I will have to switch projects, which is not too frequent.

@wojciech-kulik
Copy link
Owner

wojciech-kulik commented Apr 4, 2024

I also have this issue with sub-projects. The main Xcode project has some dependencies as child Xcode projects and like the SPM schemes, their schemes are not visible. In Xcode, I can select schemes across the projects.

Ok, this is a bug caused by looking for schemes inside a single xcodeproj. I need to verify if it's just that, if the plugin in general is able to work with other xcodeprojs included. But I think it should work if the scheme is correctly detected.

The main project has multiple peer targets (there is no main app), none of which currently have test plans. I will see whether I can add test plans for them, but it seems like each test plan would need to be configured to run the SPM tests.

If you wrap your main module inside an app project, you can then create a test plan that will include tests from each SPM package, a single test plan. I was using a similar approach in a project where I was working on a modularized application using SPM. We had just a "demo" project to include this package, run tests, and test in general the functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants