diff --git a/build.bash b/build.bash index 6aa49ad79..7c3bce076 100755 --- a/build.bash +++ b/build.bash @@ -4,16 +4,20 @@ # # Usage: # -# $ ./build.bash [output_filename] +# $ ./build.bash [output_filename] [git_repo] # # Outputs compiled program in current directory. # Default file name is 'ecaddy'. +# Default git repo is current directory. +# Builds always take place from current directory. set -euo pipefail : ${output_filename:="${1:-}"} : ${output_filename:="ecaddy"} +: ${git_repo:="${2:-}"} + pkg=main ldflags=() @@ -25,28 +29,28 @@ ldflags+=("-X" "\"${name}=${value}\"") # Current tag, if HEAD is on a tag name="${pkg}.gitTag" set +e -value="$(git describe --exact-match HEAD 2>/dev/null)" +value="$(git -C "${git_repo}" describe --exact-match HEAD 2>/dev/null)" set -e ldflags+=("-X" "\"${name}=${value}\"") # Nearest tag on branch name="${pkg}.gitNearestTag" -value="$(git describe --abbrev=0 --tags HEAD)" +value="$(git -C "${git_repo}" describe --abbrev=0 --tags HEAD)" ldflags+=("-X" "\"${name}=${value}\"") # Commit SHA name="${pkg}.gitCommit" -value="$(git rev-parse --short HEAD)" +value="$(git -C "${git_repo}" rev-parse --short HEAD)" ldflags+=("-X" "\"${name}=${value}\"") # Summary of uncommitted changes name="${pkg}.gitShortStat" -value="$(git diff-index --shortstat HEAD)" +value="$(git -C "${git_repo}" diff-index --shortstat HEAD)" ldflags+=("-X" "\"${name}=${value}\"") # List of modified files name="${pkg}.gitFilesModified" -value="$(git diff-index --name-only HEAD)" +value="$(git -C "${git_repo}" diff-index --name-only HEAD)" ldflags+=("-X" "\"${name}=${value}\"") go build -ldflags "${ldflags[*]}" -o "${output_filename}"