Skip to content

Commit 1c4dfa2

Browse files
committed
Add shellcheck
1 parent 2964458 commit 1c4dfa2

File tree

8 files changed

+55
-13
lines changed

8 files changed

+55
-13
lines changed

lint-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ clang-format>=19.1.6
22
clang-tidy>=19.1.0
33
colorama>=0.4.6
44
gersemi>=0.16.2
5+
shellcheck-py>=0.10.0
56
yamllint>=1.35.1

taskfiles/deps.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ version: "3"
22

33
tasks:
44
default:
5+
desc: "Install all required dependencies."
56
cmds:
67
- task: "pkgs"
78

89
pkgs:
10+
desc: "Install dependencies from prebuilt packages or build them from source packages."
911
cmds:
1012
- task: "linux-pkgs"
1113
- task: "macos-pkgs"
@@ -23,4 +25,4 @@ tasks:
2325
platforms:
2426
- "darwin"
2527
cmds:
26-
- "echo 'Nothing to be installed for macOS.'"
28+
- "echo 'Nothing pckages required to be installed for macOS.'"

taskfiles/lint-cmake.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ tasks:
55
desc: "Runs the CMake linters."
66
sources: &cmake_format_src_files
77
- "{{.G_LINT_VENV_CHECKSUM_FILE}}"
8-
- "{{.G_YSTDLIB_CPP_SRC_DIR}}/.gersemirc"
98
- "{{.ROOT_DIR}}/**/*.cmake"
109
- "{{.ROOT_DIR}}/**/*.cmake.in"
1110
- "{{.ROOT_DIR}}/**/CMakeLists.txt"

taskfiles/lint-cpp.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ tasks:
5252
# NOTE: clang-tidy does have the ability to fix some errors, but the fixes can be inaccurate.
5353
# When we eventually determine which errors can be safely fixed, we'll allow clang-tidy to
5454
# fix them.
55-
desc: "Runs the C++ static analyzers. Only checks for warnings and violations."
5655
aliases:
5756
- "cpp-static-fix"
57+
desc: "Runs the C++ static analyzers. Only checks for warnings and violations."
5858
sources:
5959
- "{{.G_CMAKE_CACHE}}"
6060
- "{{.G_COMPILE_COMMANDS_DB}}"

taskfiles/lint-sh.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: "3"
2+
3+
tasks:
4+
sh-check:
5+
# NOTE: shellcheck does not have the ability to fix errors.
6+
aliases:
7+
- "sh-fix"
8+
desc: "Runs the shell script linters. Only checks for warnings and violations."
9+
sources:
10+
- "{{.G_LINT_VENV_CHECKSUM_FILE}}"
11+
- "{{.G_SCRIPT_DIR}}/**/*.sh"
12+
- "{{.TASKFILE}}"
13+
- exclude: "{{.ROOT_DIR}}/**/.shellcheckrc"
14+
deps:
15+
- "venv"
16+
cmds:
17+
- task: "shellcheck"
18+
vars:
19+
FLAGS: "--enable=all --severity=style --external-sources --norc"
20+
SRC_PATHS:
21+
ref: ".G_LINT_SH_DIRS"
22+
VENV_DIR: "{{.G_LINT_VENV_DIR}}"
23+
24+
shellcheck:
25+
internal: true
26+
requires:
27+
vars: ["FLAGS", "SRC_PATHS", "VENV_DIR"]
28+
cmd: |-
29+
. "{{.VENV_DIR}}/bin/activate"
30+
find {{- range .SRC_PATHS}} "{{.}}" {{- end}} \
31+
-type f -iname "*.sh" -print0 | \
32+
xargs -0 shellcheck {{.FLAGS}}

taskfiles/lint-venv.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ tasks:
99
sources:
1010
- "{{.ROOT_DIR}}/taskfile.yaml"
1111
- "{{.TASKFILE}}"
12-
- "lint-requirements.txt"
12+
- "{{.ROOT_DIR}}/lint-requirements.txt"
1313
generates:
1414
- "{{.CHECKSUM_FILE}}"
1515
run: "once"
@@ -24,7 +24,7 @@ tasks:
2424
vars:
2525
LABEL: "lint"
2626
OUTPUT_DIR: "{{.OUTPUT_DIR}}"
27-
REQUIREMENTS_FILE: "lint-requirements.txt"
27+
REQUIREMENTS_FILE: "{{.ROOT_DIR}}/lint-requirements.txt"
2828
# This command must be last
2929
- task: ":utils:compute-checksum"
3030
vars:

taskfiles/lint.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ includes:
1010
venv:
1111
flatten: true
1212
taskfile: "./lint-venv.yaml"
13+
sh:
14+
flatten: true
15+
taskfile: "./lint-sh.yaml"
1316
yaml:
1417
flatten: true
1518
taskfile: "./lint-yaml.yaml"
1619

1720
vars:
1821
G_LINT_CPP_DIRS:
1922
- "{{.G_CPP_SRC_DIR}}"
23+
G_LINT_SH_DIRS:
24+
- "{{.G_SCRIPT_DIR}}"
2025
G_LINT_VENV_DIR: "{{.G_BUILD_DIR}}/lint-venv"
2126
G_LINT_VENV_CHECKSUM_FILE: "{{.G_BUILD_DIR}}/lint#venv.md5"
2227

@@ -26,11 +31,13 @@ tasks:
2631
cmds:
2732
- task: "cmake-check"
2833
- task: "cpp-check"
34+
- task: "sh-check"
2935
- task: "yaml-check"
3036

3137
fix:
3238
desc: "Runs the full suite of linters and fixes some violations."
3339
cmds:
3440
- task: "cmake-fix"
3541
- task: "cpp-fix"
42+
- task: "sh-fix"
3643
- task: "yaml-fix"

tools/scripts/lib_install/linux/install-all.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@ script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
1010

1111
echo "Checking for elevated privileges..."
1212
privileged_command_prefix=""
13-
if [ ${EUID:-$(id -u)} -ne 0 ] ; then
13+
USER_ID=${EUID:-$(id -u)}
14+
if [[ 0 -ne ${USER_ID} ]] ; then
1415
sudo echo "Script can elevate privileges."
1516
privileged_command_prefix="${privileged_command_prefix} sudo"
1617
fi
1718

1819
# Check if the system is running Ubuntu and determine the version
1920
if [[ -f /etc/os-release ]]; then
2021
source /etc/os-release
21-
if [[ "$ID" == "ubuntu" &&
22-
( "$VERSION_CODENAME" == "focal" ||
23-
"$VERSION_CODENAME" == "jammy" ||
24-
"$VERSION_CODENAME" == "noble" ) ]]; then
25-
dist_dir="$script_dir/ubuntu-$VERSION_CODENAME"
22+
if [[ "${ID}" == "ubuntu" &&
23+
( "${VERSION_CODENAME}" == "focal" ||
24+
"${VERSION_CODENAME}" == "jammy" ||
25+
"${VERSION_CODENAME}" == "noble" ) ]]; then
26+
dist_dir="${script_dir}/ubuntu-${VERSION_CODENAME}"
2627
for exe_file in \
27-
"$dist_dir/install-prebuilt-packages.sh" "$dist_dir/install-packages-from-source.sh"; do
28-
[[ -f "$exe_file" ]] && ${privileged_command_prefix} $exe_file
28+
"${dist_dir}/install-prebuilt-packages.sh" "${dist_dir}/install-packages-from-source.sh"; do
29+
[[ -f "${exe_file}" ]] && "${privileged_command_prefix} ${exe_file}"
2930
done
3031
exit 0
3132
fi

0 commit comments

Comments
 (0)