Validate code formatting when CI job runs
This will execute the format-code.sh script from
within the docker container that runs the per repo
CI job
Change-Id: I50321ddad1d664fcae0f168ba973ab23cf3c6f32
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/run-unit-test-docker.sh b/run-unit-test-docker.sh
index 283017b..2048d1b 100755
--- a/run-unit-test-docker.sh
+++ b/run-unit-test-docker.sh
@@ -17,6 +17,7 @@
OBMC_BUILD_SCRIPTS="openbmc-build-scripts"
UNIT_TEST_PY_DIR="scripts"
UNIT_TEST_PY="unit-test.py"
+FORMAT_CODE_SH="format-code.sh"
DBUS_UNIT_TEST_PY="dbus-unit-test.py"
DBUS_SYS_CONFIG_FILE=${dbus_sys_config_file:-"/usr/share/dbus-1/system.conf"}
@@ -55,6 +56,11 @@
${WORKSPACE}/${DBUS_UNIT_TEST_PY}
chmod a+x ${WORKSPACE}/${DBUS_UNIT_TEST_PY}
+# Copy format code script into workspace
+cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${FORMAT_CODE_SH} \
+${WORKSPACE}/${FORMAT_CODE_SH}
+chmod a+x ${WORKSPACE}/${FORMAT_CODE_SH}
+
# Configure docker build
cd ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}
echo "Building docker image with build-unit-test-docker.sh"
diff --git a/scripts/unit-test.py b/scripts/unit-test.py
index b3d7fd5..f526c9a 100755
--- a/scripts/unit-test.py
+++ b/scripts/unit-test.py
@@ -394,6 +394,11 @@
else:
printline = lambda *l: None
+ # First validate code formattting if repo has clang file
+ CODE_SCAN_DIR = WORKSPACE + "/" + UNIT_TEST_PKG
+ if os.path.exists(CODE_SCAN_DIR + "/.clang-format"):
+ check_call_cmd(WORKSPACE, "./format-code.sh", CODE_SCAN_DIR)
+
prev_umask = os.umask(000)
# Determine dependencies and add them
dep_added = dict()