From 177480078300294a65916eec4b3db512e28060d0 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 21 Jun 2023 19:13:31 -0400 Subject: [PATCH] Make bootstrap.sh more friendly to other shells. (#27392) * Make bootstrap.sh more friendly to other shells. I found some CI systems trying to use dash, and that does not seem to work at all due to it not understanding '<<<' or `[[`. Dash is still not ok because overall because arguments to `.` do not get passed along, however it would work as a default. Changes: - loop using IFS (and set sh_word_split for ZSH) - replaced `[[` tests with `[` * Restyle * Remove quoting logic that breaks execution * Stop restyling bootstrap.sh * Fix path * Do not permanently alter zsh options, use local_options * update sh_word_split to shwordsplit. Both seem to work, the non-underscore seems more common in docs --- .restyled.yaml | 1 + scripts/setup/bootstrap.sh | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.restyled.yaml b/.restyled.yaml index a57f9ce75a838a..32a77fee6fe5f9 100644 --- a/.restyled.yaml +++ b/.restyled.yaml @@ -80,6 +80,7 @@ exclude: - "zzz_generated/**/*" # already clang-formatted by our zap tooling - "src/controller/java/generated/java/**/*" # not formatted: generated files - "src/controller/java/zap-generated/**/*" # not formatted: generated files + - "scripts/setup/bootstrap.sh" # tries to quote loop variable changed_paths: diff --git a/scripts/setup/bootstrap.sh b/scripts/setup/bootstrap.sh index 925183b9e3f353..2fea8adc8f702d 100644 --- a/scripts/setup/bootstrap.sh +++ b/scripts/setup/bootstrap.sh @@ -19,7 +19,7 @@ _install_additional_pip_requirements() { shift # figure out additional pip install items - while [[ $# -gt 0 ]]; do + while [ $# -gt 0 ]; do case $1 in -p | --platform) _SETUP_PLATFORM=$2 @@ -32,13 +32,14 @@ _install_additional_pip_requirements() { esac done - if ! [ -z "$_SETUP_PLATFORM" ]; then + if [ -n "$_SETUP_PLATFORM" ]; then + _OLD_IFS=$IFS + IFS="," if [ -n "$ZSH_VERSION" ]; then - IFS="," read -r -A _PLATFORMS <<<"$_SETUP_PLATFORM" - else - IFS="," read -r -a _PLATFORMS <<<"$_SETUP_PLATFORM" + setopt local_options shwordsplit fi - for platform in "${_PLATFORMS[@]}"; do + + for platform in ${_SETUP_PLATFORM}; do # Allow none as an alias of nothing extra installed (like -p none) if [ "$platform" != "none" ]; then echo "Installing pip requirements for $platform..." @@ -47,6 +48,8 @@ _install_additional_pip_requirements() { -c "$_CHIP_ROOT/scripts/setup/constraints.txt" fi done + IFS=$_OLD_IFS + unset _OLD_IFS unset _PLATFORMS fi