-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
721e41e
commit d0f63b3
Showing
6 changed files
with
258 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,88 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -u | ||
set -eu | ||
set -o pipefail | ||
|
||
readonly PROGDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
readonly BUILDPACKDIR="$(cd "${PROGDIR}/.." && pwd)" | ||
|
||
function main() { | ||
mkdir -p "${BUILDPACKDIR}/bin" | ||
while [[ "${#}" != 0 ]]; do | ||
case "${1}" in | ||
--help|-h) | ||
shift 1 | ||
usage | ||
exit 0 | ||
;; | ||
|
||
if [[ -f "${BUILDPACKDIR}/run/main.go" ]]; then | ||
pushd "${BUILDPACKDIR}/bin" > /dev/null || return | ||
printf "%s" "Building run..." | ||
"") | ||
# skip if the argument is empty | ||
shift 1 | ||
;; | ||
|
||
GOOS=linux \ | ||
go build \ | ||
-ldflags="-s -w" \ | ||
-o "run" \ | ||
"${BUILDPACKDIR}/run" | ||
*) | ||
util::print::error "unknown argument \"${1}\"" | ||
esac | ||
done | ||
|
||
echo "Success!" | ||
mkdir -p "${BUILDPACKDIR}/bin" | ||
|
||
for name in detect build; do | ||
printf "%s" "Linking ${name}..." | ||
run::build | ||
cmd::build | ||
} | ||
|
||
function usage() { | ||
cat <<-USAGE | ||
build.sh [OPTIONS] | ||
Builds the buildpack executables. | ||
OPTIONS | ||
--help -h prints the command usage | ||
USAGE | ||
} | ||
|
||
ln -sf "run" "${name}" | ||
function run::build() { | ||
if [[ -f "${BUILDPACKDIR}/run/main.go" ]]; then | ||
pushd "${BUILDPACKDIR}/bin" > /dev/null || return | ||
printf "%s" "Building run... " | ||
|
||
echo "Success!" | ||
done | ||
popd > /dev/null || return | ||
fi | ||
GOOS=linux \ | ||
go build \ | ||
-ldflags="-s -w" \ | ||
-o "run" \ | ||
"${BUILDPACKDIR}/run" | ||
|
||
echo "Success!" | ||
|
||
for name in detect build; do | ||
printf "%s" "Linking ${name}... " | ||
|
||
ln -sf "run" "${name}" | ||
|
||
echo "Success!" | ||
done | ||
popd > /dev/null || return | ||
fi | ||
} | ||
|
||
if [[ -d "${BUILDPACKDIR}/cmd" ]]; then | ||
local name | ||
for src in "${BUILDPACKDIR}"/cmd/*; do | ||
name="$(basename "${src}")" | ||
function cmd::build() { | ||
if [[ -d "${BUILDPACKDIR}/cmd" ]]; then | ||
local name | ||
for src in "${BUILDPACKDIR}"/cmd/*; do | ||
name="$(basename "${src}")" | ||
|
||
printf "%s" "Building ${name}..." | ||
printf "%s" "Building ${name}... " | ||
|
||
GOOS="linux" \ | ||
go build \ | ||
-ldflags="-s -w" \ | ||
-o "${BUILDPACKDIR}/bin/${name}" \ | ||
"${src}/main.go" | ||
GOOS="linux" \ | ||
go build \ | ||
-ldflags="-s -w" \ | ||
-o "${BUILDPACKDIR}/bin/${name}" \ | ||
"${src}/main.go" | ||
|
||
echo "Success!" | ||
done | ||
fi | ||
echo "Success!" | ||
done | ||
fi | ||
} | ||
|
||
main "${@:-}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.