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

Migrate to v2 with SPM package.swift #508

Open
soucolline opened this issue Aug 2, 2024 · 17 comments
Open

Migrate to v2 with SPM package.swift #508

soucolline opened this issue Aug 2, 2024 · 17 comments

Comments

@soucolline
Copy link

Hello,

I'm trying to migrate to v2 using SPM with a package.swift file.
I'm updating the dependency to 2.0.9
.package(url: "https://github.com/Brightify/Cuckoo.git", exact: "2.0.9"),
But then I don't have access to the CuckooPluginSingleFile mentioned in the doc. Is it only in the case where you install it from Xcode ?

Even if I try to launch my tests i'm getting this warning about the file being stalled from my DerivedData, so I supposed it's existing even though i'm not importing it in the Run Build Tools Plug-ins phase
Screenshot 2024-08-02 at 11 38 36 AM

Am I missing something there or the install from a Package.swift is not supported ?

Thanks

@soucolline
Copy link
Author

After some investigations I managed to run the CockkoPluginSingleFile by adding

plugins: [
    .plugin(name: "CuckooPluginSingleFile", package: "Cuckoo")
]

to my package definition but now i'm getting the same errors as mentioned in this issue

@MatyasKriz
Copy link
Collaborator

Hey, @soucolline, that message is not an error per se, it's only a disclaimer when multiple outputs are defined in Cuckoofile, but I agree that it should be fixed and hidden when the Swift build tool plugin forces the derived data mock output.

However, it shouldn't cause any issues otherwise, do the mocks not get generated? Unfortunately I think it's not possible to generate the mocks anywhere else as a Swift build tool plugin, maybe an investigation is in order.

@soucolline
Copy link
Author

Hey @MatyasKriz thanks for the answer, the mocks are generated on the derivedData folder when I specify the plugin option in my Package.swift

If it's impossible to generate mocks outside of the derivedData maybe a third option with a CLI to generate the mocks whenever you want could work ? So that you don't have to rely on the plugin or a script phase

@MatyasKriz
Copy link
Collaborator

I'm not sure I understand, you can simply call the run script as defined in the script phase and it will work as you need, you can call it whenever you want and have the mocks generated.

Did I miss something?

@soucolline
Copy link
Author

Oh ok I didn't see I could do that. I've tried running cuckoonator script and the mocks are created at the right location with it. I'll continue to dig a bit but it sounds good

@soucolline
Copy link
Author

Ok I've migrated everything to 2.0.9 and it's working fine !

The only thing a bit annoying is that Cuckoo is located in the derived data because of how SPM works, the name of the folder is always changing so if I clean the project i need to find again the location of Cuckoo + rerun the run file which takes a bit of time to compile.

I'm wondering if it's technically possible to make a complete CLI of Cuckoo (which you would download from homebrew for exemple) ? This way you completely abstract the code generation from Xcode or a dependency manager and it can be run from anywhere (as long as you specify the location of the TOML file)

@MatyasKriz
Copy link
Collaborator

I think there's nothing preventing the creation of a CLI which manages the Cuckoonator version (this would allow specifying it in Cuckoofile as well, sounds cool), fetching it if it's not present and running it.

Unfortunately I don't have enough free time on my hands to implement it in the foreseeable future.

@soucolline
Copy link
Author

For sure that's an idea worth exploring, I'll try to play a bit with it on my side

@soucolline
Copy link
Author

Hey @MatyasKriz, I've played a bit with it this week-end and ended up making this repository : https://github.com/soucolline/homebrew-cuckoo

It's simply storing the Cuckoonator binary and then you can install it globally using homebrew

brew tap soucolline/homebrew-cuckoo
brew install cuckoonator

This way you can run cuckoonator whenever you want from the root of you project to generate the mocks

I find it a great installation + run alternative as it is not dependant on any package manager and can be installed the same using cocoapods / carthage and SPM and doesn't require any script phase or plugin.

