Skip to content

Commit

Permalink
workbench: consistent shell variable prefix: all workbench env vars a…
Browse files Browse the repository at this point in the history
…re now WB_*
  • Loading branch information
deepfire committed Jun 24, 2022
1 parent a1c346d commit 6e08bff
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 52 deletions.
36 changes: 18 additions & 18 deletions nix/workbench/backend.sh
Expand Up @@ -39,33 +39,33 @@ backend() {
local op=${1:-$(usage_backend)} # No need to shift -- backends will use the op.

case "${op}" in
is-running ) backend_$WORKBENCH_BACKEND "$@";;
setenv-defaults ) backend_$WORKBENCH_BACKEND "$@";;
allocate-run ) backend_$WORKBENCH_BACKEND "$@";;
describe-run ) backend_$WORKBENCH_BACKEND "$@";;
start ) backend_$WORKBENCH_BACKEND "$@";;
start-nodes ) backend_$WORKBENCH_BACKEND "$@";;
start-node ) backend_$WORKBENCH_BACKEND "$@";;
stop-node ) backend_$WORKBENCH_BACKEND "$@";;
wait-node ) backend_$WORKBENCH_BACKEND "$@";;
wait-node-stopped ) backend_$WORKBENCH_BACKEND "$@";;
get-node-socket-path ) backend_$WORKBENCH_BACKEND "$@";;
start-generator ) backend_$WORKBENCH_BACKEND "$@";;
wait-pools-stopped ) backend_$WORKBENCH_BACKEND "$@";;
stop-cluster ) backend_$WORKBENCH_BACKEND "$@";;
cleanup-cluster ) backend_$WORKBENCH_BACKEND "$@";;
is-running ) backend_$WB_BACKEND "$@";;
setenv-defaults ) backend_$WB_BACKEND "$@";;
allocate-run ) backend_$WB_BACKEND "$@";;
describe-run ) backend_$WB_BACKEND "$@";;
start ) backend_$WB_BACKEND "$@";;
start-nodes ) backend_$WB_BACKEND "$@";;
start-node ) backend_$WB_BACKEND "$@";;
stop-node ) backend_$WB_BACKEND "$@";;
wait-node ) backend_$WB_BACKEND "$@";;
wait-node-stopped ) backend_$WB_BACKEND "$@";;
get-node-socket-path ) backend_$WB_BACKEND "$@";;
start-generator ) backend_$WB_BACKEND "$@";;
wait-pools-stopped ) backend_$WB_BACKEND "$@";;
stop-cluster ) backend_$WB_BACKEND "$@";;
cleanup-cluster ) backend_$WB_BACKEND "$@";;

## Handle non-generic calls:
passthrough | pass ) backend_$WORKBENCH_BACKEND "$@";;
passthrough | pass ) backend_$WB_BACKEND "$@";;

assert-is )
local usage="USAGE: wb run $op BACKEND-NAME"
local name=${2:?$usage}

## Check the backend echoes own name:
local actual_name=$(backend_$WORKBENCH_BACKEND name)
local actual_name=$(backend_$WB_BACKEND name)
if test "$actual_name" != "$name"
then fatal "Workbench is broken: 'workbench_$WORKBENCH_BACKEND name' returned: '$actual_name'"; fi
then fatal "Workbench is broken: 'workbench_$WB_BACKEND name' returned: '$actual_name'"; fi
;;

assert-stopped )
Expand Down
10 changes: 5 additions & 5 deletions nix/workbench/env.sh
@@ -1,22 +1,22 @@
WORKBENCH_ENV_DEFAULT='
WB_ENV_DEFAULT='
{ "type": "supervisor"
, "cacheDir": "'$HOME'/.cache/cardano-workbench"
, "basePort": 30000
, "staggerPorts": true
}'

export WORKBENCH_ENV=$WORKBENCH_ENV_DEFAULT
export WB_ENV=$WB_ENV_DEFAULT

envjq() {
jq ".$1" <<<$WORKBENCH_ENV
jq ".$1" <<<$WB_ENV
}

envjqr() {
jq -r ".$1" <<<$WORKBENCH_ENV
jq -r ".$1" <<<$WB_ENV
}

setenvjq() {
export WORKBENCH_ENV=$(jq ". * { $1: $2 }" <<<$WORKBENCH_ENV)
export WB_ENV=$(jq ". * { $1: $2 }" <<<$WB_ENV)
}

