Browse code

Fix a few minor issues with building/running inside msysGit

Signed-off-by: Andrew "Tianon" Page <admwiggin@gmail.com>

Tianon Gravi authored on 2015/01/10 09:28:40
Showing 10 changed files
... ...
@@ -4,7 +4,6 @@ import (
4 4
 	"fmt"
5 5
 	"os"
6 6
 	"os/exec"
7
-	"runtime"
8 7
 )
9 8
 
10 9
 var (
... ...
@@ -26,28 +25,15 @@ var (
26 26
 	workingDirectory string
27 27
 )
28 28
 
29
-func binarySearchCommand() *exec.Cmd {
30
-	if runtime.GOOS == "windows" {
31
-		// Windows where.exe is included since Windows Server 2003. It accepts
32
-		// wildcards, which we use here to match the development builds binary
33
-		// names (such as docker-$VERSION.exe).
34
-		return exec.Command("where.exe", "docker*.exe")
35
-	}
36
-	return exec.Command("which", "docker")
37
-}
38
-
39 29
 func init() {
40 30
 	if dockerBin := os.Getenv("DOCKER_BINARY"); dockerBin != "" {
41 31
 		dockerBinary = dockerBin
42
-	} else {
43
-		whichCmd := binarySearchCommand()
44
-		out, _, err := runCommandWithOutput(whichCmd)
45
-		if err == nil {
46
-			dockerBinary = stripTrailingCharacters(out)
47
-		} else {
48
-			fmt.Printf("ERROR: couldn't resolve full path to the Docker binary (%v)", err)
49
-			os.Exit(1)
50
-		}
32
+	}
33
+	var err error
34
+	dockerBinary, err = exec.LookPath(dockerBinary)
35
+	if err != nil {
36
+		fmt.Printf("ERROR: couldn't resolve full path to the Docker binary (%v)", err)
37
+		os.Exit(1)
51 38
 	}
52 39
 	if registryImage := os.Getenv("REGISTRY_IMAGE"); registryImage != "" {
53 40
 		registryImageName = registryImage
... ...
@@ -178,21 +178,28 @@ go_test_dir() {
178 178
 	)
179 179
 }
180 180
 
181
+# a helper to provide ".exe" when it's appropriate
182
+binary_extension() {
183
+	if [ "$(go env GOOS)" = 'windows' ]; then
184
+		echo -n '.exe'
185
+	fi
186
+}
187
+
181 188
 # This helper function walks the current directory looking for directories
182 189
 # holding certain files ($1 parameter), and prints their paths on standard
183 190
 # output, one per line.
184 191
 find_dirs() {
185 192
 	find . -not \( \
186 193
 		\( \
187
-			-wholename './vendor' \
188
-			-o -wholename './integration' \
189
-			-o -wholename './integration-cli' \
190
-			-o -wholename './contrib' \
191
-			-o -wholename './pkg/mflag/example' \
192
-			-o -wholename './.git' \
193
-			-o -wholename './bundles' \
194
-			-o -wholename './docs' \
195
-			-o -wholename './pkg/libcontainer/nsinit' \
194
+			-path './vendor/*' \
195
+			-o -path './integration/*' \
196
+			-o -path './integration-cli/*' \
197
+			-o -path './contrib/*' \
198
+			-o -path './pkg/mflag/example/*' \
199
+			-o -path './.git/*' \
200
+			-o -path './bundles/*' \
201
+			-o -path './docs/*' \
202
+			-o -path './pkg/libcontainer/nsinit/*' \
196 203
 		\) \
197 204
 		-prune \
198 205
 	\) -name "$1" -print0 | xargs -0n1 dirname | sort -u
... ...
@@ -4,7 +4,13 @@ set -e
4 4
 # Compile phase run by parallel in test-unit. No support for coverpkg
5 5
 
6 6
 dir=$1
7
+in_file="$dir/$(basename "$dir").test"
7 8
 out_file="$DEST/precompiled/$dir.test"
9
+# we want to use binary_extension() here, but we can't because it's in main.sh and this file gets re-execed
10
+if [ "$(go env GOOS)" = 'windows' ]; then
11
+	in_file+='.exe'
12
+	out_file+='.exe'
13
+fi
8 14
 testcover=()
9 15
 if [ "$HAVE_GO_TEST_COVER" ]; then
10 16
 	# if our current go install has -cover, we want to use it :)
... ...
@@ -16,11 +22,14 @@ fi
16 16
 if [ "$BUILDFLAGS_FILE" ]; then
17 17
 	readarray -t BUILDFLAGS < "$BUILDFLAGS_FILE"
18 18
 fi
19
-(
19
+
20
+if ! (
20 21
 	cd "$dir"
21 22
 	go test "${testcover[@]}" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS -c
22
-)
23
-[ $? -ne 0 ] && return 1
23
+); then
24
+	exit 1
25
+fi
26
+
24 27
 mkdir -p "$(dirname "$out_file")"
25
-mv "$dir/$(basename "$dir").test" "$out_file"
28
+mv "$in_file" "$out_file"
26 29
 echo "Precompiled: ${DOCKER_PKG}${dir#.}"
... ...
@@ -1,7 +1,9 @@
1 1
 #!/bin/bash
2 2
 
3
-for pid in $(find "$DEST" -name docker.pid); do
4
-	DOCKER_PID=$(set -x; cat "$pid")
5
-	( set -x; kill $DOCKER_PID )
6
-	wait $DOCKERD_PID || true
3
+for pidFile in $(find "$DEST" -name docker.pid); do
4
+	pid=$(set -x; cat "$pidFile")
5
+	( set -x; kill $pid )
6
+	if ! wait $pid; then
7
+		echo >&2 "warning: PID $pid from $pidFile had a nonzero exit code"
8
+	fi
7 9
 done
... ...
@@ -3,10 +3,7 @@ set -e
3 3
 
4 4
 DEST=$1
5 5
 BINARY_NAME="docker-$VERSION"
6
-BINARY_EXTENSION=
7
-if [ "$(go env GOOS)" = 'windows' ]; then
8
-	BINARY_EXTENSION='.exe'
9
-fi
6
+BINARY_EXTENSION="$(binary_extension)"
10 7
 BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION"
11 8
 
12 9
 # Cygdrive paths don't play well with go build -o.
... ...
@@ -4,7 +4,6 @@ set -e
4 4
 DEST=$1
5 5
 
6 6
 # subshell so that we can export PATH without breaking other things
7
-exec > >(tee -a $DEST/test.log) 2>&1
8 7
 (
9 8
 	source "$(dirname "$BASH_SOURCE")/.integration-daemon-start"
10 9
 
... ...
@@ -19,4 +18,4 @@ exec > >(tee -a $DEST/test.log) 2>&1
19 19
 	python tests/integration_test.py
20 20
 
21 21
 	source "$(dirname "$BASH_SOURCE")/.integration-daemon-stop"
22
-)
22
+) 2>&1 | tee -a $DEST/test.log
... ...
@@ -10,6 +10,6 @@ bundle_test_integration() {
10 10
 
11 11
 # this "grep" hides some really irritating warnings that "go test -coverpkg"
12 12
 # spews when it is given packages that aren't used
13
-exec > >(tee -a $DEST/test.log) 2>&1
14 13
 bundle_test_integration 2>&1 \
15
-	| grep --line-buffered -v '^warning: no packages being tested depend on '
14
+	| grep --line-buffered -v '^warning: no packages being tested depend on ' \
15
+	| tee -a $DEST/test.log
... ...
@@ -8,7 +8,6 @@ bundle_test_integration_cli() {
8 8
 }
9 9
 
10 10
 # subshell so that we can export PATH without breaking other things
11
-exec > >(tee -a $DEST/test.log) 2>&1
12 11
 (
13 12
 	source "$(dirname "$BASH_SOURCE")/.integration-daemon-start"
14 13
 
... ...
@@ -20,4 +19,4 @@ exec > >(tee -a $DEST/test.log) 2>&1
20 20
 	bundle_test_integration_cli
21 21
 
22 22
 	source "$(dirname "$BASH_SOURCE")/.integration-daemon-stop"
23
-)
23
+) 2>&1 | tee -a $DEST/test.log
... ...
@@ -2,7 +2,7 @@
2 2
 set -e
3 3
 
4 4
 DEST=$1
5
-: ${PARALLEL_JOBS:=$(nproc)}
5
+: ${PARALLEL_JOBS:=$(nproc 2>/dev/null || echo 1)} # if nproc fails (usually because we don't have it), let's not parallelize by default
6 6
 
7 7
 RED=$'\033[31m'
8 8
 GREEN=$'\033[32m'
... ...
@@ -38,12 +38,13 @@ bundle_test_unit() {
38 38
 				export BUILDFLAGS_FILE="$HOME/buildflags_file"
39 39
 				( IFS=$'\n'; echo "${BUILDFLAGS[*]}" ) > "$BUILDFLAGS_FILE"
40 40
 
41
-				echo "$TESTDIRS" | parallel --jobs "$PARALLEL_JOBS" --halt 2 --env _ "$(dirname "$BASH_SOURCE")/.go-compile-test-dir"
41
+				echo "$TESTDIRS" | parallel --jobs "$PARALLEL_JOBS" --env _ "$(dirname "$BASH_SOURCE")/.go-compile-test-dir"
42 42
 				rm -rf "$HOME"
43 43
 			else
44 44
 				# aww, no "parallel" available - fall back to boring
45 45
 				for test_dir in $TESTDIRS; do
46
-					"$(dirname "$BASH_SOURCE")/.go-compile-test-dir" "$test_dir"
46
+					"$(dirname "$BASH_SOURCE")/.go-compile-test-dir" "$test_dir" || true
47
+					# don't let one directory that fails to build tank _all_ our tests!
47 48
 				done
48 49
 			fi
49 50
 		)
... ...
@@ -56,7 +57,7 @@ go_run_test_dir() {
56 56
 	while read dir; do
57 57
 		echo
58 58
 		echo '+ go test' $TESTFLAGS "${DOCKER_PKG}${dir#.}"
59
-		precompiled="$DEST/precompiled/$dir.test"
59
+		precompiled="$DEST/precompiled/$dir.test$(binary_extension)"
60 60
 		if ! ( cd "$dir" && "$precompiled" $TESTFLAGS ); then
61 61
 			TESTS_FAILED+=("$dir")
62 62
 			echo
... ...
@@ -82,5 +83,4 @@ go_run_test_dir() {
82 82
 	fi
83 83
 }
84 84
 
85
-exec > >(tee -a $DEST/test.log) 2>&1
86
-bundle_test_unit
85
+bundle_test_unit 2>&1 | tee -a $DEST/test.log
... ...
@@ -14,10 +14,7 @@ for d in "$CROSS/"*/*; do
14 14
 	GOARCH="$(basename "$d")"
15 15
 	GOOS="$(basename "$(dirname "$d")")"
16 16
 	BINARY_NAME="docker-$VERSION"
17
-	BINARY_EXTENSION=
18
-	if [ "$GOOS" = 'windows' ]; then
19
-		BINARY_EXTENSION='.exe'
20
-	fi
17
+	BINARY_EXTENSION="$(binary_extension)"
21 18
 	BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION"
22 19
 	mkdir -p "$DEST/$GOOS/$GOARCH"
23 20
 	TGZ="$DEST/$GOOS/$GOARCH/$BINARY_NAME.tgz"