build-cli-bin: POSIX compatible & handle whitespace paths (#3623)

Getting the directory where the script resides can easily be done
without bash-specific functionality, and hence the script can be POSIX
compatible. Also adding the missing pieces for handling paths with
whitespaces.

Change-Id: Ie2e867929be0322e476342438d9cf4a3d36f58f1
Signed-off-by: Joakim Roubert <joakimr@axis.com>
This commit is contained in:
Joakim Roubert 2019-10-28 22:36:53 +01:00 committed by Alejandro Pedraza
parent 015ea9e17a
commit 0341af86e8
2 changed files with 10 additions and 9 deletions

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
set -eu
@ -6,9 +6,9 @@ set -eu
# Note: This script is used by Brew when running `brew install linkerd`:
# https://github.com/Homebrew/homebrew-core/pull/36957
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rootdir="$( cd $bindir/.. && pwd )"
. $bindir/_tag.sh
bindir=$( cd "${0%/*}" && pwd )
rootdir=$( cd "$bindir"/.. && pwd )
. "$bindir"/_tag.sh
current_platform=$(uname)
host_platform="windows"
@ -19,10 +19,11 @@ elif [ "${current_platform}" = 'Linux' ]; then
fi
(
cd $rootdir
cd "$rootdir"
cd "$(pwd -P)"
target="target/cli/${host_platform}/linkerd"
GO111MODULE=on go generate -mod=readonly ./pkg/charts/static # TODO: `go generate` does not honor -mod=readonly
GO111MODULE=on CGO_ENABLED=0 go build -o $target -tags prod -mod=readonly -ldflags "-s -w -X github.com/linkerd/linkerd2/pkg/version.Version=$($bindir/root-tag)" ./cli
root_tag=$("$bindir"/root-tag)
GO111MODULE=on CGO_ENABLED=0 go build -o $target -tags prod -mod=readonly -ldflags "-s -w -X github.com/linkerd/linkerd2/pkg/version.Version=$root_tag" ./cli
echo "$target"
)

View File

@ -1,7 +1,7 @@
#!/bin/bash
#!/bin/sh
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bindir=$( cd "${0%/*}" && pwd )
. $bindir/_tag.sh
. "$bindir"/_tag.sh
head_root_tag