patches and low-level development discussion
 help / color / mirror / code / Atom feed
* [PATCH 1/2] scripts: fix shellcheck warnings
@ 2022-11-10 11:22 Alyssa Ross
  2022-11-10 11:22 ` [PATCH 2/2] release.nix: run shellcheck on build scripts Alyssa Ross
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alyssa Ross @ 2022-11-10 11:22 UTC (permalink / raw)
  To: devel; +Cc: Henri Rosten

Signed-off-by: Alyssa Ross <alyssa.ross@unikie.com>
---

Henri, I've CCed you on this series, in case you'd like to review.
We have some documentation on reviewing patches here:

 https://spectrum-os.org/doc/development/reviewing-patches.html

 scripts/format-uuid.sh | 12 ++++++------
 scripts/make-gpt.sh    |  6 +++---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/scripts/format-uuid.sh b/scripts/format-uuid.sh
index 6758088..441ed64 100755
--- a/scripts/format-uuid.sh
+++ b/scripts/format-uuid.sh
@@ -8,12 +8,12 @@ substr () {
     str=$1
     beg=$2
     end=$3
-    echo $str | cut -c $beg-$end
+    echo "$str" | cut -c "$beg-$end"
 }
 
-u1=$(substr $1 1 8)
-u2=$(substr $1 9 12)
-u3=$(substr $1 13 16)
-u4=$(substr $1 17 20)
-u5=$(substr $1 21 32)
+u1=$(substr "$1" 1 8)
+u2=$(substr "$1" 9 12)
+u3=$(substr "$1" 13 16)
+u4=$(substr "$1" 17 20)
+u5=$(substr "$1" 21 32)
 printf "%s\n" "$u1-$u2-$u3-$u4-$u5"
diff --git a/scripts/make-gpt.sh b/scripts/make-gpt.sh
index 3215edb..554182f 100755
--- a/scripts/make-gpt.sh
+++ b/scripts/make-gpt.sh
@@ -23,7 +23,7 @@ sizeMiB() {
 fillPartition() {
 	sfdisk -J "$1" | jq -r --argjson index "$2" \
 		'.partitiontable.partitions[$index] | "\(.start) \(.size)"' |
-		(read start size;
+		(read -r start size;
 		 dd if="$3" of="$1" seek="$start" count="$size" conv=notrunc)
 }
 
@@ -48,7 +48,7 @@ gptBytes=$TWO_MiB
 for partition; do
 	sizeMiB="$(sizeMiB "$(partitionPath "$partition")")"
 	table="$table${nl}size=${sizeMiB}MiB,$(awk -f "$scriptsDir/sfdisk-field.awk" -v partition="$partition")"
-	gptBytes="$(expr "$gptBytes" + "$sizeMiB" \* $ONE_MiB)"
+	gptBytes="$((gptBytes + sizeMiB * ONE_MiB))"
 done
 
 rm -f "$out"
@@ -60,5 +60,5 @@ EOF
 n=0
 for partition; do
 	fillPartition "$out" "$n" "$(partitionPath "$partition")"
-	n="$(expr "$n" + 1)"
+	n="$((n + 1))"
 done
-- 
2.35.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] release.nix: run shellcheck on build scripts
  2022-11-10 11:22 [PATCH 1/2] scripts: fix shellcheck warnings Alyssa Ross
@ 2022-11-10 11:22 ` Alyssa Ross
  2022-11-10 13:40   ` Henri Rosten
  2022-11-11 14:28   ` Alyssa Ross
  2022-11-10 13:38 ` [PATCH 1/2] scripts: fix shellcheck warnings Henri Rosten
  2022-11-11 14:28 ` Alyssa Ross
  2 siblings, 2 replies; 6+ messages in thread
From: Alyssa Ross @ 2022-11-10 11:22 UTC (permalink / raw)
  To: devel; +Cc: Henri Rosten

This will make the binary cache build (which I expect to become more
CI-like over time) fail if shellcheck doesn't pass on any shell
scripts found in the tree.  This will help ensure we are sticking to
POSIX shell features and following shell scripting best practices.

At present, only scripts with names ending in ".sh" are processed, as
we don't have any others, and discovering extensionless scripts would
be quite a bit more complex.  We can worry about that when the time
comes.

Signed-off-by: Alyssa Ross <alyssa.ross@unikie.com>
---
 nix/checks.nix | 24 ++++++++++++++++++++++++
 release.nix    |  2 ++
 2 files changed, 26 insertions(+)
 create mode 100644 nix/checks.nix

