Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShellOut "swift package update" not working in some scenarios #36

Open
thecb4 opened this issue Jul 14, 2018 · 0 comments
Open

ShellOut "swift package update" not working in some scenarios #36

thecb4 opened this issue Jul 14, 2018 · 0 comments

Comments

@thecb4
Copy link

thecb4 commented Jul 14, 2018

I'm working on using Swift in some pre-commit scripts. For some reason when I attempted to run various versions of "swift package update" as a script for git pre-commit I would get a failure.

// swift script in ./.git/hooks/pre-commit
shellOut(to: "swift package update")

produces the following error:

xcrun --sdk macosx --show-sdk-path
xcrun --sdk macosx --show-sdk-platform-path
xcrun --find clang
sandbox-exec -p '(version 1)
(deny default)
(import "system.sb")
(allow file-read*)
(allow process*)
(allow sysctl*)
(allow file-write*
    (regex #"^/private/var/tmp/org\.llvm\.clang.*")
    (regex #"^/var/folders/h8/2l1nf2ss5qqfblyby0tnl7sm0000gn/T/org\.llvm\.clang.*")
    (regex #"^/private/var/folders/h8/2l1nf2ss5qqfblyby0tnl7sm0000gn/T/org\.llvm\.clang.*")
    (regex #"^/private/var/folders/h8/2l1nf2ss5qqfblyby0tnl7sm0000gn/C/org\.llvm\.clang.*")
)
' /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc --driver-mode=swift -L /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -lPackageDescription -suppress-warnings -swift-version 4 -I /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk ~redacted~/b4/cache/SwiftPreCommitHooks/Package.swift -fileno 5
sandbox-exec -p '(version 1)
(deny default)
(import "system.sb")
(allow file-read*)
(allow process*)
(allow sysctl*)
(allow file-write*
    (regex #"^/private/var/tmp/org\.llvm\.clang.*")
    (regex #"^/var/folders/h8/2l1nf2ss5qqfblyby0tnl7sm0000gn/T/org\.llvm\.clang.*")
    (regex #"^/private/var/folders/h8/2l1nf2ss5qqfblyby0tnl7sm0000gn/T/org\.llvm\.clang.*")
    (regex #"^/private/var/folders/h8/2l1nf2ss5qqfblyby0tnl7sm0000gn/C/org\.llvm\.clang.*")
)
' /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc --driver-mode=swift -L /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -lPackageDescription -suppress-warnings -swift-version 4 -I /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk /var/folders/h8/2l1nf2ss5qqfblyby0tnl7sm0000gn/T/TemporaryFile.TJUETQ.swift -fileno 6
git -C /Users/cavellebenjamin/Development/b4/cache/SwiftPreCommitHooks/.build/repositories/PathKit.git--1865447967743163058 rev-parse --is-bare-repositorygit -C ~redacted~/b4/cache/SwiftPreCommitHooks/.build/repositories/SwiftCLI.git-1996021284977509885 rev-parse --is-bare-repositorygit -C ~redacted~/b4/cache/SwiftPreCommitHooks/.build/repositories/ShellOut.git--4208804319273938067 rev-parse --is-bare-repository


git -C /Users/cavellebenjamin/Development/b4/cache/SwiftPreCommitHooks/.build/repositories/ShellOut.git--4208804319273938067 remote update -p
git -C /Users/cavellebenjamin/Development/b4/cache/SwiftPreCommitHooks/.build/repositories/SwiftCLI.git-1996021284977509885 remote update -p
Updating https://github.com/JohnSundell/ShellOut.git
Updating https://github.com/jakeheis/SwiftCLI.git
Updating https://github.com/kylef/PathKit.git
git -C ~redacted~/b4/cache/SwiftPreCommitHooks/.build/repositories/PathKit.git--1865447967743163058 remote update -p
error: terminated(128): git -C ~redacted~/b4/cache/SwiftPreCommitHooks/.build/repositories/PathKit.git--1865447967743163058 remote update -p output:

Appears to correct itself if I add Environment variables to the script that changes the PATH variable.

let updated = try bash( 
    command: .swiftPackageUpdate(),
    at: "\(FileManager.default.homeDirectoryForCurrentUser.path)/Development/b4/cache/SwiftPreCommitHooks",
    env: ["PATH":"/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"]
"PATH":"/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"]
  )

thoughts on a pull request? or am I overthinking the situation and should use shellOut as is with additional arguments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant