From 1adb5852ec0c7da69073c8881b581851c72cbe03 Mon Sep 17 00:00:00 2001
From: smlng <s@mlng.net>
Date: Tue, 5 Jun 2018 17:06:11 +0200
Subject: [PATCH] tools: allow static checks to be run from any directory

---
 dist/tools/coccinelle/check.sh   | 5 ++++-
 dist/tools/cppcheck/check.sh     | 5 ++++-
 dist/tools/externc/check.sh      | 5 ++++-
 dist/tools/flake8/check.sh       | 5 ++++-
 dist/tools/headerguards/check.sh | 5 ++++-
 dist/tools/licenses/check.sh     | 5 ++++-
 dist/tools/pr_check/pr_check.sh  | 8 ++++++--
 7 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/dist/tools/coccinelle/check.sh b/dist/tools/coccinelle/check.sh
index d2aa3a8055..73b7bd533c 100755
--- a/dist/tools/coccinelle/check.sh
+++ b/dist/tools/coccinelle/check.sh
@@ -6,7 +6,10 @@
 # General Public License v2.1. See the file LICENSE in the top level
 # directory for more details.
 
-: "${RIOTTOOLS:=${PWD}/dist/tools}"
+: "${RIOTBASE:=$(cd $(dirname $0)/../../../; pwd)}"
+cd $RIOTBASE
+
+: "${RIOTTOOLS:=${RIOTBASE}/dist/tools}"
 . "${RIOTTOOLS}"/ci/changed_files.sh
 
 EXIT_CODE=0
diff --git a/dist/tools/cppcheck/check.sh b/dist/tools/cppcheck/check.sh
index b09f0b14d8..7d504ccb4f 100755
--- a/dist/tools/cppcheck/check.sh
+++ b/dist/tools/cppcheck/check.sh
@@ -8,7 +8,10 @@
 # General Public License v2.1. See the file LICENSE in the top level
 # directory for more details.
 
-: "${RIOTTOOLS:=${PWD}/dist/tools}"
+: "${RIOTBASE:=$(cd $(dirname $0)/../../../; pwd)}"
+cd $RIOTBASE
+
+: "${RIOTTOOLS:=${RIOTBASE}/dist/tools}"
 . "${RIOTTOOLS}"/ci/changed_files.sh
 
 # Don't show warnings about unusedStructMembers by default
diff --git a/dist/tools/externc/check.sh b/dist/tools/externc/check.sh
index 74f30b932d..a8a9cd791e 100755
--- a/dist/tools/externc/check.sh
+++ b/dist/tools/externc/check.sh
@@ -8,7 +8,10 @@
 # General Public License v2.1. See the file LICENSE in the top level
 # directory for more details.
 
-: "${RIOTTOOLS:=${PWD}/dist/tools}"
+: "${RIOTBASE:=$(cd $(dirname $0)/../../../; pwd)}"
+cd $RIOTBASE
+
+: "${RIOTTOOLS:=${RIOTBASE}/dist/tools}"
 . "${RIOTTOOLS}"/ci/changed_files.sh
 
 # prepare
diff --git a/dist/tools/flake8/check.sh b/dist/tools/flake8/check.sh
index 0b604f6706..b404949218 100755
--- a/dist/tools/flake8/check.sh
+++ b/dist/tools/flake8/check.sh
@@ -17,7 +17,10 @@ else
     CRESET=
 fi
 
-: "${RIOTTOOLS:=${PWD}/dist/tools}"
+: "${RIOTBASE:=$(cd $(dirname $0)/../../../; pwd)}"
+cd $RIOTBASE
+
+: "${RIOTTOOLS:=${RIOTBASE}/dist/tools}"
 . "${RIOTTOOLS}"/ci/changed_files.sh
 
 FILES=$(FILEREGEX='(?=*.py$|pyterm$)' changed_files)
diff --git a/dist/tools/headerguards/check.sh b/dist/tools/headerguards/check.sh
index bbac91323e..612a2e5cae 100755
--- a/dist/tools/headerguards/check.sh
+++ b/dist/tools/headerguards/check.sh
@@ -6,7 +6,10 @@
 # General Public License v2.1. See the file LICENSE in the top level
 # directory for more details.
 
-: "${RIOTTOOLS:=${PWD}/dist/tools}"
+: "${RIOTBASE:=$(cd $(dirname $0)/../../../; pwd)}"
+cd $RIOTBASE
+
+: "${RIOTTOOLS:=${RIOTBASE}/dist/tools}"
 . "${RIOTTOOLS}"/ci/changed_files.sh
 
 EXIT_CODE=0
diff --git a/dist/tools/licenses/check.sh b/dist/tools/licenses/check.sh
index 959f563800..92bab9798a 100755
--- a/dist/tools/licenses/check.sh
+++ b/dist/tools/licenses/check.sh
@@ -7,7 +7,10 @@
 # General Public License v2.1. See the file LICENSE in the top level
 # directory for more details.
 
-: "${RIOTTOOLS:=${PWD}/dist/tools}"
+: "${RIOTBASE:=$(cd $(dirname $0)/../../../; pwd)}"
+cd $RIOTBASE
+
+: "${RIOTTOOLS:=${RIOTBASE}/dist/tools}"
 . "${RIOTTOOLS}"/ci/changed_files.sh
 
 # customizable
diff --git a/dist/tools/pr_check/pr_check.sh b/dist/tools/pr_check/pr_check.sh
index f8c93e687c..5a88e832a9 100755
--- a/dist/tools/pr_check/pr_check.sh
+++ b/dist/tools/pr_check/pr_check.sh
@@ -7,10 +7,14 @@
 # directory for more details.
 #
 
-EXIT_CODE=0
-: "${RIOTTOOLS:=${PWD}/dist/tools}"
+: "${RIOTBASE:=$(cd $(dirname $0)/../../../; pwd)}"
+cd $RIOTBASE
+
+: "${RIOTTOOLS:=${RIOTBASE}/dist/tools}"
 . "${RIOTTOOLS}"/pr_check/check_labels.sh
 
+EXIT_CODE=0
+
 if tput colors &> /dev/null && [ $(tput colors) -ge 8 ]; then
     CERROR="\e[1;31m"
     CRESET="\e[0m"
-- 
GitLab