Skip to content

Commit

Permalink
unbound variable checking
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Dec 16, 2019
1 parent 2b70ddf commit 631f498
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 11 deletions.
6 changes: 5 additions & 1 deletion industrial_ci/src/ci_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
## See ./README.rst for the detailed usage.

set -e # exit script on errors
if [ "$DEBUG_BASH" ]; then set -x; fi # print trace if DEBUG
set -u # exit script on unbound variables
if [ "${DEBUG_BASH:=}" ]; then set -x; fi # print trace if DEBUG

# Define some env vars that need to come earlier than util.sh
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.

# shellcheck source=industrial_ci/src/util.sh
source "${ICI_SRC_PATH}/variables.sh"

# shellcheck source=industrial_ci/src/util.sh
source "${ICI_SRC_PATH}/util.sh"
# shellcheck source=industrial_ci/src/docker.sh
Expand Down
2 changes: 1 addition & 1 deletion industrial_ci/src/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# (None)
#######################################
function ici_require_run_in_docker() {
if ! [ "$IN_DOCKER" ]; then
if ! [ "${IN_DOCKER:-}" ]; then
ici_prepare_docker_image

local docker_target_repo_path=/root/src/$TARGET_REPO_NAME
Expand Down
1 change: 1 addition & 0 deletions industrial_ci/src/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function use_repo_or_final_snapshot() {
fi
}
function set_ros_variables {
ROS_VERSION_EOL=false
case "$ROS_DISTRO" in
"indigo"|"jade")
ros1_defaults "trusty"
Expand Down
28 changes: 19 additions & 9 deletions industrial_ci/src/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,11 @@ function ici_color_output {
}

function ici_source_setup {
local u_set=1
[[ $- =~ u ]] || u_set=0
set +u
local old_u_status=${-//[^u]/}
set +u # disable checking for unbound variables
# shellcheck disable=SC1090
source "$1/setup.bash"
if [ $u_set ]; then
set -u
fi
test -n "$old_u_status" && set -u # restore variable checking option
}

function rosenv() {
Expand All @@ -88,16 +85,20 @@ function ici_with_ws() {
}

function _sub_shell() (
set -u
local old_u_status=${-//[^u]/}
set -u # enable variable checking
eval "$@"
set +u
test -z "$old_u_status" && set +u # restore variable checking option
)

function ici_hook() {
local name=${1^^}
name=${name//[^A-Z0-9_]/_}

local old_u_status=${-//[^u]/}
set +u # disable checking for unbound variables
local script=${!name}
test -n "$old_u_status" && set -u # restore variable checking option
if [ -n "$script" ]; then
ici_run "$1" _sub_shell "$script"
fi
Expand Down Expand Up @@ -237,12 +238,15 @@ function ici_warn {
}

function ici_mark_deprecated {
if ! [ "$IN_DOCKER" ]; then
if ! [ "${IN_DOCKER:-}" ]; then
local e=$1
shift
local old_u_status=${-//[^u]/}
set +u # disable checking for unbound variables
if [ "${!e}" ]; then
ici_warn "'$e' is deprecated. $*"
fi
test -n "$old_u_status" && set -u # restore variable checking option
fi
}

Expand Down Expand Up @@ -275,9 +279,12 @@ function ici_error {
function ici_enforce_deprecated {
local e=$1
shift
local old_u_status=${-//[^u]/}
set +u # disable checking for unbound variables
if [ "${!e}" ]; then
ici_error "'$e' is not used anymore. $*"
fi
test -n "$old_u_status" && set -u # restore variable checking option
}

function ici_retry {
Expand Down Expand Up @@ -314,5 +321,8 @@ function ici_split_array {

function ici_parse_env_array {
# shellcheck disable=SC2034
local old_u_status=${-//[^u]/}
set +u # disable checking for unbound variables
eval "$1=(${!2})"
test -n "$old_u_status" && set -u # restore variable checking option
}
73 changes: 73 additions & 0 deletions industrial_ci/src/variables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
_DO_NOT_FOLD=${_DO_NOT_FOLD:-}

ABICHECK_URL=${ABICHECK_URL:-}
ABICHECK_VERSION=${ABICHECK_VERSION:-}

APTKEY_STORE_SKS=${APTKEY_STORE_SKS:-}

ADDITIONAL_DEBS=${ADDITIONAL_DEBS:-}

BUILDER=${BUILDER:-}
CATKIN_LINT=${CATKIN_LINT:-}
CATKIN_LINT_ARGS=${CATKIN_LINT_ARGS:-}

CC=${CC:-}
CFLAGS=${CFLAGS:-}
CLANG_FORMAT_CHECK=${CLANG_FORMAT_CHECK:-}
CLANG_FORMAT_VERSION=${CLANG_FORMAT_VERSION:-}
CLANG_TIDY=${CLANG_TIDY:-}
CLANG_TIDY_ARGS=${CLANG_TIDY_ARGS:-}
CLANG_TIDY_JOBS=${CLANG_TIDY_JOBS:-}
CMAKE_ARGS=${CMAKE_ARGS:-}
CPPFLAGS=${CPPFLAGS:-}
CXX=${CXX:-}
CXXFLAGS=${CXXFLAGS:-}
CCACHE_DIR=${CCACHE_DIR:-$HOME/.ccache}

DEBUG_BASH=${DEBUG_BASH:-}

DOWNSTREAM_CMAKE_ARGS=${DOWNSTREAM_CMAKE_ARGS:-}
DOWNSTREAM_WORKSPACE=${DOWNSTREAM_WORKSPACE:-}
HASHKEY_SKS=${HASHKEY_SKS:-}
IMMEDIATE_TEST_OUTPUT=${IMMEDIATE_TEST_OUTPUT:-}
LC_ALL=C.UTF-8

NOT_TEST_BUILD=${NOT_TEST_BUILD:-}
NOT_TEST_DOWNSTREAM=${NOT_TEST_DOWNSTREAM:-}
NOT_TEST_INSTALL=${NOT_TEST_INSTALL:-}

OS_NAME=${OS_NAME:-}
OS_CODE_NAME=${OS_CODE_NAME:-}
UBUNTU_OS_CODE_NAME=${UBUNTU_OS_CODE_NAME:-}

PRERELEASE=${PRERELEASE:-}
PYTHONUNBUFFERED=${PYTHONUNBUFFERED:-}
ROSDEP_SKIP_KEYS=${ROSDEP_SKIP_KEYS:-}
ROSINSTALL_FILENAME=${ROSINSTALL_FILENAME:-}

ROS_DISTRO=${ROS_DISTRO:-}
ROS_REPO=${ROS_REPO:-}
ROS_REPOSITORY_PATH=${ROS_REPOSITORY_PATH:-}
DOCKER_IMAGE=${DOCKER_IMAGE:-}
DOCKER_BASE_IMAGE=${DOCKER_BASE_IMAGE:-}
USE_DEB=${USE_DEB:-}

DOCKER_FILE=${DOCKER_FILE:-}
INJECT_QEMU=${INJECT_QEMU:-}
APTKEY_STORE_HTTPS=${APTKEY_STORE_HTTPS:-}
DOCKER_PULL=${DOCKER_PULL:-}
DOCKER_COMMIT=${DOCKER_COMMIT:-}

SSH_AUTH_SOCK=${SSH_AUTH_SOCK:-}

ROS_PYTHON_VERSION=${ROS_PYTHON_VERSION:-}
TARGET_CMAKE_ARGS=${TARGET_CMAKE_ARGS:-}
TARGET_REPO_NAME=${TARGET_REPO_NAME:-}
TARGET_REPO_PATH=${TARGET_REPO_PATH:-}
TARGET_WORKSPACE=${TARGET_WORKSPACE:-}
TERM=${TERM:-}
USE_MOCKUP=${USE_MOCKUP:-}
UPSTREAM_CMAKE_ARGS=${UPSTREAM_CMAKE_ARGS:-}
UPSTREAM_WORKSPACE=${UPSTREAM_WORKSPACE:-}
VERBOSE_OUTPUT=${VERBOSE_OUTPUT:-}
VERBOSE_TESTS=${VERBOSE_TESTS:-}

0 comments on commit 631f498

Please sign in to comment.