I'll be maintaining and using it for my work and personal projects but if you want to officially support it one day it's only uploading a targ.gz of the Cuckoonator executable (I've used this https://bharathvaj-ganesan.medium.com/how-to-publish-your-nodejs-application-on-homebrew-7a24de9ea973)

@MatyasKriz
Copy link
Collaborator

Thanks for letting me know, perhaps some users will prefer this way of distribution. 🙂

I've been thinking of making the distributed binary a Cuckoonator manager, so that it will automatically make sure it's using the correct generator version to match the project's, but is customizable through Cuckoofile if needed.

@nalounguyen
Copy link

Ok I've migrated everything to 2.0.9 and it's working fine !

The only thing a bit annoying is that Cuckoo is located in the derived data because of how SPM works, the name of the folder is always changing so if I clean the project i need to find again the location of Cuckoo + rerun the run file which takes a bit of time to compile.

I'm wondering if it's technically possible to make a complete CLI of Cuckoo (which you would download from homebrew for exemple) ? This way you completely abstract the code generation from Xcode or a dependency manager and it can be run from anywhere (as long as you specify the location of the TOML file)

Hi @soucolline ,
I have the same issue, and this is my workaround
Screenshot 2024-09-08 at 15 36 00

Then I also created .sh file and can run with cmd.

@aiKrice
Copy link

aiKrice commented Oct 9, 2024

I have the same workaround @nalounguyen but R.swift, sourcery, swiftgen has their own standalone tool in order to be used like this. I still agree on @soucolline POV.

@aiKrice
Copy link

aiKrice commented Oct 14, 2024

I share for the community my script to manually download the cuckoonator from the last version:

source .cuckoo-version

if [ ! -f "cuckoonator" ] || [ "$(md5 -q cuckoonator)" != "$CUCKOONATOR_HASH" ]; then
    echo "🔵 Downloading Cuckoonator"
    curl -L -o cuckoonator https://github.com/Brightify/Cuckoo/releases/latest/download/cuckoonator
    chmod 700 cuckoonator
    echo "🟢 Cuckoonator successfully downloaded"
else
    echo "🔵 Cuckoonator already installed"
fi

if [ ! -f "cuckoonator" ]; then
    echo "🔴 Cuckoonator was not downloaded. Can't generate mocks later. Please retry with this command:\ncurl -L -o cuckoonator https://github.com/Brightify/Cuckoo/releases/latest/download/cuckoonator"
    exit 1
fi

@nalounguyen
Copy link

I share for the community my script to manually download the cuckoonator from the last version:

source .cuckoo-version

if [ ! -f "cuckoonator" ] || [ "$(md5 -q cuckoonator)" != "$CUCKOONATOR_HASH" ]; then
    echo "🔵 Downloading Cuckoonator"
    curl -L -o cuckoonator https://github.com/Brightify/Cuckoo/releases/latest/download/cuckoonator
    chmod 700 cuckoonator
    echo "🟢 Cuckoonator successfully downloaded"
else
    echo "🔵 Cuckoonator already installed"
fi

if [ ! -f "cuckoonator" ]; then
    echo "🔴 Cuckoonator was not downloaded. Can't generate mocks later. Please retry with this command:\ncurl -L -o cuckoonator https://github.com/Brightify/Cuckoo/releases/latest/download/cuckoonator"
    exit 1
fi

this script is support dowload cuckoo and we can use it, right ?

@MatyasKriz
Copy link
Collaborator

MatyasKriz commented Oct 21, 2024

@aiKrice what does this script do that the official run script doesn't?

@aiKrice
Copy link

aiKrice commented Oct 21, 2024

@aiKrice what does this script do that the official run script doesn't?

I don't need to download the SPM to be able to generate mocks, which is the difference

@MatyasKriz
Copy link
Collaborator

@aiKrice what does this script do that the official run script doesn't?

I don't need to download the SPM to be able to generate mocks, which is the difference

https://github.com/Brightify/Cuckoo/blob/master/run this is the run script which does that and runs the generator at the same time with the passed arguments. 🙂 It checks the Cuckoo version against cuckoonator version and makes sure your binary is up to date. This script is called when not using SPM, take a look at README if you need more info.

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

No branches or pull requests

4 participants