Skip to content

Commit

Permalink
Merge pull request #10014 from tianon/fix-msys
Browse files Browse the repository at this point in the history
Fix a few minor issues with building/running inside msysGit
  • Loading branch information
crosbymichael committed Jan 12, 2015
2 parents 83ab623 + d43f0b9 commit 862a124
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 57 deletions.
26 changes: 6 additions & 20 deletions integration-cli/docker_test_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"os/exec"
"runtime"
)

var (
Expand All @@ -26,28 +25,15 @@ var (
workingDirectory string
)

func binarySearchCommand() *exec.Cmd {
if runtime.GOOS == "windows" {
// Windows where.exe is included since Windows Server 2003. It accepts
// wildcards, which we use here to match the development builds binary
// names (such as docker-$VERSION.exe).
return exec.Command("where.exe", "docker*.exe")
}
return exec.Command("which", "docker")
}

func init() {
if dockerBin := os.Getenv("DOCKER_BINARY"); dockerBin != "" {
dockerBinary = dockerBin
} else {
whichCmd := binarySearchCommand()
out, _, err := runCommandWithOutput(whichCmd)
if err == nil {
dockerBinary = stripTrailingCharacters(out)
} else {
fmt.Printf("ERROR: couldn't resolve full path to the Docker binary (%v)", err)
os.Exit(1)
}
}
var err error
dockerBinary, err = exec.LookPath(dockerBinary)
if err != nil {
fmt.Printf("ERROR: couldn't resolve full path to the Docker binary (%v)", err)
os.Exit(1)
}
if registryImage := os.Getenv("REGISTRY_IMAGE"); registryImage != "" {
registryImageName = registryImage
Expand Down
25 changes: 16 additions & 9 deletions project/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,28 @@ go_test_dir() {
)
}

# a helper to provide ".exe" when it's appropriate
binary_extension() {
if [ "$(go env GOOS)" = 'windows' ]; then
echo -n '.exe'
fi
}

# This helper function walks the current directory looking for directories
# holding certain files ($1 parameter), and prints their paths on standard
# output, one per line.
find_dirs() {
find . -not \( \
\( \
-wholename './vendor' \
-o -wholename './integration' \
-o -wholename './integration-cli' \
-o -wholename './contrib' \
-o -wholename './pkg/mflag/example' \
-o -wholename './.git' \
-o -wholename './bundles' \
-o -wholename './docs' \
-o -wholename './pkg/libcontainer/nsinit' \
-path './vendor/*' \
-o -path './integration/*' \
-o -path './integration-cli/*' \
-o -path './contrib/*' \
-o -path './pkg/mflag/example/*' \
-o -path './.git/*' \
-o -path './bundles/*' \
-o -path './docs/*' \
-o -path './pkg/libcontainer/nsinit/*' \
\) \
-prune \
\) -name "$1" -print0 | xargs -0n1 dirname | sort -u
Expand Down
17 changes: 13 additions & 4 deletions project/make/.go-compile-test-dir
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ set -e
# Compile phase run by parallel in test-unit. No support for coverpkg

dir=$1
in_file="$dir/$(basename "$dir").test"
out_file="$DEST/precompiled/$dir.test"
# we want to use binary_extension() here, but we can't because it's in main.sh and this file gets re-execed
if [ "$(go env GOOS)" = 'windows' ]; then
in_file+='.exe'
out_file+='.exe'
fi
testcover=()
if [ "$HAVE_GO_TEST_COVER" ]; then
# if our current go install has -cover, we want to use it :)
Expand All @@ -16,11 +22,14 @@ fi
if [ "$BUILDFLAGS_FILE" ]; then
readarray -t BUILDFLAGS < "$BUILDFLAGS_FILE"
fi
(

if ! (
cd "$dir"
go test "${testcover[@]}" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS -c
)
[ $? -ne 0 ] && return 1
); then
exit 1
fi

mkdir -p "$(dirname "$out_file")"
mv "$dir/$(basename "$dir").test" "$out_file"
mv "$in_file" "$out_file"
echo "Precompiled: ${DOCKER_PKG}${dir#.}"
10 changes: 6 additions & 4 deletions project/make/.integration-daemon-stop
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/bash

for pid in $(find "$DEST" -name docker.pid); do
DOCKER_PID=$(set -x; cat "$pid")
( set -x; kill $DOCKER_PID )
wait $DOCKERD_PID || true
for pidFile in $(find "$DEST" -name docker.pid); do
pid=$(set -x; cat "$pidFile")
( set -x; kill $pid )
if ! wait $pid; then
echo >&2 "warning: PID $pid from $pidFile had a nonzero exit code"
fi
done
5 changes: 1 addition & 4 deletions project/make/binary
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ set -e

DEST=$1
BINARY_NAME="docker-$VERSION"
BINARY_EXTENSION=
if [ "$(go env GOOS)" = 'windows' ]; then
BINARY_EXTENSION='.exe'
fi
BINARY_EXTENSION="$(binary_extension)"
BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION"

# Cygdrive paths don't play well with go build -o.
Expand Down
3 changes: 1 addition & 2 deletions project/make/test-docker-py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ set -e
DEST=$1

# subshell so that we can export PATH without breaking other things
exec > >(tee -a $DEST/test.log) 2>&1
(
source "$(dirname "$BASH_SOURCE")/.integration-daemon-start"

Expand All @@ -19,4 +18,4 @@ exec > >(tee -a $DEST/test.log) 2>&1
python tests/integration_test.py

source "$(dirname "$BASH_SOURCE")/.integration-daemon-stop"
)
) 2>&1 | tee -a $DEST/test.log
4 changes: 2 additions & 2 deletions project/make/test-integration
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ bundle_test_integration() {

# this "grep" hides some really irritating warnings that "go test -coverpkg"
# spews when it is given packages that aren't used
exec > >(tee -a $DEST/test.log) 2>&1
bundle_test_integration 2>&1 \
| grep --line-buffered -v '^warning: no packages being tested depend on '
| grep --line-buffered -v '^warning: no packages being tested depend on ' \
| tee -a $DEST/test.log
3 changes: 1 addition & 2 deletions project/make/test-integration-cli
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ bundle_test_integration_cli() {
}

# subshell so that we can export PATH without breaking other things
exec > >(tee -a $DEST/test.log) 2>&1
(
source "$(dirname "$BASH_SOURCE")/.integration-daemon-start"

Expand All @@ -20,4 +19,4 @@ exec > >(tee -a $DEST/test.log) 2>&1
bundle_test_integration_cli

source "$(dirname "$BASH_SOURCE")/.integration-daemon-stop"
)
) 2>&1 | tee -a $DEST/test.log
12 changes: 6 additions & 6 deletions project/make/test-unit
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e

DEST=$1
: ${PARALLEL_JOBS:=$(nproc)}
: ${PARALLEL_JOBS:=$(nproc 2>/dev/null || echo 1)} # if nproc fails (usually because we don't have it), let's not parallelize by default

RED=$'\033[31m'
GREEN=$'\033[32m'
Expand Down Expand Up @@ -38,12 +38,13 @@ bundle_test_unit() {
export BUILDFLAGS_FILE="$HOME/buildflags_file"
( IFS=$'\n'; echo "${BUILDFLAGS[*]}" ) > "$BUILDFLAGS_FILE"

echo "$TESTDIRS" | parallel --jobs "$PARALLEL_JOBS" --halt 2 --env _ "$(dirname "$BASH_SOURCE")/.go-compile-test-dir"
echo "$TESTDIRS" | parallel --jobs "$PARALLEL_JOBS" --env _ "$(dirname "$BASH_SOURCE")/.go-compile-test-dir"
rm -rf "$HOME"
else
# aww, no "parallel" available - fall back to boring
for test_dir in $TESTDIRS; do
"$(dirname "$BASH_SOURCE")/.go-compile-test-dir" "$test_dir"
"$(dirname "$BASH_SOURCE")/.go-compile-test-dir" "$test_dir" || true
# don't let one directory that fails to build tank _all_ our tests!
done
fi
)
Expand All @@ -56,7 +57,7 @@ go_run_test_dir() {
while read dir; do
echo
echo '+ go test' $TESTFLAGS "${DOCKER_PKG}${dir#.}"
precompiled="$DEST/precompiled/$dir.test"
precompiled="$DEST/precompiled/$dir.test$(binary_extension)"
if ! ( cd "$dir" && "$precompiled" $TESTFLAGS ); then
TESTS_FAILED+=("$dir")
echo
Expand All @@ -82,5 +83,4 @@ go_run_test_dir() {
fi
}

exec > >(tee -a $DEST/test.log) 2>&1
bundle_test_unit
bundle_test_unit 2>&1 | tee -a $DEST/test.log
5 changes: 1 addition & 4 deletions project/make/tgz
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ for d in "$CROSS/"*/*; do
GOARCH="$(basename "$d")"
GOOS="$(basename "$(dirname "$d")")"
BINARY_NAME="docker-$VERSION"
BINARY_EXTENSION=
if [ "$GOOS" = 'windows' ]; then
BINARY_EXTENSION='.exe'
fi
BINARY_EXTENSION="$(binary_extension)"
BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION"
mkdir -p "$DEST/$GOOS/$GOARCH"
TGZ="$DEST/$GOOS/$GOARCH/$BINARY_NAME.tgz"
Expand Down

0 comments on commit 862a124

Please sign in to comment.