setenvjqstr() {
Expand Down
31 changes: 16 additions & 15 deletions nix/workbench/lib-cabal.sh
@@ -1,18 +1,18 @@
progress "workbench" "cabal-inside-nix-shell mode enabled, calling cardano-* via '$(white cabal run)' (instead of using Nix store) $*"

if test ! -v WORKBENCH_PROFILED
then export WORKBENCH_PROFILED=
if test ! -v WB_PROFILED
then export WB_PROFILED=
fi

while test $# -gt 0
do case "$1" in
--profiled ) progress "workbench" "enabling $(white profiled) mode"
export WORKBENCH_PROFILED='true';;
export WB_PROFILED='true';;
* ) break;; esac; shift; done

export WBRTSARGS=${WORKBENCH_PROFILED:+-xc}
export WBFLAGS_RTS=${WBRTSARGS:++RTS $WBRTSARGS -RTS}
export WBFLAGS_CABAL=${WORKBENCH_PROFILED:+--enable-profiling}
export WB_RTSARGS=${WB_PROFILED:+-xc}
export WB_FLAGS_RTS=${WB_RTSARGS:++RTS $WB_RTSARGS -RTS}
export WB_FLAGS_CABAL=${WB_PROFILED:+--enable-profiling}

function workbench-prebuild-executables()
{
Expand All @@ -26,40 +26,41 @@ function workbench-prebuild-executables()
unset NIX_ENFORCE_PURITY
for exe in cardano-node cardano-cli cardano-topology cardano-tracer tx-generator locli
do echo "workbench: $(blue prebuilding) $(red $exe)"
cabal -v0 build ${WBFLAGS_CABAL} -- exe:$exe 2>&1 >/dev/null |
cabal -v0 build ${WB_FLAGS_CABAL} -- exe:$exe 2>&1 >/dev/null |
{ grep -v 'exprType TYPE'; true; } || return 1
done
echo
}

function cardano-cli() {
cabal -v0 run exe:cardano-cli ${WBFLAGS_RTS} -- "$@"
cabal -v0 run ${WB_FLAGS_CABAL} exe:cardano-cli -- ${WB_FLAGS_RTS} "$@"
}

function cardano-node() {
cabal -v0 run exe:cardano-node ${WBFLAGS_RTS} -- "$@"
cabal -v0 run ${WB_FLAGS_CABAL} exe:cardano-node -- ${WB_FLAGS_RTS} "$@"
}

function cardano-topology() {
cabal -v0 run exe:cardano-topology ${WBFLAGS_RTS} -- "$@"
env | grep WB
cabal -v0 run ${WB_FLAGS_CABAL} exe:cardano-topology -- ${WB_FLAGS_RTS} "$@"
}

function cardano-tracer() {
cabal -v0 run exe:cardano-tracer ${WBFLAGS_RTS} -- "$@"
cabal -v0 run ${WB_FLAGS_CABAL} exe:cardano-tracer -- ${WB_FLAGS_RTS} "$@"
}

function locli() {
cabal -v0 build ${WBFLAGS_CABAL} exe:locli
cabal -v0 build ${WB_FLAGS_CABAL} exe:locli
set-git-rev \
$(git rev-parse HEAD) \
$(find ./dist-newstyle/build/ -type f -name locli) || true
cabal -v0 exec ${WBFLAGS_CABAL} locli -- ${WBFLAGS_RTS} "$@"
cabal -v0 exec ${WB_FLAGS_CABAL} exe:locli -- ${WB_FLAGS_RTS} "$@"
}

function tx-generator() {
cabal -v0 run exe:tx-generator ${WBFLAGS_RTS} -- "$@"
cabal -v0 run ${WB_FLAGS_CABAL} exe:tx-generator -- ${WB_FLAGS_RTS} "$@"
}

export WORKBENCH_CABAL_MODE=t
export WB_MODE_CABAL=t

export -f cardano-cli cardano-node cardano-topology cardano-tracer locli tx-generator
4 changes: 2 additions & 2 deletions nix/workbench/profile.sh
Expand Up @@ -64,7 +64,7 @@ case "$op" in

json | show )
local usage="USAGE: wb profile $op [NAME=<current-shell-profile>"
local name=${1:-${WORKBENCH_SHELL_PROFILE:?variable unset, no profile name to use as a default.}}
local name=${1:-${WB_SHELL_PROFILE:?variable unset, no profile name to use as a default.}}

