diff --git a/.github/action.sh b/.github/action.sh index d57cae9ef..659c80e54 100755 --- a/.github/action.sh +++ b/.github/action.sh @@ -18,14 +18,14 @@ # This is the entrypoint for GitHub Actions only. # 2016/05/18 http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in -DIR_THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +DIR_THIS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" export TARGET_REPO_PATH=$GITHUB_WORKSPACE export TARGET_REPO_NAME=${GITHUB_REPOSITORY##*/} export _FOLDING_TYPE=github_actions if [ -n "$INPUT_CONFIG" ]; then - vars=$(jq -r 'keys[] as $k | "export \($k)=\(.[$k]|tojson)" | gsub("\\$\\$";"\\$")' <<< "$INPUT_CONFIG" | grep "^export [A-Z][A-Z_]*=") + vars=$(jq -r 'keys[] as $k | "export \($k)=\(.[$k]|tojson)" | gsub("\\$\\$";"\\$")' <<<"$INPUT_CONFIG" | grep "^export [A-Z][A-Z_]*=") echo "$vars" eval "$vars" fi diff --git a/bitbucket.sh b/bitbucket.sh index e72bd6bc5..4b7c76d19 100755 --- a/bitbucket.sh +++ b/bitbucket.sh @@ -20,7 +20,7 @@ # This is the entrypoint for BitBucket Pipelines only. # 2016/05/18 http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in -DIR_THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +DIR_THIS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" export TARGET_REPO_PATH=$BITBUCKET_CLONE_DIR export TARGET_REPO_NAME=${BITBUCKET_REPO_SLUG##*/} diff --git a/ci.sh b/ci.sh index 590f5a311..820d5758d 100755 --- a/ci.sh +++ b/ci.sh @@ -19,7 +19,7 @@ # This is the generic entrypoint for CI services. # 2016/05/18 http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in -DIR_THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +DIR_THIS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" export TARGET_REPO_PATH=${TARGET_REPO_PATH:-$(pwd)} export TARGET_REPO_NAME=${TARGET_REPO_NAME:-${TARGET_REPO_PATH##*/}} diff --git a/gitlab.sh b/gitlab.sh index 83067c98a..8707782e0 100755 --- a/gitlab.sh +++ b/gitlab.sh @@ -19,29 +19,33 @@ # This is the entrypoint for Gitlab CI only. # 2016/05/18 http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in -DIR_THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +DIR_THIS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" export TARGET_REPO_PATH=$CI_PROJECT_DIR export TARGET_REPO_NAME=$CI_PROJECT_NAME export _FOLDING_TYPE=gitlab if [ -n "$SSH_PRIVATE_KEY" ]; then - if [ "$CI_DISPOSABLE_ENVIRONMENT" != true ] && ! [ -f /.dockerenv ] ; then - echo "SSH auto set-up cannot be used in non-disposable environments" - exit 1 - fi - - # start SSH agent - # shellcheck disable=SC2046 - eval $(ssh-agent -s) - # add key to agent - ssh-add <(echo "$SSH_PRIVATE_KEY") || { res=$?; echo "could not add ssh key"; exit $res; } - - if [ -n "$SSH_SERVER_HOSTKEYS" ]; then - mkdir -p ~/.ssh - # setup known hosts - echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts - fi + if [ "$CI_DISPOSABLE_ENVIRONMENT" != true ] && ! [ -f /.dockerenv ]; then + echo "SSH auto set-up cannot be used in non-disposable environments" + exit 1 + fi + + # start SSH agent + # shellcheck disable=SC2046 + eval $(ssh-agent -s) + # add key to agent + ssh-add <(echo "$SSH_PRIVATE_KEY") || { + res=$? + echo "could not add ssh key" + exit $res + } + + if [ -n "$SSH_SERVER_HOSTKEYS" ]; then + mkdir -p ~/.ssh + # setup known hosts + echo "$SSH_SERVER_HOSTKEYS" >~/.ssh/known_hosts + fi fi env "$@" bash "$DIR_THIS/industrial_ci/src/ci_main.sh" diff --git a/industrial_ci/scripts/rerun_ci b/industrial_ci/scripts/rerun_ci index a2492e5bd..97925b27f 100755 --- a/industrial_ci/scripts/rerun_ci +++ b/industrial_ci/scripts/rerun_ci @@ -15,10 +15,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" function show_help { - cat - <<'EOF' + cat - <<'EOF' Usage: rerun_ci --list rerun_ci [--clean] TARGET_PATH [PARAM=VALUE>]... @@ -28,47 +28,46 @@ EOF case "$1" in "--list") - mapfile -t images < <(docker images -q "industrial-ci/rerun_ci/*") - exec docker image inspect --format '{{index .RepoTags 0}} - {{.Comment}}' "${images[@]}" 2> /dev/null + mapfile -t images < <(docker images -q "industrial-ci/rerun_ci/*") + exec docker image inspect --format '{{index .RepoTags 0}} - {{.Comment}}' "${images[@]}" 2>/dev/null ;; "--rm") - remove=true - shift + remove=true + shift ;; "--clean") - clean=true - shift + clean=true + shift ;; "-h" | "--help" | "") - show_help - exit 0 + show_help + exit 0 ;; esac if [ ! -d "$1" ]; then - show_help - exit 1 + show_help + exit 1 fi repo_dir=$(cd "$1" && pwd) shift DOCKER_COMMIT_MSG="$repo_dir $*" -env_hash=$(sha256sum <<< "$DOCKER_COMMIT_MSG") +env_hash=$(sha256sum <<<"$DOCKER_COMMIT_MSG") DOCKER_COMMIT="industrial-ci/rerun_ci/$(basename "$repo_dir"):${env_hash:0:12}" if [ "$remove" ]; then - exec docker rmi "$DOCKER_COMMIT" + exec docker rmi "$DOCKER_COMMIT" elif [ "$clean" ]; then - docker rmi "$DOCKER_COMMIT" + docker rmi "$DOCKER_COMMIT" fi - force_env=("DOCKER_COMMIT=$DOCKER_COMMIT" "DOCKER_COMMIT_MSG=$DOCKER_COMMIT_MSG") keep_env=("DOCKER_PORT=$DOCKER_PORT" "HOME=$HOME" "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" "TERM=$TERM") -if docker image inspect "$DOCKER_COMMIT" &> /dev/null; then - force_env+=("DOCKER_IMAGE=$DOCKER_COMMIT" "DOCKER_PULL=false") +if docker image inspect "$DOCKER_COMMIT" &>/dev/null; then + force_env+=("DOCKER_IMAGE=$DOCKER_COMMIT" "DOCKER_PULL=false") fi env -i "${keep_env[@]}" "$script_dir/run_ci" "$repo_dir" "$@" "${force_env[@]}" || ret=$? diff --git a/industrial_ci/scripts/run_ci b/industrial_ci/scripts/run_ci index b0e36dc56..d69fec307 100755 --- a/industrial_ci/scripts/run_ci +++ b/industrial_ci/scripts/run_ci @@ -15,7 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" if [ -n "$1" ] && [[ ! "$1" =~ "=" ]]; then if [ -d "$1" ]; then @@ -39,7 +39,10 @@ if [ -f "$script_dir/../src/ci_main.sh" ]; then # devel space elif [ -f "$script_dir/../../share/industrial_ci/src/ci_main.sh" ]; then # install space ci_dir="$script_dir/../../share/industrial_ci/" else - ci_dir=$(python2 -c "import rospkg; print rospkg.RosPack().get_path('industrial_ci')" 2>/dev/null) || { echo "could not find ci_main.sh"; exit 1; } + ci_dir=$(python2 -c "import rospkg; print rospkg.RosPack().get_path('industrial_ci')" 2>/dev/null) || { + echo "could not find ci_main.sh" + exit 1 + } fi env "$@" /bin/bash "$ci_dir/src/ci_main.sh" diff --git a/industrial_ci/src/builders/catkin_make.sh b/industrial_ci/src/builders/catkin_make.sh index 040a53e31..7bc868237 100644 --- a/industrial_ci/src/builders/catkin_make.sh +++ b/industrial_ci/src/builders/catkin_make.sh @@ -29,23 +29,29 @@ function builder_setup { } function builder_run_build { - local extend=$1; shift - local ws=$1; shift + local extend=$1 + shift + local ws=$1 + shift local opts=() _append_job_opts opts PARALLEL_BUILDS 0 ici_exec_in_workspace "$extend" "$ws" catkin_make --make-args install "${opts[@]}" "$@" } function builder_run_tests { - local extend=$1; shift - local ws=$1; shift + local extend=$1 + shift + local ws=$1 + shift local opts=() _append_job_opts opts PARALLEL_TESTS 1 ici_exec_in_workspace "$extend" "$ws" catkin_make --make-args run_tests "${opts[@]}" "$@" } function builder_test_results { - local extend=$1; shift - local ws=$1; shift + local extend=$1 + shift + local ws=$1 + shift ici_exec_in_workspace "$extend" "$ws" catkin_test_results --verbose } diff --git a/industrial_ci/src/builders/catkin_make_isolated.sh b/industrial_ci/src/builders/catkin_make_isolated.sh index 361c652c4..914885c78 100644 --- a/industrial_ci/src/builders/catkin_make_isolated.sh +++ b/industrial_ci/src/builders/catkin_make_isolated.sh @@ -24,11 +24,14 @@ function _append_job_opts() { fi } -function _run_catkin_make_isolated () { - local target=$1; shift - local extend=$1; shift - local ws=$1; shift - ici_exec_in_workspace "$extend" "$ws" catkin_make_isolated --build-space "$ws/build" --install-space "$ws/install" --make-args "$target" "$@" +function _run_catkin_make_isolated() { + local target=$1 + shift + local extend=$1 + shift + local ws=$1 + shift + ici_exec_in_workspace "$extend" "$ws" catkin_make_isolated --build-space "$ws/build" --install-space "$ws/install" --make-args "$target" "$@" } function builder_setup { @@ -48,7 +51,9 @@ function builder_run_tests { } function builder_test_results { - local extend=$1; shift - local ws=$1; shift + local extend=$1 + shift + local ws=$1 + shift ici_exec_in_workspace "$extend" "$ws" catkin_test_results --verbose } diff --git a/industrial_ci/src/builders/catkin_tools.sh b/industrial_ci/src/builders/catkin_tools.sh index 038e5b5f2..8003b707f 100644 --- a/industrial_ci/src/builders/catkin_tools.sh +++ b/industrial_ci/src/builders/catkin_tools.sh @@ -27,37 +27,43 @@ function _append_job_opts() { } function builder_setup { - ici_install_pkgs_for_command catkin "${PYTHON_VERSION_NAME}-catkin-tools" "ros-$ROS_DISTRO-catkin" + ici_install_pkgs_for_command catkin "${PYTHON_VERSION_NAME}-catkin-tools" "ros-$ROS_DISTRO-catkin" } function builder_run_build { - local extend=$1; shift - local ws=$1; shift + local extend=$1 + shift + local ws=$1 + shift local opts=() if [ "${VERBOSE_OUTPUT:-false}" != false ]; then opts+=("-vi") fi _append_job_opts opts PARALLEL_BUILDS 0 ici_exec_in_workspace "$extend" "$ws" catkin config --install - ici_exec_in_workspace "$extend" "$ws" catkin build "${opts[@]}" --summarize --no-status "$@" + ici_exec_in_workspace "$extend" "$ws" catkin build "${opts[@]}" --summarize --no-status "$@" } function builder_run_tests { - local extend=$1; shift - local ws=$1; shift + local extend=$1 + shift + local ws=$1 + shift local opts=() if [ "${VERBOSE_TESTS:-false}" != false ]; then - opts+=(-v) - fi - if [ "$IMMEDIATE_TEST_OUTPUT" == true ]; then - opts+=(-i) + opts+=(-v) + fi + if [ "$IMMEDIATE_TEST_OUTPUT" == true ]; then + opts+=(-i) fi _append_job_opts opts PARALLEL_TESTS 1 ici_exec_in_workspace "$extend" "$ws" catkin build --catkin-make-args run_tests -- "${opts[@]}" --no-status } function builder_test_results { - local extend=$1; shift - local ws=$1; shift + local extend=$1 + shift + local ws=$1 + shift ici_exec_in_workspace "$extend" "$ws" catkin_test_results --verbose } diff --git a/industrial_ci/src/builders/colcon.sh b/industrial_ci/src/builders/colcon.sh index 0b82ede95..d63d4da47 100644 --- a/industrial_ci/src/builders/colcon.sh +++ b/industrial_ci/src/builders/colcon.sh @@ -26,8 +26,10 @@ function builder_setup { } function builder_run_build { - local extend=$1; shift - local ws=$1; shift + local extend=$1 + shift + local ws=$1 + shift local opts=(--event-handlers "${_colcon_event_handlers[@]}") local jobs ici_parse_jobs jobs PARALLEL_BUILDS 0 @@ -40,8 +42,10 @@ function builder_run_build { } function builder_run_tests { - local extend=$1; shift - local ws=$1; shift + local extend=$1 + shift + local ws=$1 + shift local output_handler if [ "$IMMEDIATE_TEST_OUTPUT" == true ]; then output_handler="console_direct+" @@ -56,11 +60,13 @@ function builder_run_tests { elif [ "$jobs" -gt 1 ]; then opts+=(--executor parallel --parallel-workers "$jobs") fi - ici_exec_in_workspace "$extend" "$ws" colcon test "${opts[@]}" + ici_exec_in_workspace "$extend" "$ws" colcon test "${opts[@]}" } function builder_test_results { - local extend=$1; shift - local ws=$1; shift + local extend=$1 + shift + local ws=$1 + shift ici_exec_in_workspace "$extend" "$ws" colcon test-result --verbose } diff --git a/industrial_ci/src/ci_main.sh b/industrial_ci/src/ci_main.sh index db227bda7..3d11802f9 100644 --- a/industrial_ci/src/ci_main.sh +++ b/industrial_ci/src/ci_main.sh @@ -23,8 +23,9 @@ set -e # exit script on errors [[ "${BASH_VERSINFO[0]}_${BASH_VERSINFO[1]}" < "4_4" ]] || set -u -export ICI_SRC_PATH; ICI_SRC_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # The path on CI service (e.g. Travis CI) to industrial_ci src dir. - _CLEANUP="" +export ICI_SRC_PATH +ICI_SRC_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # The path on CI service (e.g. Travis CI) to industrial_ci src dir. +_CLEANUP="" # shellcheck source=industrial_ci/src/env.sh source "${ICI_SRC_PATH}/env.sh" @@ -42,11 +43,11 @@ source "${ICI_SRC_PATH}/ros.sh" trap ici_exit EXIT # install industrial_ci exit handler export ISOLATION=${ISOLATION:-docker} -if [ "${CI:-}" != true ] ; then - if [ "${ISOLATION}" = "shell" ]; then - ici_warn 'ISOLATION=shell needs CI=true, falling back to ISOLATION=docker' - fi - ISOLATION=docker +if [ "${CI:-}" != true ]; then + if [ "${ISOLATION}" = "shell" ]; then + ici_warn 'ISOLATION=shell needs CI=true, falling back to ISOLATION=docker' + fi + ISOLATION=docker fi ici_source_component ISOLATION isolation @@ -54,15 +55,15 @@ ici_configure_ros # Start prerelease, and once it finishs then finish this script too. if [ "$PRERELEASE" = true ]; then - TEST=ros_prerelease + TEST=ros_prerelease elif [ -n "$ABICHECK_URL" ]; then - TEST=abi_check + TEST=abi_check elif [ -n "$CLANG_FORMAT_CHECK" ]; then - TEST=clang_format_check + TEST=clang_format_check elif [ "$BLACK_CHECK" = true ]; then - TEST=black_check + TEST=black_check elif [ -z "$TEST" ]; then - TEST=source_tests + TEST=source_tests fi ici_source_component TEST tests diff --git a/industrial_ci/src/deprecated.sh b/industrial_ci/src/deprecated.sh index ac42bc48c..ebaaa0f7f 100644 --- a/industrial_ci/src/deprecated.sh +++ b/industrial_ci/src/deprecated.sh @@ -47,48 +47,48 @@ ici_mark_deprecated UBUNTU_OS_CODE_NAME "Was renamed to OS_CODE_NAME." ici_mark_deprecated DEFAULT_DOCKER_IMAGE "Official ROS Docker images are not the default anymore" if [ -n "${USE_MOCKUP:-}" ]; then - if [ -z "$TARGET_WORKSPACE" ]; then - export TARGET_WORKSPACE="$USE_MOCKUP" - ici_warn "Replacing 'USE_MOCKUP=$USE_MOCKUP' with 'TARGET_WORKSPACE=$TARGET_WORKSPACE'" - else - ici_error "USE_MOCKUP is not supported anymore, please migrate to 'TARGET_WORKSPACE=$TARGET_WORKSPACE $USE_MOCKUP'" - fi + if [ -z "$TARGET_WORKSPACE" ]; then + export TARGET_WORKSPACE="$USE_MOCKUP" + ici_warn "Replacing 'USE_MOCKUP=$USE_MOCKUP' with 'TARGET_WORKSPACE=$TARGET_WORKSPACE'" + else + ici_error "USE_MOCKUP is not supported anymore, please migrate to 'TARGET_WORKSPACE=$TARGET_WORKSPACE $USE_MOCKUP'" + fi fi # legacy support for UPSTREAM_WORKSPACE and USE_DEB if [ "${UPSTREAM_WORKSPACE:-}" = "debian" ]; then - ici_warn "Setting 'UPSTREAM_WORKSPACE=debian' is superfluous and gets removed" - unset UPSTREAM_WORKSPACE + ici_warn "Setting 'UPSTREAM_WORKSPACE=debian' is superfluous and gets removed" + unset UPSTREAM_WORKSPACE fi if [ "${USE_DEB:-}" = true ]; then - if [ "${UPSTREAM_WORKSPACE:-debian}" != "debian" ]; then - ici_error "USE_DEB and UPSTREAM_WORKSPACE are in conflict" - fi - ici_warn "Setting 'USE_DEB=true' is superfluous" + if [ "${UPSTREAM_WORKSPACE:-debian}" != "debian" ]; then + ici_error "USE_DEB and UPSTREAM_WORKSPACE are in conflict" + fi + ici_warn "Setting 'USE_DEB=true' is superfluous" fi if [ "${UPSTREAM_WORKSPACE:-}" = "file" ] || [ "${USE_DEB:-true}" != true ]; then - ROSINSTALL_FILENAME="${ROSINSTALL_FILENAME:-.travis.rosinstall}" - if [ -f "$TARGET_REPO_PATH/$ROSINSTALL_FILENAME.${ROS_DISTRO:?ROS_DISTRO not set}" ]; then - ROSINSTALL_FILENAME="$ROSINSTALL_FILENAME.$ROS_DISTRO" - fi + ROSINSTALL_FILENAME="${ROSINSTALL_FILENAME:-.travis.rosinstall}" + if [ -f "$TARGET_REPO_PATH/$ROSINSTALL_FILENAME.${ROS_DISTRO:?ROS_DISTRO not set}" ]; then + ROSINSTALL_FILENAME="$ROSINSTALL_FILENAME.$ROS_DISTRO" + fi - if [ "${USE_DEB:-true}" != true ]; then # means UPSTREAM_WORKSPACE=file - if [ "${UPSTREAM_WORKSPACE:-file}" != "file" ]; then - ici_error "USE_DEB and UPSTREAM_WORKSPACE are in conflict" - fi - ici_warn "Replacing 'USE_DEB=false' with 'UPSTREAM_WORKSPACE=$ROSINSTALL_FILENAME'" - else - ici_warn "Replacing 'UPSTREAM_WORKSPACE=file' with 'UPSTREAM_WORKSPACE=$ROSINSTALL_FILENAME'" - fi - export UPSTREAM_WORKSPACE="$ROSINSTALL_FILENAME" + if [ "${USE_DEB:-true}" != true ]; then # means UPSTREAM_WORKSPACE=file + if [ "${UPSTREAM_WORKSPACE:-file}" != "file" ]; then + ici_error "USE_DEB and UPSTREAM_WORKSPACE are in conflict" + fi + ici_warn "Replacing 'USE_DEB=false' with 'UPSTREAM_WORKSPACE=$ROSINSTALL_FILENAME'" + else + ici_warn "Replacing 'UPSTREAM_WORKSPACE=file' with 'UPSTREAM_WORKSPACE=$ROSINSTALL_FILENAME'" + fi + export UPSTREAM_WORKSPACE="$ROSINSTALL_FILENAME" fi if [ "${DOCKER_PULL:-true}" = true ]; then - ici_migrate_hook prepare_docker_image pull_docker_image + ici_migrate_hook prepare_docker_image pull_docker_image else - ici_removed_hook prepare_docker_image "Hook 'prepare_docker_image' got removed." + ici_removed_hook prepare_docker_image "Hook 'prepare_docker_image' got removed." fi ici_mark_deprecated DOCKER_COMMIT_CREDENTIALS "Credentials will be copied, but never committed!" diff --git a/industrial_ci/src/env.sh b/industrial_ci/src/env.sh index e70318d2f..a6ee6de93 100644 --- a/industrial_ci/src/env.sh +++ b/industrial_ci/src/env.sh @@ -67,7 +67,7 @@ export PRERELEASE=${PRERELEASE:-false} case "${OS_CODE_NAME-}" in # https://wiki.debian.org/DebianReleases#Production_Releases -"jessie"|"stretch"|"buster"|"bullseye"|"bookwork"|"trixie") +"jessie" | "stretch" | "buster" | "bullseye" | "bookwork" | "trixie") export OS_NAME=debian ;; *) diff --git a/industrial_ci/src/folding/github_actions.sh b/industrial_ci/src/folding/github_actions.sh index 1c4989593..141e110d5 100644 --- a/industrial_ci/src/folding/github_actions.sh +++ b/industrial_ci/src/folding/github_actions.sh @@ -15,12 +15,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -function ici_start_fold() { +function ici_start_fold() { shift 3 echo -en "##[group]" } -function ici_end_fold() { +function ici_end_fold() { shift 4 echo -e "##[endgroup]" } diff --git a/industrial_ci/src/folding/gitlab.sh b/industrial_ci/src/folding/gitlab.sh index 90b2a52dc..17f8d824f 100644 --- a/industrial_ci/src/folding/gitlab.sh +++ b/industrial_ci/src/folding/gitlab.sh @@ -15,17 +15,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -function ici_start_fold() { +function ici_start_fold() { + shift + local name=$1 + shift + local start=$1 shift - local name=$1; shift - local start=$1; shift ici_ansi_cleared_line "section_start:${start::-9}:$name" } -function ici_end_fold() { +function ici_end_fold() { + shift + local name=$1 + shift shift - local name=$1; shift + local end=$1 shift - local end=$1; shift ici_ansi_cleared_line "section_end:${end::-9}:$name" } diff --git a/industrial_ci/src/folding/none.sh b/industrial_ci/src/folding/none.sh index b034f0304..57d39b40e 100644 --- a/industrial_ci/src/folding/none.sh +++ b/industrial_ci/src/folding/none.sh @@ -15,10 +15,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -function ici_start_fold() { +function ici_start_fold() { shift 3 } -function ici_end_fold() { +function ici_end_fold() { shift 4 } diff --git a/industrial_ci/src/folding/travis.sh b/industrial_ci/src/folding/travis.sh index ffb309e10..e5ca46fc2 100644 --- a/industrial_ci/src/folding/travis.sh +++ b/industrial_ci/src/folding/travis.sh @@ -15,20 +15,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -function ici_start_fold() { - local tag=$1; shift - local name=$1; shift - local start=$1; shift +function ici_start_fold() { + local tag=$1 + shift + local name=$1 + shift + local start=$1 + shift ici_ansi_cleared_line "travis_fold:start:$name" ici_ansi_cleared_line "travis_time:start:$tag" } -function ici_end_fold() { - local tag=$1; shift - local name=$1; shift - local start=$1; shift - local end=$1; shift +function ici_end_fold() { + local tag=$1 + shift + local name=$1 + shift + local start=$1 + shift + local end=$1 + shift ici_ansi_cleared_line "travis_time:end:$tag:start=$start,finish=$end,duration=$((end - start))" ici_ansi_cleared_line "travis_fold:end:$name" } diff --git a/industrial_ci/src/isolation/docker.sh b/industrial_ci/src/isolation/docker.sh index a760cf32f..41ec48dcd 100644 --- a/industrial_ci/src/isolation/docker.sh +++ b/industrial_ci/src/isolation/docker.sh @@ -22,30 +22,30 @@ export DOCKER_PULL=${DOCKER_PULL:-true} # ici_forward_mount VARNAME/FILE rw/ro [PATH] function ici_forward_mount() { - local p=$1 - local v= - if ! [ -e "$1" ]; then - v=$1 - p=${!1:-} - fi - if [ -n "$p" ]; then - local p_abs - p_abs=$(readlink -m "$p") - local p_inner=${3:-$p_abs} - _docker_run_opts+=(-v "$p_abs:$p_inner:$2") - if [ -n "$v" ]; then - ici_forward_variable "$v" "$p_inner" + local p=$1 + local v= + if ! [ -e "$1" ]; then + v=$1 + p=${!1:-} + fi + if [ -n "$p" ]; then + local p_abs + p_abs=$(readlink -m "$p") + local p_inner=${3:-$p_abs} + _docker_run_opts+=(-v "$p_abs:$p_inner:$2") + if [ -n "$v" ]; then + ici_forward_variable "$v" "$p_inner" + fi fi - fi } # ici_forward_variable VARNAME [VALUE] function ici_forward_variable() { - if [ -n "${2-}" ]; then - _docker_run_opts+=(-e "$1=$2") - else - _docker_run_opts+=(-e "$1") - fi + if [ -n "${2-}" ]; then + _docker_run_opts+=(-e "$1=$2") + else + _docker_run_opts+=(-e "$1") + fi } ####################################### @@ -61,57 +61,58 @@ function ici_forward_variable() { # (None) ####################################### function ici_isolate() { - local file=${1}; shift - - if [ "${DOCKER_IMAGE-x}" = "" ]; then - ici_error "Empty string passed to DOCKER_IMAGE. Specify a valid docker image or unset the environment variable to use the default image." - fi - - if [ -n "${OS_CODE_NAME-}" ]; then - DOCKER_IMAGE=${DOCKER_IMAGE:-${OS_NAME}:$OS_CODE_NAME} # scheme works for all supported OS images - elif [ -z "${DOCKER_IMAGE-}" ]; then - ici_error "Please set ROS_DISTRO, OS_CODE_NAME or DOCKER_IMAGE." - fi - - if [ "$DOCKER_PULL" != false ]; then - ici_run "pull_docker_image" docker pull "$DOCKER_IMAGE" - fi - - if [ -z "${ROS_DISTRO:-}" ]; then - ROS_DISTRO=$(docker image inspect --format "{{.Config.Env}}" "${DOCKER_IMAGE}" | grep -o -P "(?<=ROS_DISTRO=)[a-z]*") || ici_error "ROS_DISTRO is not set" - elif [ "${ROS_DISTRO}" = "false" ]; then - unset ROS_DISTRO - fi - - if [ -n "${BASEDIR:-}" ]; then - # $BASEDIR is most-likely contained in $TARGET_REPO_PATH - # copy target repo to temporary folder first - local tmp_src - ici_make_temp_dir tmp_src - cp -a "$TARGET_REPO_PATH" "$tmp_src/" - export TARGET_REPO_PATH; - TARGET_REPO_PATH="$tmp_src/$(basename "$TARGET_REPO_PATH")" - fi - - ici_forward_mount TARGET_REPO_PATH ro - ici_forward_mount ICI_SRC_PATH ro - ici_forward_mount BASEDIR rw - ici_forward_mount CCACHE_DIR rw - ici_forward_mount SSH_AUTH_SOCK rw # forward ssh agent into docker container - - local run_opts - ici_parse_env_array run_opts DOCKER_RUN_OPTS - - for hook in $(env | grep -o '^\(BEFORE\|AFTER\)_[^=]*'); do - ici_forward_variable "$hook" - done - - ici_run_cmd_in_docker "${_docker_run_opts[@]}" "${run_opts[@]}" \ - -t \ - --entrypoint '' \ - -w "$TARGET_REPO_PATH" \ - "$DOCKER_IMAGE" \ - /bin/bash "$ICI_SRC_PATH/run.sh" "$file" "$@" + local file=${1} + shift + + if [ "${DOCKER_IMAGE-x}" = "" ]; then + ici_error "Empty string passed to DOCKER_IMAGE. Specify a valid docker image or unset the environment variable to use the default image." + fi + + if [ -n "${OS_CODE_NAME-}" ]; then + DOCKER_IMAGE=${DOCKER_IMAGE:-${OS_NAME}:$OS_CODE_NAME} # scheme works for all supported OS images + elif [ -z "${DOCKER_IMAGE-}" ]; then + ici_error "Please set ROS_DISTRO, OS_CODE_NAME or DOCKER_IMAGE." + fi + + if [ "$DOCKER_PULL" != false ]; then + ici_run "pull_docker_image" docker pull "$DOCKER_IMAGE" + fi + + if [ -z "${ROS_DISTRO:-}" ]; then + ROS_DISTRO=$(docker image inspect --format "{{.Config.Env}}" "${DOCKER_IMAGE}" | grep -o -P "(?<=ROS_DISTRO=)[a-z]*") || ici_error "ROS_DISTRO is not set" + elif [ "${ROS_DISTRO}" = "false" ]; then + unset ROS_DISTRO + fi + + if [ -n "${BASEDIR:-}" ]; then + # $BASEDIR is most-likely contained in $TARGET_REPO_PATH + # copy target repo to temporary folder first + local tmp_src + ici_make_temp_dir tmp_src + cp -a "$TARGET_REPO_PATH" "$tmp_src/" + export TARGET_REPO_PATH + TARGET_REPO_PATH="$tmp_src/$(basename "$TARGET_REPO_PATH")" + fi + + ici_forward_mount TARGET_REPO_PATH ro + ici_forward_mount ICI_SRC_PATH ro + ici_forward_mount BASEDIR rw + ici_forward_mount CCACHE_DIR rw + ici_forward_mount SSH_AUTH_SOCK rw # forward ssh agent into docker container + + local run_opts + ici_parse_env_array run_opts DOCKER_RUN_OPTS + + for hook in $(env | grep -o '^\(BEFORE\|AFTER\)_[^=]*'); do + ici_forward_variable "$hook" + done + + ici_run_cmd_in_docker "${_docker_run_opts[@]}" "${run_opts[@]}" \ + -t \ + --entrypoint '' \ + -w "$TARGET_REPO_PATH" \ + "$DOCKER_IMAGE" \ + /bin/bash "$ICI_SRC_PATH/run.sh" "$file" "$@" } ####################################### # wrapper for running a command in docker @@ -129,63 +130,63 @@ function ici_isolate() { # (None) ####################################### function ici_run_cmd_in_docker() { - local credentials=() - ici_parse_env_array credentials DOCKER_CREDENTIALS - local to_copy=() - local cleanup="" - - for d in "${credentials[@]}"; do - if [ -d "$HOME/$d" ]; then - to_copy+=(~/"$d") - # shellcheck disable=SC2088 - cleanup=$(ici_join_array : "$cleanup" "~/$d") + local credentials=() + ici_parse_env_array credentials DOCKER_CREDENTIALS + local to_copy=() + local cleanup="" + + for d in "${credentials[@]}"; do + if [ -d "$HOME/$d" ]; then + to_copy+=(~/"$d") + # shellcheck disable=SC2088 + cleanup=$(ici_join_array : "$cleanup" "~/$d") + fi + done + + local opts=(--env-file "${ICI_SRC_PATH}/isolation/docker.env") + if [ -z "$DOCKER_COMMIT" ]; then + opts+=(--rm) + else + opts+=(-e "_CLEANUP=$cleanup") fi - done - - local opts=(--env-file "${ICI_SRC_PATH}/isolation/docker.env") - if [ -z "$DOCKER_COMMIT" ]; then - opts+=(--rm) - else - opts+=(-e "_CLEANUP=$cleanup") - fi - - local cid - cid=$(docker create "${opts[@]}" "$@") - - # detect user inside container - local image - image=$(docker inspect --format='{{.Config.Image}}' "$cid") - local docker_query=() - # shellcheck disable=SC2016 - IFS=" " read -r -a docker_query <<< "$(docker run --rm --entrypoint '/bin/sh' "$image" -c 'echo "$(id -u) $(id -g) $HOME"')" - - # pass common credentials to container - for d in "${to_copy[@]}"; do - ici_warn "Copy credentials: $d" - docker_cp "$d" "$cid:${docker_query[*]:2}/" "${docker_query[0]}" "${docker_query[1]}" - done - - docker start -a "$cid" & - trap 'docker kill --signal=SIGTERM $cid' INT - local ret=0 - wait %% || ret=$? - trap - INT - if [ -n "$DOCKER_COMMIT" ]; then - echo "Committing container to tag: '$DOCKER_COMMIT'" - local msg=() - if [ -n "$DOCKER_COMMIT_MSG" ]; then - msg=(-m "$DOCKER_COMMIT_MSG") + + local cid + cid=$(docker create "${opts[@]}" "$@") + + # detect user inside container + local image + image=$(docker inspect --format='{{.Config.Image}}' "$cid") + local docker_query=() + # shellcheck disable=SC2016 + IFS=" " read -r -a docker_query <<<"$(docker run --rm --entrypoint '/bin/sh' "$image" -c 'echo "$(id -u) $(id -g) $HOME"')" + + # pass common credentials to container + for d in "${to_copy[@]}"; do + ici_warn "Copy credentials: $d" + docker_cp "$d" "$cid:${docker_query[*]:2}/" "${docker_query[0]}" "${docker_query[1]}" + done + + docker start -a "$cid" & + trap 'docker kill --signal=SIGTERM $cid' INT + local ret=0 + wait %% || ret=$? + trap - INT + if [ -n "$DOCKER_COMMIT" ]; then + echo "Committing container to tag: '$DOCKER_COMMIT'" + local msg=() + if [ -n "$DOCKER_COMMIT_MSG" ]; then + msg=(-m "$DOCKER_COMMIT_MSG") + fi + ici_quiet docker commit "${msg[@]}" "$cid" "$DOCKER_COMMIT" + ici_quiet docker rm "$cid" fi - ici_quiet docker commit "${msg[@]}" "$cid" "$DOCKER_COMMIT" - ici_quiet docker rm "$cid" - fi - return $ret + return $ret } # work-around for https://github.com/moby/moby/issues/34096 # ensures that copied files are owned by the target user function docker_cp { - set -o pipefail - tar --numeric-owner --owner="${3:-root}" --group="${4:-root}" -c -f - -C "$(dirname "$1")" "$(basename "$1")" | docker cp - "$2" - set +o pipefail + set -o pipefail + tar --numeric-owner --owner="${3:-root}" --group="${4:-root}" -c -f - -C "$(dirname "$1")" "$(basename "$1")" | docker cp - "$2" + set +o pipefail } diff --git a/industrial_ci/src/isolation/shell.sh b/industrial_ci/src/isolation/shell.sh index 6abf2c207..116e2ee58 100644 --- a/industrial_ci/src/isolation/shell.sh +++ b/industrial_ci/src/isolation/shell.sh @@ -17,27 +17,27 @@ # ici_forward_mount VARNAME/FILE rw/ro [PATH] function ici_forward_mount() { - true + true } # ici_forward_variable VARNAME [VALUE] function ici_forward_variable() { - if [ -n "${2-}" ]; then - export "$1"="$2" - fi + if [ -n "${2-}" ]; then + export "$1"="$2" + fi } function ici_isolate { - if [ "${CI:-}" != true ] ; then - ici_error 'ISOLATION=shell needs CI=true' - fi - if [ -z "${ROS_DISTRO:-}" ]; then - ici_error "ROS_DISTRO is not set" - elif [ "${ROS_DISTRO}" = "false" ]; then - unset ROS_DISTRO - fi - if [ -n "${BASEDIR-}" ]; then - mkdir -p "$BASEDIR" - fi - "${ICI_SRC_PATH}/run.sh" "$@" + if [ "${CI:-}" != true ]; then + ici_error 'ISOLATION=shell needs CI=true' + fi + if [ -z "${ROS_DISTRO:-}" ]; then + ici_error "ROS_DISTRO is not set" + elif [ "${ROS_DISTRO}" = "false" ]; then + unset ROS_DISTRO + fi + if [ -n "${BASEDIR-}" ]; then + mkdir -p "$BASEDIR" + fi + "${ICI_SRC_PATH}/run.sh" "$@" } diff --git a/industrial_ci/src/ros.sh b/industrial_ci/src/ros.sh index a53795007..7eae8ca94 100644 --- a/industrial_ci/src/ros.sh +++ b/industrial_ci/src/ros.sh @@ -16,7 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -function _ros1_defaults { +function _ros1_defaults { export OS_CODE_NAME=${OS_CODE_NAME:-$1} export ROS1_DISTRO=${ROS1_DISTRO:-$ROS_DISTRO} export BUILDER=${BUILDER:-catkin_tools} @@ -25,7 +25,7 @@ function _ros1_defaults { export ROS_PYTHON_VERSION=${ROS_PYTHON_VERSION:-2} } -function _ros2_defaults { +function _ros2_defaults { export OS_CODE_NAME=${OS_CODE_NAME:-$1} export ROS2_DISTRO=${ROS2_DISTRO:-$ROS_DISTRO} export BUILDER=${BUILDER:-colcon} @@ -36,7 +36,7 @@ function _ros2_defaults { function _set_ros_defaults { case "$ROS_DISTRO" in - "indigo"|"jade") + "indigo" | "jade") _ros1_defaults "trusty" export ROS_VERSION_EOL=true ;; @@ -59,7 +59,7 @@ function _set_ros_defaults { _ros2_defaults "xenial" export ROS_VERSION_EOL=true ;; - "bouncy"|"crystal") + "bouncy" | "crystal") _ros2_defaults "bionic" export ROS_VERSION_EOL=true ;; @@ -142,7 +142,7 @@ function _set_ros_package_path { "testing") _use_repo_or_final_snapshot "http://packages.ros.org/$(_get_prefix)-testing/ubuntu" ;; - "ros-shadow-fixed"|"ros-testing") + "ros-shadow-fixed" | "ros-testing") if [ "$ROS_VERSION" -eq 2 ]; then ici_warn "ROS_REPO=$ROS_REPO would select the ROS1 repository, please use ROS_REPO=testing" fi @@ -154,7 +154,7 @@ function _set_ros_package_path { "ros2-testing") _use_repo_or_final_snapshot "http://packages.ros.org/ros2-testing/ubuntu" ;; - "final"|????-??-??) + "final" | ????-??-??) _use_snapshot "${ROS_REPO}" ;; *) diff --git a/industrial_ci/src/run.sh b/industrial_ci/src/run.sh index 9f1866765..49ed911d5 100755 --- a/industrial_ci/src/run.sh +++ b/industrial_ci/src/run.sh @@ -59,7 +59,8 @@ if [ -z "${CPPFLAGS:-}" ]; then unset CPPFLAGS; fi if [ -z "${CXX:-}" ]; then unset CXX; fi if [ -z "${CXXFLAGS:-}" ]; then unset CXXLAGS; fi -TEST=$1; shift +TEST=$1 +shift ici_source_component TEST tests ici_run "init" ici_init_apt diff --git a/industrial_ci/src/tests/abi_check.sh b/industrial_ci/src/tests/abi_check.sh index 56028ba4c..bb89a1223 100644 --- a/industrial_ci/src/tests/abi_check.sh +++ b/industrial_ci/src/tests/abi_check.sh @@ -23,11 +23,13 @@ function _install_universal_ctags() { } function _import_and_make_install() { - local repo=$1; shift - ici_import_repository /tmp "github:$repo.git#master" - local dir; dir=/tmp/$(basename "$repo") - (cd "$dir" && ici_asroot make install prefix=/usr) - rm -rf "$dir" + local repo=$1 + shift + ici_import_repository /tmp "github:$repo.git#master" + local dir + dir=/tmp/$(basename "$repo") + (cd "$dir" && ici_asroot make install prefix=/usr) + rm -rf "$dir" } function _install_vtable_dumper() { @@ -46,115 +48,124 @@ function _install_abi_compliance_checker() { } function abi_install_dumper() { - ici_exec_for_command vtable-dumper ici_quiet _install_vtable_dumper - ici_exec_for_command abi-dumper ici_quiet _install_abi_dumper - ici_exec_for_command ctags ici_quiet _install_universal_ctags + ici_exec_for_command vtable-dumper ici_quiet _install_vtable_dumper + ici_exec_for_command abi-dumper ici_quiet _install_abi_dumper + ici_exec_for_command ctags ici_quiet _install_universal_ctags } function abi_install_compliance_checker() { - ici_exec_for_command abi-compliance-checker ici_quiet _install_abi_compliance_checker + ici_exec_for_command abi-compliance-checker ici_quiet _install_abi_compliance_checker } function abi_dump_libraries() { abi_install_dumper - local extend=$1; shift - local output=$1; shift + local extend=$1 + shift + local output=$1 + shift local ld_library_path ld_library_path=$(ici_source_setup "$extend" && echo "$LD_LIBRARY_PATH") mkdir -p "$output" for d in "$extend"/*/lib "$extend/lib"; do - for l in "$d"/*.so; do - if [ "$l" != "$d/*.so" ]; then - abi-dumper "$l" -ld-library-path "$ld_library_path" -o "$output/$(basename "$l" .so).dump" -public-headers "$d/../include" "$@" - fi - done + for l in "$d"/*.so; do + if [ "$l" != "$d/*.so" ]; then + abi-dumper "$l" -ld-library-path "$ld_library_path" -o "$output/$(basename "$l" .so).dump" -public-headers "$d/../include" "$@" + fi + done done } function abi_process_workspace() { - local extend=$1; shift - local workspace=$1; shift - local tag=$1; shift - local version=${1:-$tag} - - local cflags="-g -Og" - local cmake_args=(--cmake-args "-DCMAKE_C_FLAGS=$cflags" "-DCMAKE_CXX_FLAGS=$cflags") - - ici_run "install_${tag}_dependencies" ici_install_dependencies "$extend" "$ROSDEP_SKIP_KEYS" "$workspace/src" - ici_run "abi_build_${tag}" builder_run_build "$extend" "$workspace" "${cmake_args[@]}" - ici_run "abi_dump_${tag}" abi_dump_libraries "$workspace/install" "$workspace/abi_dumps" -lver "$version" + local extend=$1 + shift + local workspace=$1 + shift + local tag=$1 + shift + local version=${1:-$tag} + + local cflags="-g -Og" + local cmake_args=(--cmake-args "-DCMAKE_C_FLAGS=$cflags" "-DCMAKE_CXX_FLAGS=$cflags") + + ici_run "install_${tag}_dependencies" ici_install_dependencies "$extend" "$ROSDEP_SKIP_KEYS" "$workspace/src" + ici_run "abi_build_${tag}" builder_run_build "$extend" "$workspace" "${cmake_args[@]}" + ici_run "abi_dump_${tag}" abi_dump_libraries "$workspace/install" "$workspace/abi_dumps" -lver "$version" } function abi_configure() { - if [ "$ABICHECK_MERGE" = true ]; then - ici_exec_for_command git ici_error "ABICHECK_MERGE=true needs git client" - local ref_list - if ici_split_array ref_list "$(cd "$TARGET_REPO_PATH" && git rev-list --parents -n 1 HEAD)" && [ "${#ref_list[@]}" -gt 2 ]; then - ABICHECK_VERSION="${ref_list[1]}" - ABICHECK_URL="#${ABICHECK_VERSION}" - else - ici_error "Could not find merge commit for ABI check" + if [ "$ABICHECK_MERGE" = true ]; then + ici_exec_for_command git ici_error "ABICHECK_MERGE=true needs git client" + local ref_list + if ici_split_array ref_list "$(cd "$TARGET_REPO_PATH" && git rev-list --parents -n 1 HEAD)" && [ "${#ref_list[@]}" -gt 2 ]; then + ABICHECK_VERSION="${ref_list[1]}" + ABICHECK_URL="#${ABICHECK_VERSION}" + else + ici_error "Could not find merge commit for ABI check" + fi fi - fi - - if [ -z "$ABICHECK_VERSION" ]; then - if [[ $ABICHECK_URL =~ [@#]([[:alnum:]_.-]+)$ ]]; then - ABICHECK_VERSION=${BASH_REMATCH[1]} - else - local target_ext - target_ext=$(grep -Pio '\.(zip|tar\.\w+|tgz|tbz2)\Z' <<< "${ABICHECK_URL%%\?*}" || echo "") - if [ -n "$target_ext" ]; then - ABICHECK_VERSION=$(basename "$ABICHECK_URL" "$target_ext") + + if [ -z "$ABICHECK_VERSION" ]; then + if [[ $ABICHECK_URL =~ [@#]([[:alnum:]_.-]+)$ ]]; then + ABICHECK_VERSION=${BASH_REMATCH[1]} else - ici_warn "could not determine ABICHECK_VERSION" - ABICHECK_VERSION=unknown + local target_ext + target_ext=$(grep -Pio '\.(zip|tar\.\w+|tgz|tbz2)\Z' <<<"${ABICHECK_URL%%\?*}" || echo "") + if [ -n "$target_ext" ]; then + ABICHECK_VERSION=$(basename "$ABICHECK_URL" "$target_ext") + else + ici_warn "could not determine ABICHECK_VERSION" + ABICHECK_VERSION=unknown + fi fi fi - fi } function abi_report() { - local base_dumps=$1; shift - local target_dumps=$1; shift - local reports_dir=$1; shift - - abi_install_compliance_checker - ici_quiet ici_install_pkgs_for_command links links - - mkdir -p "$reports_dir" - - local broken=() - for n in "$target_dumps"/*.dump; do - local l; l=$(basename "$n" ".dump") - local o="$base_dumps/$l.dump" - if [ -f "$o" ]; then - ici_time_start "abi_check_$l" - local ret=0 - abi-compliance-checker -report-path "$reports_dir/$l.html" -l "$l" -n "$n" -o "$o" || ret=$? - if [ "$ret" -eq "0" ]; then - ici_time_end # abi_check_* - elif [ "$ret" -eq "1" ]; then - links -dump "$reports_dir/$l.html" - broken+=("$l") - ici_time_end "${ANSI_YELLOW}" "$ret" # abi_check_*, yellow - elif [ "$ret" -eq "7" ]; then - ici_warn "'$(basename "$l" .dump)': Invalid input ABI dump. Perhaps this library does not any export symbols." - ici_time_end "${ANSI_YELLOW}" - else - ici_exit "$ret" - fi - fi - done - - if [ "${#broken[@]}" -gt "0" ]; then - ici_error "Broken libraries: ${broken[*]}" - fi + local base_dumps=$1 + shift + local target_dumps=$1 + shift + local reports_dir=$1 + shift + + abi_install_compliance_checker + ici_quiet ici_install_pkgs_for_command links links + + mkdir -p "$reports_dir" + + local broken=() + for n in "$target_dumps"/*.dump; do + local l + l=$(basename "$n" ".dump") + local o="$base_dumps/$l.dump" + if [ -f "$o" ]; then + ici_time_start "abi_check_$l" + local ret=0 + abi-compliance-checker -report-path "$reports_dir/$l.html" -l "$l" -n "$n" -o "$o" || ret=$? + if [ "$ret" -eq "0" ]; then + ici_time_end # abi_check_* + elif [ "$ret" -eq "1" ]; then + links -dump "$reports_dir/$l.html" + broken+=("$l") + ici_time_end "${ANSI_YELLOW}" "$ret" # abi_check_*, yellow + elif [ "$ret" -eq "7" ]; then + ici_warn "'$(basename "$l" .dump)': Invalid input ABI dump. Perhaps this library does not any export symbols." + ici_time_end "${ANSI_YELLOW}" + else + ici_exit "$ret" + fi + fi + done + + if [ "${#broken[@]}" -gt "0" ]; then + ici_error "Broken libraries: ${broken[*]}" + fi } - function prepare_abi_check() { +function prepare_abi_check() { if [ "$ABICHECK_MERGE" = "auto" ]; then ici_error "ABICHECK_MERGE auto mode is available for travis only. " fi @@ -165,7 +176,7 @@ function abi_report() { ici_check_builder abi_configure # handle merge and detect version - } +} function run_abi_check() { if [[ $ABICHECK_URL =~ ^[@#]([[:alnum:]_.-]+)$ ]]; then diff --git a/industrial_ci/src/tests/black_check.sh b/industrial_ci/src/tests/black_check.sh index 0f18666ce..459d8e7c6 100644 --- a/industrial_ci/src/tests/black_check.sh +++ b/industrial_ci/src/tests/black_check.sh @@ -1,16 +1,16 @@ #!/bin/bash function prepare_black_check() { - export DOCKER_IMAGE=${DOCKER_IMAGE:-python:3} - export ROS_DISTRO=${ROS_DISTRO:-false} + export DOCKER_IMAGE=${DOCKER_IMAGE:-python:3} + export ROS_DISTRO=${ROS_DISTRO:-false} } function install_black() { - ici_quiet ici_install_pkgs_for_command pip3 python3-pip python3-setuptools python3-wheel - ici_asroot pip3 install black + ici_quiet ici_install_pkgs_for_command pip3 python3-pip python3-setuptools python3-wheel + ici_asroot pip3 install black } function run_black_check() { - ici_exec_for_command black ici_run install_black install_black - ici_run run_black_check black --check --color --diff --verbose --exclude "/\..*/" "$TARGET_WORKSPACE" # Exclude hidden directories. + ici_exec_for_command black ici_run install_black install_black + ici_run run_black_check black --check --color --diff --verbose --exclude "/\..*/" "$TARGET_WORKSPACE" # Exclude hidden directories. } diff --git a/industrial_ci/src/tests/clang_format_check.sh b/industrial_ci/src/tests/clang_format_check.sh index c0ef3a593..45cb8d677 100644 --- a/industrial_ci/src/tests/clang_format_check.sh +++ b/industrial_ci/src/tests/clang_format_check.sh @@ -16,38 +16,38 @@ # limitations under the License. function prepare_clang_format_check() { - true + true } function run_clang_format_check() { - local err=0 - local path - ici_make_temp_dir path - - # Check whether a specific version of clang-format is desired - local clang_format_executable="clang-format${CLANG_FORMAT_VERSION:+-$CLANG_FORMAT_VERSION}" - - ici_time_start install_clang_format - ici_quiet ici_apt_install git-core "$clang_format_executable" - ici_time_end # install_clang_format - - local sources=() - ici_parse_env_array sources TARGET_WORKSPACE - ici_run "prepare_sourcespace" ici_prepare_sourcespace "$path" "${sources[@]}" - - ici_time_start run_clang_format_check - while read -r file; do - echo "Checking '${file#$path/}'" - if ! $clang_format_executable -style="$CLANG_FORMAT_CHECK" "$file" | git diff --exit-code "$file" - ; then - err=$((err +1)) + local err=0 + local path + ici_make_temp_dir path + + # Check whether a specific version of clang-format is desired + local clang_format_executable="clang-format${CLANG_FORMAT_VERSION:+-$CLANG_FORMAT_VERSION}" + + ici_time_start install_clang_format + ici_quiet ici_apt_install git-core "$clang_format_executable" + ici_time_end # install_clang_format + + local sources=() + ici_parse_env_array sources TARGET_WORKSPACE + ici_run "prepare_sourcespace" ici_prepare_sourcespace "$path" "${sources[@]}" + + ici_time_start run_clang_format_check + while read -r file; do + echo "Checking '${file#$path/}'" + if ! $clang_format_executable -style="$CLANG_FORMAT_CHECK" "$file" | git diff --exit-code "$file" -; then + err=$((err + 1)) + fi + done < <(ici_find_nonhidden "$path" -iname '*.h' -or -iname '*.hpp' -or -iname '*.c' -or -iname '*.cc' -or -iname '*.cpp' -or -iname '*.cxx') + + if [ "$err" -ne "0" ]; then + ici_error "Clang format check failed for $err file(s)." + echo "Changes required to comply to formatting rules. See diff above." + exit 1 fi - done < <(ici_find_nonhidden "$path" -iname '*.h' -or -iname '*.hpp' -or -iname '*.c' -or -iname '*.cc' -or -iname '*.cpp' -or -iname '*.cxx') - - if [ "$err" -ne "0" ]; then - ici_error "Clang format check failed for $err file(s)." - echo "Changes required to comply to formatting rules. See diff above." - exit 1 - fi - echo 'Clang format check went successful.' - ici_time_end # run_clang_format_check + echo 'Clang format check went successful.' + ici_time_end # run_clang_format_check } diff --git a/industrial_ci/src/tests/ros_prerelease.sh b/industrial_ci/src/tests/ros_prerelease.sh index 3c9ce3138..f1f6b4d2e 100644 --- a/industrial_ci/src/tests/ros_prerelease.sh +++ b/industrial_ci/src/tests/ros_prerelease.sh @@ -29,7 +29,7 @@ function setup_ros_prerelease() { ici_asroot useradd -m -d "$WORKSPACE/home" ci if ! [ -d "$WORKSPACE/home/.ccache" ]; then - ici_asroot mkdir -p "$WORKSPACE/home/.ccache" + ici_asroot mkdir -p "$WORKSPACE/home/.ccache" fi if [ -e /var/run/docker.sock ]; then @@ -45,36 +45,37 @@ function setup_ros_prerelease() { } function prepare_prerelease_workspaces() { - local ws_upstream=() - ici_parse_env_array ws_upstream UPSTREAM_WORKSPACE - local ws_target=() - ici_parse_env_array ws_target TARGET_WORKSPACE - local workspace=$1 - local reponame=$2 - local targetname=$3 - ici_with_ws "$workspace/ws" ici_prepare_sourcespace "$workspace/ws/src/" "${ws_upstream[@]}" "${ws_target[@]}" - - if ! [ -d "$workspace/ws/src/$reponame" ]; then - mv "$workspace/ws/src/$targetname" "$workspace/ws/src/$reponame" - fi - - local overlay=() - ici_parse_env_array overlay DOWNSTREAM_WORKSPACE - ici_with_ws "$workspace/ws_overlay" ici_prepare_sourcespace "$workspace/ws_overlay/src/" "${overlay[@]}" - ici_asroot chown -R ci "$workspace" + local ws_upstream=() + ici_parse_env_array ws_upstream UPSTREAM_WORKSPACE + local ws_target=() + ici_parse_env_array ws_target TARGET_WORKSPACE + local workspace=$1 + local reponame=$2 + local targetname=$3 + ici_with_ws "$workspace/ws" ici_prepare_sourcespace "$workspace/ws/src/" "${ws_upstream[@]}" "${ws_target[@]}" + + if ! [ -d "$workspace/ws/src/$reponame" ]; then + mv "$workspace/ws/src/$targetname" "$workspace/ws/src/$reponame" + fi + + local overlay=() + ici_parse_env_array overlay DOWNSTREAM_WORKSPACE + ici_with_ws "$workspace/ws_overlay" ici_prepare_sourcespace "$workspace/ws_overlay/src/" "${overlay[@]}" + ici_asroot chown -R ci "$workspace" } function prepare_ros_prerelease() { if [ "$BUILDER" != "colcon" ]; then export BUILDER=catkin_make_isolated fi - export WORKSPACE; WORKSPACE=$(mktemp -d) + export WORKSPACE + WORKSPACE=$(mktemp -d) if [ -z "${ROSDISTRO_INDEX_URL:-}" ]; then - if [ "$ROS_VERSION" -eq 2 ]; then - export ROSDISTRO_INDEX_URL="https://raw.githubusercontent.com/ros2/ros_buildfarm_config/ros2/index.yaml" - else - export ROSDISTRO_INDEX_URL="https://raw.githubusercontent.com/ros-infrastructure/ros_buildfarm_config/production/index.yaml" - fi + if [ "$ROS_VERSION" -eq 2 ]; then + export ROSDISTRO_INDEX_URL="https://raw.githubusercontent.com/ros2/ros_buildfarm_config/ros2/index.yaml" + else + export ROSDISTRO_INDEX_URL="https://raw.githubusercontent.com/ros-infrastructure/ros_buildfarm_config/production/index.yaml" + fi fi export PRERELEASE_DISTRO="$ROS_DISTRO" @@ -82,7 +83,7 @@ function prepare_ros_prerelease() { for e in TRAVIS OS_NAME OS_CODE_NAME OS_ARCH PRERELEASE_DOWNSTREAM_DEPTH PRERELEASE_REPONAME ROSDISTRO_INDEX_URL PRERELEASE_DISTRO; do ici_forward_variable "$e" done - + ici_forward_mount WORKSPACE rw if [ -n "${DOCKER_PORT:-}" ]; then @@ -91,8 +92,8 @@ function prepare_ros_prerelease() { ici_forward_mount /var/run/docker.sock rw fi if [ -n "${CCACHE_DIR}" ]; then - ici_forward_mount CCACHE_DIR rw "$WORKSPACE/home/.ccache" - CCACHE_DIR= # prevent cachedir from beeing added twice + ici_forward_mount CCACHE_DIR rw "$WORKSPACE/home/.ccache" + CCACHE_DIR= # prevent cachedir from beeing added twice fi export DOCKER_IMAGE=${DOCKER_IMAGE:-ros:noetic-ros-core} export ROS_DISTRO=noetic diff --git a/industrial_ci/src/tests/source_tests.sh b/industrial_ci/src/tests/source_tests.sh index 51041fadb..1c6df82d1 100644 --- a/industrial_ci/src/tests/source_tests.sh +++ b/industrial_ci/src/tests/source_tests.sh @@ -38,8 +38,10 @@ function run_clang_tidy { return 0 fi - local build; build="$(dirname "$db")" - local name; name="$(basename "$build")" + local build + build="$(dirname "$db")" + local name + name="$(basename "$build")" local max_jobs="${CLANG_TIDY_JOBS:-$(nproc)}" if ! [ "$max_jobs" -ge 1 ]; then @@ -47,7 +49,7 @@ function run_clang_tidy { fi rm -rf "$db".{command,warn,error} - cat > "$db.command" << EOF + cat >"$db.command" <&2 ici_color_output ${ANSI_RED} "$1" + ici_color_output >&2 ${ANSI_RED} "$1" fi if [ "$exit_code" == "0" ]; then # 0 is not error ici_exit 1 @@ -257,56 +264,58 @@ function ici_enforce_deprecated { local e=$1 shift if [ "${!e:-}" ]; then - ici_error "'$e' is not used anymore. $*" + ici_error "'$e' is not used anymore. $*" fi } function ici_migrate_hook() { - local oldname=${1^^} - oldname=${oldname//[^A-Z0-9_]/_} - local newname=${2^^} - newname=${newname//[^A-Z0-9_]/_} + local oldname=${1^^} + oldname=${oldname//[^A-Z0-9_]/_} + local newname=${2^^} + newname=${newname//[^A-Z0-9_]/_} - mapfile -t envs < <(env | grep -oE "(BEFORE_|AFTER_)+$oldname(_EMBED)?") + mapfile -t envs < <(env | grep -oE "(BEFORE_|AFTER_)+$oldname(_EMBED)?") - for oldhook in "${envs[@]}"; do - local newhook=${oldhook/$oldname/$newname} - ici_warn "hook '$oldhook' was renamed to '$newhook'." - eval "export $newhook=\$$oldhook" - done + for oldhook in "${envs[@]}"; do + local newhook=${oldhook/$oldname/$newname} + ici_warn "hook '$oldhook' was renamed to '$newhook'." + eval "export $newhook=\$$oldhook" + done } function ici_removed_hook() { - local oldname=${1^^} - shift - oldname=${oldname//[^A-Z0-9_]/_} + local oldname=${1^^} + shift + oldname=${oldname//[^A-Z0-9_]/_} - mapfile -t envs < <(env | grep -oE "(BEFORE_|AFTER_)+$oldname(_EMBED)?") + mapfile -t envs < <(env | grep -oE "(BEFORE_|AFTER_)+$oldname(_EMBED)?") - for oldhook in "${envs[@]}"; do - ici_enforce_deprecated "$oldhook" "$@" - done + for oldhook in "${envs[@]}"; do + ici_enforce_deprecated "$oldhook" "$@" + done } function ici_retry { - local tries=$1; shift - local ret=0 + local tries=$1 + shift + local ret=0 - for ((i=1;i<=tries;i++)); do - "$@" && return 0 - ret=$? - sleep 1; - done + for ((i = 1; i <= tries; i++)); do + "$@" && return 0 + ret=$? + sleep 1 + done - ici_color_output ${ANSI_RED} "'$*' failed $tries times" - return $ret + ici_color_output ${ANSI_RED} "'$*' failed $tries times" + return $ret } function ici_quiet { - local out; out=$(mktemp) + local out + out=$(mktemp) # shellcheck disable=SC2216 # shellcheck disable=SC2260 - "$@" &> "$out" | true # '|| err=$?' disables errexit + "$@" &>"$out" | true # '|| err=$?' disables errexit local err=${PIPESTATUS[0]} if [ "$err" -ne 0 ]; then cat "$out" @@ -316,23 +325,24 @@ function ici_quiet { } function ici_asroot { - if command -v sudo > /dev/null; then - sudo "$@" - else - "$@" - fi + if command -v sudo >/dev/null; then + sudo "$@" + else + "$@" + fi } function ici_exec_for_command { - local command=$1; shift - if ! command -v "$command" > /dev/null; then - "$@" - fi + local command=$1 + shift + if ! command -v "$command" >/dev/null; then + "$@" + fi } function ici_split_array { # shellcheck disable=SC2034 - IFS=" " read -r -a "$1" <<< "$*" + IFS=" " read -r -a "$1" <<<"$*" } function ici_parse_env_array { @@ -341,81 +351,85 @@ function ici_parse_env_array { } function ici_parse_jobs { - local -n _ici_parse_jobs_res=$1 - # shellcheck disable=SC2034 - _ici_parse_jobs_res=${!2:-} - - case "$_ici_parse_jobs_res" in - "") - _ici_parse_jobs_res="$3";; - "true") - _ici_parse_jobs_res="0";; - "false") - _ici_parse_jobs_res="1";; - *) - if ! [[ "$_ici_parse_jobs_res" =~ ^[0-9]+$ ]]; then - ici_error "cannot parse $2=$_ici_parse_jobs_res as a number" - fi - ;; - esac + local -n _ici_parse_jobs_res=$1 + # shellcheck disable=SC2034 + _ici_parse_jobs_res=${!2:-} + + case "$_ici_parse_jobs_res" in + "") + _ici_parse_jobs_res="$3" + ;; + "true") + _ici_parse_jobs_res="0" + ;; + "false") + _ici_parse_jobs_res="1" + ;; + *) + if ! [[ "$_ici_parse_jobs_res" =~ ^[0-9]+$ ]]; then + ici_error "cannot parse $2=$_ici_parse_jobs_res as a number" + fi + ;; + esac } function ici_find_nonhidden { - local path=$1; shift - local args=() - if [ $# -gt 0 ]; then - args=(-a \( "$@" \)) - fi - find "$path" \( \! \( -path "${path}*/.*" -prune \) \) "${args[@]}" + local path=$1 + shift + local args=() + if [ $# -gt 0 ]; then + args=(-a \( "$@" \)) + fi + find "$path" \( \! \( -path "${path}*/.*" -prune \) \) "${args[@]}" } function ici_resolve_component { - local label=$1 - local group=$2 - for file in "${TARGET_REPO_PATH}/${!label}" "${ICI_SRC_PATH}/$group/${!label}.sh"; do - if [ -f "$file" ]; then - echo "$file" - return - fi - done - ici_error "$label '${!label}' not found" + local label=$1 + local group=$2 + for file in "${TARGET_REPO_PATH}/${!label}" "${ICI_SRC_PATH}/$group/${!label}.sh"; do + if [ -f "$file" ]; then + echo "$file" + return + fi + done + ici_error "$label '${!label}' not found" } function ici_source_component { - local script - script=$(ici_resolve_component "$@") - # shellcheck disable=SC1090 - source "$script" + local script + script=$(ici_resolve_component "$@") + # shellcheck disable=SC1090 + source "$script" } function ici_check_builder { - [ -z "$BUILDER" ] || ici_resolve_component BUILDER builders > /dev/null + [ -z "$BUILDER" ] || ici_resolve_component BUILDER builders >/dev/null } function ici_source_builder { - ici_source_component BUILDER builders + ici_source_component BUILDER builders } function ici_join_array { - local sep=$1 - shift - local res="" - for elem in "$@"; do - if [ -n "$elem" ]; then - res+="$sep$elem" - fi - done - echo "${res#$sep}" + local sep=$1 + shift + local res="" + for elem in "$@"; do + if [ -n "$elem" ]; then + res+="$sep$elem" + fi + done + echo "${res#$sep}" } function ici_cleanup_later { - _CLEANUP=$(ici_join_array : "$_CLEANUP" "$@") + _CLEANUP=$(ici_join_array : "$_CLEANUP" "$@") } function ici_make_temp_dir { - local -n ici_make_temp_dir_res=$1; - ici_make_temp_dir_res=$(mktemp -d) - ici_cleanup_later "$ici_make_temp_dir_res" + local -n ici_make_temp_dir_res=$1 + ici_make_temp_dir_res=$(mktemp -d) + ici_cleanup_later "$ici_make_temp_dir_res" } # shellcheck disable=SC1090 diff --git a/industrial_ci/src/workspace.sh b/industrial_ci/src/workspace.sh index a5b8f1420..b1b61f9ce 100644 --- a/industrial_ci/src/workspace.sh +++ b/industrial_ci/src/workspace.sh @@ -19,7 +19,8 @@ export _DEFAULT_DEBS=${_DEFAULT_DEBS:-} function ici_parse_repository_url { - local url=$1; shift + local url=$1 + shift if [[ $url =~ ([^:]+):([^#]+)#(.+) ]]; then local fragment="${BASH_REMATCH[3]}" local repo=${BASH_REMATCH[2]} @@ -27,24 +28,24 @@ function ici_parse_repository_url { local scheme=${BASH_REMATCH[1]} case "$scheme" in - bitbucket | bb) - echo "${name%.git}" "git" "https://bitbucket.org/$repo" "$fragment" - ;; - github | gh) - echo "${name%.git}" "git" "https://github.com/$repo" "$fragment" - ;; - gitlab | gl) - echo "${name%.git}" "git" "https://gitlab.com/$repo" "$fragment" - ;; - 'git+file'*|'git+http'*) - echo "${name%.git}" "git" "${scheme#git+}:$repo" "$fragment" - ;; - git+*) - echo "${name%.git}" "git" "$scheme:$repo" "$fragment" - ;; - *) - echo "$name" "$scheme" "$scheme:$repo" "$fragment" - ;; + bitbucket | bb) + echo "${name%.git}" "git" "https://bitbucket.org/$repo" "$fragment" + ;; + github | gh) + echo "${name%.git}" "git" "https://github.com/$repo" "$fragment" + ;; + gitlab | gl) + echo "${name%.git}" "git" "https://gitlab.com/$repo" "$fragment" + ;; + 'git+file'* | 'git+http'*) + echo "${name%.git}" "git" "${scheme#git+}:$repo" "$fragment" + ;; + git+*) + echo "${name%.git}" "git" "$scheme:$repo" "$fragment" + ;; + *) + echo "$name" "$scheme" "$scheme:$repo" "$fragment" + ;; esac else ici_error "Could not parse URL '$url'. It does not match the expected pattern: :#." @@ -66,7 +67,7 @@ function ici_init_apt { ici_asroot apt-get update -qq local debs_default=(apt-utils build-essential) - if ! ls /etc/ssl/certs/* 2&> /dev/null; then + if ! ls /etc/ssl/certs/* 2 &>/dev/null; then debs_default+=(ca-certificates) fi if [ -n "$_DEFAULT_DEBS" ]; then @@ -88,7 +89,7 @@ function ici_init_apt { fi ici_retry 3 eval "$keycmd" - ici_asroot tee "/etc/apt/sources.list.d/ros${ROS_VERSION}-latest.list" <<< "deb ${ROS_REPOSITORY_PATH} $(lsb_release -sc) main" > /dev/null + ici_asroot tee "/etc/apt/sources.list.d/ros${ROS_VERSION}-latest.list" <<<"deb ${ROS_REPOSITORY_PATH} $(lsb_release -sc) main" >/dev/null ici_asroot apt-get update -qq fi @@ -101,20 +102,22 @@ function ici_init_apt { } function ici_install_pkgs_for_command { - local command=$1; shift - ici_exec_for_command "$command" ici_apt_install "$@" + local command=$1 + shift + ici_exec_for_command "$command" ici_apt_install "$@" } function ici_install_pypi_pkgs_for_command { - local command=$1; shift - ici_exec_for_command "$command" ici_pip_install "$@" + local command=$1 + shift + ici_exec_for_command "$command" ici_pip_install "$@" } function ici_setup_git_client { - ici_install_pkgs_for_command git git-core - if [ -d ~/.ssh ]; then - ici_install_pkgs_for_command ssh ssh-client - fi + ici_install_pkgs_for_command git git-core + if [ -d ~/.ssh ]; then + ici_install_pkgs_for_command ssh ssh-client + fi } function ici_vcs_import { @@ -122,56 +125,63 @@ function ici_vcs_import { } function ici_import_repository { - local sourcespace=$1; shift - local url=$1; shift + local sourcespace=$1 + shift + local url=$1 + shift ici_install_pkgs_for_command vcs python3-vcstool - local parsed; parsed=$(ici_parse_repository_url "$url") - IFS=" " read -r -a parts <<< "$parsed" # name, type, url, version + local parsed + parsed=$(ici_parse_repository_url "$url") + IFS=" " read -r -a parts <<<"$parsed" # name, type, url, version echo "${parts[*]}" case "${parts[1]}" in - git) - ici_setup_git_client - ;; - *) - ;; + git) + ici_setup_git_client + ;; + *) ;; + esac if [ "${parts[3]}" = "HEAD" ]; then - ici_vcs_import "$sourcespace" <<< "{repositories: {'${parts[0]}': {type: '${parts[1]}', url: '${parts[2]}'}}}" + ici_vcs_import "$sourcespace" <<<"{repositories: {'${parts[0]}': {type: '${parts[1]}', url: '${parts[2]}'}}}" else - ici_vcs_import "$sourcespace" <<< "{repositories: {'${parts[0]}': {type: '${parts[1]}', url: '${parts[2]}', version: '${parts[3]}'}}}" + ici_vcs_import "$sourcespace" <<<"{repositories: {'${parts[0]}': {type: '${parts[1]}', url: '${parts[2]}', version: '${parts[3]}'}}}" fi } function ici_import_file { - local sourcespace=$1; shift - local file=$1; shift + local sourcespace=$1 + shift + local file=$1 + shift case "$file" in - *.zip|*.tar|*.tar.*|*.tgz|*.tbz2) + *.zip | *.tar | *.tar.* | *.tgz | *.tbz2) ici_install_pkgs_for_command bsdtar bsdtar bsdtar -C "$sourcespace" -xf "$file" ;; *) ici_install_pkgs_for_command vcs python3-vcstool ici_setup_git_client - ici_vcs_import "$sourcespace" < "$file" - ;; + ici_vcs_import "$sourcespace" <"$file" + ;; esac } function ici_import_url { - local sourcespace=$1; shift - local url=$1; shift + local sourcespace=$1 + shift + local url=$1 + shift local processor ici_install_pkgs_for_command wget wget case "$url" in - *.zip|*.tar|*.tar.*|*.tgz|*.tbz2) + *.zip | *.tar | *.tar.* | *.tgz | *.tbz2) ici_install_pkgs_for_command bsdtar bsdtar processor=(bsdtar -C "$sourcespace" -xf-) ;; @@ -179,7 +189,7 @@ function ici_import_url { ici_install_pkgs_for_command vcs python3-vcstool ici_setup_git_client processor=(ici_vcs_import "$sourcespace") - ;; + ;; esac set -o pipefail @@ -187,15 +197,18 @@ function ici_import_url { set +o pipefail } -function ici_import_directory { - local sourcespace=$1; shift - local dir=$1; shift +function ici_import_directory { + local sourcespace=$1 + shift + local dir=$1 + shift rm -rf "$sourcespace:?/$(basename "$dir")" cp -a "$dir" "$sourcespace" } function ici_prepare_sourcespace { - local sourcespace=$1; shift + local sourcespace=$1 + shift local basepath=$TARGET_REPO_PATH mkdir -p "$sourcespace" @@ -209,14 +222,15 @@ function ici_prepare_sourcespace { ici_import_url "$sourcespace" "$source" ;; -.) - local file; file=$(basename "$basepath") + local file + file=$(basename "$basepath") echo "Removing '${sourcespace:?}/$file'" rm -r "${sourcespace:?}/$file" ;; -*) local file="${source:1}" if [ ! -e "${sourcespace:?}/$file" ]; then - file="$(basename "$basepath")/$file" + file="$(basename "$basepath")/$file" fi echo "Removing '${sourcespace:?}/$file'" rm -r "${sourcespace:?}/$file" @@ -228,7 +242,7 @@ function ici_prepare_sourcespace { /*) if [ -d "$source" ]; then echo "Copying '$source'" - ici_import_directory "$sourcespace" "$source" + ici_import_directory "$sourcespace" "$source" elif [ -f "$source" ]; then ici_import_file "$sourcespace" "$source" else @@ -280,24 +294,28 @@ function ici_setup_rosdep { } function ici_exec_in_workspace { - local extend=$1; shift - local path=$1; shift - ( { [ ! -e "$extend/setup.bash" ] || ici_source_setup "$extend"; } && cd "$path" && exec "$@") + local extend=$1 + shift + local path=$1 + shift + ({ [ ! -e "$extend/setup.bash" ] || ici_source_setup "$extend"; } && cd "$path" && exec "$@") } function ici_install_dependencies { - local extend=$1; shift - local skip_keys=$1; shift + local extend=$1 + shift + local skip_keys=$1 + shift local cmake_prefix_path= if [ "$ROS_VERSION" -eq 2 ]; then - # work-around for https://github.com/ros-infrastructure/rosdep/issues/724 - cmake_prefix_path="$(ici_exec_in_workspace "$extend" . env | grep -oP '^CMAKE_PREFIX_PATH=\K.*'):" || true + # work-around for https://github.com/ros-infrastructure/rosdep/issues/724 + cmake_prefix_path="$(ici_exec_in_workspace "$extend" . env | grep -oP '^CMAKE_PREFIX_PATH=\K.*'):" || true fi rosdep_opts=(-q --from-paths "$@" --ignore-src -y) if [ -n "$skip_keys" ]; then - rosdep_opts+=(--skip-keys "$skip_keys") + rosdep_opts+=(--skip-keys "$skip_keys") fi set -o pipefail # fail if rosdep install fails ROS_PACKAGE_PATH="$cmake_prefix_path${ROS_PACKAGE_PATH:-}" ici_exec_in_workspace "$extend" "." rosdep install "${rosdep_opts[@]}" | { grep "executing command" || true; } @@ -305,16 +323,19 @@ function ici_install_dependencies { } function ici_build_workspace { - local name=$1; shift - local extend=$1; shift - local ws=$1; shift + local name=$1 + shift + local extend=$1 + shift + local ws=$1 + shift local ws_sources=() - ici_parse_env_array ws_sources "${name^^}_WORKSPACE" + ici_parse_env_array ws_sources "${name^^}_WORKSPACE" local sources=("$@" "${ws_sources[@]}") local cmake_args ws_cmake_args=() - ici_parse_env_array cmake_args CMAKE_ARGS - ici_parse_env_array ws_cmake_args "${name^^}_CMAKE_ARGS" + ici_parse_env_array cmake_args CMAKE_ARGS + ici_parse_env_array ws_cmake_args "${name^^}_CMAKE_ARGS" local args=() if [ ${#cmake_args[@]} -gt 0 ] || [ ${#ws_cmake_args[@]} -gt 0 ]; then args+=(--cmake-args "${cmake_args[@]}" "${ws_cmake_args[@]}") @@ -326,9 +347,12 @@ function ici_build_workspace { } function ici_test_workspace { - local name=$1; shift - local extend=$1; shift - local ws=$1; shift + local name=$1 + shift + local extend=$1 + shift + local ws=$1 + shift ici_run "run_${name}_test" builder_run_tests "$extend" "$ws" builder_test_results "$extend" "$ws" diff --git a/travis.sh b/travis.sh index 12155aa04..2cf57ebcf 100755 --- a/travis.sh +++ b/travis.sh @@ -19,7 +19,7 @@ # This is the entrypoint for Travis CI only. # 2016/05/18 http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in -DIR_THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +DIR_THIS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" export TARGET_REPO_PATH=$TRAVIS_BUILD_DIR export TARGET_REPO_NAME=${TRAVIS_REPO_SLUG##*/} @@ -29,17 +29,16 @@ export _FOLDING_TYPE=travis sudo apt-get update -qq && sudo apt-get install -y -qq libseccomp2 if [ "$ABICHECK_MERGE" = "auto" ]; then - export ABICHECK_MERGE=false - [ "$TRAVIS_PULL_REQUEST" = "false" ] || ABICHECK_MERGE=true + export ABICHECK_MERGE=false + [ "$TRAVIS_PULL_REQUEST" = "false" ] || ABICHECK_MERGE=true fi function watch_output() { - while read -r -t "${_GUARD_INTERVAL:-540}" || + while read -r -t "${_GUARD_INTERVAL:-540}" || { [[ $? -gt 128 ]] && - echo -en "${ANSI_YELLOW}...industrial_ci is still running...${ANSI_RESET}"; } - do - echo "$REPLY" - done + echo -en "${ANSI_YELLOW}...industrial_ci is still running...${ANSI_RESET}"; }; do + echo "$REPLY" + done } set -o pipefail