| 1 |
#!/bin/bash -eu |
| 2 |
|
| 3 |
git_hash="master" |
| 4 |
clone_dir="frama-c-clones" |
| 5 |
repository_path="[email protected]:frama-c/frama-c" |
| 6 |
show_usage="" |
| 7 |
|
| 8 |
while [[ $# > 0 ]] |
| 9 |
do |
| 10 |
case $1 in |
| 11 |
-d|--clone-dir) |
| 12 |
clone_dir="$2" |
| 13 |
shift |
| 14 |
;; |
| 15 |
|
| 16 |
-p|--repository-path) |
| 17 |
repository_path="$2" |
| 18 |
shift |
| 19 |
;; |
| 20 |
|
| 21 |
-h|--help) |
| 22 |
show_usage="yes" |
| 23 |
;; |
| 24 |
|
| 25 |
*) |
| 26 |
git_hash="$1" |
| 27 |
;; |
| 28 |
esac |
| 29 |
shift |
| 30 |
done |
| 31 |
|
| 32 |
if [ -n "$show_usage" ] |
| 33 |
then |
| 34 |
echo "Usage: $0 HASH" |
| 35 |
echo "Provides a working tree of Frama-C." |
| 36 |
echo "" |
| 37 |
echo "The following arguments can be given:" |
| 38 |
echo " -d, --clone-dir path to the directory where frama-c versions are" |
| 39 |
echo " cloned" |
| 40 |
echo " -p, --repository-path PATH do not clone from frama-c gitlab, use this path instead" |
| 41 |
echo " -h, --help prints this help and quits" |
| 42 |
exit 1 |
| 43 |
fi |
| 44 |
|
| 45 |
|
| 46 |
bare="$clone_dir/frama-c.git" |
| 47 |
|
| 48 |
# Check if bench clone exists |
| 49 |
if [ ! -d "$bare" ] |
| 50 |
then |
| 51 |
git clone --bare --quiet $repository_path "$bare" |
| 52 |
sed --in-place '/bare = true/d' $bare/config |
| 53 |
fi |
| 54 |
|
| 55 |
# Fetch all refs |
| 56 |
git -C $bare fetch origin '+refs/heads/*:refs/heads/*' --prune |
| 57 |
|
| 58 |
# Resolve branch name if given |
| 59 |
git_hash=`git --git-dir="$bare" rev-parse "$git_hash"` |
| 60 |
|
| 61 |
# target_path must be an absolute path |
| 62 |
target_path="$(readlink -f "$clone_dir/$git_hash")" |
| 63 |
|
| 64 |
# Checkout |
| 65 |
if [ ! -e "$target_path" ] |
| 66 |
then |
| 67 |
# The workdir cmd can extract a working tree of the desired hash |
| 68 |
# without cloning once more |
| 69 |
workdir_cmd=`locate git-new-workdir --limit 1` |
| 70 |
if [ -z "$workdir_cmd" ] |
| 71 |
then |
| 72 |
git --git-dir="$bare" worktree add "$target_path" "$git_hash" |
| 73 |
else |
| 74 |
bash "$workdir_cmd" "$bare" "$target_path" "$git_hash" |
| 75 |
fi |
| 76 |
fi |
| 77 |
|
| 78 |
# Build Frama-C |
| 79 |
if [ ! -e "$target_path/build/bin/frama-c" ] |
| 80 |
then |
| 81 |
( |
| 82 |
cd "$target_path"; |
| 83 |
autoconf -f --warnings=none; |
| 84 |
./configure --quiet --prefix=$(pwd)/build > /dev/null; |
| 85 |
make -j > /dev/null; |
| 86 |
make install > /dev/null; |
| 87 |
) |
| 88 |
fi |
| 89 |
|
| 90 |
# Output repository path |
| 91 |
echo "$target_path" |