Misc. updates to bash scripts

This commit is contained in:
Abraham Gonzalez
2022-09-21 22:45:13 -07:00
parent 85f16d3342
commit c5447b168c
5 changed files with 136 additions and 100 deletions

View File

@@ -28,7 +28,7 @@ usage() {
echo "Options" echo "Options"
echo " --help -h : Display this message" echo " --help -h : Display this message"
echo " --unpinned-deps -ud : Use unpinned conda environment" echo " --unpinned-deps -ud : Use unpinned conda environment"
echo " --skip-validate : Skip prompt checking for tagged release/conda" echo " --batch : Skip prompt checking for tagged release/conda"
echo " --skip-conda : Skip conda env creation" echo " --skip-conda : Skip conda env creation"
echo " --skip-toolchain-extra : Skip building extra RISC-V toolchain collateral (Spike, PK, tests, libgloos)" echo " --skip-toolchain-extra : Skip building extra RISC-V toolchain collateral (Spike, PK, tests, libgloos)"
exit "$1" exit "$1"
@@ -36,7 +36,7 @@ usage() {
TOOLCHAIN="riscv-tools" TOOLCHAIN="riscv-tools"
USE_PINNED_DEPS=true USE_PINNED_DEPS=true
SKIP_VALIDATE_FLAG="" BATCH_FLAG=""
SKIP_CONDA=false SKIP_CONDA=false
SKIP_TOOLCHAIN=false SKIP_TOOLCHAIN=false
@@ -50,8 +50,8 @@ do
TOOLCHAIN=$1 ;; TOOLCHAIN=$1 ;;
-ud | --unpinned-deps ) -ud | --unpinned-deps )
USE_PINNED_DEPS=false ;; USE_PINNED_DEPS=false ;;
--skip-validate) --batch)
SKIP_VALIDATE_FLAG=$1 ;; BATCH_FLAG=$1 ;;
--skip-conda) --skip-conda)
SKIP_CONDA=true ;; SKIP_CONDA=true ;;
--skip-toolchain-extra) --skip-toolchain-extra)
@@ -80,19 +80,21 @@ if [ "$SKIP_CONDA" = false ]; then
conda activate $DIR/.conda-env conda activate $DIR/.conda-env
fi fi
if [ -z "$SKIP_VALIDATE_FLAG" ]; then if [ -z "$BATCH_FLAG" ]; then
if [ -z ${CONDA_DEFAULT_ENV+x} ]; 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')?" error "ERROR: No conda environment detected. Did you activate the conda environment (e.x. 'conda activate base')?"
exit 1 exit 1
fi fi
fi fi
$DIR/scripts/init-submodules-no-riscv-tools.sh $SKIP_VALIDATE_FLAG $DIR/scripts/init-submodules-no-riscv-tools.sh $BATCH_FLAG
if [ "$SKIP_TOOLCHAIN" = false ]; then if [ "$SKIP_TOOLCHAIN" = false ]; then
$DIR/scripts/build-toolchain-extra.sh $SKIP_VALIDATE_FLAG $TOOLCHAIN $DIR/scripts/build-toolchain-extra.sh $BATCH_FLAG $TOOLCHAIN
fi fi
$DIR/scripts/gen-tags.sh
cat << EOT >> env.sh cat << EOT >> env.sh
# line auto-generated by $0 # line auto-generated by $0
conda activate $DIR/.conda-env conda activate $DIR/.conda-env

View File

