forked from Dronecode/air-iop-definitions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_library.sh
executable file
·88 lines (79 loc) · 3.02 KB
/
update_library.sh
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
#!/usr/bin/env bash
# library repository update script
# Author: Thomas Gubler <[email protected]>
# Adaptation for RAS-A IOP: Nuno Marques <[email protected]>
#
# This script can be used together with a github webhook to automatically
# generate new C/C++/Java header files and push to the library repository
# whenever the message specifications are updated.
# The script assumes that the git repositories in MAVLINK_GIT_PATH and
# LIBRARY_GIT_PATH are set up prior to invoking the script.
#
# Usage, for example:
# cd ~/src
# git clone [email protected]:mavlink/mavlink.git
# cd mavlink
# git remote rename origin upstream
# mkdir -p include/mavlink/v1.0
# cd include/mavlink/v1.0
# git clone [email protected]:mavlink/c_library_v1.git
# cd ~/src/mavlink
# ./scripts/update_library.sh 1
#
# A one-liner for the TMP directory (e.g. for crontab)
# cd /tmp; git clone [email protected]:mavlink/mavlink.git &> /dev/null; \
# cd /tmp/mavlink && git remote rename origin upstream &> /dev/null; \
# mkdir -p include/mavlink/v1.0 && cd include/mavlink/v1.0 && git clone [email protected]:mavlink/c_library_v1.git &> /dev/null; \
# cd /tmp/mavlink && ./scripts/update_library.sh &> /dev/null
function generate_headers() {
lang=""
if [ "$3" = "c" ]; then
lang="C"
elif [ "$3" = "cpp" ]; then
lang="C++11"
elif [ "$3" = "java" ]; then
lang="Java"
else
echo "Unkown or unsupported language to be generated and deployed through this script. Exiting..."
exit 1
fi
python pymavlink/tools/mavgen.py \
--output $LIBRARY_PATH \
--lang $lang \
--wire-protocol $2.0 \
message_definitions/v1.0/$1.xml
}
# settings
MAVLINK_PATH=$PWD
MAVLINK_GIT_REMOTENAME=upstream
MAVLINK_GIT_BRANCHNAME=master
LIBRARY_PATH=$MAVLINK_PATH/include/mavlink/v$1.0/air-iop-$2_library_v$1
LIBRARY_GIT_REMOTENAME=origin
LIBRARY_GIT_BRANCHNAME=master
# fetch latest message specifications
#cd $MAVLINK_PATH
#git fetch $MAVLINK_GIT_REMOTENAME
#git diff $MAVLINK_GIT_REMOTENAME/$MAVLINK_GIT_BRANCHNAME --exit-code
#RETVAL=$?
# if the diff value is zero nothing changed - abort
#[ $RETVAL -eq 0 ] && exit 0
#echo -e "\0033[34mFetching latest protocol specifications\0033[0m\n"
#git pull $MAVLINK_GIT_REMOTENAME $MAVLINK_GIT_BRANCHNAME || exit 1
# save git hash
MAVLINK_GITHASH=$(git rev-parse HEAD)
# delete old library headers
rm -rf $LIBRARY_PATH/*
# generate new library headers
echo -e "\0033[34mStarting to generate $2 headers\0033[0m\n"
generate_headers ras_a $1 $2
mkdir -p $LIBRARY_PATH/message_definitions
cp message_definitions/v1.0/* $LIBRARY_PATH/message_definitions/.
echo -e "\0033[34mFinished generating $2 headers\0033[0m\n"
# git add and git commit in local library repository
cd $LIBRARY_PATH
git add --all :/ || exit 1
COMMIT_MESSAGE="autogenerated headers for rev https://github.com/Dronecode/air-iop-definitions/tree/"$MAVLINK_GITHASH
git commit -m "$COMMIT_MESSAGE" || exit 0 # for the case when nothing is there to commit
# push to library repository
git push $LIBRARY_GIT_REMOTENAME $LIBRARY_GIT_BRANCHNAME || exit 1
echo -e "\0033[34mHeaders updated and pushed successfully\0033[0m"