Skip to content

Commit c777a79

Browse files
committed
Resolve shellcheck issues in build-functions
1 parent c85ed43 commit c777a79

10 files changed

+62
-51
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
# Make the build directory, configure, and build
2+
# shellcheck disable=SC2154
23
build_and_install()
34
{
45
num_threads=${arg_j}
56
build_path="${OPENCOARRAYS_SRC_DIR}/prerequisites/builds/${package_to_build}-${version_to_build}"
67

7-
info "Building ${package_to_build} ${version_to_build}"
8-
info "Build path: ${build_path}"
8+
info "Building ${package_to_build} ${version_to_build}"
9+
info "Build path: ${build_path}"
910

1011
set_SUDO_if_needed_to_write_to_directory "${build_path}"
1112
set_SUDO_if_needed_to_write_to_directory "${install_path}"
1213
mkdir -p "${build_path}"
1314
info "pushd ${build_path}"
1415
pushd "${build_path}"
1516
if [[ "${package_to_build}" == "gcc" ]]; then
16-
info 'pushd ${download_path}/${package_source_directory} '
17+
info "pushd ${download_path}/${package_source_directory} "
1718
pushd "${download_path}/${package_source_directory}"
18-
"${PWD}"/contrib/download_prerequisites
19+
"${PWD}"/contrib/download_prerequisites
1920
info "popd"
20-
popd
21+
popd
2122
info "Configuring with the following command:"
22-
info "${download_path}/${package_source_directory}/configure --prefix=${install_path} --enable-languages=c,c++,fortran,lto --disable-multilib --disable-werror"
23+
info "${download_path}/${package_source_directory}/configure --prefix=${install_path} --enable-languages=c,c++,fortran,lto --disable-multilib --disable-werror"
2324
"${download_path}/${package_source_directory}/configure" --prefix="${install_path}" --enable-languages=c,c++,fortran,lto --disable-multilib --disable-werror
2425
info "Building with the following command: 'make -j${num_threads} bootstrap'"
2526
make "-j${num_threads}" bootstrap
2627
if [[ ! -z "${SUDO:-}" ]]; then
2728
info "You do not have write permissions to the installation path ${install_path}"
2829
info "If you have administrative privileges, enter your password to install ${package_to_build}"
29-
fi
30+
fi
3031
info "Installing with the following command: ${SUDO:-} make install"
3132
${SUDO:-} make install
3233
else
@@ -41,9 +42,9 @@ build_and_install()
4142
info "You do not have write permissions to the installation path ${install_path}"
4243
info "If you have administrative privileges, enter your password to install ${package_to_build}"
4344
fi
44-
info "Installing with the following command: ${SUDO:-} make install"
45+
info "Installing with the following command: ${SUDO:-} make install"
4546
${SUDO:-} make install
46-
fi
47+
fi
4748
info "popd"
4849
popd
4950
}

prerequisites/build-functions/download_if_necessary.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
# shellcheck source=./ftp-url.sh
12
source "${OPENCOARRAYS_SRC_DIR:-}/prerequisites/build-functions/ftp-url.sh"
3+
# shellcheck source=./set_SUDO_if_needed_to_write_to_directory.sh
24
source "${OPENCOARRAYS_SRC_DIR:-}/prerequisites/build-functions/set_SUDO_if_needed_to_write_to_directory.sh"
35

