swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.74k stars 1.34k forks source link

[SR-3275] Lack of command 'git' causes swift-build crash. #5165

Closed swift-ci closed 7 years ago

swift-ci commented 7 years ago
Previous ID SR-3275
Radar None
Original Reporter scoot (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment Swift version 3.0 (swift-3.0-RELEASE) Target: x86_64-unknown-linux-gnu
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Package Manager | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 695fa998c110daea59a7f5c65a9ca3e6

is duplicated by:

Issue Description:

I noticed following crash when there is no 'git' command in the system.

$ swift build
(...)
Cloning https://github.com/.............
git clone --recursive --depth 10 https://github.com/.......... 

fatal error: unexpectedly found nil while unwrapping an Optional value
Current stack trace:
0    libswiftCore.so                    0x00007fa1d0787690 swift_reportError + 117
1    libswiftCore.so                    0x00007fa1d0798b00 _swift_stdlib_reportFatalError + 61
2    libswiftCore.so                    0x00007fa1d05aa063 <unavailable> + 0
3    libswiftCore.so                    0x00007fa1d070512d <unavailable> + 0
4    libswiftCore.so                    0x00007fa1d05aa063 <unavailable> + 0
5    libswiftCore.so                    0x00007fa1d06c9130 specialized _fatalErrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> Never + 96
6    swift-build                        0x00000000005b3575 <unavailable> + 0
7    swift-build                        0x00000000005ff4b7 <unavailable> + 0
8    swift-build                        0x000000000060ab22 <unavailable> + 0
9    swift-build                        0x000000000060c822 <unavailable> + 0
10   swift-build                        0x0000000000601cf1 <unavailable> + 0
11   swift-build                        0x0000000000603c6e <unavailable> + 0
12   swift-build                        0x000000000060338d <unavailable> + 0
13   swift-build                        0x0000000000603d3c <unavailable> + 0
14   libswiftCore.so                    0x00007fa1d064c360 Sequence.flatMap<A where ...> ((A.Iterator.Element) throws -> A1) throws -> [A1.Iterator.Element] + 576
15   swift-build                        0x00000000005fff8c <unavailable> + 0
16   swift-build                        0x00000000005ff964 <unavailable> + 0
17   swift-build                        0x00000000006080b2 <unavailable> + 0
18   swift-build                        0x000000000062f400 <unavailable> + 0
19   swift-build                        0x000000000069befa <unavailable> + 0
20   swift-build                        0x0000000000692327 <unavailable> + 0
21   swift-build                        0x0000000000414748 <unavailable> + 0
22   libc.so.6                          0x00007fa1ce812a50 __libc_start_main + 245
23   swift-build                        0x0000000000414619 <unavailable> + 0
Illegal instruction

$ git
-bash: git: command not found
Bouke commented 7 years ago

Using the development snapshot of 15 december on Ubuntu 16.04;

bouke@ubuntu-imac:~/Developer/HAP$ which git
bouke@ubuntu-imac:~/Developer/HAP$ git
The program 'git' is currently not installed. You can install it by typing:
sudo apt install git
bouke@ubuntu-imac:~/Developer/HAP$ swift build
Fetching https://github.com/Bouke/CLibSodium.git
git clone --bare https://github.com/Bouke/CLibSodium.git /media/sf_Developer/HAP/.build/repositories/CLibSodium.git--9212624310367625262

error: Failed to clone https://github.com/Bouke/CLibSodium.git to <AbsolutePath:"/media/sf_Developer/HAP/.build/repositories/CLibSodium.git--9212624310367625262">

So, no longer a crash, but improved diagnostics would be welcome.

heckj commented 7 years ago

Hey scoot (JIRA User), I was looking for some relatively self-contained bugs to get into the swiftpm code base. Saw that it no longer crashed and verified with the 3.1 and master branch what it was doing - but wasn't sure what "improved diagnostics" you were thinking about.

I thought "If git doesn't exist on the local system, fail out early and report that..." as a first order cut of something useful, but did you have something else in mind?

aciidgh commented 7 years ago

Right now we don't report what error actually occurred when we fail to clone, I think fixing that problem will fix this issue.
See: https://github.com/apple/swift-package-manager/blob/master/Sources/SourceControl/GitRepository.swift#L62

aciidgh commented 7 years ago

https://github.com/apple/swift-package-manager/pull/921