From 46669220a06c7cc14d62c8caebc7a27dd126922b Mon Sep 17 00:00:00 2001
From: Benjamin Kampmann <ben@gnunicorn.org>
Date: Mon, 25 Nov 2019 13:56:45 +0100
Subject: [PATCH] Reactivate depenency script:  - only enforce the now achieved
 status quo will remain  - allow for primitives to depend on /client for now
 without failing  - more discriptive error message so people understand, what
 it wants  - minor fix to differentiative between ../client and /client (which
 may be a subfolder)  - don't allow this to fail anylonger.

---
 .gitlab-ci.yml           |  1 -
 .maintain/ensure-deps.sh | 49 ++++++++++++++++++++++++++++------------
 2 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e4226ee8ad..439fda5fab 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -148,7 +148,6 @@ test-linux-stable:                 &test-linux
 test-dependency-rules:             &test-linux
   stage:                           test
   <<:                              *docker-env
-  allow_failure:                   true
   except:
     variables:
       - $DEPLOY_TAG
diff --git a/.maintain/ensure-deps.sh b/.maintain/ensure-deps.sh
index d8383cd313..696d0d56ca 100755
--- a/.maintain/ensure-deps.sh
+++ b/.maintain/ensure-deps.sh
@@ -3,36 +3,41 @@
 # The script is meant to check if the rules regarding packages
 # dependencies are satisfied.
 # The general format is:
-# [top-lvl-dir]<[crate-name-prefix]
+# [top-lvl-dir] MESSAGE/[other-top-dir]
 
 # For instance no crate within `./client` directory
 # is allowed to import any crate with a directory path containing `frame`.
-# Such rule is just: `client<frame`.
+# Such rule is just: `client crates must not depend on anything in /frame`.
 
 # The script should be run from the main repo directory!
 
 set -u
 
+# HARD FAILING
+MUST_NOT=(
+	"client crates must not depend on anything in /frame"
+	"client crates must not depend on anything in /node"
+	"frame crates must not depend on anything in /node"
+	"frame crates must not depend on anything in /client"
+	"primitives crates must not depend on anything in /frame"
+)
+
+# ONLY DISPLAYED, script still succeeds
 PLEASE_DONT=(
-	"client<frame"
-	"client<node"
-	"frame<node"
-	"frame<client"
-	"primitives<frame"
-	"primitives<client"
+	"primitives crates must not depend on anything in /client"
 )
 
 VIOLATIONS=()
 PACKAGES=()
 
-for rule in "${PLEASE_DONT[@]}"
-do
-	from=$(echo $rule | cut -f1 -d\<)
-	to=$(echo $rule | cut -f2 -d\<)
+function check_rule() {
+	rule=$1
+	from=$(echo $rule | cut -f1 -d\ )
+	to=$(echo $rule | cut -f2 -d\/)
 
 	cd $from
-	echo "Checking rule $rule"
-	packages=$(find -name Cargo.toml | xargs grep -wn "path.*$to")
+	echo "Checking rule '$rule'"
+	packages=$(find -name Cargo.toml | xargs grep -wn "path.*\.\.\/$to")
 	has_references=$(echo -n $packages | wc -c)
 	if [ "$has_references" != "0" ]; then
 		VIOLATIONS+=("$rule")
@@ -40,6 +45,20 @@ do
 		PACKAGES+=("$packages")
 	fi
 	cd - > /dev/null
+}
+
+for rule in "${MUST_NOT[@]}"
+do
+	check_rule "$rule";
+done
+
+# Only the MUST NOT will be counted towards failure
+HARD_VIOLATIONS=${#VIOLATIONS[@]}
+
+
+for rule in "${PLEASE_DONT[@]}"
+do
+	check_rule "$rule";
 done
 
 # Display violations and fail
@@ -58,4 +77,4 @@ EOF
 	I=$I+1
 done
 
-exit ${#VIOLATIONS[@]}
+exit $HARD_VIOLATIONS
-- 
GitLab