update_c_library.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. # c_library repository update script
  3. # Author: Thomas Gubler <thomasgubler@gmail.com>
  4. #
  5. # This script can be used together with a github webhook to automatically
  6. # generate new c header files and push to the c_library repository whenever
  7. # the message specifications are updated.
  8. # The script assumes that the git repositories in MAVLINK_GIT_PATH and
  9. # CLIBRARY_GIT_PATH are set up prior to invoking the script.
  10. #
  11. # Usage, for example:
  12. # cd ~/src
  13. # git clone git@github.com:mavlink/mavlink.git
  14. # cd mavlink
  15. # git remote rename origin upstream
  16. # mkdir -p include/mavlink/v1.0
  17. # cd include/mavlink/v1.0
  18. # git clone git@github.com:mavlink/c_library_v1.git
  19. # cd ~/src/mavlink
  20. # ./scripts/update_c_library.sh 1
  21. #
  22. # A one-liner for the TMP directory (e.g. for crontab)
  23. # cd /tmp; git clone git@github.com:mavlink/mavlink.git &> /dev/null; \
  24. # cd /tmp/mavlink && git remote rename origin upstream &> /dev/null; \
  25. # mkdir -p include/mavlink/v1.0 && cd include/mavlink/v1.0 && git clone git@github.com:mavlink/c_library_v1.git &> /dev/null; \
  26. # cd /tmp/mavlink && ./scripts/update_c_library.sh &> /dev/null
  27. function generate_headers() {
  28. python pymavlink/tools/mavgen.py \
  29. --output $CLIBRARY_PATH \
  30. --lang C \
  31. --wire-protocol $2.0 \
  32. message_definitions/v1.0/$1.xml
  33. }
  34. # settings
  35. MAVLINK_PATH=$PWD
  36. MAVLINK_GIT_REMOTENAME=upstream
  37. MAVLINK_GIT_BRANCHNAME=master
  38. CLIBRARY_PATH=$MAVLINK_PATH/include/mavlink/v$1.0/c_library_v$1
  39. CLIBRARY_GIT_REMOTENAME=origin
  40. CLIBRARY_GIT_BRANCHNAME=master
  41. # fetch latest message specifications
  42. #cd $MAVLINK_PATH
  43. #git fetch $MAVLINK_GIT_REMOTENAME
  44. #git diff $MAVLINK_GIT_REMOTENAME/$MAVLINK_GIT_BRANCHNAME --exit-code
  45. #RETVAL=$?
  46. # if the diff value is zero nothing changed - abort
  47. #[ $RETVAL -eq 0 ] && exit 0
  48. #echo -e "\0033[34mFetching latest protocol specifications\0033[0m\n"
  49. #git pull $MAVLINK_GIT_REMOTENAME $MAVLINK_GIT_BRANCHNAME || exit 1
  50. # save git hash
  51. MAVLINK_GITHASH=$(git rev-parse HEAD)
  52. # delete old c headers
  53. rm -rf $CLIBRARY_PATH/*
  54. # generate new c headers
  55. echo -e "\0033[34mStarting to generate c headers\0033[0m\n"
  56. generate_headers ardupilotmega $1
  57. generate_headers autoquad $1
  58. generate_headers matrixpilot $1
  59. generate_headers minimal $1
  60. generate_headers slugs $1
  61. generate_headers test $1
  62. generate_headers ASLUAV $1
  63. generate_headers standard $1
  64. mkdir -p $CLIBRARY_PATH/message_definitions
  65. cp message_definitions/v1.0/* $CLIBRARY_PATH/message_definitions/.
  66. echo -e "\0033[34mFinished generating c headers\0033[0m\n"
  67. # git add and git commit in local c_library repository
  68. cd $CLIBRARY_PATH
  69. git add --all :/ || exit 1
  70. COMMIT_MESSAGE="autogenerated headers for rev https://github.com/mavlink/mavlink/tree/"$MAVLINK_GITHASH
  71. git commit -m "$COMMIT_MESSAGE" || exit 1
  72. # push to c_library repository
  73. git push $CLIBRARY_GIT_REMOTENAME $CLIBRARY_GIT_BRANCHNAME || exit 1
  74. echo -e "\0033[34mHeaders updated and pushed successfully\0033[0m"