Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added useful "Build script exited at step X" errors for each step in build-setup.sh #1614

Merged
merged 7 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 72 additions & 38 deletions scripts/build-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,13 @@ fi

# setup and install conda environment
if run_step "1"; then
# note: lock file must end in .conda-lock.yml - see https://github.com/conda-incubator/conda-lock/issues/154
CONDA_REQS=$CYDIR/conda-reqs
CONDA_LOCK_REQS=$CONDA_REQS/conda-lock-reqs
# must match with the file generated by generate-conda-lockfile.sh
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
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
try; (
source $CYDIR/scripts/build-step-init-conda-environment.sh
)
catch || {
echo "Build script exited with exit code $? at step 1: conda environment setup. Check the above logs for more details on the error."
exit $?
}
fi

if [ -z "$FORCE_FLAG" ]; then
Expand All @@ -138,7 +129,13 @@ fi

# initialize all submodules (without the toolchain submodules)
if run_step "2"; then
$CYDIR/scripts/init-submodules-no-riscv-tools.sh $FORCE_FLAG
try; (
$CYDIR/scripts/init-submodules-no-riscv-tools.sh $FORCE_FLAG
)
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

# build extra toolchain collateral (i.e. spike, pk, riscv-tests, libgloss)
Expand All @@ -152,58 +149,95 @@ if run_step "3"; then
fi
PREFIX=$RISCV
fi
$CYDIR/scripts/build-toolchain-extra.sh $TOOLCHAIN_TYPE -p $PREFIX
try; (
$CYDIR/scripts/build-toolchain-extra.sh $TOOLCHAIN_TYPE -p $PREFIX
)
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

# run ctags for code navigation
if run_step "4"; then
$CYDIR/scripts/gen-tags.sh
try; (
$CYDIR/scripts/gen-tags.sh
)
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

# precompile chipyard scala sources
if run_step "5"; then
pushd $CYDIR/sims/verilator
make launch-sbt SBT_COMMAND=";project chipyard; compile"
make launch-sbt SBT_COMMAND=";project tapeout; compile"
popd
try; (
source $CYDIR/scripts/build-step-precompile-chipyard-scala.sh
)
catch || {
echo "Build script exited with exit code $? at step 5: chipyard pre-compile sources. Check the above logs for more details on the error."
exit $?
}
fi

# setup firesim
if run_step "6"; then
$CYDIR/scripts/firesim-setup.sh
$CYDIR/sims/firesim/gen-tags.sh
try; (
$CYDIR/scripts/firesim-setup.sh &&
$CYDIR/sims/firesim/gen-tags.sh
)
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
if run_step "7"; then
pushd $CYDIR/sims/firesim
(
echo $CYDIR
source sourceme-manager.sh --skip-ssh-setup
pushd sim
make sbt SBT_COMMAND="project {file:$CYDIR}firechip; compile" TARGET_PROJECT=firesim
popd
try; (
source $CYDIR/scripts/build-step-precompile-firesim-scala.sh
)
popd
catch || {
echo "Build script exited with exit code $? at step 7: firesim pre-compile sources. Check the above logs for more details on the error."
exit $?
}
fi
fi

# setup firemarshal
if run_step "8"; then
pushd $CYDIR/software/firemarshal
./init-submodules.sh
try; (
./init-submodules.sh
)
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
if run_step "9"; then
source $CYDIR/scripts/fix-open-files.sh
./marshal $VERBOSE_FLAG build br-base.json
./marshal $VERBOSE_FLAG clean br-base.json
try; (
source $CYDIR/scripts/fix-open-files.sh &&
./marshal $VERBOSE_FLAG build br-base.json &&
./marshal $VERBOSE_FLAG clean br-base.json
)
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
popd
fi

# do misc. cleanup for a "clean" git status
if run_step "10"; then
$CYDIR/scripts/repo-clean.sh
try; (
$CYDIR/scripts/repo-clean.sh
)
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

cat <<EOT >> env.sh
Expand Down
21 changes: 21 additions & 0 deletions scripts/build-step-init-conda-environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# This script is intended to be used as a sub-step of build-setup.sh.

# note: lock file must end in .conda-lock.yml - see https://github.com/conda-incubator/conda-lock/issues/154
set -e
CONDA_REQS=$CYDIR/conda-reqs
CONDA_LOCK_REQS=$CONDA_REQS/conda-lock-reqs
# must match with the file generated by generate-conda-lockfile.sh
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
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
10 changes: 10 additions & 0 deletions scripts/build-step-precompile-chipyard-scala.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

# This script is intended to be used as a sub-step of build-setup.sh.

set -e
pushd $CYDIR/sims/verilator
make launch-sbt SBT_COMMAND=";project chipyard; compile"
make launch-sbt SBT_COMMAND=";project tapeout; compile"
popd

12 changes: 12 additions & 0 deletions scripts/build-step-precompile-firesim-scala.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

# This script is intended to be used as a sub-step of build-setup.sh.
pushd $CYDIR/sims/firesim
(
echo $CYDIR
source sourceme-manager.sh --skip-ssh-setup
pushd sim
make sbt SBT_COMMAND="project {file:$CYDIR}firechip; compile" TARGET_PROJECT=firesim
popd
)
popd
21 changes: 21 additions & 0 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,24 @@ function restore_bash_options
{
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
}