Replaced "try-catch" with a more special-purpose set of functions
This also fixed the weird issue I was experiencing where the try-catch in step 1 caused step 3 to break
This commit is contained in:
@@ -109,15 +109,49 @@ if [ $TOOLCHAIN_TYPE == "esp-tools" ]; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
###### BEGIN STEP-BY-STEP SETUP #######
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
# In order to run code on error, we must handle errors manually
|
||||||
|
set +e;
|
||||||
|
|
||||||
|
function begin_step
|
||||||
|
{
|
||||||
|
thisStepNum=$1;
|
||||||
|
thisStepDesc=$2;
|
||||||
|
echo " ========== BEGINNING STEP $thisStepNum: $thisStepDesc =========="
|
||||||
|
}
|
||||||
|
function exit_if_last_command_failed
|
||||||
|
{
|
||||||
|
local exitcode=$?;
|
||||||
|
if [ $exitcode -ne 0 ]; then
|
||||||
|
die "Build script failed with exit code $exitcode at step $thisStepNum: $thisStepDesc" $exitcode;
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# setup and install conda environment
|
# setup and install conda environment
|
||||||
if run_step "1"; then
|
if run_step "1"; then
|
||||||
try; (
|
begin_step "1" "Conda environment setup"
|
||||||
source $CYDIR/scripts/build-step-init-conda-environment.sh
|
# note: lock file must end in .conda-lock.yml - see https://github.com/conda-incubator/conda-lock/issues/154
|
||||||
)
|
CONDA_REQS=$CYDIR/conda-reqs
|
||||||
catch || {
|
CONDA_LOCK_REQS=$CONDA_REQS/conda-lock-reqs
|
||||||
echo "Build script exited with exit code $? at step 1: conda environment setup. Check the above logs for more details on the error."
|
# must match with the file generated by generate-conda-lockfile.sh
|
||||||
exit $?
|
LOCKFILE=$CONDA_LOCK_REQS/conda-requirements-$TOOLCHAIN_TYPE-linux-64.conda-lock.yml
|
||||||
}
|
|
||||||
|
if [ "$USE_UNPINNED_DEPS" = true ]; then
|
||||||
|
# auto-gen the lockfiles
|
||||||
|
$CYDIR/scripts/generate-conda-lockfiles.sh
|
||||||
|
exit_if_last_command_failed
|
||||||
|
fi
|
||||||
|
|
||||||
|
# use conda-lock to create env
|
||||||
|
conda-lock install --conda $(which conda) -p $CYDIR/.conda-env $LOCKFILE &&
|
||||||
|
|
||||||
|
source $CYDIR/.conda-env/etc/profile.d/conda.sh &&
|
||||||
|
conda activate $CYDIR/.conda-env
|
||||||
|
exit_if_last_command_failed
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$FORCE_FLAG" ]; then
|
if [ -z "$FORCE_FLAG" ]; then
|
||||||
@@ -129,17 +163,14 @@ fi
|
|||||||
|
|
||||||
# initialize all submodules (without the toolchain submodules)
|
# initialize all submodules (without the toolchain submodules)
|
||||||
if run_step "2"; then
|
if run_step "2"; then
|
||||||
try; (
|
begin_step "2" "Initializing Chipyard submodules"
|
||||||
$CYDIR/scripts/init-submodules-no-riscv-tools.sh $FORCE_FLAG
|
$CYDIR/scripts/init-submodules-no-riscv-tools.sh $FORCE_FLAG
|
||||||
)
|
exit_if_last_command_failed
|
||||||
catch || {
|
|
||||||
echo "Build script exited with exit code $? at step 2: submodule initialization. Check the above logs for more details on the error."
|
|
||||||
exit $?
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# build extra toolchain collateral (i.e. spike, pk, riscv-tests, libgloss)
|
# build extra toolchain collateral (i.e. spike, pk, riscv-tests, libgloss)
|
||||||
if run_step "3"; then
|
if run_step "3"; then
|
||||||
|
begin_step "3" "Building toolchain collateral"
|
||||||
if run_step "1"; then
|
if run_step "1"; then
|
||||||
PREFIX=$CONDA_PREFIX/$TOOLCHAIN_TYPE
|
PREFIX=$CONDA_PREFIX/$TOOLCHAIN_TYPE
|
||||||
else
|
else
|
||||||
@@ -149,95 +180,74 @@ if run_step "3"; then
|
|||||||
fi
|
fi
|
||||||
PREFIX=$RISCV
|
PREFIX=$RISCV
|
||||||
fi
|
fi
|
||||||
try; (
|
$CYDIR/scripts/build-toolchain-extra.sh $TOOLCHAIN_TYPE -p $PREFIX
|
||||||
$CYDIR/scripts/build-toolchain-extra.sh $TOOLCHAIN_TYPE -p $PREFIX
|
exit_if_last_command_failed
|
||||||
)
|
|
||||||
catch || {
|
|
||||||
echo "Build script exited with exit code $? at step 3: toolchain collateral. Check the above logs for more details on the error."
|
|
||||||
exit $?
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# run ctags for code navigation
|
# run ctags for code navigation
|
||||||
if run_step "4"; then
|
if run_step "4"; then
|
||||||
try; (
|
begin_step "4" "Running ctags for code navigation"
|
||||||
$CYDIR/scripts/gen-tags.sh
|
$CYDIR/scripts/gen-tags.sh
|
||||||
)
|
exit_if_last_command_failed
|
||||||
catch || {
|
|
||||||
echo "Build script exited with exit code $? at step 4: ctags generation. Check the above logs for more details on the error."
|
|
||||||
exit $?
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# precompile chipyard scala sources
|
# precompile chipyard scala sources
|
||||||
if run_step "5"; then
|
if run_step "5"; then
|
||||||
try; (
|
begin_step "5" "Pre-compiling Chipyard Scala sources"
|
||||||
source $CYDIR/scripts/build-step-precompile-chipyard-scala.sh
|
pushd $CYDIR/sims/verilator
|
||||||
)
|
make launch-sbt SBT_COMMAND=";project chipyard; compile"
|
||||||
catch || {
|
make launch-sbt SBT_COMMAND=";project tapeout; compile"
|
||||||
echo "Build script exited with exit code $? at step 5: chipyard pre-compile sources. Check the above logs for more details on the error."
|
popd
|
||||||
exit $?
|
exit_if_last_command_failed
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# setup firesim
|
# setup firesim
|
||||||
if run_step "6"; then
|
if run_step "6"; then
|
||||||
try; (
|
begin_step "6" "Setting up FireSim"
|
||||||
$CYDIR/scripts/firesim-setup.sh &&
|
$CYDIR/scripts/firesim-setup.sh
|
||||||
$CYDIR/sims/firesim/gen-tags.sh
|
$CYDIR/sims/firesim/gen-tags.sh
|
||||||
)
|
exit_if_last_command_failed
|
||||||
catch || {
|
|
||||||
echo "Build script exited with exit code $? at step 6: firesim setup. Check the above logs for more details on the error."
|
|
||||||
exit $?
|
|
||||||
}
|
|
||||||
|
|
||||||
# precompile firesim scala sources
|
# precompile firesim scala sources
|
||||||
if run_step "7"; then
|
if run_step "7"; then
|
||||||
try; (
|
begin_step "7" "Pre-compiling Firesim Scala sources"
|
||||||
source $CYDIR/scripts/build-step-precompile-firesim-scala.sh
|
pushd $CYDIR/sims/firesim
|
||||||
|
(
|
||||||
|
set -e # Subshells un-set "set -e" so it must be re enabled
|
||||||
|
echo $CYDIR
|
||||||
|
source sourceme-manager.sh --skip-ssh-setup
|
||||||
|
pushd sim
|
||||||
|
make sbt SBT_COMMAND="project {file:$CYDIR}firechip; compile" TARGET_PROJECT=firesim
|
||||||
|
popd
|
||||||
)
|
)
|
||||||
catch || {
|
exit_if_last_command_failed
|
||||||
echo "Build script exited with exit code $? at step 7: firesim pre-compile sources. Check the above logs for more details on the error."
|
popd
|
||||||
exit $?
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# setup firemarshal
|
# setup firemarshal
|
||||||
if run_step "8"; then
|
if run_step "8"; then
|
||||||
|
begin_step "8" "Setting up FireMarshal"
|
||||||
pushd $CYDIR/software/firemarshal
|
pushd $CYDIR/software/firemarshal
|
||||||
try; (
|
./init-submodules.sh
|
||||||
./init-submodules.sh
|
exit_if_last_command_failed
|
||||||
)
|
|
||||||
catch || {
|
|
||||||
echo "Build script exited with exit code $? at step 8: firemarshal setup. Check the above logs for more details on the error."
|
|
||||||
exit $?
|
|
||||||
}
|
|
||||||
|
|
||||||
# precompile firemarshal buildroot sources
|
# precompile firemarshal buildroot sources
|
||||||
if run_step "9"; then
|
if run_step "9"; then
|
||||||
try; (
|
begin_step "9" "Pre-compiling FireMarshal buildroot sources"
|
||||||
source $CYDIR/scripts/fix-open-files.sh &&
|
source $CYDIR/scripts/fix-open-files.sh &&
|
||||||
./marshal $VERBOSE_FLAG build br-base.json &&
|
./marshal $VERBOSE_FLAG build br-base.json &&
|
||||||
./marshal $VERBOSE_FLAG clean br-base.json
|
./marshal $VERBOSE_FLAG clean br-base.json
|
||||||
)
|
exit_if_last_command_failed
|
||||||
catch || {
|
|
||||||
echo "Build script exited with exit code $? at step 9: firemarshal pre-compile buildroot sources. Check the above logs for more details on the error."
|
|
||||||
exit $?
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
popd
|
popd
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# do misc. cleanup for a "clean" git status
|
# do misc. cleanup for a "clean" git status
|
||||||
if run_step "10"; then
|
if run_step "10"; then
|
||||||
try; (
|
begin_step "10" "Cleaning up repository"
|
||||||
$CYDIR/scripts/repo-clean.sh
|
$CYDIR/scripts/repo-clean.sh
|
||||||
)
|
exit_if_last_command_failed
|
||||||
catch || {
|
|
||||||
echo "Build script exited with exit code $? at step 10: repository cleanup. Check the above logs for more details on the error."
|
|
||||||
exit $?
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat <<EOT >> env.sh
|
cat <<EOT >> env.sh
|
||||||
|
|||||||
@@ -53,24 +53,3 @@ function restore_bash_options
|
|||||||
{
|
{
|
||||||
set +vx; eval "$OLDSTATE"
|
set +vx; eval "$OLDSTATE"
|
||||||
}
|
}
|
||||||
|
|
||||||
#######################################
|
|
||||||
# Basic try-catch block implementation
|
|
||||||
# for bash scripts.
|
|
||||||
# Usage: try; ( run commands )
|
|
||||||
# catch || { handle error }
|
|
||||||
# Source: https://stackoverflow.com/a/25180186/5121242
|
|
||||||
#######################################
|
|
||||||
function try()
|
|
||||||
{
|
|
||||||
[[ $- = *e* ]]; SAVED_OPT_E=$?
|
|
||||||
set +e
|
|
||||||
}
|
|
||||||
|
|
||||||
function catch()
|
|
||||||
{
|
|
||||||
export ex_code=$?
|
|
||||||
(( $SAVED_OPT_E )) && set +e
|
|
||||||
return $ex_code
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user