2015-07-22 02:06:54 +00:00
|
|
|
#!/usr/bin/env bash
|
2023-03-15 16:00:52 +00:00
|
|
|
# Copyright (c) HashiCorp, Inc.
|
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2015-03-04 07:14:18 +00:00
|
|
|
#
|
|
|
|
# This script builds the application from source for multiple platforms.
|
|
|
|
set -e
|
|
|
|
|
2020-07-03 00:45:41 +00:00
|
|
|
GO_CMD=${GO_CMD:-go}
|
|
|
|
|
2015-03-04 07:14:18 +00:00
|
|
|
# Get the parent directory of where this script is.
|
|
|
|
SOURCE="${BASH_SOURCE[0]}"
|
2022-04-19 18:28:08 +00:00
|
|
|
SOURCE_DIR=$( dirname "$SOURCE" )
|
2015-03-04 07:14:18 +00:00
|
|
|
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
2022-04-19 18:28:08 +00:00
|
|
|
DIR="$( cd -P "$SOURCE_DIR/.." && pwd )"
|
2015-03-04 07:14:18 +00:00
|
|
|
|
|
|
|
# Change into that directory
|
|
|
|
cd "$DIR"
|
|
|
|
|
2016-04-28 00:47:44 +00:00
|
|
|
# Set build tags
|
2016-04-28 00:59:33 +00:00
|
|
|
BUILD_TAGS="${BUILD_TAGS:-"vault"}"
|
2016-04-28 00:47:44 +00:00
|
|
|
|
2015-03-04 07:14:18 +00:00
|
|
|
# Get the git commit
|
2022-12-12 20:46:04 +00:00
|
|
|
GIT_COMMIT="$("$SOURCE_DIR"/ci-helper.sh revision)"
|
2016-03-17 17:57:25 +00:00
|
|
|
GIT_DIRTY="$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)"
|
2015-03-04 07:14:18 +00:00
|
|
|
|
2022-12-12 20:46:04 +00:00
|
|
|
BUILD_DATE="$("$SOURCE_DIR"/ci-helper.sh date)"
|
2022-04-19 18:28:08 +00:00
|
|
|
|
2020-07-03 00:45:41 +00:00
|
|
|
GOPATH=${GOPATH:-$(${GO_CMD} env GOPATH)}
|
2015-07-06 21:55:26 +00:00
|
|
|
case $(uname) in
|
|
|
|
CYGWIN*)
|
2016-02-18 19:19:02 +00:00
|
|
|
GOPATH="$(cygpath $GOPATH)"
|
2015-07-06 21:55:26 +00:00
|
|
|
;;
|
|
|
|
esac
|
2015-03-04 07:14:18 +00:00
|
|
|
|
|
|
|
# Delete the old dir
|
|
|
|
echo "==> Removing old directory..."
|
|
|
|
rm -f bin/*
|
|
|
|
rm -rf pkg/*
|
|
|
|
mkdir -p bin/
|
|
|
|
|
|
|
|
# Build!
|
|
|
|
echo "==> Building..."
|
2022-07-20 17:44:41 +00:00
|
|
|
${GO_CMD} build \
|
2017-10-11 15:36:26 +00:00
|
|
|
-gcflags "${GCFLAGS}" \
|
2022-12-07 18:29:51 +00:00
|
|
|
-ldflags "${LD_FLAGS} -X github.com/hashicorp/vault/version.GitCommit='${GIT_COMMIT}${GIT_DIRTY}' -X github.com/hashicorp/vault/version.BuildDate=${BUILD_DATE}" \
|
2022-07-20 17:44:41 +00:00
|
|
|
-o "bin/vault" \
|
|
|
|
-tags "${BUILD_TAGS}" \
|
2015-03-04 07:14:18 +00:00
|
|
|
.
|
|
|
|
|
|
|
|
# Move all the compiled things to the $GOPATH/bin
|
|
|
|
OLDIFS=$IFS
|
2023-04-17 22:57:17 +00:00
|
|
|
IFS=: FIRST=($GOPATH) BIN_PATH=${GOBIN:-${FIRST}/bin}
|
2015-03-04 07:14:18 +00:00
|
|
|
IFS=$OLDIFS
|
|
|
|
|
2023-04-17 22:57:17 +00:00
|
|
|
# Ensure the go bin folder exists
|
|
|
|
mkdir -p ${BIN_PATH}
|
|
|
|
rm -f ${BIN_PATH}/vault
|
|
|
|
cp bin/vault ${BIN_PATH}
|
2015-03-04 07:14:18 +00:00
|
|
|
|
|
|
|
# Done!
|
|
|
|
echo
|
|
|
|
echo "==> Results:"
|
|
|
|
ls -hl bin/
|