Tizen_4.0 base
[platform/upstream/docker-engine.git] / hack / validate / vendor
1 #!/usr/bin/env bash
2
3 export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4 source "${SCRIPTDIR}/.validate"
5
6 validate_vendor_diff(){
7         IFS=$'\n'
8         files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.conf' 'vendor/' || true) )
9         unset IFS
10
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
29         else
30                 echo 'No vendor changes in diff.'
31         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