local json=$(if test -f "$name"
then jq '.' "$name"
Expand Down Expand Up @@ -118,7 +118,7 @@ case "$op" in

local args=(
-L "$global_basedir"
--argjson env "$WORKBENCH_ENV"
--argjson env "$WB_ENV"
)
## WARNING: this is structured in correspondence
## with the output generated by cardano-topology
Expand Down
6 changes: 3 additions & 3 deletions nix/workbench/run.sh
Expand Up @@ -28,7 +28,7 @@ usage_run() {
Options:
--rundir DIR Set the runs directory. Defaults to $global_rundir_def,
if it exists, otherwise to \$WORKBENCH_RUNDIR, if that
if it exists, otherwise to \$WB_RUNDIR, if that
exists, and finally unconditionally to $global_rundir_def.
EOF
}
Expand All @@ -38,8 +38,8 @@ set -eu
if test -d "$global_rundir_def"
then global_rundir=$global_rundir_def
## Allow compatibility with cardano-ops legacy runs directory layout:
elif test -v "WORKBENCH_RUNDIR" && test -d "$WORKBENCH_RUNDIR"
then global_rundir=$WORKBENCH_RUNDIR
elif test -v "WB_RUNDIR" && test -d "$WB_RUNDIR"
then global_rundir=$WB_RUNDIR
else global_rundir=$global_rundir_def
mkdir "$global_rundir"
fi
Expand Down
10 changes: 5 additions & 5 deletions nix/workbench/shell.nix
Expand Up @@ -11,17 +11,17 @@ with lib;
let
shellHook = ''
echo 'workbench shellHook: workbenchDevMode=${toString workbenchDevMode} useCabalRun=${toString useCabalRun} profileName=${profileName}'
export WORKBENCH_BACKEND=supervisor
export WORKBENCH_SHELL_PROFILE=${profileName}
export WB_BACKEND=supervisor
export WB_SHELL_PROFILE=${profileName}
${optionalString
workbenchDevMode
''
export WORKBENCH_CARDANO_NODE_REPO_ROOT=$(git rev-parse --show-toplevel)
export WORKBENCH_EXTRA_FLAGS=
export WB_CARDANO_NODE_REPO_ROOT=$(git rev-parse --show-toplevel)
export WB_EXTRA_FLAGS=
function wb() {
$WORKBENCH_CARDANO_NODE_REPO_ROOT/nix/workbench/wb --set-mode ${checkoutWbMode} $WORKBENCH_EXTRA_FLAGS "$@"
$WB_CARDANO_NODE_REPO_ROOT/nix/workbench/wb --set-mode ${checkoutWbMode} $WB_EXTRA_FLAGS "$@"
}
export -f wb
''}
Expand Down
4 changes: 2 additions & 2 deletions nix/workbench/supervisor-run.nix
Expand Up @@ -51,7 +51,7 @@ let
--profile ${profile} \
--cache-dir ${cacheDir} \
--base-port ${toString basePort} \
''${WORKBENCH_CABAL_MODE:+--cabal} \
''${WB_MODE_CABAL:+--cabal} \
"$@"
'';

Expand Down Expand Up @@ -99,7 +99,7 @@ let
mkdir -p $out/{cache,nix-support}
cd $out
export WORKBENCH_BACKEND=supervisor
export WB_BACKEND=supervisor
export CARDANO_NODE_SOCKET_PATH=$(wb backend get-node-socket-path ${stateDir})
cmd=(
Expand Down
4 changes: 2 additions & 2 deletions nix/workbench/wb
Expand Up @@ -131,7 +131,7 @@ start()

--verbose ) export verbose=t;;
--trace | --debug ) set -x;;
--trace-wb | --trace-workbench ) export WORKBENCH_EXTRA_FLAGS=--trace;;
--trace-wb | --trace-workbench ) export WB_EXTRA_FLAGS=--trace;;
--help ) usage_start
exit 1;;
* ) fatal "while parsing remaining 'wb start' args: $*";;
Expand Down Expand Up @@ -180,7 +180,7 @@ finish()
while test $# -gt 0
do case "$1" in
--trace | --debug ) set -x;;
--trace-wb | --trace-workbench ) export WORKBENCH_EXTRA_FLAGS=--trace;;
--trace-wb | --trace-workbench ) export WB_EXTRA_FLAGS=--trace;;
* ) break;; esac; shift; done

run stop $(run current-tag)
Expand Down

0 comments on commit 6e08bff

Please sign in to comment.