<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 15 May 2017, at 10:40, Rien <<a href="mailto:Rien@balancingrock.nl" class="">Rien@balancingrock.nl</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><blockquote type="cite" class="">On 15 May 2017, at 10:12, David Hart <<a href="mailto:david@hartbit.com" class="">david@hartbit.com</a>> wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">On 15 May 2017, at 10:03, Rien <<a href="mailto:Rien@balancingrock.nl" class="">Rien@balancingrock.nl</a>> wrote:<br class=""><br class="">I always wondered why it did not exist already ;-)<br class=""><br class="">However, I am not sure if I like the “auto build” aspect. For example I may have started working on a change, but quickly want to verify the exact old behaviour. Then I want to run the old build again. While this proposal does not make this impossible, it makes it more cumbersome as I now need to remember when to use the old method and the new run command.<br class=""></blockquote><br class="">There is a —skip-build option to run without building. I think it’s better this way before (1) building before running seems like the most common scenario and (2) it mirrors how it works with swift test. Having it work the other way round for run would be very confusing IMHO.<br class=""></blockquote><br class="">To me this violates the “least surprising use” rule. (Same for ‘test’, even though it sets a precedence)<br class="">Command line execution should either do as it says, or give an error message. This is quite different from a GUI behaviour: a GUI ‘run’ command should build if necessary - and indeed Xcode does just that) <br class="">I think it’s a mistake to try to mimic GUI behaviour in a command line environment.<br class=""></div></div></blockquote><div><br class=""></div><div>Firstly, there are other precedents. <b class="">swift build</b> itself will get dependencies if needed. In <b class="">cargo</b>, the closest equivalent to SwiftPM (i.e., a package manager/build tool for a language that needs a compilation stage) <b class="">cargo run</b> builds beforehand.</div><div><div class=""><br class=""></div><div class="">Secondly, if we agree that building before running is the most common scenario, why not make it the default?</div><div class=""><br class=""></div><div class="">David.</div></div><br class=""><blockquote type="cite" class=""><div class=""><div class="">Regards,<br class="">Rien.<br class=""><br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">Having a build option would make more sense imo, i.e:<br class="">$ swift run <br class="">Always runs the present build<br class="">$ swift run -b<br class="">Builds first, then runs the new build.<br class=""><br class=""><br class="">Regards,<br class="">Rien<br class=""><br class="">Site: <a href="http://balancingrock.nl" class="">http://balancingrock.nl</a><br class="">Blog: <a href="http://swiftrien.blogspot.com" class="">http://swiftrien.blogspot.com</a><br class="">Github: <a href="http://github.com/Balancingrock" class="">http://github.com/Balancingrock</a><br class="">Project: <a href="http://swiftfire.nl" class="">http://swiftfire.nl</a> - A server for websites build in Swift<br class=""><br class=""><br class=""><br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class="">On 15 May 2017, at 09:47, David Hart via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">Hello evolution (and build-dev),<br class=""><br class="">I’d like to pitch a QOL proposal to improve the development of command-line Swift Packages by introducing a `swift run` command. I’d value any feedback before moving forward.<br class=""><br class=""><a href="https://github.com/hartbit/swift-evolution/blob/swift-run-command/proposals/XXXX-swift-run-command.md" class="">https://github.com/hartbit/swift-evolution/blob/swift-run-command/proposals/XXXX-swift-run-command.md</a><br class=""><br class="">Regards,<br class="">David.<br class=""><br class="">Swift run Command<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>• Proposal: SE-XXXX<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>• Authors: David Hart<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>• Review Manager: TBD<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>• Status: TBD<br class="">Introduction<br class=""><br class="">The proposal introduces a new swift run command to build and run an executable defined in the current package.<br class=""><br class="">Motivation<br class=""><br class="">It is common to want to build and run an executable during development. For now, one must first build it and then execute it from the build folder:<br class=""><br class="">$ swift build<br class="">$ .build/debug/myexecutable<br class=""><br class="">In Swift 4, the Swift Package Manager will build to a different path, containing a platform sub-folder (.build/macosx-x86_64/debug for mac and .build/linux-x86_64/debug for linux), making it more cumbersome to run the executable from the command line.<br class=""><br class="">To improve the development workflow, the proposal suggest introducing a new first-level swift run command that will build if necessary and then run an executable defined in the Package.swift manifest, replacing the above steps into just one.<br class=""><br class="">Proposed solution<br class=""><br class="">The swift run command would be defined as:<br class=""><br class="">$ swift run --help<br class="">OVERVIEW: Build and run executable<br class=""><br class="">USAGE: swift run [options] [executable] [-- arguments]<br class=""><br class="">OPTIONS:<br class=""> --build-path Specify build/cache directory [default: ./.build]<br class=""> --chdir, -C Change working directory before any other operation<br class=""> --in-dir, -I Change working directory before running the executable<br class=""> --color Specify color mode (auto<br class="">|always|<br class="">never) [default: auto]<br class=""> --configuration, -c Build with configuration (debug<br class="">|<br class="">release) [default: debug]<br class=""> --enable-prefetching Enable prefetching <br class="">in<br class="">resolver<br class=""> --skip-build Skip building the executable product<br class=""> --verbose, -v Increase verbosity of informational output<br class=""> -Xcc Pass flag through to all C compiler invocations<br class=""> -Xlinker Pass flag through to all linker invocations<br class=""> -Xswiftc Pass flag through to all Swift compiler invocations<br class=""> --help Display available options<br class=""><br class="">If needed, the command will build the product before running it. As a result, it can be passed any options swift buildaccepts. As for swift test, it also accepts an extra --skip-build option to skip the build phase. A new --in-diroption is also introduced to run the executable from another directory.<br class=""><br class="">After the options, the command optionally takes the name of an executable product defined in the Package.swiftmanifest and introduced in SE-0146. If called without an executable and the manifest defines one and only one executable product, it will default to running that one. In any other case, the command fails.<br class=""><br class="">The executable can be called with arguments by prefixing them with a -- to separate them from the executable name.<br class=""><br class="">Alternatives considered<br class=""><br class="">One alternative to the Swift 4 change of build folder would be for the Swift Package Manager to create and update a symlink at .build/debug and .build/release that point to the latest build folder for that configuration. Although that should probably be done to retain backward-compatibility with tools that depended on the build location, it does not completely invalid the usefulness of the run command.<br class="">_______________________________________________<br class="">swift-evolution mailing list<br class="">swift-evolution@swift.org<br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><br class=""></blockquote><br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></body></html>