github.com/devdivbcp/moby@v17.12.0-ce-rc1.0.20200726071732-2d4bfdc789ad+incompatible/hack/make.sh (about) 1 #!/usr/bin/env bash 2 set -e 3 4 # This script builds various binary artifacts from a checkout of the docker 5 # source code. 6 # 7 # Requirements: 8 # - The current directory should be a checkout of the docker source code 9 # (https://github.com/docker/docker). Whatever version is checked out 10 # will be built. 11 # - The VERSION file, at the root of the repository, should exist, and 12 # will be used as Docker binary version and package version. 13 # - The hash of the git commit will also be included in the Docker binary, 14 # with the suffix -unsupported if the repository isn't clean. 15 # - The script is intended to be run inside the docker container specified 16 # in the Dockerfile at the root of the source. In other words: 17 # DO NOT CALL THIS SCRIPT DIRECTLY. 18 # - The right way to call this script is to invoke "make" from 19 # your checkout of the Docker repository. 20 # the Makefile will do a "docker build -t docker ." and then 21 # "docker run hack/make.sh" in the resulting image. 22 # 23 24 set -o pipefail 25 26 export DOCKER_PKG='github.com/docker/docker' 27 export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 28 export MAKEDIR="$SCRIPTDIR/make" 29 export PKG_CONFIG=${PKG_CONFIG:-pkg-config} 30 31 echo 32 33 # List of bundles to create when no argument is passed 34 DEFAULT_BUNDLES=( 35 binary-daemon 36 dynbinary 37 38 test-integration 39 test-docker-py 40 41 cross 42 ) 43 44 VERSION=${VERSION:-dev} 45 ! BUILDTIME=$(date -u -d "@${SOURCE_DATE_EPOCH:-$(date +%s)}" --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/') 46 if [ "$DOCKER_GITCOMMIT" ]; then 47 GITCOMMIT="$DOCKER_GITCOMMIT" 48 elif command -v git &> /dev/null && [ -e .git ] && git rev-parse &> /dev/null; then 49 GITCOMMIT=$(git rev-parse --short HEAD) 50 if [ -n "$(git status --porcelain --untracked-files=no)" ]; then 51 GITCOMMIT="$GITCOMMIT-unsupported" 52 echo "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 53 echo "# GITCOMMIT = $GITCOMMIT" 54 echo "# The version you are building is listed as unsupported because" 55 echo "# there are some files in the git repository that are in an uncommitted state." 56 echo "# Commit these changes, or add to .gitignore to remove the -unsupported from the version." 57 echo "# Here is the current list:" 58 git status --porcelain --untracked-files=no 59 echo "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 60 fi 61 else 62 echo >&2 'error: .git directory missing and DOCKER_GITCOMMIT not specified' 63 echo >&2 ' Please either build with the .git directory accessible, or specify the' 64 echo >&2 ' exact (--short) commit hash you are building using DOCKER_GITCOMMIT for' 65 echo >&2 ' future accountability in diagnosing build issues. Thanks!' 66 exit 1 67 fi 68 69 if [ "$AUTO_GOPATH" ]; then 70 rm -rf .gopath 71 mkdir -p .gopath/src/"$(dirname "${DOCKER_PKG}")" 72 ln -sf ../../../.. .gopath/src/"${DOCKER_PKG}" 73 export GOPATH="${PWD}/.gopath" 74 fi 75 76 if [ ! "$GOPATH" ]; then 77 echo >&2 'error: missing GOPATH; please see https://golang.org/doc/code.html#GOPATH' 78 echo >&2 ' alternatively, set AUTO_GOPATH=1' 79 exit 1 80 fi 81 82 # Adds $1_$2 to DOCKER_BUILDTAGS unless it already 83 # contains a word starting from $1_ 84 add_buildtag() { 85 [[ " $DOCKER_BUILDTAGS" == *" $1_"* ]] || DOCKER_BUILDTAGS+=" $1_$2" 86 } 87 88 if ${PKG_CONFIG} 'libsystemd >= 209' 2> /dev/null ; then 89 DOCKER_BUILDTAGS+=" journald" 90 elif ${PKG_CONFIG} 'libsystemd-journal' 2> /dev/null ; then 91 DOCKER_BUILDTAGS+=" journald journald_compat" 92 fi 93 94 # test whether "libdevmapper.h" is new enough to support deferred remove 95 # functionality. We favour libdm_dlsym_deferred_remove over 96 # libdm_no_deferred_remove in dynamic cases because the binary could be shipped 97 # with a newer libdevmapper than the one it was built with. 98 if \ 99 command -v gcc &> /dev/null \ 100 && ! ( echo -e '#include <libdevmapper.h>\nint main() { dm_task_deferred_remove(NULL); }'| gcc -xc - -o /dev/null $(pkg-config --libs devmapper) &> /dev/null ) \ 101 ; then 102 add_buildtag libdm dlsym_deferred_remove 103 fi 104 105 # Use these flags when compiling the tests and final binary 106 107 IAMSTATIC='true' 108 if [ -z "$DOCKER_DEBUG" ]; then 109 LDFLAGS='-w' 110 fi 111 112 LDFLAGS_STATIC='' 113 EXTLDFLAGS_STATIC='-static' 114 # ORIG_BUILDFLAGS is necessary for the cross target which cannot always build 115 # with options like -race. 116 ORIG_BUILDFLAGS=( -tags "autogen netgo osusergo static_build $DOCKER_BUILDTAGS" -installsuffix netgo ) 117 # see https://github.com/golang/go/issues/9369#issuecomment-69864440 for why -installsuffix is necessary here 118 119 BUILDFLAGS=( ${BUILDFLAGS} "${ORIG_BUILDFLAGS[@]}" ) 120 121 LDFLAGS_STATIC_DOCKER=" 122 $LDFLAGS_STATIC 123 -extldflags \"$EXTLDFLAGS_STATIC\" 124 " 125 126 if [ "$(uname -s)" = 'FreeBSD' ]; then 127 # Tell cgo the compiler is Clang, not GCC 128 # https://code.google.com/p/go/source/browse/src/cmd/cgo/gcc.go?spec=svne77e74371f2340ee08622ce602e9f7b15f29d8d3&r=e6794866ebeba2bf8818b9261b54e2eef1c9e588#752 129 export CC=clang 130 131 # "-extld clang" is a workaround for 132 # https://code.google.com/p/go/issues/detail?id=6845 133 LDFLAGS="$LDFLAGS -extld clang" 134 fi 135 136 bundle() { 137 local bundle="$1"; shift 138 echo "---> Making bundle: $(basename "$bundle") (in $DEST)" 139 source "$SCRIPTDIR/make/$bundle" "$@" 140 } 141 142 main() { 143 if [ -z "${KEEPBUNDLE-}" ]; then 144 echo "Removing bundles/" 145 rm -rf bundles/* 146 echo 147 fi 148 mkdir -p bundles 149 150 if [ $# -lt 1 ]; then 151 bundles=(${DEFAULT_BUNDLES[@]}) 152 else 153 bundles=($@) 154 fi 155 for bundle in ${bundles[@]}; do 156 export DEST="bundles/$(basename "$bundle")" 157 # Cygdrive paths don't play well with go build -o. 158 if [[ "$(uname -s)" == CYGWIN* ]]; then 159 export DEST="$(cygpath -mw "$DEST")" 160 fi 161 mkdir -p "$DEST" 162 ABS_DEST="$(cd "$DEST" && pwd -P)" 163 bundle "$bundle" 164 echo 165 done 166 } 167 168 main "$@"