Skip to content
This repository has been archived by the owner on Feb 15, 2019. It is now read-only.

Commit

Permalink
Refactor silencing commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mietek committed May 31, 2014
1 parent 04a4d9b commit 7c2e7e6
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 86 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,20 @@ It is also possible to prepare packages off Heroku, using any 64-bit machine run

To set [configuration variables][], use `heroku config:set`.

Variable | Default | Description
------------------------|-----------|------------
`AWS_ACCESS_KEY_ID` | — | Use this Amazon S3 key to access private prepared packages
`AWS_SECRET_ACCESS_KEY` | — | Use this Amazon S3 key to access private prepared packages
`HALCYON_S3_BUCKET` | — | Use this Amazon S3 bucket to keep prepared packages
`HALCYON_S3_ACL` | `private` | Use this Amazon S3 ACL to control access to prepared packages
`PURGE_HALCYON_CACHE` | `0` | When `1`, delete all prepared packages from cache before compiling
`FORCE_GHC_VERSION` | — | Use this GHC version instead of inferring it
`NO_CUT_GHC` | `0` | When `1`, use GHC prepared without deleting extraneous files
`FORCE_CABAL_VERSION` | — | Use this Cabal version instead of inferring the version
`FORCE_CABAL_UPDATE` | `0` | When `1`, update Cabal instead of using a recently updated prepared package
`NO_EXTEND_SANDBOX` | `0` | When `1`, avoid matching and extending prepared sandboxes
`FORCE_SANDBOX_BUILD` | `0` | When `1`, prepare the sandbox from scratch
Variable | Default | Description
-------------------------|-----------|------------
`AWS_ACCESS_KEY_ID` | — | Use this Amazon S3 key to access private prepared packages
`AWS_SECRET_ACCESS_KEY` | — | Use this Amazon S3 key to access private prepared packages
`HALCYON_S3_BUCKET` | — | Use this Amazon S3 bucket to keep prepared packages
`HALCYON_S3_ACL` | `private` | Use this Amazon S3 ACL to control access to prepared packages
`PURGE_HALCYON_CACHE` | `0` | When `1`, delete all prepared packages from cache before compiling
`SILENCE_HALCYON_OUTPUT` | `0` | When `1`, hide all expected external command output
`FORCE_GHC_VERSION` | — | Use this GHC version instead of inferring it
`NO_CUT_GHC` | `0` | When `1`, use GHC prepared without deleting extraneous files
`FORCE_CABAL_VERSION` | — | Use this Cabal version instead of inferring the version
`FORCE_CABAL_UPDATE` | `0` | When `1`, update Cabal instead of using a recently updated prepared package
`NO_EXTEND_SANDBOX` | `0` | When `1`, avoid matching and extending prepared sandboxes
`FORCE_SANDBOX_BUILD` | `0` | When `1`, prepare the sandbox from scratch


### I still have questions. Can I ask you a question?
Expand Down
75 changes: 15 additions & 60 deletions src/cabal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ function echo_cabal_tmp_dir () {
}


function echo_cabal_tmp_log () {
mktemp -u "/tmp/halcyon-cabal.log.XXXXXXXXXX"
}