diff --git a/nix/checks.nix b/nix/checks.nix
new file mode 100644
index 0000000..9eb261f
--- /dev/null
+++ b/nix/checks.nix
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: MIT
+# SPDX-FileCopyrightText: 2022 Unikie
+
+{ config ? import ../nix/eval-config.nix {} }:
+
+{
+  recurseForDerivations = true;
+
+  shellcheck = config.pkgs.callPackage (
+    { lib, runCommand, shellcheck }:
+    runCommand "spectrum-shellcheck" {
+      src = lib.cleanSourceWith {
+        filter = path: type:
+          type == "directory" || builtins.match ''.*[^/]\.sh'' path != null;
+        src = lib.cleanSource ../.;
+      };
+
+      nativeBuildInputs = [ shellcheck ];
+    } ''
+      shellcheck $src/**/*.sh
+      touch $out
+    ''
+  ) {};
+}
diff --git a/release.nix b/release.nix
index 91a843b..3ecf8a7 100644
--- a/release.nix
+++ b/release.nix
@@ -12,5 +12,7 @@
 {
   doc = import ./Documentation { inherit config; };
 
+  checks = import nix/checks.nix { inherit config; };
+
   combined = import img/combined/run-vm.nix { inherit config; };
 }
-- 
2.35.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] scripts: fix shellcheck warnings
  2022-11-10 11:22 [PATCH 1/2] scripts: fix shellcheck warnings Alyssa Ross
  2022-11-10 11:22 ` [PATCH 2/2] release.nix: run shellcheck on build scripts Alyssa Ross
@ 2022-11-10 13:38 ` Henri Rosten
  2022-11-11 14:28 ` Alyssa Ross
  2 siblings, 0 replies; 6+ messages in thread
From: Henri Rosten @ 2022-11-10 13:38 UTC (permalink / raw)
  To: Alyssa Ross; +Cc: devel

On Thu, Nov 10, 2022 at 11:22:19AM +0000, Alyssa Ross wrote:
> Signed-off-by: Alyssa Ross <alyssa.ross@unikie.com>

Reviewed-by: Henri Rosten <henri.rosten@unikie.com>

> ---
> 
> Henri, I've CCed you on this series, in case you'd like to review.
> We have some documentation on reviewing patches here:
> 
>  https://spectrum-os.org/doc/development/reviewing-patches.html
> 
>  scripts/format-uuid.sh | 12 ++++++------
>  scripts/make-gpt.sh    |  6 +++---
>  2 files changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/scripts/format-uuid.sh b/scripts/format-uuid.sh
> index 6758088..441ed64 100755
> --- a/scripts/format-uuid.sh
> +++ b/scripts/format-uuid.sh
> @@ -8,12 +8,12 @@ substr () {
>      str=$1
>      beg=$2
>      end=$3
> -    echo $str | cut -c $beg-$end
> +    echo "$str" | cut -c "$beg-$end"
>  }
>  
> -u1=$(substr $1 1 8)
> -u2=$(substr $1 9 12)
> -u3=$(substr $1 13 16)
> -u4=$(substr $1 17 20)
> -u5=$(substr $1 21 32)
> +u1=$(substr "$1" 1 8)
> +u2=$(substr "$1" 9 12)
> +u3=$(substr "$1" 13 16)
> +u4=$(substr "$1" 17 20)
> +u5=$(substr "$1" 21 32)
>  printf "%s\n" "$u1-$u2-$u3-$u4-$u5"
> diff --git a/scripts/make-gpt.sh b/scripts/make-gpt.sh
> index 3215edb..554182f 100755
> --- a/scripts/make-gpt.sh
> +++ b/scripts/make-gpt.sh
> @@ -23,7 +23,7 @@ sizeMiB() {
>  fillPartition() {
>  	sfdisk -J "$1" | jq -r --argjson index "$2" \
>  		'.partitiontable.partitions[$index] | "\(.start) \(.size)"' |
> -		(read start size;
> +		(read -r start size;
>  		 dd if="$3" of="$1" seek="$start" count="$size" conv=notrunc)
>  }
>  
> @@ -48,7 +48,7 @@ gptBytes=$TWO_MiB
>  for partition; do
>  	sizeMiB="$(sizeMiB "$(partitionPath "$partition")")"
>  	table="$table${nl}size=${sizeMiB}MiB,$(awk -f "$scriptsDir/sfdisk-field.awk" -v partition="$partition")"
> -	gptBytes="$(expr "$gptBytes" + "$sizeMiB" \* $ONE_MiB)"
> +	gptBytes="$((gptBytes + sizeMiB * ONE_MiB))"
>  done
>  
>  rm -f "$out"
> @@ -60,5 +60,5 @@ EOF
>  n=0
>  for partition; do
>  	fillPartition "$out" "$n" "$(partitionPath "$partition")"
> -	n="$(expr "$n" + 1)"
> +	n="$((n + 1))"
>  done
> -- 
> 2.35.1
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] release.nix: run shellcheck on build scripts
  2022-11-10 11:22 ` [PATCH 2/2] release.nix: run shellcheck on build scripts Alyssa Ross
@ 2022-11-10 13:40   ` Henri Rosten
  2022-11-11 14:28   ` Alyssa Ross
  1 sibling, 0 replies; 6+ messages in thread
