[PATCH 0/2] release/checks/shfmt: init
The default formatting seems unobjectionable to me, but if anybody wants to lobby for different sh formatting rules, now's the time. :) Alyssa Ross (2): scripts: format with shfmt release/checks/shfmt: init release/checks/default.nix | 2 + release/checks/shfmt.nix | 15 +++++ scripts/dist-cloud-hypervisor.sh | 4 +- scripts/format-uuid.sh | 2 +- scripts/make-erofs.sh | 8 +-- scripts/run-qemu.sh | 109 ++++++++++++++++--------------- scripts/update-nixpkgs.sh | 4 +- 7 files changed, 81 insertions(+), 63 deletions(-) create mode 100644 release/checks/shfmt.nix base-commit: e9480cfdf8cba16d0e0b8ee2db3a916979804db9 -- 2.51.0
This is actually a treewide shfmt run, but I guess nothing outside of scripts/ has any formatting issues. Signed-off-by: Alyssa Ross <hi@alyssa.is> --- scripts/dist-cloud-hypervisor.sh | 4 +- scripts/format-uuid.sh | 2 +- scripts/make-erofs.sh | 8 +-- scripts/run-qemu.sh | 109 ++++++++++++++++--------------- scripts/update-nixpkgs.sh | 4 +- 5 files changed, 64 insertions(+), 63 deletions(-) diff --git a/scripts/dist-cloud-hypervisor.sh b/scripts/dist-cloud-hypervisor.sh index 603c2df..22bcbaa 100755 --- a/scripts/dist-cloud-hypervisor.sh +++ b/scripts/dist-cloud-hypervisor.sh @@ -16,6 +16,6 @@ trap 'rm -rf -- "$dir"' EXIT mkdir -p -- "$dir/$name/LICENSES" cp -- LICENSES/Apache-2.0.txt LICENSES/LicenseRef-BSD-3-Clause-Google.txt \ "$dir/$name/LICENSES" -cat pkgs/cloud-hypervisor/*.patch > "$dir/$name/cloud-hypervisor.patch" -cat pkgs/cloud-hypervisor/vhost/*.patch > "$dir/$name/vhost.patch" +cat pkgs/cloud-hypervisor/*.patch >"$dir/$name/cloud-hypervisor.patch" +cat pkgs/cloud-hypervisor/vhost/*.patch >"$dir/$name/vhost.patch" tar -C "$dir" -czf "$name.tar.gz" -- "$name" diff --git a/scripts/format-uuid.sh b/scripts/format-uuid.sh index 497a5f2..3b38278 100755 --- a/scripts/format-uuid.sh +++ b/scripts/format-uuid.sh @@ -4,7 +4,7 @@ # SPDX-FileCopyrightText: 2022 Unikie # SPDX-License-Identifier: EUPL-1.2+ -substr () { +substr() { str=$1 beg=$2 end=$3 diff --git a/scripts/make-erofs.sh b/scripts/make-erofs.sh index ad04844..7e46847 100755 --- a/scripts/make-erofs.sh +++ b/scripts/make-erofs.sh @@ -35,8 +35,8 @@ while read -r arg1; do # a subset of all paths, but this subset includes all of # the ones passed in practice other than /. case $arg2 in - (*/*) parent=${arg2%/*};; - (*) parent=.;; + */*) parent=${arg2%/*} ;; + *) parent=. ;; esac # Ensure any existing directories we want to write into are writable. @@ -50,8 +50,8 @@ while read -r arg1; do # shellcheck disable=SC2030 # shadowed on purpose case "$parent" in - */*) parent="${parent%/*}" ;; - *) break ;; + */*) parent="${parent%/*}" ;; + *) break ;; esac done diff --git a/scripts/run-qemu.sh b/scripts/run-qemu.sh index 64fd292..75ecef4 100755 --- a/scripts/run-qemu.sh +++ b/scripts/run-qemu.sh @@ -6,14 +6,14 @@ # which can't be handled portably in Make language. case "${ARCH:="$(uname -m)"}" in - aarch64) - machine=virt,accel=kvm:tcg,gic-version=3,iommu=smmuv3 - ;; - x86_64) - append="console=ttyS0${append:+ $append}" - iommu=intel-iommu,intremap=on - machine=q35,accel=kvm:tcg,kernel-irqchip=split - ;; +aarch64) + machine=virt,accel=kvm:tcg,gic-version=3,iommu=smmuv3 + ;; +x86_64) + append="console=ttyS0${append:+ $append}" + iommu=intel-iommu,intremap=on + machine=q35,accel=kvm:tcg,kernel-irqchip=split + ;; esac i=0 @@ -22,49 +22,50 @@ while [ $i -lt $# ]; do shift case "$arg" in - -append) - set -- "$@" -append "${append:+$append }$1" - i=$((i + 2)) - shift - continue - ;; - -device) - IFS=, - for opt in $1; do - case "$opt" in - *-iommu) - unset iommu - ;; + -append) + set -- "$@" -append "${append:+$append }$1" + i=$((i + 2)) + shift + continue + ;; + -device) + IFS=, + for opt in $1; do + case "$opt" in + *-iommu) + unset iommu + ;; + esac + break + done + unset IFS + ;; + -machine) + set -- "$@" "$arg" + i=$((i + 1)) + arg= + + IFS=, + for opt in $1; do + case "$opt" in + virtualization=on) + case "$ARCH" in + aarch64) + opt="$opt,accel=tcg" + ;; + *) + continue + ;; esac - break - done - unset IFS - ;; - -machine) - set -- "$@" "$arg" - i=$((i + 1)) - arg= + ;; + esac - IFS=, - for opt in $1; do - case "$opt" in - virtualization=on) - case "$ARCH" in - aarch64) - opt="$opt,accel=tcg" - ;; - *) - continue - ;; - esac - ;; - esac + arg="$arg${arg:+,}$opt" + done + unset IFS - arg="$arg${arg:+,}$opt" - done - unset IFS - - shift + shift + ;; esac set -- "$@" "$arg" @@ -74,12 +75,12 @@ done for arg; do case "$arg" in - -append) - append= - ;; - -kernel) - kernel=1 - ;; + -append) + append= + ;; + -kernel) + kernel=1 + ;; esac done diff --git a/scripts/update-nixpkgs.sh b/scripts/update-nixpkgs.sh index dd1b7de..e481eb0 100755 --- a/scripts/update-nixpkgs.sh +++ b/scripts/update-nixpkgs.sh @@ -12,11 +12,11 @@ set -ueo pipefail root="$(dirname "$0")/.." out="$(mktemp -p "$root/lib" -t nixpkgs.default.nix.XXXXXXXXXX)" -exec > "$out" +exec >"$out" rev="$( curl -fsLS "https://api.github.com/repos/NixOS/nixpkgs/branches/${1-nixos-unstable}" | - jq -r .commit.sha + jq -r .commit.sha )" url="https://github.com/NixOS/nixpkgs/archive/$rev.tar.gz" -- 2.51.0
On 10/1/25 06:27, Alyssa Ross wrote:
This is actually a treewide shfmt run, but I guess nothing outside of scripts/ has any formatting issues.
Signed-off-by: Alyssa Ross <hi@alyssa.is> --- scripts/dist-cloud-hypervisor.sh | 4 +- scripts/format-uuid.sh | 2 +- scripts/make-erofs.sh | 8 +-- scripts/run-qemu.sh | 109 ++++++++++++++++--------------- scripts/update-nixpkgs.sh | 4 +- 5 files changed, 64 insertions(+), 63 deletions(-)
diff --git a/scripts/dist-cloud-hypervisor.sh b/scripts/dist-cloud-hypervisor.sh index 603c2df..22bcbaa 100755 --- a/scripts/dist-cloud-hypervisor.sh +++ b/scripts/dist-cloud-hypervisor.sh @@ -16,6 +16,6 @@ trap 'rm -rf -- "$dir"' EXIT mkdir -p -- "$dir/$name/LICENSES" cp -- LICENSES/Apache-2.0.txt LICENSES/LicenseRef-BSD-3-Clause-Google.txt \ "$dir/$name/LICENSES" -cat pkgs/cloud-hypervisor/*.patch > "$dir/$name/cloud-hypervisor.patch" -cat pkgs/cloud-hypervisor/vhost/*.patch > "$dir/$name/vhost.patch" +cat pkgs/cloud-hypervisor/*.patch >"$dir/$name/cloud-hypervisor.patch" +cat pkgs/cloud-hypervisor/vhost/*.patch >"$dir/$name/vhost.patch" tar -C "$dir" -czf "$name.tar.gz" -- "$name" diff --git a/scripts/format-uuid.sh b/scripts/format-uuid.sh index 497a5f2..3b38278 100755 --- a/scripts/format-uuid.sh +++ b/scripts/format-uuid.sh @@ -4,7 +4,7 @@ # SPDX-FileCopyrightText: 2022 Unikie # SPDX-License-Identifier: EUPL-1.2+
-substr () { +substr() { str=$1 beg=$2 end=$3 diff --git a/scripts/make-erofs.sh b/scripts/make-erofs.sh index ad04844..7e46847 100755 --- a/scripts/make-erofs.sh +++ b/scripts/make-erofs.sh @@ -35,8 +35,8 @@ while read -r arg1; do # a subset of all paths, but this subset includes all of # the ones passed in practice other than /. case $arg2 in - (*/*) parent=${arg2%/*};; - (*) parent=.;; + */*) parent=${arg2%/*} ;; + *) parent=. ;; esac
I *really* don't like introducing mismatched parentheses, as it breaks parentheses matching in editors. Editors know about quoting, but probably not about case statements. Also, at least some shells misparse the form without the extra parentheses when inside $(...).
# Ensure any existing directories we want to write into are writable. @@ -50,8 +50,8 @@ while read -r arg1; do
# shellcheck disable=SC2030 # shadowed on purpose case "$parent" in - */*) parent="${parent%/*}" ;; - *) break ;; + */*) parent="${parent%/*}" ;; + *) break ;; esac done
diff --git a/scripts/run-qemu.sh b/scripts/run-qemu.sh index 64fd292..75ecef4 100755 --- a/scripts/run-qemu.sh +++ b/scripts/run-qemu.sh @@ -6,14 +6,14 @@ # which can't be handled portably in Make language.
case "${ARCH:="$(uname -m)"}" in - aarch64) - machine=virt,accel=kvm:tcg,gic-version=3,iommu=smmuv3 - ;; - x86_64) - append="console=ttyS0${append:+ $append}" - iommu=intel-iommu,intremap=on - machine=q35,accel=kvm:tcg,kernel-irqchip=split - ;; +aarch64) + machine=virt,accel=kvm:tcg,gic-version=3,iommu=smmuv3 + ;; +x86_64) + append="console=ttyS0${append:+ $append}" + iommu=intel-iommu,intremap=on + machine=q35,accel=kvm:tcg,kernel-irqchip=split + ;; esac
i=0 @@ -22,49 +22,50 @@ while [ $i -lt $# ]; do shift
case "$arg" in - -append) - set -- "$@" -append "${append:+$append }$1" - i=$((i + 2)) - shift - continue - ;; - -device) - IFS=, - for opt in $1; do - case "$opt" in - *-iommu) - unset iommu - ;; + -append) + set -- "$@" -append "${append:+$append }$1" + i=$((i + 2)) + shift + continue + ;; + -device) + IFS=, + for opt in $1; do + case "$opt" in + *-iommu) + unset iommu + ;; + esac + break + done + unset IFS + ;; + -machine) + set -- "$@" "$arg" + i=$((i + 1)) + arg= + + IFS=, + for opt in $1; do + case "$opt" in + virtualization=on) + case "$ARCH" in + aarch64) + opt="$opt,accel=tcg" + ;; + *) + continue + ;; esac - break - done - unset IFS - ;; - -machine) - set -- "$@" "$arg" - i=$((i + 1)) - arg= + ;; + esac
- IFS=, - for opt in $1; do - case "$opt" in - virtualization=on) - case "$ARCH" in - aarch64) - opt="$opt,accel=tcg" - ;; - *) - continue - ;; - esac - ;; - esac + arg="$arg${arg:+,}$opt" + done + unset IFS
- arg="$arg${arg:+,}$opt" - done - unset IFS - - shift + shift + ;; esac
set -- "$@" "$arg" @@ -74,12 +75,12 @@ done
for arg; do case "$arg" in - -append) - append= - ;; - -kernel) - kernel=1 - ;; + -append) + append= + ;; + -kernel) + kernel=1 + ;; esac done
diff --git a/scripts/update-nixpkgs.sh b/scripts/update-nixpkgs.sh index dd1b7de..e481eb0 100755 --- a/scripts/update-nixpkgs.sh +++ b/scripts/update-nixpkgs.sh @@ -12,11 +12,11 @@ set -ueo pipefail root="$(dirname "$0")/.." out="$(mktemp -p "$root/lib" -t nixpkgs.default.nix.XXXXXXXXXX)"
-exec > "$out" +exec >"$out"
rev="$( curl -fsLS "https://api.github.com/repos/NixOS/nixpkgs/branches/${1-nixos-unstable}" | - jq -r .commit.sha + jq -r .commit.sha
This seems to be pointless extra indentation.
)" url="https://github.com/NixOS/nixpkgs/archive/$rev.tar.gz"
-- Sincerely, Demi Marie Obenour (she/her/hers)
Demi Marie Obenour <demiobenour@gmail.com> writes:
On 10/1/25 06:27, Alyssa Ross wrote:
This is actually a treewide shfmt run, but I guess nothing outside of scripts/ has any formatting issues.
Signed-off-by: Alyssa Ross <hi@alyssa.is> --- scripts/dist-cloud-hypervisor.sh | 4 +- scripts/format-uuid.sh | 2 +- scripts/make-erofs.sh | 8 +-- scripts/run-qemu.sh | 109 ++++++++++++++++--------------- scripts/update-nixpkgs.sh | 4 +- 5 files changed, 64 insertions(+), 63 deletions(-)
diff --git a/scripts/dist-cloud-hypervisor.sh b/scripts/dist-cloud-hypervisor.sh index 603c2df..22bcbaa 100755 --- a/scripts/dist-cloud-hypervisor.sh +++ b/scripts/dist-cloud-hypervisor.sh @@ -16,6 +16,6 @@ trap 'rm -rf -- "$dir"' EXIT mkdir -p -- "$dir/$name/LICENSES" cp -- LICENSES/Apache-2.0.txt LICENSES/LicenseRef-BSD-3-Clause-Google.txt \ "$dir/$name/LICENSES" -cat pkgs/cloud-hypervisor/*.patch > "$dir/$name/cloud-hypervisor.patch" -cat pkgs/cloud-hypervisor/vhost/*.patch > "$dir/$name/vhost.patch" +cat pkgs/cloud-hypervisor/*.patch >"$dir/$name/cloud-hypervisor.patch" +cat pkgs/cloud-hypervisor/vhost/*.patch >"$dir/$name/vhost.patch" tar -C "$dir" -czf "$name.tar.gz" -- "$name" diff --git a/scripts/format-uuid.sh b/scripts/format-uuid.sh index 497a5f2..3b38278 100755 --- a/scripts/format-uuid.sh +++ b/scripts/format-uuid.sh @@ -4,7 +4,7 @@ # SPDX-FileCopyrightText: 2022 Unikie # SPDX-License-Identifier: EUPL-1.2+
-substr () { +substr() { str=$1 beg=$2 end=$3 diff --git a/scripts/make-erofs.sh b/scripts/make-erofs.sh index ad04844..7e46847 100755 --- a/scripts/make-erofs.sh +++ b/scripts/make-erofs.sh @@ -35,8 +35,8 @@ while read -r arg1; do # a subset of all paths, but this subset includes all of # the ones passed in practice other than /. case $arg2 in - (*/*) parent=${arg2%/*};; - (*) parent=.;; + */*) parent=${arg2%/*} ;; + *) parent=. ;; esac
I *really* don't like introducing mismatched parentheses, as it breaks parentheses matching in editors. Editors know about quoting, but probably not about case statements. Also, at least some shells misparse the form without the extra parentheses when inside $(...).
Emacs seems to, but it's probably an exception. I would like to have soem standard, and I wouldn't mind adopting matched parentheses style, but I didn't see an option for that in shfmt, at least. If there's a way to get formatted shell scripts with matched parantheses case items, then we can both be happy, but otherwise I'm inclined to favour consistent formatting, especially because I don't think we'd be able to standardize on a syntax I suspect most shell scripters don't even know exists (I didn't) without tooling support.
diff --git a/scripts/update-nixpkgs.sh b/scripts/update-nixpkgs.sh index dd1b7de..e481eb0 100755 --- a/scripts/update-nixpkgs.sh +++ b/scripts/update-nixpkgs.sh @@ -12,11 +12,11 @@ set -ueo pipefail root="$(dirname "$0")/.." out="$(mktemp -p "$root/lib" -t nixpkgs.default.nix.XXXXXXXXXX)"
-exec > "$out" +exec >"$out"
rev="$( curl -fsLS "https://api.github.com/repos/NixOS/nixpkgs/branches/${1-nixos-unstable}" | - jq -r .commit.sha + jq -r .commit.sha
This seems to be pointless extra indentation.
I think it's probably a good thing to have a consistent way of showing that something is part of a pipeline, since it's so easy to miss the line-final |.
This patch has been committed as dc9b9ff8f8fb5eee3545235d1c2f04b760faf51d, which can be viewed online at https://spectrum-os.org/git/spectrum/commit/?id=dc9b9ff8f8fb5eee3545235d1c2f.... This is an automated message. Send comments/questions/requests to: Alyssa Ross <hi@alyssa.is>
Signed-off-by: Alyssa Ross <hi@alyssa.is> --- release/checks/default.nix | 2 ++ release/checks/shfmt.nix | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 release/checks/shfmt.nix diff --git a/release/checks/default.nix b/release/checks/default.nix index 7d49dc9..ac47cb3 100644 --- a/release/checks/default.nix +++ b/release/checks/default.nix @@ -26,6 +26,8 @@ import ../../lib/call-package.nix ({ callSpectrumPackage }: shellcheck = callSpectrumPackage ./shellcheck.nix {}; + shfmt = callSpectrumPackage ./shfmt.nix {}; + uncrustify = callSpectrumPackage ./uncrustify.nix {}; wayland = callSpectrumPackage ./wayland {}; diff --git a/release/checks/shfmt.nix b/release/checks/shfmt.nix new file mode 100644 index 0000000..bd626ad --- /dev/null +++ b/release/checks/shfmt.nix @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: MIT +# SPDX-FileCopyrightText: 2025 Alyssa Ross <hi@alyssa.is> + +import ../../lib/call-package.nix ({ src, lib, runCommand, shfmt }: + +runCommand "spectrum-shfmt" { + src = lib.fileset.toSource { + root = ../..; + fileset = src; + }; + nativeBuildInputs = [ shfmt ]; +} '' + shfmt -d $src + touch $out +'') (_: {}) -- 2.51.0
This patch has been committed as 71fabd7fb23969854d9bba35e3a525da4e7d0785, which can be viewed online at https://spectrum-os.org/git/spectrum/commit/?id=71fabd7fb23969854d9bba35e3a5.... This is an automated message. Send comments/questions/requests to: Alyssa Ross <hi@alyssa.is>
participants (3)
-
Alyssa Ross -
Alyssa Ross -
Demi Marie Obenour