Files
chipyard/scripts/build-setup.sh
JL102 6b70dd6d39 Added "try-catch" to all build-setup steps
This was the only way I knew how to display the step at which the build-setup process failed.
I've personally experienced failures at multiple of the build steps, and before I got used to Chipyard,
it was hard to figure out which step was the culprit. With this, users should have a bit more info to
troubleshoot their issues. For some of the build steps that required multiple lines, I figured it made
more sense to put them into a sub-script, rather than putting a && at the end of each line. But for the
firesim one for example, since it was two .sh calls, I just put a && after the first one, inside of the
try block, to make sure both lines run.
2023-10-05 02:17:25 -04:00

252 lines
7.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# exit script if any command fails
set -e
set -o pipefail
CYDIR=$(git rev-parse --show-toplevel)
# get helpful utilities
source $CYDIR/scripts/utils.sh
common_setup
usage() {
echo "Usage: ${0} [OPTIONS] [riscv-tools | esp-tools]"
echo ""
echo "Installation Types"
echo " riscv-tools: if set, builds the riscv toolchain (this is also the default)"
echo " esp-tools: if set, builds esp-tools toolchain used for the hwacha vector accelerator"
echo ""
echo "Helper script to fully initialize repository that wraps other scripts."
echo "By default it initializes/installs things in the following order:"
echo " 1. Conda environment"
echo " 2. Chipyard submodules"
echo " 3. Toolchain collateral (Spike, PK, tests, libgloss)"
echo " 4. Ctags"
echo " 5. Chipyard pre-compile sources"
echo " 6. FireSim"
echo " 7. FireSim pre-compile sources"
echo " 8. FireMarshal"
echo " 9. FireMarshal pre-compile default buildroot Linux sources"
echo " 10. Runs repository clean-up"
echo ""
echo "**See below for options to skip parts of the setup. Skipping parts of the setup is not guaranteed to be tested/working.**"
echo ""
echo "Options"
echo " --help -h : Display this message"
echo " --force -f : Skip all prompts and checks"
echo " --skip-validate : DEPRECATED: Same functionality as --force"
echo " --verbose -v : Verbose printout"
echo " --use-unpinned-deps -ud : Use unpinned conda environment"
echo " --skip -s N : Skip step N in the list above. Use multiple times to skip multiple steps ('-s N -s M ...')."
exit "$1"
}
TOOLCHAIN_TYPE="riscv-tools"
FORCE_FLAG=""
VERBOSE=false
VERBOSE_FLAG=""
USE_UNPINNED_DEPS=false
SKIP_LIST=()
# getopts does not support long options, and is inflexible
while [ "$1" != "" ];
do
case $1 in
-h | --help )
usage 3 ;;
riscv-tools | esp-tools)
TOOLCHAIN_TYPE=$1 ;;
--force | -f | --skip-validate)
FORCE_FLAG=$1 ;;
--verbose | -v)
VERBOSE_FLAG=$1
set -x ;;
-ud | --use-unpinned-deps )
USE_UNPINNED_DEPS=true ;;
--skip | -s)
shift
SKIP_LIST+=(${1}) ;;
* )
error "invalid option $1"
usage 1 ;;
esac
shift
done
# return true if the arg is not found in the SKIP_LIST
run_step() {
local value=$1
[[ ! " ${SKIP_LIST[*]} " =~ " ${value} " ]]
}
{
# esp-tools should ONLY be used for hwacha.
# Check for this, since many users will be attempting to use this with gemmini
if [ $TOOLCHAIN_TYPE == "esp-tools" ]; then
while true; do
printf '\033[2J'
read -p "WARNING: You are trying to install the esp-tools toolchain."$'\n'"This should ONLY be used for Hwacha development."$'\n'"Gemmini should be used with riscv-tools."$'\n'"Type \"y\" to continue if this is intended, or \"n\" if not: " validate
case "$validate" in
y | Y)
echo "Installing esp-tools."
break
;;
n | N)
error "Rerun with riscv-tools"
exit 3
;;
*)
error "Invalid response. Please type \"y\" or \"n\""
;;
esac
done
fi
# setup and install conda environment
if run_step "1"; then
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
if [ -z ${CONDA_DEFAULT_ENV+x} ]; then
error "ERROR: No conda environment detected. Did you activate the conda environment (e.x. 'conda activate base')?"
exit 1
fi
fi
# initialize all submodules (without the toolchain submodules)
if run_step "2"; then
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)
if run_step "3"; then
if run_step "1"; then
PREFIX=$CONDA_PREFIX/$TOOLCHAIN_TYPE
else
if [ -z "$RISCV" ] ; then
error "ERROR: If conda initialization skipped, \$RISCV variable must be defined."
exit 1
fi
PREFIX=$RISCV
fi
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
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
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
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
try; (
source $CYDIR/scripts/build-step-precompile-firesim-scala.sh
)
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
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
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
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
# line auto-generated by $0
conda activate $CYDIR/.conda-env
source $CYDIR/scripts/fix-open-files.sh
EOT
echo "Setup complete!"
} 2>&1 | tee build-setup.log