util.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/bin/bash
  2. function set_source_dir ()
  3. {
  4. if [[ -z ${TRAVIS_BUILD_DIR+x} ]]; then
  5. if [[ ! -z ${1+x} ]]; then
  6. SLIC3R_DIR=$1
  7. echo "Using SLIC3R_DIR = $1"
  8. else
  9. SLIC3R_DIR=$(pwd)
  10. echo "Using current directory as source dir"
  11. fi
  12. else
  13. SLIC3R_DIR="$TRAVIS_BUILD_DIR"
  14. echo "Using Travis build dir"
  15. fi
  16. }
  17. # must be run from the root
  18. function set_version ()
  19. {
  20. SLIC3R_VERSION=$(grep "VERSION" ${SLIC3R_DIR}/xs/src/libslic3r/libslic3r.h | awk -F\" '{print $2}')
  21. }
  22. # Cache the SHA1 for this build commit.
  23. function get_commit () {
  24. if [ ! -z ${TRAVIS_COMMIT+x} ]; then
  25. # Travis sets the sha1 in TRAVIS_COMMIT
  26. COMMIT_SHA1=$(git rev-parse --short $TRAVIS_COMMIT)
  27. else
  28. # should be able to get it properly
  29. COMMIT_SHA1=$(git rev-parse --short HEAD)
  30. fi
  31. }
  32. function set_build_id ()
  33. {
  34. echo "Setting SLIC3R_BUILD_ID"
  35. if [ $(git describe &>/dev/null) ]; then
  36. SLIC3R_BUILD_ID=$(git describe)
  37. TAGGED=true
  38. else
  39. SLIC3R_BUILD_ID=${SLIC3R_VERSION}-${COMMIT_SHA1}
  40. fi
  41. }
  42. function set_branch ()
  43. {
  44. echo "Setting current_branch"
  45. if [ -z ${TRAVIS_BRANCH} ] && [ -z ${GIT_BRANCH+x} ] && [ -z ${APPVEYOR_REPO_BRANCH+x} ]; then
  46. current_branch=$(git symbolic-ref HEAD | sed 's!refs\/heads\/!!')
  47. else
  48. current_branch="unknown"
  49. if [ ! -z ${GIT_BRANCH+x} ]; then
  50. echo "Setting to GIT_BRANCH"
  51. current_branch=$(echo $GIT_BRANCH | cut -d / -f 2)
  52. fi
  53. if [ ! -z ${APPVEYOR_REPO_BRANCH+x} ]; then
  54. echo "Setting to APPVEYOR_REPO_BRANCH"
  55. current_branch=$APPVEYOR_REPO_BRANCH
  56. fi
  57. if [ ! -z ${TRAVIS_BRANCH} ]; then
  58. if [ "${TRAVIS_BRANCH}" != "false" ]; then
  59. echo "Setting to TRAVIS_BRANCH"
  60. current_branch=$TRAVIS_BRANCH
  61. fi
  62. fi
  63. fi
  64. if [ -z ${current_branch+x} ]; then
  65. current_branch="unknown"
  66. fi
  67. }
  68. function set_app_name ()
  69. {
  70. set_branch
  71. if [ "$current_branch" == "master" ]; then
  72. appname=Slic3r
  73. else
  74. appname=Slic3r-${current_branch}
  75. fi
  76. }
  77. function set_pr_id ()
  78. {
  79. echo "Setting PR_ID if available."
  80. if [ ! -z ${GITHUB_PR_NUMBER+x} ]; then
  81. PR_ID=$GITHUB_PR_NUMBER
  82. fi
  83. if [ ! -z ${APPVEYOR_PULL_REQUEST_NUMBER+x} ]; then
  84. PR_ID=$APPVEYOR_PULL_REQUEST_NUMBER
  85. fi
  86. if [ ! -z ${TRAVIS_PULL_REQUEST_BRANCH+x} ] && [ "${TRAVIS_PULL_REQUEST}" != "false" ] ; then
  87. PR_ID=$TRAVIS_PULL_REQUEST
  88. fi
  89. if [ ! -z ${PR_ID+x} ]; then
  90. echo "Setting PR_ID to $PR_ID."
  91. else
  92. echo "PR_ID remains unset."
  93. fi
  94. }
  95. function install_par ()
  96. {
  97. cpanm -q PAR::Packer
  98. cpanm -q Wx::Perl::Packager
  99. }