function validate_cabal_tag () {
Expand Down Expand Up @@ -205,7 +200,7 @@ function match_updated_cabal_archive () {



function cabal_silently () {
function cabal_do () {
expect_vars HALCYON
expect "${HALCYON}/cabal/tag"

Expand All @@ -214,69 +209,31 @@ function cabal_silently () {
shift
expect "${work_dir}"

local tmp_log
tmp_log=$( echo_cabal_tmp_log ) || die

if ! (
cd "${work_dir}" &&
cabal --config-file="${HALCYON}/cabal/config" "$@" &>"${tmp_log}"
cabal --config-file="${HALCYON}/cabal/config" "$@"
); then
log_file_indent <"${tmp_log}"
die 'Using Cabal failed'
fi

rm -f "${tmp_log}" || die
}


function cabal_verbosely () {
expect_vars HALCYON
expect "${HALCYON}/cabal/tag"

local work_dir
expect_args work_dir -- "$@"
shift
expect "${work_dir}"

if ! (
cd "${work_dir}" &&
cabal --config-file="${HALCYON}/cabal/config" "$@" |& log_file_indent
); then
die 'Using Cabal failed'
fi
}




function sandboxed_cabal_silently () {
expect_vars HALCYON

local work_dir
expect_args work_dir -- "$@"
shift

cabal_silently "${work_dir}" \
--sandbox-config-file="${HALCYON}/sandbox/cabal.sandbox.config" "$@"
}


function sandboxed_cabal_verbosely () {
function sandboxed_cabal_do () {
expect_vars HALCYON

local work_dir
expect_args work_dir -- "$@"
shift

cabal_verbosely "${work_dir}" \
cabal_do "${work_dir}" \
--sandbox-config-file="${HALCYON}/sandbox/cabal.sandbox.config" "$@"
}




function cabal_update () {
cabal_silently '.' update || die
silently cabal_do '.' update || die
}


Expand All @@ -286,15 +243,15 @@ function cabal_create_sandbox () {
expect_no "${sandbox_dir}"

mkdir -p "${sandbox_dir}" || die
cabal_silently "${sandbox_dir}" sandbox init --sandbox '.' || die
silently cabal_do "${sandbox_dir}" sandbox init --sandbox '.' || die
}


function cabal_install () {
local build_dir
expect_args build_dir -- "$@"

sandboxed_cabal_silently "${build_dir}" install "$@" || die
silently sandboxed_cabal_do "${build_dir}" install "$@" || die
}


Expand All @@ -306,10 +263,10 @@ function cabal_install_deps () {
log_warning "Installing implicit versions of alex and happy"
log

sandboxed_cabal_silently "${build_dir}" install alex happy || die
silently sandboxed_cabal_do "${build_dir}" install alex happy || die
fi

sandboxed_cabal_silently "${build_dir}" install --dependencies-only || die
silently sandboxed_cabal_do "${build_dir}" install --dependencies-only || die
}


Expand All @@ -319,16 +276,16 @@ function cabal_configure_app () {
local build_dir
expect_args build_dir -- "$@"

sandboxed_cabal_verbosely "${build_dir}" configure --prefix="${HALCYON}/app" || die
silently sandboxed_cabal_do "${build_dir}" configure --prefix="${HALCYON}/app" || die
}


function cabal_build_app () {
local build_dir
expect_args build_dir -- "$@"

sandboxed_cabal_verbosely "${build_dir}" build || die
sandboxed_cabal_silently "${build_dir}" copy || die
silently sandboxed_cabal_do "${build_dir}" build || die
silently sandboxed_cabal_do "${build_dir}" copy || die
}


Expand All @@ -344,11 +301,10 @@ function build_cabal () {

log "Building Cabal ${cabal_version}"

local original_url original_archive tmp_dir tmp_log
local original_url original_archive tmp_dir
original_url=$( echo_cabal_original_url "${cabal_version}" ) || die
original_archive=$( basename "${original_url}" ) || die
tmp_dir=$( echo_cabal_tmp_dir ) || die
tmp_log=$( echo_cabal_tmp_log ) || die

if ! download_original "${original_archive}" "${original_url}" "${HALCYON_CACHE}"; then
die "Cabal ${cabal_version} is not available"
Expand Down Expand Up @@ -385,15 +341,14 @@ EOF
export EXTRA_CONFIGURE_OPTS="--extra-lib-dirs=${HALCYON}/ghc/lib -O2" &&
alias curl="curl -fsS" &&
cd "${tmp_dir}/cabal-install-${cabal_version}" &&
./bootstrap.sh --no-doc &>"${tmp_log}"
silently ./bootstrap.sh --no-doc
); then
log_file_indent <"${tmp_log}"
die 'Bootstrapping Cabal failed'
fi

mkdir -p "${HALCYON}/cabal/bin" || die
mv "${HOME}/.cabal/bin/cabal" "${HALCYON}/cabal/bin/cabal" || die
rm -rf "${HOME}/.cabal" "${HOME}/.ghc" "${tmp_dir}" "${tmp_log}" || die
rm -rf "${HOME}/.cabal" "${HOME}/.ghc" "${tmp_dir}" || die

echo_cabal_config >"${HALCYON}/cabal/config" || die
echo_cabal_tag "${cabal_version}" '' >"${HALCYON}/cabal/tag" || die
Expand Down
4 changes: 2 additions & 2 deletions src/constraints.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ function freeze_constraints () {
fi

if (( ${implicit} )); then
cabal_silently "${build_dir}" --no-require-sandbox freeze || die
silently cabal_do "${build_dir}" --no-require-sandbox freeze || die
else
sandboxed_cabal_silently "${build_dir}" freeze || die
silently sandboxed_cabal_do "${build_dir}" freeze || die
fi

local sandbox_constraints
Expand Down
15 changes: 4 additions & 11 deletions src/ghc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ function echo_ghc_tmp_dir () {
}


function echo_ghc_tmp_log () {
mktemp -u "/tmp/halcyon-ghc.log.XXXXXXXXXX"
}




function validate_ghc_tag () {
Expand All @@ -163,11 +158,10 @@ function build_ghc () {

log "Building GHC ${ghc_version}"

local original_url original_archive tmp_dir tmp_log
local original_url original_archive tmp_dir
original_url=$( echo_ghc_original_url "${ghc_version}" ) || die
original_archive=$( basename "${original_url}" ) || die
tmp_dir=$( echo_ghc_tmp_dir ) || die
tmp_log=$( echo_ghc_tmp_log ) || die

if ! download_original "${original_archive}" "${original_url}" "${HALCYON_CACHE}"; then
die "GHC ${ghc_version} is not available"
Expand Down Expand Up @@ -195,14 +189,13 @@ function build_ghc () {

if ! (
cd "${tmp_dir}/ghc-${ghc_version}" &&
./configure --prefix="${HALCYON}/ghc" &>"${tmp_log}" &&
make install &>>"${tmp_log}"
silently ./configure --prefix="${HALCYON}/ghc" &&
silently make install
); then
log_file_indent <"${tmp_log}"
die 'Installing GHC failed'
fi

rm -rf "${HALCYON}/ghc/share" "${tmp_dir}" "${tmp_log}" || die
rm -rf "${HALCYON}/ghc/share" "${tmp_dir}" || die

echo_ghc_tag "${ghc_version}" 'uncut' >"${HALCYON}/ghc/tag" || die

Expand Down
1 change: 1 addition & 0 deletions src/halcyon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function set_defaults () {
export HALCYON_S3_ACL="${HALCYON_S3_ACL:-private}"

export PURGE_HALCYON_CACHE="${PURGE_CACHE:-0}"
export SILENCE_HALCYON_OUTPUT="${SILENCE_HALCYON_OUTPUT:-0}"
export FORCE_GHC_VERSION="${FORCE_GHC_VERSION:-}"
export NO_CUT_GHC="${NO_CUT_GHC:-0}"
export FORCE_CABAL_VERSION="${FORCE_CABAL_VERSION:-}"
Expand Down
24 changes: 24 additions & 0 deletions src/lib/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,27 @@ function compare_recursively () {
sort_naturally |
awk '{ print $2 " " $1 }'
}




function silently () {
expect_vars SILENCE_HALCYON_OUTPUT

expect_args cmd -- "$@"
shift

if (( ${SILENCE_HALCYON_OUTPUT} )); then
local tmp_log
tmp_log=$( mktemp -u "/tmp/${cmd}.log.XXXXXXXXXX" ) || die

if ! "${cmd}" "$@" >&"${tmp_log}"; then
log_file_indent <"${tmp_log}"
die
fi

rm -f "${tmp_log}" || die
else
"${cmd}" "$@" |& log_file_indent || die
fi
}

0 comments on commit 7c2e7e6

Please sign in to comment.