yonaskolb / Mint

A package manager that installs and runs executable Swift packages
MIT License
2.26k stars 122 forks source link

warning: SwiftLint not installed when using mint #212

Closed Isuru-Nanayakkara closed 2 years ago

Isuru-Nanayakkara commented 3 years ago

Hi,

I installed SwiftLint via mint. Here is my Mintfile.

realm/SwiftLint@0.43.1

When I ran mint bootstrap, I got the following output.

🌱 Cloning SwiftLint 0.43.1
🌱 Resolving package
🌱 Building package
🌱 Installed SwiftLint 0.43.1
🌱 Installed 1/1 package

Then I added the following as a build script.

if which swiftlint >/dev/null; then
  swiftlint
else
  echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

But when I build my Xcode project, I still get the warning: SwiftLint not installed message.

I installed mint (v0.16.0) via Homebrew and I'm using Xcode 12.5 on a 2014 iMac running macOS 11.2.3.

regnerjr commented 2 years ago

@Isuru-Nanayakkara I think you'll need to bootstrap with the -l or --link flag to link the built and installed tools into a global accessible place.

As of the most recent release the tools will be symlinked into ~/.mint/bin (ref: https://github.com/yonaskolb/Mint/releases/tag/0.17.0)

You'll want to add that to the front of your path so that the tools are found first. Something like this in your ~/.zshrc should do it. export PATH="$HOME/.mint/bin:$PATH"


Once you've setup your path, and run mint bootstrap --link you should be able to run which swiftlint and see that it's found in~/.mint/bin.


Alternatively, you don't have to link the tools or mess with your path. mint can find the right tool for you. Update your script to ask mint to run the tool for you using:

mint bootstrap #(will be fast if it's already installed)
mint run swiftlint #run the tool installed by mint (no path updates required.
xuefan-eero commented 2 years ago

@regnerjr I am running into a similar issue. in my terminal (zsh) mint bootstrap --link works great after exporting the path. i can run which swiftlint and it correctly finds the one in mint bin. However it can't seem to find it in xcode build phase. In the attached file, line 4 works but line 3 doesn't.

Screen Shot 2022-01-11 at 10 50 04 AM

Any idea on how to begin debug?

regnerjr commented 2 years ago

@xuefan-eero Yup there are 2 problems here:

  1. using sh shell probably won't have your export where you updated the path, i.e. export PATH="~/.mint/bin:$PATH" won't have run so the shell won't be able to find that too. (check in the output (Xcode logs tab) what the PATH variable is set to), you might try to change this to say it's a /bin/bash or /bin/zsh script, I'm not sure what setup files will be sourced in those instances (If I remember correctly the ~/.bashrc and ~/.zshrc won't be loaded..., but maybe ~/.zshenv will?)
  2. Xcode build phases have their own rules about what "shell setup" they do, Mostly it's safe to assume they won't do any. The fix might be to "just run using the full path" like you have, or update the PATH if you need to. (we have a few things like this at walmart where we need to setup rbenv or nvm specifically in a build phase and yeah it's a pain)
  3. Alternatively you could use mint run swiftgen to ensure you're using the right version for your current project, but I'm guessing mint might also not be in the path when running from an Xcode build phase script.

An example for 2 might look like:

# check if directory exists then add it to path
if [ -d ~/.mint/bin ]; then
    echo "Adding ~/.mint/bin to PATH"
    export PATH=~/.mint/bin:$PATH
else
  echo "~/.mint/bin folder is missing"
fi

# check if swiftgen tool can be found.
if [ $(command -v swiftgen) ]; then
  swiftgen
else
  echo "SwiftGen tool is missing, try running `mint bootstrap --link`"
  exit 1
fi
xuefan-eero commented 2 years ago

@regnerjr thank you! that makes sense!

Isuru-Nanayakkara commented 2 years ago

Thank you very much, @regnerjr. I just tried the steps you've laid out in the first comment but I also ran into the same issue as @xuefan-eero. SwiftLint is linked globally and even though I had added it to the PATH, it still wasn't being picked up within Xcode. Your script in the second comment worked for me too.

Screenshot 2022-01-16 at 8 47 44 AM