Skip to content

File tree

13 files changed

+92
-56
lines changed

13 files changed

+92
-56
lines changed

.github/workflows/lint-shellcheck.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
on:
2+
push:
3+
paths:
4+
- '**/*.{sh,bash,fish}'
5+
- './bin/*'
6+
- './scripts/git/pre-commit'
7+
- '.github/workflows/lint-shellcheck.yml'
8+
pull_request:
9+
paths:
10+
- '**/*.{sh,bash,fish}'
11+
- './bin/*'
12+
- './scripts/git/pre-commit'
13+
- '.github/workflows/lint-shellcheck.yml'
14+
15+
name: "Lint Shellcheck"
16+
permissions: {}
17+
18+
jobs:
19+
shellcheck:
20+
name: Shellcheck
21+
runs-on: ubuntu-24.04
22+
steps:
23+
- run: shellcheck --version
24+
- uses: actions/checkout@v4
25+
- run: make lint-shellcheck

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ interpreter_spec: $(O)/interpreter_spec$(EXE) ## Run interpreter specs
133133
smoke_test: ## Build specs as a smoke test
134134
smoke_test: $(O)/std_spec$(EXE) $(O)/compiler_spec$(EXE) $(O)/$(CRYSTAL_BIN)
135135

136+
SHELLCHECK_SOURCES := $(wildcard **/*.sh) bin/crystal bin/ci bin/check-compiler-flag scripts/git/pre-commit
137+
138+
.PHONY: lint-shellcheck
139+
lint-shellcheck:
140+
shellcheck --severity=warning $(SHELLCHECK_SOURCES)
141+
136142
.PHONY: all_spec
137143
all_spec: $(O)/all_spec$(EXE) ## Run all specs (note: this builds a huge program; `test` recipe builds individual binaries and is recommended for reduced resource usage)
138144
$(O)/all_spec$(EXE) $(SPEC_FLAGS)

bin/ci

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/bin/sh
22

33
fail() {
4-
echo "${@}" >&2
4+
echo "${*}" >&2
55
exit 1
66
}
77

88
on_tag() {
99
if [ -n "$CURRENT_TAG" ]; then
10-
echo "${@}"
11-
eval "${@}"
10+
echo "${*}"
11+
eval "${*}"
1212
return $?
1313
else
1414
return 0
@@ -20,7 +20,7 @@ fail_on_error() {
2020

2121
exit=$?
2222
if [ "$exit" -ne "0" ]; then
23-
fail "${@} exited with $exit"
23+
fail "${*} exited with $exit"
2424
fi
2525

2626
return 0
@@ -50,8 +50,8 @@ on_os() {
5050
verify_environment
5151

5252
if [ "$TRAVIS_OS_NAME" = "$os" ]; then
53-
echo "${@}"
54-
eval "${@}"
53+
echo "${*}"
54+
eval "${*}"
5555
return $?
5656
else
5757
return 0
@@ -62,30 +62,30 @@ on_os() {
6262
}
6363

6464
on_linux() {
65-
fail_on_error on_os "linux" "${@}"
65+
fail_on_error on_os "linux" "${*}"
6666
}
6767

6868
on_osx() {
69-
fail_on_error on_os "osx" "${@}"
69+
fail_on_error on_os "osx" "${*}"
7070
}
7171

7272
on_nix_shell_eval() {
7373
if [ -n "$CI_NIX_SHELL" ]; then
74-
echo "${@}"
75-
eval "${@}"
74+
echo "${*}"
75+
eval "${*}"
7676
return $?
7777
else
7878
return 0
7979
fi
8080
}
8181

8282
on_nix_shell() {
83-
fail_on_error on_nix_shell_eval "${@}"
83+
fail_on_error on_nix_shell_eval "${*}"
8484
}
8585

8686
on_github() {
8787
if [ "$GITHUB_ACTIONS" = "true" ]; then
88-
eval "${@}"
88+
eval "${*}"
8989
return $?
9090
else
9191
return 0
@@ -153,7 +153,7 @@ prepare_build() {
153153

154154
# Install a recent bash version for nix-shell.
155155
# macos ships with an ancient one.
156-
if [ `uname` = "Darwin" ]; then
156+
if [ "$(uname)" = "Darwin" ]; then
157157
on_nix_shell "brew install bash"
158158
fi
159159
# initialize nix environment
@@ -172,7 +172,7 @@ prepare_build() {
172172

173173
verify_version() {
174174
# If building a tag, check it matches with file
175-
FILE_VERSION=`cat ./src/VERSION`
175+
FILE_VERSION=$(cat ./src/VERSION)
176176

177177
if [ "$FILE_VERSION" != "$CURRENT_TAG" ]
178178
then
@@ -205,8 +205,8 @@ with_build_env() {
205205

206206
on_linux docker run \
207207
--rm -t \
208-
-u $(id -u) \
209-
-v $PWD:/mnt \
208+
-u "$(id -u)" \
209+
-v "$PWD":/mnt \
210210
-v /etc/passwd:/etc/passwd \
211211
-v /etc/group:/etc/group \
212212
-w /mnt \
@@ -222,6 +222,7 @@ with_build_env() {
222222
CRYSTAL_CACHE_DIR="/tmp/crystal" \
223223
/bin/sh -c "'$command'"
224224

225+
# shellcheck disable=SC2086
225226
on_nix_shell nix-shell --pure $CI_NIX_SHELL_ARGS --run "'TZ=$TZ $command'"
226227

227228
on_github echo "::endgroup::"
@@ -254,7 +255,7 @@ case $command in
254255
prepare_build
255256
;;
256257
with_build_env)
257-
target_command="${@}"
258+
target_command="${*}"
258259
with_build_env "$target_command"
259260
;;
260261
build)

bin/crystal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fi
175175
# CRYSTAL_PATH has all symlinks resolved. In order to avoid issues with duplicate file
176176
# paths when the working directory is a symlink, we cd into the current directory
177177
# with symlinks resolved as well (see https://github.com/crystal-lang/crystal/issues/12969).
178-
cd "$(realpath "$(pwd)")"
178+
cd "$(realpath "$(pwd)")" || exit
179179

180180
case "$(uname -s)" in
181181
CYGWIN*|MSYS_NT*|MINGW32_NT*|MINGW64_NT*)

scripts/git/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ changed_cr_files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.cr$
2222

2323
if [ -x bin/crystal ]; then
2424
# use bin/crystal wrapper when available to run local compiler build
25+
# shellcheck disable=SC2086
2526
exec bin/crystal tool format --check $changed_cr_files >&2
2627
else
28+
# shellcheck disable=SC2086
2729
exec crystal tool format --check $changed_cr_files >&2
2830
fi

scripts/release-update.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ sed -i -E "s|crystal: \"[0-9.]+\"|crystal: \"$CRYSTAL_VERSION\"|g" .github/workf
4444

4545
# Edit shell.nix latestCrystalBinary using nix-prefetch-url --unpack <url>
4646
darwin_url="https://github.com/crystal-lang/crystal/releases/download/$CRYSTAL_VERSION/crystal-$CRYSTAL_VERSION-1-darwin-universal.tar.gz"
47-
darwin_sha=$(nix-prefetch-url --unpack $darwin_url)
47+
darwin_sha=$(nix-prefetch-url --unpack "$darwin_url")
4848

4949
sed -i -E "s|https://github.com/crystal-lang/crystal/releases/download/[0-9.]+/crystal-[0-9.]+-[0-9]-darwin-universal.tar.gz|$darwin_url|" shell.nix
5050
sed -i -E "/darwin-universal\.tar\.gz/ {n;s|sha256:[^\"]+|sha256:$darwin_sha|}" shell.nix
5151

5252
linux_url="https://github.com/crystal-lang/crystal/releases/download/$CRYSTAL_VERSION/crystal-$CRYSTAL_VERSION-1-linux-x86_64.tar.gz"
53-
linux_sha=$(nix-prefetch-url --unpack $linux_url)
53+
linux_sha=$(nix-prefetch-url --unpack "$linux_url")
5454

5555
sed -i -E "s|https://github.com/crystal-lang/crystal/releases/download/[0-9.]+/crystal-[0-9.]+-[0-9]-linux-x86_64.tar.gz|$linux_url|" shell.nix
5656
sed -i -E "/linux-x86_64\.tar\.gz/ {n;s|sha256:[^\"]+|sha256:$linux_sha|}" shell.nix

scripts/update-changelog.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ branch="changelog/$VERSION"
3535
current_changelog="CHANGELOG.$VERSION.md"
3636

3737
echo "Generating $current_changelog..."
38-
scripts/github-changelog.cr $VERSION > $current_changelog
38+
scripts/github-changelog.cr "$VERSION" > "$current_changelog"
3939

4040
echo "Switching to branch $branch"
41-
git switch $branch 2>/dev/null || git switch -c $branch;
41+
git switch "$branch" 2>/dev/null || git switch -c "$branch";
4242

4343
# Write release version into src/VERSION
4444
echo "${VERSION}" > src/VERSION
@@ -49,8 +49,8 @@ sed -i -E "s/version: .*/version: ${VERSION}/" shard.yml
4949
git add shard.yml
5050

5151
# Write release date into src/SOURCE_DATE_EPOCH
52-
release_date=$(head -n1 $current_changelog | grep -o -P '(?<=\()[^)]+')
53-
echo "$(date --utc --date="${release_date}" +%s)" > src/SOURCE_DATE_EPOCH
52+
release_date=$(head -n1 "$current_changelog" | grep -o -P '(?<=\()[^)]+')
53+
date --utc --date="${release_date}" +%s > src/SOURCE_DATE_EPOCH
5454
git add src/SOURCE_DATE_EPOCH
5555

5656
if grep --silent -E "^## \[$VERSION\]" CHANGELOG.md; then
@@ -70,7 +70,7 @@ else
7070

7171
git add CHANGELOG.md
7272
git commit -m "Add changelog for $VERSION"
73-
git push -u upstream $branch
73+
git push -u upstream "$branch"
7474

7575
gh pr create --draft --base "$base_branch" \
7676
--body "Preview: https://github.com/crystal-lang/crystal/blob/$branch/CHANGELOG.md" \

scripts/update-distribution-scripts.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ branch="${2:-"ci/update-distribution-scripts"}"
3535
git switch -C "$branch" master
3636

3737
old_reference=$(sed -n "/distribution-scripts-version:/{n;n;n;p}" .circleci/config.yml | grep -o -P '(?<=default: ")[^"]+')
38-
echo $old_reference..$reference
38+
echo "$old_reference".."$reference"
3939

4040
sed -i -E "/distribution-scripts-version:/{n;n;n;s/default: \".*\"/default: \"$reference\"/}" .circleci/config.yml
4141

4242
git add .circleci/config.yml
4343

4444
message="Updates \`distribution-scripts\` dependency to https://github.com/crystal-lang/distribution-scripts/commit/$reference"
45-
log=$($GIT_DS log $old_reference..$reference --format="%s" | sed "s/.*(/crystal-lang\/distribution-scripts/;s/^/* /;s/)$//")
45+
log=$($GIT_DS log "$old_reference".."$reference" --format="%s" | sed "s/.*(/crystal-lang\/distribution-scripts/;s/^/* /;s/)$//")
4646
message=$(printf "%s\n\nThis includes the following changes:\n\n%s" "$message" "$log")
4747

4848
git commit -m "Update distribution-scripts" -m "$message"

scripts/update-shards.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ if [ -z "$SHARDS_VERSION" ]; then
2020
fi
2121

2222
# Update shards ref in mingw64 and win-msvc build actions
23-
sed -i "/repository: crystal-lang\/shards/{n;s/ref: .*/ref: ${shards_version}/}" .github/workflows/mingw-w64.yml .github/workflows/win_build_portable.yml
23+
sed -i "/repository: crystal-lang\/shards/{n;s/ref: .*/ref: ${SHARDS_VERISON}/}" .github/workflows/mingw-w64.yml .github/workflows/win_build_portable.yml

spec/debug/test.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ BUILD_DIR=$SCRIPT_ROOT/../../.build
3636
crystal=${CRYSTAL_SPEC_COMPILER_BIN:-$SCRIPT_ROOT/../../bin/crystal}
3737
debugger=${1:-lldb}
3838
driver=$BUILD_DIR/debug_driver
39-
mkdir -p $BUILD_DIR
40-
"$crystal" build $SCRIPT_ROOT/driver.cr -o $driver
39+
mkdir -p "$BUILD_DIR"
40+
"$crystal" build "$SCRIPT_ROOT"/driver.cr -o "$driver"
4141

42-
$driver $SCRIPT_ROOT/top_level.cr $debugger
43-
$driver $SCRIPT_ROOT/strings.cr $debugger
44-
$driver $SCRIPT_ROOT/arrays.cr $debugger
45-
$driver $SCRIPT_ROOT/blocks.cr $debugger
46-
$driver $SCRIPT_ROOT/large_enums.cr $debugger
42+
$driver "$SCRIPT_ROOT"/top_level.cr "$debugger"
43+
$driver "$SCRIPT_ROOT"/strings.cr "$debugger"
44+
$driver "$SCRIPT_ROOT"/arrays.cr "$debugger"
45+
$driver "$SCRIPT_ROOT"/blocks.cr "$debugger"
46+
$driver "$SCRIPT_ROOT"/large_enums.cr "$debugger"

spec/generate_wasm32_spec.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ set +x
2424

2525
WORK_DIR=$(mktemp -d)
2626
function cleanup {
27-
rm -rf $WORK_DIR
27+
rm -rf "$WORK_DIR"
2828
}
2929
trap cleanup EXIT
3030

@@ -39,8 +39,8 @@ echo
3939

4040
for spec in $(find "spec/std" -type f -iname "*_spec.cr" | LC_ALL=C sort); do
4141
require="require \"./${spec##spec/}\""
42-
target=$WORK_DIR"/"$spec".wasm"
43-
mkdir -p $(dirname "$target")
42+
target="$WORK_DIR/$spec.wasm"
43+
mkdir -p "$(dirname "$target")"
4444

4545
if ! output=$(bin/crystal build "$spec" -o "$target" --target wasm32-wasi 2>&1); then
4646
if [[ "$output" =~ "execution of command failed" ]]; then

spec/llvm-ir/test.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,32 @@ SCRIPT_PATH="$(realpath "$0")"
99
SCRIPT_ROOT="$(dirname "$SCRIPT_PATH")"
1010

1111
BUILD_DIR=$SCRIPT_ROOT/../../.build
12-
LLVM_CONFIG="$(basename $($SCRIPT_ROOT/../../src/llvm/ext/find-llvm-config.sh))"
12+
LLVM_CONFIG="$(basename $("$SCRIPT_ROOT"/../../src/llvm/ext/find-llvm-config.sh))"
1313
FILE_CHECK=FileCheck-"${LLVM_CONFIG#llvm-config-}"
1414
crystal=${CRYSTAL_SPEC_COMPILER_BIN:-$SCRIPT_ROOT/../../bin/crystal}
1515

16-
mkdir -p $BUILD_DIR
16+
mkdir -p "$BUILD_DIR"
1717

1818
function test() {
19-
echo "test: $@"
19+
echo "test: $*"
2020

2121
input_cr="$SCRIPT_ROOT/$1"
2222
output_ll="$BUILD_DIR/${1%.cr}.ll"
23-
compiler_options="$2"
23+
# FIXME: unused variable
24+
# compiler_options="$2"
2425
check_prefix="${3+--check-prefix $3}"
2526

2627
# $BUILD_DIR/test-ir is never used
2728
# pushd $BUILD_DIR + $output_ll is a workaround due to the fact that we can't control
2829
# the filename generated by --emit=llvm-ir
29-
"$crystal" build --single-module --no-color --emit=llvm-ir $2 -o $BUILD_DIR/test-ir $input_cr
30-
$FILE_CHECK $input_cr --input-file $output_ll $check_prefix
30+
"$crystal" build --single-module --no-color --emit=llvm-ir "$2" -o "$BUILD_DIR"/test-ir "$input_cr"
31+
$FILE_CHECK "$input_cr" --input-file "$output_ll" "$check_prefix"
3132

32-
rm $BUILD_DIR/test-ir.o
33-
rm $output_ll
33+
rm "$BUILD_DIR"/test-ir.o
34+
rm "$output_ll"
3435
}
3536

36-
pushd $BUILD_DIR >/dev/null
37+
pushd "$BUILD_DIR" >/dev/null
3738

3839
test argless-initialize-debug-loc.cr "--cross-compile --target x86_64-unknown-linux-gnu --prelude=empty"
3940
test proc-call-debug-loc.cr "--cross-compile --target x86_64-unknown-linux-gnu --prelude=empty"

src/llvm/ext/find-llvm-config.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
if ! LLVM_CONFIG=$(command -v "$LLVM_CONFIG"); then
44
llvm_config_version=$(llvm-config --version 2>/dev/null)
5-
for version in $(cat "$(dirname $0)/llvm-versions.txt"); do
5+
# shellcheck disable=SC2013
6+
for version in $(cat "$(dirname "$0")/llvm-versions.txt"); do
67
LLVM_CONFIG=$(
7-
([ "${llvm_config_version#$version}" != "$llvm_config_version" ] && command -v llvm-config) || \
8-
command -v llvm-config-${version%.*} || \
9-
command -v llvm-config-$version || \
10-
command -v llvm-config${version%.*}${version#*.} || \
11-
command -v llvm-config${version%.*} || \
12-
command -v llvm-config$version || \
13-
command -v llvm${version%.*}-config)
8+
([ "${llvm_config_version#"$version"}" != "$llvm_config_version" ] && command -v llvm-config) || \
9+
command -v llvm-config-"${version%.*}" || \
10+
command -v llvm-config-"$version" || \
11+
command -v "llvm-config${version%.*}${version#*.}" || \
12+
command -v llvm-config"${version%.*}" || \
13+
command -v llvm-config"$version" || \
14+
command -v llvm"${version%.*}"-config)
1415
[ "$LLVM_CONFIG" ] && break
1516
done
1617
fi
@@ -26,6 +27,6 @@ if [ "$LLVM_CONFIG" ]; then
2627
esac
2728
else
2829
printf "Error: Could not find location of llvm-config. Please specify path in environment variable LLVM_CONFIG.\n" >&2
29-
printf "Supported LLVM versions: $(cat "$(dirname $0)/llvm-versions.txt" | sed 's/\.0//g')\n" >&2
30+
printf "Supported LLVM versions: %s\n" "$(sed 's/\.0//g' "$(dirname "$0")/llvm-versions.txt")" >&2
3031
exit 1
3132
fi

0 commit comments

Comments
 (0)