From: Henri Rosten @ 2022-11-10 13:40 UTC (permalink / raw)
  To: Alyssa Ross; +Cc: devel

On Thu, Nov 10, 2022 at 11:22:20AM +0000, Alyssa Ross wrote:
> This will make the binary cache build (which I expect to become more
> CI-like over time) fail if shellcheck doesn't pass on any shell
> scripts found in the tree.  This will help ensure we are sticking to
> POSIX shell features and following shell scripting best practices.
> 
> At present, only scripts with names ending in ".sh" are processed, as
> we don't have any others, and discovering extensionless scripts would
> be quite a bit more complex.  We can worry about that when the time
> comes.
> 
> Signed-off-by: Alyssa Ross <alyssa.ross@unikie.com>

Reviewed-by: Henri Rosten <henri.rosten@unikie.com>

> ---
>  nix/checks.nix | 24 ++++++++++++++++++++++++
>  release.nix    |  2 ++
>  2 files changed, 26 insertions(+)
>  create mode 100644 nix/checks.nix
> 
> diff --git a/nix/checks.nix b/nix/checks.nix
> new file mode 100644
> index 0000000..9eb261f
> --- /dev/null
> +++ b/nix/checks.nix
> @@ -0,0 +1,24 @@
> +# SPDX-License-Identifier: MIT
> +# SPDX-FileCopyrightText: 2022 Unikie
> +
> +{ config ? import ../nix/eval-config.nix {} }:
> +
> +{
> +  recurseForDerivations = true;
> +
> +  shellcheck = config.pkgs.callPackage (
> +    { lib, runCommand, shellcheck }:
> +    runCommand "spectrum-shellcheck" {
> +      src = lib.cleanSourceWith {
> +        filter = path: type:
> +          type == "directory" || builtins.match ''.*[^/]\.sh'' path != null;
> +        src = lib.cleanSource ../.;
> +      };
> +
> +      nativeBuildInputs = [ shellcheck ];
> +    } ''
> +      shellcheck $src/**/*.sh
> +      touch $out
> +    ''
> +  ) {};
> +}
> diff --git a/release.nix b/release.nix
> index 91a843b..3ecf8a7 100644
> --- a/release.nix
> +++ b/release.nix
> @@ -12,5 +12,7 @@
>  {
>    doc = import ./Documentation { inherit config; };
>  
> +  checks = import nix/checks.nix { inherit config; };
> +
>    combined = import img/combined/run-vm.nix { inherit config; };
>  }
> -- 
> 2.35.1
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] release.nix: run shellcheck on build scripts
  2022-11-10 11:22 ` [PATCH 2/2] release.nix: run shellcheck on build scripts Alyssa Ross
  2022-11-10 13:40   ` Henri Rosten
@ 2022-11-11 14:28   ` Alyssa Ross
  1 sibling, 0 replies; 6+ messages in thread
From: Alyssa Ross @ 2022-11-11 14:28 UTC (permalink / raw)
  To: Alyssa Ross, devel; +Cc: Henri Rosten

This patch has been committed as 169fdd697771326fb111ab4532804a40e0fbeaa1,
which can be viewed online at
https://spectrum-os.org/git/spectrum/commit/?id=169fdd697771326fb111ab4532804a40e0fbeaa1.

This is an automated message.  Send comments/questions/requests to:
Alyssa Ross <hi@alyssa.is>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] scripts: fix shellcheck warnings
  2022-11-10 11:22 [PATCH 1/2] scripts: fix shellcheck warnings Alyssa Ross
  2022-11-10 11:22 ` [PATCH 2/2] release.nix: run shellcheck on build scripts Alyssa Ross
  2022-11-10 13:38 ` [PATCH 1/2] scripts: fix shellcheck warnings Henri Rosten
@ 2022-11-11 14:28 ` Alyssa Ross
  2 siblings, 0 replies; 6+ messages in thread
From: Alyssa Ross @ 2022-11-11 14:28 UTC (permalink / raw)
  To: Alyssa Ross, devel; +Cc: Henri Rosten

This patch has been committed as 1c8b473f048e55e316900ea83abc40fdb3cdd66a,
which can be viewed online at
https://spectrum-os.org/git/spectrum/commit/?id=1c8b473f048e55e316900ea83abc40fdb3cdd66a.

This is an automated message.  Send comments/questions/requests to:
Alyssa Ross <hi@alyssa.is>


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-11-11 14:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10 11:22 [PATCH 1/2] scripts: fix shellcheck warnings Alyssa Ross
2022-11-10 11:22 ` [PATCH 2/2] release.nix: run shellcheck on build scripts Alyssa Ross
2022-11-10 13:40   ` Henri Rosten
2022-11-11 14:28   ` Alyssa Ross
2022-11-10 13:38 ` [PATCH 1/2] scripts: fix shellcheck warnings Henri Rosten
2022-11-11 14:28 ` Alyssa Ross

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).