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

📦 Adds support for Swift Package plugin command #1093

Merged
merged 18 commits into from
Sep 14, 2022

Conversation

polpielladev
Copy link
Collaborator

@polpielladev polpielladev commented Sep 9, 2022

Following a conversation with @krzysztofzablocki and the creation of issue #1090, this PR starts the work to add support for Swift Package Plugins for Sourcery

At the moment, this PR only includes support for Swift Package command plugins but not for build plugins yet, I'll be investigating those next as there are a set of challenges which must be overcome.

This PR also updates to using swift-tools version 5.6 to be able to make use of SPM plugins.

Discussion

I have left the --disableCache flag in this PR as I wanted to hear your opinion on how we can tackle the issue. From what I can see, since cacheBasePath is only an argument on config and not a cli argument, we have a few options:

  • Remove the --disableCache parameter and not do anything else. The client will have to provide a cacheBasePath in the configuration file that is within the package directory. It might be a bit misleading and the plugin won't work out of the box.
  • Read and re-write the .sourcery.yml to always provide a cacheBasePath that is in the pluginWorkDirectory. This could be done only when the key isn't present on the .sourcery.yml file?
  • Make cacheBasePath a command line argument which can be used only when the config key isn't present. This allows the package to provide a 'default value' that works while allowing the user to modify it?

I think my preferred option is the last one, but keen to hear your thoughts as you might have a different opinion on it 👍

How to test the plugin

I have create a small repo called sourcery-plugins-playground which will help with the testing. There are two folders:

swift-package-playground

Command Line

  • cd into swift-package-playground.
  • Do swift package plugin --list and verify that sourcery-command is part of the list.
  • Run swift package --allow-writing-to-package-directory sourcery-command.
  • Assert that a file named AutoMockable.generated.swift is generated in the right directory.

Xcode 14

  • cd into swift-package-playground.
  • Open Package.swift
  • Right click on swift-package-playground package
  • Run the sorcery-command from the list.
  • This should generate the same file.

xcodeproj-playground

Xcode 14

  • cd into xcodeproj-playground.
  • Open SourceryPluginSampleProj.xcodeproj
  • Right click on the project and select the plugin
  • The file that is missing should now be present, you can see it in the file explorer.

README.md Outdated Show resolved Hide resolved
Copy link
Owner

@krzysztofzablocki krzysztofzablocki left a comment

Choose a reason for hiding this comment

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

Love this 🙇

@krzysztofzablocki
Copy link
Owner

@pol-piella I agree with 3rd option sounding the most reasonable

@polpielladev
Copy link
Collaborator Author

@pol-piella I agree with 3rd option sounding the most reasonable

Amazing! I will get that done and let you know when it’s ready to be reviewed again. So excited to get this into Sourcery ❤️

@polpielladev
Copy link
Collaborator Author

@krzysztofzablocki Updated with the changes suggested to provide a default cache path 👍

Let me know if you're happy with the changes and we can get it merged 🚀

@krzysztofzablocki
Copy link
Owner

lgtm, you can go ahead and merge 👏

@polpielladev polpielladev merged commit 9846370 into krzysztofzablocki:master Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants