Logo AND Algorithmique Numérique Distribuée

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