Skip to content

Commit d9e7531

Browse files
authored
Fix various shellcheck warnings (#928)
1 parent 06f1cbf commit d9e7531

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

lib/setupHooks/cargoHelperFunctionsHook.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ cargo() {
1010
# Injects `--profile $CARGO_PROFILE` into a particular cargo invocation
1111
# if the environment variable is set
1212
cargoWithProfile() {
13-
local profileArgs
13+
local profileArgs=()
1414
if [[ "${CARGO_PROFILE}" == "release" ]]; then
15-
profileArgs="--release"
16-
else
17-
profileArgs="${CARGO_PROFILE:+--profile ${CARGO_PROFILE}}"
15+
profileArgs+=("--release")
16+
elif [[ -n "${CARGO_PROFILE:-}" ]]; then
17+
profileArgs+=("--profile" "${CARGO_PROFILE}")
1818
fi
19-
cargo "${@:1:1}" ${profileArgs} "${@:2}"
19+
cargo "${@:1:1}" "${profileArgs[@]}" "${@:2}"
2020
}

lib/setupHooks/configureCargoVendoredDepsHook.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ configureCargoVendoredDepsHook() {
99
# doing and has its own source replacement going on, it can happily
1010
# ignore the changes we are trying to make!
1111
if [[ -f "${vendoredDir}/config.toml" ]]; then
12-
echo will append ${cargoConfig} with contents of ${vendoredDir}/config.toml
12+
echo "will append ${cargoConfig} with contents of ${vendoredDir}/config.toml"
1313
cat "${vendoredDir}/config.toml" >>"${cargoConfig}"
1414
return
1515
fi
1616

17-
echo setting source replacement config in ${cargoConfig} using vendored directory ${vendoredDir}
17+
echo "setting source replacement config in ${cargoConfig} using vendored directory ${vendoredDir}"
1818
cat >>"${cargoConfig}" <<EOF
1919
2020
[source.crates-io]

lib/setupHooks/inheritCargoArtifactsHook.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ inheritCargoArtifacts() {
9090
done
9191
' \;
9292

93-
local linkCandidates=$(mktemp linkCandidatesXXXX.txt)
93+
local linkCandidates
94+
linkCandidates="$(mktemp linkCandidatesXXXX.txt)"
9495
find "${preparedArtifacts}" \
9596
'(' -path '*/deps/*.rlib' -or -path '*/deps/*.rmeta' ')' \
9697
-printf "%P\n" \
@@ -100,14 +101,14 @@ inheritCargoArtifacts() {
100101
cat "${linkCandidates}" \
101102
| xargs --no-run-if-empty -n1 dirname \
102103
| sort -u \
103-
| (cd "${cargoTargetDir}"; xargs --no-run-if-empty mkdir -p)
104+
| (cd "${cargoTargetDir}" || exit 1; xargs --no-run-if-empty mkdir -p)
104105

105106
# Lastly do the actual symlinking
106107
cat "${linkCandidates}" \
107-
| xargs -P ${NIX_BUILD_CORES} -I '##{}##' ln -s "${preparedArtifacts}/##{}##" "${cargoTargetDir}/##{}##"
108+
| xargs -P "${NIX_BUILD_CORES:-0}" -I '##{}##' ln -s "${preparedArtifacts}/##{}##" "${cargoTargetDir}/##{}##"
108109
fi
109110
else
110-
echo unable to copy cargo artifacts, \"${preparedArtifacts}\" looks invalid
111+
echo "unable to copy cargo artifacts, \"${preparedArtifacts}\" looks invalid"
111112
false
112113
fi
113114
}

lib/setupHooks/installCargoArtifactsHook.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ compressAndInstallCargoArtifactsDir() {
3535
)
3636

3737
if [[ -d "${cargoTargetDir}" ]]; then
38+
# shellcheck disable=SC2086
3839
dynTar \
3940
--sort=name \
4041
--mtime="@${SOURCE_DATE_EPOCH}" \

lib/setupHooks/installFromCargoBuildLogHook.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ function installFromCargoBuildLog() (
33
local log=${2:-${cargoBuildLog:?not defined}}
44

55
if ! [ -f "${log}" ]; then
6-
echo unable to install, cargo build log does not exist at: ${log}
6+
echo "unable to install, cargo build log does not exist at: ${log}"
77
false
88
fi
99

10-
echo searching for bins/libs to install from cargo build log at ${log}
10+
echo "searching for bins/libs to install from cargo build log at ${log}"
1111

1212
local logs
1313
logs=$(@jq@ -R 'fromjson?' <"${log}")
@@ -19,7 +19,9 @@ function installFromCargoBuildLog() (
1919
local select_non_deps_artifact='select(contains("/deps/artifact/") | not)'
2020

2121
# Only install binaries and libraries from the current workspace as a sanity check
22-
local members="$(command cargo metadata --format-version 1 | @jq@ -c '.workspace_members')"
22+
local members
23+
members="$(command cargo metadata --format-version 1 | @jq@ -c '.workspace_members')"
24+
# shellcheck disable=SC2016
2325
local select_non_test_members='select(.reason == "compiler-artifact" and .profile.test == false)
2426
| select(.package_id as $pid
2527
| '"${members}"'
@@ -42,7 +44,7 @@ function installFromCargoBuildLog() (
4244
mkdir -p "${loc}"
4345

4446
while IFS= read -r to_install; do
45-
echo installing ${to_install} in "${loc}"
47+
echo "installing ${to_install} in ${loc}"
4648
cp "${to_install}" "${loc}"
4749
done
4850

@@ -59,7 +61,7 @@ function installFromCargoBuildLog() (
5961
# we are planning to install (see https://github.com/ipetkov/crane/issues/765). To work around
6062
# this we'll capture any installables immediately after running and actually install them later
6163
function postBuildInstallFromCargoBuildLog() (
62-
if [ -n "${cargoBuildLog:-}" -a -f "${cargoBuildLog}" ]; then
64+
if [ -n "${cargoBuildLog:-}" ] && [ -f "${cargoBuildLog}" ]; then
6365
installFromCargoBuildLog "${postBuildInstallFromCargoBuildLogOut}" "${cargoBuildLog}"
6466
else
6567
cat <<-'EOF'

0 commit comments

Comments
 (0)