Run shell script from Package.swift -


i'm trying include hardcoded version string generated git describe within cli i'm writing in swift.

the idea have shell script executes git describe , writes global constant file called version.swift, can reference within tool.

i don't want have think running script before every build though or building project via shell script. ideal way keep using swift build , having swift invoke said script when compiles , evaluates package.swift.

so included following in package manifest.

import foundation  let task = process() task.launchpath = "./" task.arguments = ["update_version.sh"] task.launch() task.waituntilexit() 

whilst importing foundation , initializing task seems work fine, launching crashes , outputs following stack trace.

error: manifest parse error(s): 2017-07-28 15:07:43.711 swift[39828:16163314] *** terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'couldn't posix_spawn: error 13' *** first throw call stack: (     0   corefoundation                      0x00007fff9be232cb __exceptionpreprocess + 171     1   libobjc.a.dylib                     0x00007fffb0c5d48d objc_exception_throw + 48     2   corefoundation                      0x00007fff9bea1c3d +[nsexception raise:format:] + 205     3   foundation                          0x00007fff9d84c54e -[nsconcretetask launchwithdictionary:] + 3134     4   ???                                 0x0000000109ccb1c3 0x0 + 4459377091     5   swift                               0x00000001045fe84f _zn4llvm5mcjit11runfunctionepns_8functionens_8arrayrefins_12genericvalueeee + 655     6   swift                               0x0000000104604ab3 _zn4llvm15executionengine17runfunctionasmainepns_8functionerknst3__16vectorins3_12basic_stringicns3_11char_traitsiceens3_9allocatoriceeeens8_isa_eeeepkpkc + 707     7   swift                               0x00000001039f4512 _zl14performcompilern5swift16compilerinstanceerns_18compilerinvocationen4llvm8arrayrefipkceeripns_16frontendobserverepns_20unifiedstatsreportere + 22802     8   swift                               0x00000001039ed394 _zn5swift15performfrontenden4llvm8arrayrefipkcees3_pvpns_16frontendobservere + 7332     9   swift                               0x00000001039a2ad8 main + 12248     10  libdyld.dylib                       0x00007fffb1542235 start + 1 ) libc++abi.dylib: terminating uncaught exception of type nsexception 0  swift                    0x0000000107073eaa printstacktracesignalhandler(void*) + 42 1  swift                    0x00000001070732e6 signalhandler(int) + 662 2  libsystem_platform.dylib 0x00007fffb1751b3a _sigtramp + 26 3  libsystem_platform.dylib 0x00000003ba442240 _sigtramp + 147785504 4  libsystem_c.dylib        0x00007fffb15d6420 abort + 129 5  libc++abi.dylib          0x00007fffb012c84a __cxa_bad_cast + 0 6  libc++abi.dylib          0x00007fffb0151c4f default_unexpected_handler() + 0 7  libobjc.a.dylib          0x00007fffb0c5f6fe _objc_terminate() + 103 8  libc++abi.dylib          0x00007fffb014ed69 std::__terminate(void (*)()) + 8 9  libc++abi.dylib          0x00007fffb014e9f2 __cxa_rethrow + 99 10 libobjc.a.dylib          0x00007fffb0c5d94a objc_exception_rethrow + 40 11 foundation               0x00007fff9d84c884 -[nsconcretetask launchwithdictionary:] + 3956 12 foundation               0x0000000109ccb1c3 -[nsconcretetask launchwithdictionary:] + 1816656051 13 swift                    0x00000001045fe84f llvm::mcjit::runfunction(llvm::function*, llvm::arrayref<llvm::genericvalue>) + 655 14 swift                    0x0000000104604ab3 llvm::executionengine::runfunctionasmain(llvm::function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 707 15 swift                    0x00000001039f4512 performcompile(swift::compilerinstance&, swift::compilerinvocation&, llvm::arrayref<char const*>, int&, swift::frontendobserver*, swift::unifiedstatsreporter*) + 22802 16 swift                    0x00000001039ed394 swift::performfrontend(llvm::arrayref<char const*>, char const*, void*, swift::frontendobserver*) + 7332 17 swift                    0x00000001039a2ad8 main + 12248 18 libdyld.dylib            0x00007fffb1542235 start + 1 stack dump: 0.  program arguments: /applications/xcode-beta.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/swift -frontend -interpret /users/kilian/dev/apodidae/package.swift -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /applications/xcode-beta.app/contents/developer/platforms/macosx.platform/developer/sdks/macosx10.13.sdk -i /applications/xcode-beta.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/lib/swift/pm/4 -swift-version 4 -module-name package -lpackagedescription -- -fileno 5 

the content of update_version.sh following

echo "// file auto-generated\npublic let version = \""$(git describe)"\"" > sources/target/version.swift 

what here work? have package manifest being executed within sandbox? , if so, options have accomplish i'm trying do? if in way possible i'd love run swift build , have rest just work.

the exception has nothing approach, system raised because launchpath not valid launch path :-). have absolutely sure validity of launchpath, otherwise, execution terminated uncaught exception. solution see how solve it


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -