Closed radex closed 6 years ago
In general I would say it's better if it's part of the build process, because it will prevent the bugs I mentioned in readme when people refactor code, but I agree it would be convienent to also be able to grab this via brew
.
Right now easiest way to play with the tool without Pods is to grab it from Release tab in github.
There issue here is that brew
formulas don't work with apps, we'd have to use cask for apps.
I had to make Sourcery
a mac app because it needs to be able to have embedded swift frameworks and it doesn't work with Swift CLI.
There is a way to do it by manually decomposing application, an example of that is here.
It's definitely on the my todo list, but if anyone has time / experience with brew
formulas and would like to adapt Olivier Rakefile to Sourcery
that would be amazing :)
There shouldn't be a problem with frameworks when using the SwiftPM. At least a CLI did work, when copying to another Mac.
Now that we have SPM support, maybe someone would like to contribute brew
support? it shouldn't be too hard given spm builds CLI not an app.
Right now I'm working on writing more examples, improving our parser speed, so not sure when I'll be free to work on this, so if anyone has some time that would be awesome thing to contribute as it would help people play with the tool or use daemon mode.
We'd need to add something like this to our Rakefile and just tweak the formula
Dropping some notes in here on my initial – frustrating – attempt:
rake build
and then installs the build folder to the bin path. Having sourcery.app in there is less than ideal, but until we get SwiftPM working inside Homebrew I see no alternative.# Documentation: http://docs.brew.sh/Formula-Cookbook.html
# http://www.rubydoc.info/github/Homebrew/brew/master/Formula
# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
class Sourcery < Formula
desc "Meta-programming for Swift, stop writing boilerplate code."
homepage "https://github.com/krzysztofzablocki/Sourcery"
url "https://github.com/krzysztofzablocki/Sourcery/archive/0.5.3.tar.gz"
sha256 "ad34e2146e73ce81894ac1dd9130fb2fd12c8213789aef7c5cde9580f813c823"
depends_on :xcode => ["8.0", :build]
def install
# ENV.deparallelize # if your formula fails when building in parallel
# Remove unrecognized options if warned by configure
rake "build"
bin.install Dir["build/*"]
end
test do
# `test do` will create, run in and delete a temporary directory.
#
# This test will fail and we won't accept that! It's enough to just replace
# "false" with the main program this formula installs, but it'd be nice if you
# were more thorough. Run the test with `brew test Sourcery`. Options passed
# to `brew install` such as `--HEAD` also need to be provided to `brew test`.
#
# The installed folder is not in the path, so use the entire path to any
# executables being tested: `system "#{bin}/program", "do", "something"`.
system "#{bin}/sourcery", "--version"
end
end
Will homebrew accept a formula that creates an app? I thought that's going to be rejected, maybe @vknabel has idea how to get swift pm to work with formulas?
My understanding is that you can't distribute pre-compiled apps with Homebrew (Caskroom is for that), but you can have a formula that builds its own binaries.
It's still compiling from source, I guess. But it would be good to see about SPM builds in Himebrewz
@swizzlr I could fix the clang error thanks to jakeheis/homebrew-repo/flock.rb, but I am not sure what unset CC
means. But it seems to work. Additionally some indirect dependencies are linked dynamically (e.g. libCYaml.dylib
), so some libraries need to be linked.
@radex @krzysztofzablocki @swizzlr For me the following formula works! 🎉
# Documentation: http://docs.brew.sh/Formula-Cookbook.html
# http://www.rubydoc.info/github/Homebrew/brew/master/Formula
# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
class Sourcery < Formula
desc "Meta-programming for Swift, stop writing boilerplate code."
homepage "https://github.com/krzysztofzablocki/Sourcery"
url "https://github.com/krzysztofzablocki/Sourcery/archive/0.5.3.tar.gz"
sha256 "ad34e2146e73ce81894ac1dd9130fb2fd12c8213789aef7c5cde9580f813c823"
depends_on :xcode => ["8.0", :build]
def install
# ENV.deparallelize # if your formula fails when building in parallel
# Remove unrecognized options if warned by configure
system "unset CC; swift build -c release"
bin.install ".build/release/sourcery"
lib.install Dir[".build/release/*.dylib"]
end
test do
# `test do` will create, run in and delete a temporary directory.
#
# This test will fail and we won't accept that! It's enough to just replace
# "false" with the main program this formula installs, but it'd be nice if you
# were more thorough. Run the test with `brew test Sourcery`. Options passed
# to `brew install` such as `--HEAD` also need to be provided to `brew test`.
#
# The installed folder is not in the path, so use the entire path to any
# executables being tested: `system "#{bin}/program", "do", "something"`.
system "#{bin}/sourcery", "--version"
end
end
Propose it dude!
@radex @krzysztofzablocki @swizzlr You can find the PR here: Homebrew/homebrew-core#9191
This issue can now be closed by the fabulous work of @vknabel!
@vknabel Thank you so much!
@swizzlr we need to add readme entry for it and update our Rakefile release process so brew formula gets upgraded (you can base it on SwiftGen entry I linked), want to contribute that PR ? :)
@vknabel how did you generate the brew formula?
@krzysztofzablocki will do
@swizzlr I started with your Formula, used swift build -c release
instead of rake build
and incrementally got everything to work through trial and error. Then I added some tests by hand (which I needed to disable)
Any update @swizzlr ?
Just an FYI, I was looking at Sourcery's (unofficial?) Homebrew formula as I was entertaining the idea of using the Swift Package Manager to perform the installation, and noticed a few things that I'll share here:
The current Homebrew formula here requires that the user have the exact same version of Xcode as Homebrew's Jenkins CI machines located exactly at the same location (/Applications/Xcode.app
).
That's because the homebrew formula uses Swift Package Manager to build the bottle, which adds an LC_RPATH
command to the binary with an absolute path to the SDK where the Swift runtime dynamic libraries can be found (e.g. /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx
). So if you've installed Xcode anywhere else, or if the version of Xcode you have installed at that location isn't the same version as was used on Homebrew's Jenkins machines, you'll have to build from source using a command like brew install sourcery --HEAD
.
Here's my attempt at fixing this: Homebrew/homebrew-core#12203
Based on this Twitter thread: https://twitter.com/simjp/status/850393838753464321
It looks like the attempt was successful on El Capitan but failed on Sierra, I believe because our Sierra nodes are running Xcode 8.3.1, and there's some kind of incompatibility between sourcery and Xcode 8.3.x, which leads to
==> swift build -c release -Xswiftc -static-stdlib
swift-build: error: the package has an unsupported layout, modulemap (/private/tmp/sourcery-20170412-49020-7oic81/Sourcery-0.5.9/.build/checkouts/SourceKitten.git-6484296299232452758/Source/SourceKittenFramework/clang-c/module.modulemap) is not allowed to be mixed with sources
fix: move the modulemap inside include directory
Fetching https://github.com/kylef/Stencil.git
Fetching https://github.com/kylef/Commander.git
Fetching https://github.com/kylef/PathKit.git
Fetching https://github.com/jpsim/SourceKitten.git
Fetching https://github.com/vknabel/SwiftTryCatch.git
Fetching https://github.com/IBM-Swift/CommonCrypto.git
Fetching https://github.com/SwiftGen/StencilSwiftKit.git
Fetching https://github.com/kylef/Spectre.git
Fetching https://github.com/Carthage/Commandant.git
Fetching https://github.com/drmohundro/SWXMLHash.git
Fetching https://github.com/jpsim/Yams.git
Fetching https://github.com/norio-nomura/Clang_C.git
Fetching https://github.com/norio-nomura/SourceKit.git
Fetching https://github.com/antitypical/Result.git
Cloning https://github.com/jpsim/SourceKitten.git
Resolving https://github.com/jpsim/SourceKitten.git at 0.15.3
Cloning https://github.com/jpsim/Yams.git
Resolving https://github.com/jpsim/Yams.git at 0.1.2
Cloning https://github.com/antitypical/Result.git
Resolving https://github.com/antitypical/Result.git at 3.2.1
Cloning https://github.com/kylef/Stencil.git
Resolving https://github.com/kylef/Stencil.git at 0.8.0
Cloning https://github.com/IBM-Swift/CommonCrypto.git
Resolving https://github.com/IBM-Swift/CommonCrypto.git at 0.1.4
Cloning https://github.com/norio-nomura/Clang_C.git
Resolving https://github.com/norio-nomura/Clang_C.git at 1.0.2
Cloning https://github.com/kylef/Commander.git
Resolving https://github.com/kylef/Commander.git at 0.6.1
Cloning https://github.com/kylef/PathKit.git
Resolving https://github.com/kylef/PathKit.git at 0.8.0
Cloning https://github.com/norio-nomura/SourceKit.git
Resolving https://github.com/norio-nomura/SourceKit.git at 1.0.1
Cloning https://github.com/SwiftGen/StencilSwiftKit.git
Resolving https://github.com/SwiftGen/StencilSwiftKit.git at 1.0.1
Cloning https://github.com/vknabel/SwiftTryCatch.git
Resolving https://github.com/vknabel/SwiftTryCatch.git at 1.1.0
Cloning https://github.com/kylef/Spectre.git
Resolving https://github.com/kylef/Spectre.git at 0.7.2
Cloning https://github.com/drmohundro/SWXMLHash.git
Resolving https://github.com/drmohundro/SWXMLHash.git at 3.0.3
Cloning https://github.com/Carthage/Commandant.git
Resolving https://github.com/Carthage/Commandant.git at 0.11.3
@krzysztofzablocki has the above been addressed in HEAD yet, or should we open a separate issue for this?
Yes it's addressed in HEAD, see https://github.com/Homebrew/homebrew-core/pull/12203#issuecomment-293667340 for details.
in the CP Mac app, we automate generating the PR for each new version
@ilovezfs I've been working on the task for Sourcery release process to submit a Homebrew PR and since I've never worked on formulas before I have one question:
In the Homebrew CONTRIBUTING is says that to bump the formula version the brew bump-formula-pr --strict
should be used. Can I use instead of it the following commands:
brew audit --strict --online #{formula}
brew upgrade #{formula}
brew test #{formula}
No, it will only run brew audit --strict foo
and then open the pull request.
Before doing that you do the steps you posted above locally, and then revert the formula to its original state before running the bump-formula-pr command.
Note that audit should be run after install not before as mentioned in the PR template.
@ilovezfs thanks for the tips. Can I open PR through the API post request like @orta mentioned in CocoaPods app?
Note that audit should be run after install not before as mentioned in the PR template.
Will do so, thanks 👍
@Antondomashnev probably, but bump-formula-pr is easiest because it handles things like removing revisions from the formula.
is there anything left or do we close this? @Antondomashnev @ilyapuchka
@krzysztofzablocki the only missing thing is a real test on the new release step.
seems to work, @Antondomashnev ?
Well, during the last release I had to do it manually and it didn't work in the rake release:new
. But the error was related to my laptop's configuration and I don't think it's a generic error.
Ok, I'm closing this then, and we'll see if something has to be tweaked on next release
It would be nice to have Sourcery in Homebrew.
Since it's part of the dev tooling, and not the build itself (arguably), I'd prefer not to use CocoaPods for this, but would still be nice to have easy updates with a dependency manager.