Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use xbt_cfg_setdefault everywhere.
[simgrid.git] / tools / check_dist_archive
1 #!/bin/bash
2
3 set -e
4
5 if [ "$1" = "-batch" ]; then
6     shift
7     interactive=0
8 elif [ -t 1 ]; then
9     interactive=1
10 else
11     interactive=0
12 fi
13
14 if [ $# -lt 1 -o $# -gt 3 ]; then
15     cat <<EOF
16 Usage: $0 [-batch] archive.tar.gz [git_url [git_reference]]
17 EOF
18     exit 1
19 fi
20
21 archive=$1
22 if [ ! -r "$archive" ]; then
23     printf 'File not found: %s\n' "$archive"
24     exit 1
25 fi
26
27 if [ $# -ge 2 ]; then
28     giturl=$2
29     gitref=${3:-master}
30 else
31     giturl=$(git rev-parse --show-toplevel)
32     gitref=HEAD
33 fi
34
35 tmpdir=$(mktemp -d)
36 trap "rm -fr \"$tmpdir\"" EXIT
37
38 arch_dir="$tmpdir/a"
39 git_dir="$tmpdir/b"
40
41 myname=$(type -p "$0")
42 case "$myname" in
43     /*)
44         exclude="$myname.exclude"
45         ;;
46     *)
47         exclude="$PWD/$myname.exclude"
48         ;;
49 esac
50
51 if [ ! -r "$exclude" ]; then
52     printf 'File not found: %s\n' "$exclude"
53     exit 1
54 fi
55
56 echo "Exclude patterns extracted from file: $exclude"
57
58 echo "Extracting archive: $archive -> $arch_dir"
59 tar --directory "$tmpdir" \
60     --transform 's!^[^/]*!a!' \
61     --extract --gunzip --file "$archive"
62
63 echo "Copying git repository: $giturl/$gitref -> $git_dir"
64 git archive --format=tar --prefix="b/" --remote="$giturl" "$gitref" \
65     | tar --directory "$tmpdir" --extract --file -
66
67 fa=from_tgz
68 fb=from_git
69 cd "$tmpdir"
70
71 sed -n '/^-/{s/^- //;p;}' "$exclude" > ea
72 sed -n '/^+/{s/^+ //;p;}' "$exclude" > eb
73
74 find a -type f \
75     | sed 's!^a/!!' \
76     | grep -E -v -x -f ea \
77     | sort > "$fa"
78 find b -type f \
79     | sed 's!^b/!!' \
80     | grep -E -v -x -f eb \
81     | sort > "$fb"
82
83 diffcmd() {
84     if cmp -s "$fa" "$fb"; then
85         status=0
86         echo "The archive looks good."
87     else
88         status=1
89         cat <<EOF
90 ERROR: Some files are missing and/or unexpected in the archive.
91 * lines beginning with '-' give files that are unexpected in the archive
92 * lines beginning with '+' give files that are missing from the archive
93 Please fix CMake files (e.g. "buildtools/Cmake/DefinePackages.cmake"),
94 and/or "tools/check_dist_archive.exclude".
95 EOF
96         diff -u "$fa" "$fb"
97     fi
98 }
99
100 colordiff=$(type -p colordiff)
101 colorless() {
102     if [ -x "$colordiff" ]; then
103         "$colordiff" | less -R -F -X
104     else
105         less -F -X
106     fi
107 }
108
109 if [ "$interactive" = "1" ]; then
110     diffcmd | colorless
111 else
112     diffcmd
113 fi || true
114
115 exit $status