mxcl / swift-sh

Easily script with third-party Swift dependencies.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot save files in `swift sh edit` generated xcodeproj

mxcl opened this issue · comments

Xcode doesn’t work with symlinked files, if you edit and try to save it complains that the file “doesn’t exist”…!

  • Symlinking a directory does work, but we cannot generate an executable unless the file is main.swift which it won’t be if we symlink the folder.
  • We could run swift as an interpreter. Not sure how well this will work inside Xcode though.
  • Hard links don't work due to Xcode saving atomically
  • Aliases don't work (long shot)
  • Could add a build phase which syncs changes back to the original script (not idiomatic since saves require a build execution).

More complicated solution would be to watch a copy of the file and sync when it changes, but this is a failure-prone choice.

Looks like best option will be:

  • Make own Xcode project (tuist/xcodeproj, thus make this a separate executable swift-sh-edit that we exec from swift-sh)
  • First target is a aggregate target called script-name that runs swift-build (via a script phase) and has an associated scheme that knows how to execute the product
  • Second target is a command-line-tool target that has -I and -L set to .build/debug and a source files phase that is the original script file with an explicit source type set to swift

This gives working completion, builds and runs. But errors / warnings are for the symlinked main.swift in our cache directory, so we need to mangle the messages, probably easiest would be sed in the aggregate target’s script phase.