@@ -1,22 +1,15 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# this script is based on the firesim build toolchains script
# exit script if any command fails # exit script if any command fails
set -e set -e
set -o pipefail set -o pipefail
# On macOS, use GNU readlink from 'coreutils' package in Homebrew/MacPorts RDIR=$(git rev-parse --show-toplevel)
if [ "$(uname -s)" = "Darwin" ] ; then
READLINK=greadlink
else
READLINK=readlink
fi
# If BASH_SOURCE is undefined, we may be running under zsh, in that case # get helpful utilities
# provide a zsh-compatible alternative source $RDIR/scripts/utils.sh
DIR="$(dirname "$($READLINK -f "${BASH_SOURCE[0]:-${(%):-%x}}")")"
CHIPYARD_DIR="$(dirname "$DIR")" common_setup
# Allow user to override MAKE # Allow user to override MAKE
[ -n "${MAKE:+x}" ] || MAKE=$(command -v gnumake || command -v gmake || command -v make) [ -n "${MAKE:+x}" ] || MAKE=$(command -v gnumake || command -v gmake || command -v make)
@@ -33,29 +26,21 @@ usage() {
echo " --prefix PREFIX : Install destination. If unset, defaults to $CONDA_PREFIX/riscv-tools" echo " --prefix PREFIX : Install destination. If unset, defaults to $CONDA_PREFIX/riscv-tools"
echo " or $CONDA_PREFIX/esp-tools" echo " or $CONDA_PREFIX/esp-tools"
echo " --clean-after-install : Run make clean in calls to module_make and module_build" echo " --clean-after-install : Run make clean in calls to module_make and module_build"
echo " --skip-validate : Skip prompt checking for conda" echo " --batch : Skip prompt checking for conda"
echo " --help -h : Display this message" echo " --help -h : Display this message"
exit "$1" exit "$1"
} }
error() {
echo "${0##*/}: ${1}" >&2
}
die() {
error "$1"
exit "${2:--1}"
}
TOOLCHAIN="riscv-tools" TOOLCHAIN="riscv-tools"
CLEANAFTERINSTALL="" CLEANAFTERINSTALL=""
RISCV="" RISCV=""
SKIP_VALIDATE=false BATCH=false
# getopts does not support long options, and is inflexible # getopts does not support long options, and is inflexible
while [ "$1" != "" ]; while [ "$1" != "" ];
do do
case $1 in case $1 in
-h | --help | help ) -h | -H | --help | help )
usage 3 ;; usage 3 ;;
-p | --prefix ) -p | --prefix )
shift shift
@@ -64,8 +49,8 @@ do
CLEANAFTERINSTALL="true" ;; CLEANAFTERINSTALL="true" ;;
riscv-tools | esp-tools) riscv-tools | esp-tools)
TOOLCHAIN=$1 ;; TOOLCHAIN=$1 ;;
--skip-validate) --batch)
SKIP_VALIDATE=true; BATCH=true;
;; ;;
* ) * )
error "invalid option $1" error "invalid option $1"
@@ -74,7 +59,7 @@ do
shift shift
done done
if [ "$SKIP_VALIDATE" = false ]; then if [ "$BATCH" = false ]; then
if [ -z ${CONDA_DEFAULT_ENV+x} ]; then if [ -z ${CONDA_DEFAULT_ENV+x} ]; then
error "ERROR: No conda environment detected. Did you activate the conda environment (e.x. 'conda activate chipyard')?" error "ERROR: No conda environment detected. Did you activate the conda environment (e.x. 'conda activate chipyard')?"
exit 1 exit 1
@@ -82,7 +67,7 @@ if [ "$SKIP_VALIDATE" = false ]; then
fi fi
if [ -z "$RISCV" ] ; then if [ -z "$RISCV" ] ; then
RISCV="$CONDA_PREFIX/$TOOLCHAIN" RISCV="$CONDA_PREFIX/$TOOLCHAIN"
fi fi
XLEN=64 XLEN=64
@@ -92,7 +77,7 @@ echo "Installing extra toolchain utilities/tests to $RISCV"
# install risc-v tools # install risc-v tools
export RISCV="$RISCV" export RISCV="$RISCV"
cd "${CHIPYARD_DIR}" cd "${RDIR}"
SRCDIR="$(pwd)/toolchains/${TOOLCHAIN}" SRCDIR="$(pwd)/toolchains/${TOOLCHAIN}"
[ -d "${SRCDIR}" ] || die "unsupported toolchain: ${TOOLCHAIN}" [ -d "${SRCDIR}" ] || die "unsupported toolchain: ${TOOLCHAIN}"

