Swiftgen: Convert project to Swift 3 and app bundle

Created on 4 Sep 2016  路  18Comments  路  Source: SwiftGen/SwiftGen

  • [X] Convert the SwiftGen project itself to Swift 3, so that we can continue developing it using Xcode 8 instead of Xcode 7 (at least convert it to Swift 2.3, but at this point we might as well migrate to Swift 3 directly) _(#201)_
  • [x] Reorganize the project to that it's possible to Cmd-B in Xcode to build the project from Xcode, the same way SwiftLint does it. _(#204)_

    • This would build a command-line app wrapped in a .app bundle (which Xcode knows how to produce, including linking the Swift dynamic libraries etc) so we'd be able to debug it more easily, debugging it directly from Xcode using Cmd-R (and adjusting the command-line arguments via the Xcode scheme while debugging)

    • The Rakefile would still be necessary to reorganize the build .app into a package shippable via Homebrew (moving build dylibs around, changing their install_name, etc) so that the end user doesn't see a .app bundle with no UI but still sees a command-line tool

medium help wanted internal

All 18 comments

any progress on this?

Xcode 8 and 2.3 conversion merged via #179

Would love PRs to do the other two points as I won't have much time soon

I might give item 2 (app bundle) a try next week, no promises though.

I believe I have a solution for part two of this issue. I'm just a bit unclear if there are specific requirements for the build component. As is the project builds to Products path a .app from xcode and the rake file produces the same products as before without any modification, and you can cmd+r the app and debug in llvm. Is there anything else I should address to finish this issue?

here's the diff:
https://github.com/ahtierney/SwiftGen/compare/feature/ahtierney/swift3...ahtierney:feature/ahtierney/app-bundle

Cool!

I tried it and it works as advertised. The frameworks are correctly embedded and linked (checked with otool -L), so I think if you create a pull request we could probably merge this without many changes. Just don't forget to add a changelog entry.

Whoops, spoke too early: running swiftgen itself works, but when I for example try
./swiftgen.app/Contents/MacOS/swiftgen images SwiftGen-Test/UnitTests/fixtures/Images.xcassets

It fails with

error: failed to render template Template named default not found. Use swiftgen templates to list available named templates or use --templatePath to specify a template by its full path.

You need to:

  • add the templates to the app's resources.
  • modify the relativePath logic to work with bundle resources I think

All right, this works:

let templatesRelativePath = "../Resources"

Good catch! thanks. digging into this now.

So after some consideration I decided to go with a build phase to build the templates directory, this is the same approach as the rake file and I think has the smallest footprint:

BASE_PATH="$BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH"
cp -r "$SRCROOT/templates" "$BASE_PATH"

I've updated the branch, thoughts?

Or you could simply change the Xcode project to consider the templates "group" as a folder (like the UnitTests/fixtures/Storyboards-iOS folder), and add that folder to the swiftgen target. It will then simply be copied during the "Copy bundle resources step". Do keep in mind that you'll then have to use

let templatesRelativePath = "../Resources/templates"

When I tested it in my previous comment, I just added all the individual templates to the swiftgen target, same as it is with the UnitTests.

Edit: if you do this, check if the UnitTests still work, they also depend on the templates.

I was leaning toward the build script bearing in mind that the .app is just a convenience I'd like to prioritize keeping build behaviors similar to the existing flow as opposed to relying on xcode tooling (which I would prefer in most other cases). That said if folks feel strongly otherwise I'd be happy to rearrange things to use the Resources folder.

I completely agree that we should maintain previous behaviour. The thing is that a wellformed (macOS) app bundle stores its files in the Resources folder. The simplest solution'd be what to just add all the individual templates to the swiftgen target, same as it is with the UnitTests.

If you want, you can check this patch to see what I mean: https://gist.github.com/djbe/67fa6c5383b7bcdf6a6be0bf46c33438

Edit: make sure to clean then build to see the difference in the product.

I think we're on the same page, I'll push a more "app"-y version.

I moved them to copy bundle resources and changed main and the Rakefile to use Resources as the default relative path as well. tests, xcode builds, and rake builds/test all appear to work. If it looks good I can merge it into the swift 3 branch (or replay it over the current master if you prefer).

https://github.com/ahtierney/SwiftGen/compare/feature/ahtierney/swift3...ahtierney:feature/ahtierney/app-bundle

Looks good. I have no idea what's the best plan to merge this one, but maybe a separate pull request might be better. That way, if there are any other remaining issues, we can move the discussion there.

This definitely needs an audit from at least @AliSoftware as he wrote the build system.

I think we should merge the Swift3 branch now that it looks OK (revising #201 in a bit to finally merge it) then review/merge #204 afterwards 馃憤

201 has been merged, time to take care of #204 馃帀

Both items are now done!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kacper1703 picture kacper1703  路  3Comments

embassem picture embassem  路  3Comments

romk1n picture romk1n  路  7Comments

jrmybrault picture jrmybrault  路  7Comments

filip-zielinski picture filip-zielinski  路  3Comments