From 1a91e22e0c1903f65e0f134f04877f0835bf9eb6 Mon Sep 17 00:00:00 2001
From: Spencer Wilson <spencer.wilson@uwaterloo.ca>
Date: Thu, 25 Jul 2024 11:10:27 -0400
Subject: [PATCH] Add script to format code in a CI container

Signed-off-by: Spencer Wilson <spencer.wilson@uwaterloo.ca>
---
 scripts/format_code.sh | 11 +++++++++++
 tests/run_astyle.sh    |  8 +++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100755 scripts/format_code.sh

diff --git a/scripts/format_code.sh b/scripts/format_code.sh
new file mode 100755
index 0000000000..4cce811ccb
--- /dev/null
+++ b/scripts/format_code.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# SPDX-License-Identifier: MIT
+
+if [ ! -d "$LIBOQS_DIR" ]
+then
+	echo Must set environment variable LIBOQS_DIR
+	exit 1
+fi
+
+docker run --rm -v"$LIBOQS_DIR":/root/liboqs -w /root/liboqs openquantumsafe/ci-ubuntu-focal-x86_64:latest ./tests/run_astyle.sh --no-dry-run
diff --git a/tests/run_astyle.sh b/tests/run_astyle.sh
index 53a7414b4f..487996a64d 100755
--- a/tests/run_astyle.sh
+++ b/tests/run_astyle.sh
@@ -3,8 +3,14 @@
 
 rv=0
 
+if [ "$1" = "--no-dry-run" ]; then
+	dryrun=""
+else
+	dryrun="--dry-run"
+fi
+
 # check style of non-external code:
-find src tests -name '*.[ch]' | grep -v '/external/' | grep -v 'kem/.*/.*/.*' | grep -v 'sig/.*/.*/.*' | xargs astyle --dry-run --options=.astylerc | grep Format
+find src tests -name '*.[ch]' | grep -v '/external/' | grep -v 'kem/.*/.*/.*' | grep -v 'sig/.*/.*/.*' | xargs astyle $dryrun --options=.astylerc | grep Format
 if [ $? -ne 1 ]; then
    echo "Error: Some files need reformatting. Check output above."
    rv=-1