View File

@@ -5,13 +5,12 @@
set -e set -e
set -o pipefail set -o pipefail
RDIR=$(pwd) RDIR=$(git rev-parse --show-toplevel)
scripts_dir="$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" >/dev/null 2>&1 && pwd )"
cd "${scripts_dir}/.." cd "$RDIR"
# Reenable the FireSim submodule # Reenable the FireSim submodule
git config --unset submodule.sims/firesim.update || true git config --unset submodule.sims/firesim.update || true
cd sims/firesim pushd sims/firesim
./build-setup.sh "$@" --library --skip-validate ./build-setup.sh "$@" --library --skip-validate
cd "$RDIR" popd

View File

@@ -4,27 +4,34 @@
set -e set -e
set -o pipefail set -o pipefail
SKIP_VALIDATE=false RDIR=$(git rev-parse --show-toplevel)
# get helpful utilities
source $RDIR/scripts/utils.sh
common_setup
function usage function usage
{ {
echo "Usage: $0 [--skip-validate]" echo "Usage: $0 [--batch]"
echo "Initialize Chipyard submodules and setup initial env.sh script." echo "Initialize Chipyard submodules and setup initial env.sh script."
echo "" echo ""
echo " --skip-validate Skip prompt checking for tagged release" echo " --batch Skip prompt checking for tagged release"
} }
BATCH=false
while test $# -gt 0 while test $# -gt 0
do do
case "$1" in case "$1" in
--skip-validate) --batch)
SKIP_VALIDATE=true; BATCH=true;
;; ;;
-h | -H | --help) -h | -H | --help | help)
usage usage
exit 1 exit 1
;; ;;
*) echo "ERROR: bad argument $1" *)
echo "ERROR: bad argument $1"
usage usage
exit 2 exit 2
;; ;;
@@ -32,47 +39,36 @@ do
shift shift
done done
# Check that git version is at least 1.7.8
MYGIT=$(git --version)
MYGIT=${MYGIT#'git version '} # Strip prefix
case ${MYGIT} in
[1-9]*) ;;
*) echo 'warning: unknown git version' ;;
esac
MINGIT="1.8.5"
if [ "$MINGIT" != "$(echo -e "$MINGIT\n$MYGIT" | sort -V | head -n1)" ]; then
echo "This script requires git version $MINGIT or greater. Exiting."
false
fi
# before doing anything verify that you are on a release branch/tag # before doing anything verify that you are on a release branch/tag
save_bash_options
set +e set +e
tag=$(git describe --exact-match --tags) git_tag=$(git describe --exact-match --tags)
tag_ret_code=$? git_tag_rc=$?
set -e restore_bash_options
if [ $tag_ret_code -ne 0 ]; then if [ "$git_tag_rc" -ne 0 ]; then
if [ "$SKIP_VALIDATE" = false ]; then if [ "$BATCH" == false ]; then
read -p "WARNING: You are not on an official release of Chipyard."$'\n'"Type \"y\" to continue if this is intended, otherwise see https://chipyard.readthedocs.io/en/stable/Chipyard-Basics/Initial-Repo-Setup.html#setting-up-the-chipyard-repo: " validate while true; do
[[ $validate == [yY] ]] || exit 3 read -p "WARNING: You are not on an official release of Chipyard."$'\n'"Type \"y\" to continue if this is intended or \"n\" if not: " validate
echo "Setting up non-official Chipyard release" case "$validate" in
y | Y)
echo "Continuing on to setting up non-official Chipyard release repository"
break
;;
n | N)
error "See https://chipyard.readthedocs.io/en/stable/Chipyard-Basics/Initial-Repo-Setup.html#setting-up-the-chipyard-repo for setting up an official release of Chipyard. "
exit 3
;;
*)
error "Invalid response. Please type \"y\" or \"n\""
;;
esac
done
fi fi
else else
echo "Setting up official Chipyard release: $tag" echo "Setting up official Chipyard release: $git_tag"
fi fi
# On macOS, use GNU readlink from 'coreutils' package in Homebrew/MacPorts cd "$RDIR"
if [ "$(uname -s)" = "Darwin" ] ; then
READLINK=greadlink
else
READLINK=readlink
fi
# If BASH_SOURCE is undefined we may be running under zsh, in that case
# provide a zsh-compatible alternative
DIR="$(dirname "$($READLINK -f "${BASH_SOURCE[0]:-${(%):-%x}}")")"
CHIPYARD_DIR="$(dirname "$DIR")"
cd "$CHIPYARD_DIR"
( (
# Blocklist of submodules to initially skip: # Blocklist of submodules to initially skip:
@@ -106,29 +102,28 @@ cd "$CHIPYARD_DIR"
_unskip() { git config --local --unset-all "submodule.${1}.update" || : ; } _unskip() { git config --local --unset-all "submodule.${1}.update" || : ; }
trap 'git_submodule_exclude _unskip' EXIT INT TERM trap 'git_submodule_exclude _unskip' EXIT INT TERM
set -x (
git_submodule_exclude _skip set -x
git submodule update --init --recursive #--jobs 8 git_submodule_exclude _skip
set +x git submodule update --init --recursive #--jobs 8
)
) )
set -x (
# Non-recursive clone to exclude riscv-linux
git submodule update --init generators/sha3
# Non-recursive clone to exclude riscv-linux # Non-recursive clone to exclude gemmini-software
git submodule update --init generators/sha3 git submodule update --init generators/gemmini
git -C generators/gemmini/ submodule update --init --recursive software/gemmini-rocc-tests
# Non-recursive clone to exclude gemmini-software # Minimal non-recursive clone to initialize sbt dependencies
git submodule update --init generators/gemmini git submodule update --init sims/firesim
git -C generators/gemmini/ submodule update --init --recursive software/gemmini-rocc-tests git config --local submodule.sims/firesim.update none
# Minimal non-recursive clone to initialize sbt dependencies # Only shallow clone needed for basic SW tests
git submodule update --init sims/firesim git submodule update --init software/firemarshal
git config --local submodule.sims/firesim.update none )
# Only shallow clone needed for basic SW tests
git submodule update --init software/firemarshal
set +x
# Configure firemarshal to know where our firesim installation is # Configure firemarshal to know where our firesim installation is
if [ ! -f ./software/firemarshal/marshal-config.yaml ]; then if [ ! -f ./software/firemarshal/marshal-config.yaml ]; then

55
scripts/utils.sh Normal file
View File

@@ -0,0 +1,55 @@
#/usr/bin/env bash
#######################################
# Common setup. Init MacOS compatibility
# variables.
# Globals:
# READLINK
#######################################
function common_setup
{
# On macOS, use GNU readlink from 'coreutils' package in Homebrew/MacPorts
if [ "$(uname -s)" = "Darwin" ] ; then
READLINK=greadlink
else
READLINK=readlink
fi
}
#######################################
# Error echo wrapper
#######################################
function error
{
echo "${0##*/}: ${1}" >&2
}
#######################################
# Error then exit wrapper
# Arguments:
# string to print before exit
# (optional) int error code
#######################################
function die
{
error "$1"
exit "${2:--1}"
}
#######################################
# Save bash options. Must be called
# before a corresponding `restore_bash_options`.
#######################################
function save_bash_options
{
OLDSTATE=$(set +o)
}
#######################################
# Restore bash options. Must be called
# after a corresponding `save_bash_options`.
#######################################
function restore_bash_options
{
set +vx; eval "$OLDSTATE"
}