Browse code

hack/validate/vendor: add more checks

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>

Akihiro Suda authored on 2017/02/16 16:22:24
Showing 1 changed files
... ...
@@ -3,28 +3,49 @@
3 3
 export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4 4
 source "${SCRIPTDIR}/.validate"
5 5
 
6
-IFS=$'\n'
7
-files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.conf' 'vendor/' || true) ) 
8
-unset IFS
6
+validate_vendor_diff(){
7
+	IFS=$'\n'
8
+	files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.conf' 'vendor/' || true) )
9
+	unset IFS
9 10
 
10
-if [ ${#files[@]} -gt 0 ]; then
11
-	# We run vndr to and see if we have a diff afterwards
12
-	vndr
13
-	# Let see if the working directory is clean
14
-	diffs="$(git status --porcelain -- vendor 2>/dev/null)"
15
-	if [ "$diffs" ]; then
16
-		{
17
-			echo 'The result of vndr differs'
18
-			echo
19
-			echo "$diffs"
20
-			echo
21
-			echo 'Please vendor your package with github.com/LK4D4/vndr.'
22
-			echo
23
-		} >&2
24
-		false
11
+	if [ ${#files[@]} -gt 0 ]; then
12
+		# We run vndr to and see if we have a diff afterwards
13
+		vndr
14
+		# Let see if the working directory is clean
15
+		diffs="$(git status --porcelain -- vendor 2>/dev/null)"
16
+		if [ "$diffs" ]; then
17
+			{
18
+				echo 'The result of vndr differs'
19
+				echo
20
+				echo "$diffs"
21
+				echo
22
+				echo 'Please vendor your package with github.com/LK4D4/vndr.'
23
+				echo
24
+			} >&2
25
+			false
26
+		else
27
+			echo 'Congratulations! All vendoring changes are done the right way.'
28
+		fi
25 29
 	else
26
-		echo 'Congratulations! All vendoring changes are done the right way.'
30
+		echo 'No vendor changes in diff.'
27 31
 	fi
28
-else
29
-    echo 'No vendor changes in diff.'
30
-fi
32
+}
33
+
34
+# 1. make sure all the vendored packages are used
35
+# 2. make sure all the packages contain license information (just warning, because it can cause false-positive)
36
+validate_vendor_used() {
37
+    pkgs=$(mawk '/^[a-zA-Z0-9]/ { print $1 }' < vendor.conf)
38
+    for f in $pkgs; do
39
+	if ls -d vendor/$f  > /dev/null 2>&1; then
40
+	    found=$(find vendor/$f -iregex '.*LICENSE.*' -or -iregex '.*COPYRIGHT.*' -or -iregex '.*COPYING.*' | wc -l)
41
+	    if [ $found -eq 0 ]; then
42
+		echo "WARNING: could not find copyright information for $f"
43
+	    fi
44
+	else
45
+	    echo "WARNING: $f is vendored but unused"
46
+	fi
47
+    done
48
+}
49
+
50
+validate_vendor_diff
51
+validate_vendor_used