Fix broken build when missing shfmt

This commit is contained in:
Ethan P 2019-10-22 10:51:56 -07:00
parent 358632ed9d
commit 0aeabe9bdf
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA

View File

@ -31,11 +31,27 @@ next() {
} }
# Prints a build step message. # Prints a build step message.
SMSG_CACHE_MSG=()
SMSG_CACHE_META=()
SMSG_EXPECT=1
smsg() { smsg() {
case "$2" in if [[ "$1" != "$SMSG_EXPECT" ]]; then
"SKIP") printc " %{YELLOW} %{DIM}%s [skipped]%{CLEAR}\n" "$1" 1>&2;; SMSG_CACHE_MSG["$1"]="$2"
*) printc " %{YELLOW} %s...%{CLEAR}\n" "$1" 1>&2;; SMSG_CACHE_META["$1"]="$3"
return;
fi
((SMSG_EXPECT++))
case "$3" in
"SKIP") printc " %{YELLOW} %{DIM}%s [skipped]%{CLEAR}\n" "$2" 1>&2;;
*) printc " %{YELLOW} %s...%{CLEAR}\n" "$2" 1>&2;;
esac esac
# Cached messages.
echo "${SMSG_CACHE_MSG[$SMSG_EXPECT]}" 1>&2
if [[ -n "${SMSG_CACHE_MSG[$SMSG_EXPECT]}" ]]; then
smsg "$SMSG_EXPECT" "${SMSG_CACHE_MSG[$SMSG_EXPECT]}" "${SMSG_CACHE_META[$SMSG_EXPECT]}"
fi
} }
# Build step: read # Build step: read
@ -47,7 +63,7 @@ smsg() {
# Output: # Output:
# The file contents. # The file contents.
step_read() { step_read() {
smsg "Reading" smsg 1 "Reading"
cat "$1" cat "$1"
} }
@ -62,7 +78,7 @@ step_read() {
# Output: # Output:
# The processed file contents. # The processed file contents.
step_preprocess() { step_preprocess() {
smsg "Preprocessing" smsg 2 "Preprocessing"
local line local line
while IFS='' read -r line; do while IFS='' read -r line; do
@ -111,12 +127,12 @@ step_preprocess() {
# The minified file contents. # The minified file contents.
step_minify() { step_minify() {
if [[ "$OPT_MINIFY" =~ ^all($|+.*) ]]; then if [[ "$OPT_MINIFY" =~ ^all($|+.*) ]]; then
smsg "Minifying" "SKIP" smsg 3 "Minifying" "SKIP"
cat cat
return 0 return 0
fi fi
smsg "Minifying" smsg 3 "Minifying"
printf "#!/usr/bin/env bash\n" printf "#!/usr/bin/env bash\n"
pp_minify | pp_minify_unsafe pp_minify | pp_minify_unsafe
} }
@ -131,7 +147,7 @@ step_minify() {
# The compressed self-executable script. # The compressed self-executable script.
step_compress() { step_compress() {
if ! "$OPT_COMPRESS"; then if ! "$OPT_COMPRESS"; then
smsg "Compressing" "SKIP" smsg 4 "Compressing" "SKIP"
cat cat
return 0 return 0
fi fi
@ -141,7 +157,7 @@ step_compress() {
printf "(exec -a \"\$0\" bash -c 'eval \"\$(cat <&3)\"' \"\$0\" \"\$@\" 3< <(dd bs=1 if=\"\$0\" skip=::: 2>/dev/null | gunzip)); exit \$?;\n" printf "(exec -a \"\$0\" bash -c 'eval \"\$(cat <&3)\"' \"\$0\" \"\$@\" 3< <(dd bs=1 if=\"\$0\" skip=::: 2>/dev/null | gunzip)); exit \$?;\n"
})" })"
smsg "Compressing" smsg 4 "Compressing"
sed "s/:::/$(wc -c <<< "$wrapper" | bc)/" <<< "$wrapper" sed "s/:::/$(wc -c <<< "$wrapper" | bc)/" <<< "$wrapper"
gzip gzip
} }
@ -158,7 +174,7 @@ step_compress() {
# Output: # Output:
# The file contents. # The file contents.
step_write() { step_write() {
smsg "Building" smsg 5 "Building"
tee "$1" tee "$1"
chmod +x "$1" chmod +x "$1"
} }
@ -177,12 +193,12 @@ step_write() {
step_write_install() { step_write_install() {
if [[ "$OPT_INSTALL" != true ]]; then if [[ "$OPT_INSTALL" != true ]]; then
smsg "Installing" "SKIP" smsg 6 "Installing" "SKIP"
cat cat
return 0 return 0
fi fi
smsg "Installing" smsg 6 "Installing"
tee "$1" tee "$1"
chmod +x "$1" chmod +x "$1"
} }
@ -198,9 +214,14 @@ pp_strip_comments() {
# Minify a Bash source file. # Minify a Bash source file.
# https://github.com/mvdan/sh # https://github.com/mvdan/sh
pp_minify() { pp_minify() {
shfmt -mn if [[ "$OPT_MINIFY" = "none" ]]; then
} cat
return
fi
shfmt -mn
return $?
}
# Minifies the output script (unsafely). # Minifies the output script (unsafely).
# Right now, this doesn't do anything. # Right now, this doesn't do anything.