46
# Download pkg-config if the tar ball is not already in the present working directory
7+
# shellcheck disable=SC2154
58
download_if_necessary()
69
{
710
download_path="${PWD}/downloads"
811
set_SUDO_if_needed_to_write_to_directory "${download_path}"
9-
if [ -f $url_tail ] || [ -d $url_tail ]; then
12+
if [ -f "$url_tail" ] || [ -d "$url_tail" ]; then
1013
info "Found '${url_tail}' in ${PWD}."
1114
info "If it resulted from an incomplete download, building ${package_name} could fail."
1215
info "Would you like to proceed anyway? (Y/n)"
13-
read proceed
16+
read -r proceed
1417
if [[ "${proceed}" == "n" || "${proceed}" == "N" || "${proceed}" == "no" ]]; then
1518
info "n"
1619
info "Please remove $url_tail and restart the installation to to ensure a fresh download." 1>&2
@@ -23,7 +26,7 @@ download_if_necessary()
2326
info "The default download mechanism for ${package_name} is ${fetch}."
2427
info "Please either ensure that ${fetch} is installed and in your PATH"
2528
info "or download the ${package_name} source from "
26-
info "${package_url}"
29+
info "${package_url}"
2730
#called_by_install_sh=`echo "$(ps -p $PPID -o args=)" | grep install.sh`
2831
info "Place the downloaded file in ${download_path} and restart this script."
2932
#if [[ ! -z $called_by_install_sh ]]; then
@@ -57,7 +60,7 @@ download_if_necessary()
5760
info "Download command: ${fetch} ${args} ${package_url}"
5861
info "Depending on the file size and network bandwidth, this could take several minutes or longer."
5962
pushd "${download_path}"
60-
"${fetch}" "${args}" "${package_url}"
63+
"${fetch}" "${args}" "${package_url}"
6164
popd
6265
if [[ "${version_to_build}" == '--avail' || "${version_to_build}" == '-a' ]]; then
6366
# In this case, args="ls" and the list of available versions has been printed so we can move on.
@@ -69,10 +72,10 @@ download_if_necessary()
6972
search_path="${download_path}/${url_tail}"
7073
fi
7174
if [ -f "${search_path}" ] || [ -d "${search_path}" ]; then
72-
info "Download succeeded. The "${package_name}" source is in the following location:"
75+
info "Download succeeded. The ${package_name} source is in the following location:"
7376
info "${search_path}"
7477
else
75-
info "Download failed. The "${package_name}" source is not in the following, expected location:"
78+
info "Download failed. The ${package_name} source is not in the following, expected location:"
7679
info "${search_path}"
7780
emergency "Aborting. [exit 110]"
7881
fi

prerequisites/build-functions/ftp-url.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Download a file from an anonymous ftp site
1+
# Download a file from an anonymous ftp site
22
#
33
# Usage:
44
# ftp-url <ftp-mode> <ftp-site-address>:/<path-to-file>/<file-name>
55
#
6-
# Example:
6+
# Example:
77
# ftp-url -n ftp.gnu.org:/gnu/m4/m4-1.4.17.tar.bz2
88
ftp-url()
99
{

prerequisites/build-functions/set_SUDO_if_needed_to_write_to_directory.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ set_SUDO_if_needed_to_write_to_directory()
66
else
77
directory_to_create=$1
88
fi
9-
if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then
9+
if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then
1010
info "\${LD_LIBRARY_PATH} is empty. Try setting it if the compiler encounters linking problems."
1111
fi
1212
SUDO_COMMAND="sudo env LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-""}"
13-
info "Checking whether the directory ${directory_to_create} exists... "
13+
info "Checking whether the directory ${directory_to_create} exists... "
1414
if [[ -d "${directory_to_create}" ]]; then
1515
info "yes"
1616
info "Checking whether I have write permissions to ${directory_to_create} ... "
@@ -27,6 +27,7 @@ set_SUDO_if_needed_to_write_to_directory()
2727
info "yes."
2828
else
2929
info "no."
30+
# shellcheck disable=SC2034
3031
SUDO="${SUDO_COMMAND}"
3132
fi
3233
fi
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
11
# Set CC, CXX, and FC
2+
# shellcheck disable=SC2154
23
set_compilers()
34
{
45
# If FC is already set, use the set value.
5-
# Else if FC is empty, use the value specified via the -f or --with-fortran command-line arguments.
6+
# Else if FC is empty, use the value specified via the -f or --with-fortran command-line arguments.
67
# Else use the default specifed in ../build.sh-usage.
78
FC=${FC:-${arg_f}}
8-
info "Fortran compiler: ${FC}"
9+
info "Fortran compiler: ${FC}"
910

10-
if [[ `uname` == "Darwin" && "${package_to_build}" == "cmake" ]]; then
11+
if [[ $(uname) == "Darwin" && "${package_to_build}" == "cmake" ]]; then
1112
if [[ -x "/usr/bin/gcc" ]]; then
12-
[ ! -z ${CC:-} ] && info "Overriding CC: cmake build requires Apple LLVM gcc, which XCode command-line tools puts in /usr/bin"
13+
[ ! -z "${CC:-}" ] && info "Overriding CC: cmake build requires Apple LLVM gcc, which XCode command-line tools puts in /usr/bin"
1314
CC=/usr/bin/gcc
1415
else
1516
info "OS X detected. Please install XCode command-line tools and "
1617
emergency "ensure that /usr/bin/gcc exists and is executable. Aborting."
17-
fi
18+
fi
1819
else
1920
# If CC is already set, use the set value.
20-
# Else if CC is empty, use the value specified via the -c or --with-c command-line arguments.
21+
# Else if CC is empty, use the value specified via the -c or --with-c command-line arguments.
2122
# Else use the default specifed in ../build.sh-usage.
2223
CC=${CC:-${arg_c}}
23-
fi
24-
info "C compiler: ${CC}"
24+
fi
25+
info "C compiler: ${CC}"
2526

26-
if [[ `uname` == "Darwin" && ${package_to_build} == "cmake" ]]; then
27+
if [[ $(uname) == "Darwin" && ${package_to_build} == "cmake" ]]; then
2728
if [[ -x "/usr/bin/g++" ]]; then
28-
[ ! -z ${CXX:-} ] && info "Overriding CXX: cmake build requires Apple LLVM g++, which XCode command-line tools puts in /usr/bin"
29+
[ ! -z "${CXX:-}" ] && info "Overriding CXX: cmake build requires Apple LLVM g++, which XCode command-line tools puts in /usr/bin"
2930
CXX=/usr/bin/g++
3031
else
3132
info "OS X detected. Please install XCode command-line tools and "
3233
emergency "ensure that /usr/bin/g++ exists and is executable. Aborting."
33-
fi
34+
fi
3435
else
3536
# If CXX is already set, use the set value.
36-
# Else if CXX is empty, use the value specified via the -C or --with-cxx command-line arguments.
37+
# Else if CXX is empty, use the value specified via the -C or --with-cxx command-line arguments.
3738
# Else use the default specifed in ../build.sh-usage.
3839
CXX=${CXX:-${arg_C}}
3940
fi
40-
info "C++ compiler: ${CXX}"
41+
info "C++ compiler: ${CXX}"
4142
}

prerequisites/build-functions/set_or_print_default_version.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# If -p, -D, -P, or -U specifies a package, set default_version
22
# If -V specifies a package, print the default_version and exit with normal status
33
# If -l is present, list all packages and versions and exit with normal status
4+
# shellcheck disable=SC2154
45
set_or_print_default_version()
56
{
6-
# Verify requirements
7+
# Verify requirements
78
[ "${arg_l}" == "${__flag_present}" ] && [ ! -z "${arg_D:-${arg_p:-${arg_P:-${arg_U:-${arg_V}}}}}" ] &&
89
emergency "Please pass only one of {-l, -D, -p, -P, -U, -V} or a longer equivalent (multiple detected)."
910

10-
if [[ "${arg_l}" == "${__flag_present}" ]]; then
11+
if [[ "${arg_l}" == "${__flag_present}" ]]; then
1112
echo "This script can build the following packages:"
1213
fi
1314
# Get package name from argument passed with -p, -V, -D, or -U
@@ -36,8 +37,8 @@ set_or_print_default_version()
3637
elif [[ "${package_name}" == "${KEY}" ]]; then
3738
# We recognize the package name so we set the default version:
3839
default_version=${VALUE}
39-
# If a printout of the default version number was requested, then print it and exit with normal status
40-
[[ ! -z "${arg_V}" ]] && printf "${default_version}\n" && exit 0
40+
# If a printout of the default version number was requested, then print it and exit with normal status
41+
[[ ! -z "${arg_V}" ]] && printf "%s\n" "${default_version}" && exit 0
4142
break # exit the for loop
4243
fi
4344
done

prerequisites/build-functions/set_or_print_downloader.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# If -p, -P, -U, or -V specifies a package, set fetch variable
22
# If -D specifies a package, print "${fetch}" and exit with normal status
33
# If -l is present, list all packages and versions and exit with normal status
4+
# shellcheck disable=SC2154
45
set_or_print_downloader()
56
{
6-
# Verify requirements
7+
# Verify requirements
78
[ ! -z "${arg_D}" ] && [ ! -z "${arg_p:-${arg_P:-${arg_U:-${arg_V}}}}" ] &&
89
emergency "Please pass only one of {-D, -p, -P, -U, -V} or a longer equivalent (multiple detected)."
910

@@ -12,7 +13,7 @@ set_or_print_downloader()
1213
gcc_fetch="ftp-url"
1314
else
1415
gcc_fetch="svn"
15-
fi
16+
fi
1617
# This is a bash 3 hack standing in for a bash 4 hash (bash 3 is the lowest common
1718
# denominator because, for licensing reasons, OS X only has bash 3 by default.)
1819
# See http://stackoverflow.com/questions/1494178/how-to-define-hash-tables-in-bash
@@ -34,13 +35,12 @@ set_or_print_downloader()
3435
if [[ "${package_name}" == "${KEY}" ]]; then
3536
# We recognize the package name so we set the download mechanism:
3637
fetch=${VALUE}
37-
# If a printout of the download mechanism was requested, then print it and exit with normal status
38-
[[ ! -z "${arg_D}" ]] && printf "${fetch}\n" && exit 0
38+
# If a printout of the download mechanism was requested, then print it and exit with normal status
39+
[[ ! -z "${arg_D}" ]] && printf "%s\n" "${fetch}" && exit 0
3940
break # exit the for loop
4041
fi
4142
done
4243
if [[ -z "${fetch:-}" ]]; then
4344
emergency "Package ${package_name:-} not recognized. Use --l or --list-packages to list the allowable names."
4445
fi
4546
}
46-
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# If -P specifies a package, print the installation path and exit with normal status
22
# Otherwise, set install_path
3+
# shellcheck disable=SC2154
34
set_or_print_installation_path()
45
{
5-
# Verify requirements
6+
# Verify requirements
67
[ ! -z "${arg_P}" ] && [ ! -z "${arg_D:-${arg_p:-${arg_U:-${arg_V}}}}" ] &&
78
emergency "Please pass only one of {-D, -p, -P, -U, -V} or a longer equivalent (multiple detected)."
8-
9+
910
# ../build.sh-usage specifies the following installation path default for illustrative purposes only:
1011
# Default="${OPENCOARRAYS_SRC_DIR}/prerequisites/installations/${package_name:-}/"
1112
# When the parse_command_line function executes, ${package_name:-} is empty, but it has
1213
# been set before reaching the current function so now we can get the true values if the
13-
# user didn't override the default:
14+
# user didn't override the default:
1415

1516
path_in_usage_file="${OPENCOARRAYS_SRC_DIR}/prerequisites/installations//"
1617
if [[ "${arg_i}" == "${path_in_usage_file}" ]]; then
@@ -20,10 +21,10 @@ set_or_print_installation_path()
2021
fi
2122

2223
# If -P is present, print ${install_path} and exit with normal status
23-
if [[ ! -z "${arg_P:-}" ]]; then
24-
printf "${install_path}\n"
24+
if [[ ! -z "${arg_P:-}" ]]; then
25+
printf "%s\n" "${install_path}"
2526
exit 0
2627
fi
2728

28-
info "${package_name} ${version_to_build} installation path: ${install_path}"
29+
info "${package_name} ${version_to_build} installation path: ${install_path}"
2930
}

prerequisites/build-functions/set_or_print_url.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# If -p, -D, -P, or -V specifies a package, set package_url
22
# If -U specifies a package, print the package_url and exit with normal status
3+
# shellcheck disable=SC2154
34
set_or_print_url()
45
{
5-
# Verify requirements
6+
# Verify requirements
67
[ ! -z "${arg_U}" ] && [ ! -z "${arg_D:-${arg_p:-${arg_P:-${arg_V}}}}" ] &&
78
emergency "Please pass only one of {-D, -p, -P, -U, -V} or a longer equivalent (multiple detected)."
89

@@ -76,9 +77,9 @@ set_or_print_url()
7677

7778
package_url="${url_head}""${url_tail}"
7879

79-
# If a printout of the package URL was requested, then print it and exit with normal status
80-
if [[ ! -z "${arg_U:-}" ]]; then
81-
printf "${package_url}\n"
80+
# If a printout of the package URL was requested, then print it and exit with normal status
81+
if [[ ! -z "${arg_U:-}" ]]; then
82+
printf "%s\n" "${package_url}"
8283
exit 0
8384
fi
8485
}

prerequisites/build-functions/unpack_if_necessary.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Unpack if the unpacked tar ball is not in the present working directory
2+
# shellcheck disable=SC2154
23
unpack_if_necessary()
34
{
45
if [[ "${fetch}" == "svn" || "${fetch}" == "git" ]]; then
@@ -11,6 +12,7 @@ unpack_if_necessary()
1112
tar xf "${url_tail}"
1213
info "popd"
1314
popd
15+
# shellcheck disable=SC2034
1416
package_source_directory="${package_name}-${version_to_build}"
1517
fi
1618
}

0 commit comments

Comments
 (0)