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