Commit ba2e9d80 authored by W-Mark Kubacki's avatar W-Mark Kubacki

Use best practices in build.bash

Format of main.buildDate has been locale-dependent,
and is now ISO-8601 compliant.

Caddy displayed with ```-version``` something like (mind the datetime format):

    Caddy 0.8.2 (+591b2090 Fri Mar 18 21:22:55 UTC 2016)
     2 files changed, 9 insertions(+), 4 deletions(-)
    build.bash
    main.go

which is now:

    Caddy 0.8.2 (+591b2090 2016-03-18 21:22:55Z)
     2 files changed, 9 insertions(+), 4 deletions(-)
    build.bash,main.go

See also:

 * http://wiki.bash-hackers.org/scripting/obsolete
 * https://google.github.io/styleguide/shell.xml
 * https://xkcd.com/1179/
parent a05a664d
*.bash text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,trailing-space,tabwidth=2
# files for systemd # files for systemd
*.path text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,trailing-space,tabwidth=2 *.path text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,trailing-space,tabwidth=2
*.service text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,trailing-space,tabwidth=2 *.service text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,trailing-space,tabwidth=2
......
...@@ -8,48 +8,48 @@ ...@@ -8,48 +8,48 @@
# #
# Outputs compiled program in current directory. # Outputs compiled program in current directory.
# Default file name is 'ecaddy'. # Default file name is 'ecaddy'.
#
set -e set -e
output="$1" : ${output_filename:="$1"}
if [ -z "$output" ]; then : ${output_filename:="ecaddy"}
output="ecaddy"
fi
pkg=main pkg=main
ldflags=()
# Timestamp of build # Timestamp of build
builddate_id=$pkg.buildDate name="${pkg}.buildDate"
builddate=`date -u` value=$(date --utc +"%F %H:%M:%SZ")
ldflags+=("-X" "\"${name}=${value}\"")
# Current tag, if HEAD is on a tag # Current tag, if HEAD is on a tag
tag_id=$pkg.gitTag name="${pkg}.gitTag"
set +e set +e
tag=`git describe --exact-match HEAD 2> /dev/null` value="$(git describe --exact-match HEAD 2>/dev/null)"
set -e set -e
ldflags+=("-X" "\"${name}=${value}\"")
# Nearest tag on branch # Nearest tag on branch
lasttag_id=$pkg.gitNearestTag name="${pkg}.gitNearestTag"
lasttag=`git describe --abbrev=0 --tags HEAD` value="$(git describe --abbrev=0 --tags HEAD)"
ldflags+=("-X" "\"${name}=${value}\"")
# Commit SHA # Commit SHA
commit_id=$pkg.gitCommit name="${pkg}.gitCommit"
commit=`git rev-parse --short HEAD` value="$(git rev-parse --short HEAD)"
ldflags+=("-X" "\"${name}=${value}\"")
# Summary of uncommited changes # Summary of uncommitted changes
shortstat_id=$pkg.gitShortStat name="${pkg}.gitShortStat"
shortstat=`git diff-index --shortstat HEAD` value="$(git diff-index --shortstat HEAD)"
ldflags+=("-X" "\"${name}=${value}\"")
# List of modified files # List of modified files
files_id=$pkg.gitFilesModified name="${pkg}.gitFilesModified"
files=`git diff-index --name-only HEAD` value="$(git diff-index --name-only HEAD | tr "\n" "," | sed -e 's:,$::')"
ldflags+=("-X" "\"${name}=${value}\"")
go build -ldflags " set -x
-X \"$builddate_id=$builddate\" go build \
-X \"$tag_id=$tag\" -ldflags "${ldflags[*]}" \
-X \"$lasttag_id=$lasttag\" -o "${output_filename}"
-X \"$commit_id=$commit\"
-X \"$shortstat_id=$shortstat\"
-X \"$files_id=$files\"
" -o "$output"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment