common.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/bin/bash
  2. set -ex
  3. function build_sketches()
  4. {
  5. local arduino=$1
  6. local srcpath=$2
  7. local platform=$3
  8. local sketches=$(find $srcpath -name *.ino)
  9. for sketch in $sketches; do
  10. local sketchdir=$(dirname $sketch)
  11. if [[ -f "$sketchdir/.$platform.skip" ]]; then
  12. echo -e "\n\n ------------ Skipping $sketch ------------ \n\n";
  13. continue
  14. fi
  15. echo -e "\n\n ------------ Building $sketch ------------ \n\n";
  16. $arduino --verify $sketch;
  17. local result=$?
  18. if [ $result -ne 0 ]; then
  19. echo "Build failed ($sketch) build verbose..."
  20. $arduino --verify --verbose --preserve-temp-files $sketch
  21. result=$?
  22. fi
  23. if [ $result -ne 0 ]; then
  24. echo "Build failed ($1) $sketch"
  25. return $result
  26. fi
  27. done
  28. }
  29. function build_sketch()
  30. {
  31. local arduino=$1
  32. local sketch=$2
  33. $arduino --verify $sketch;
  34. local result=$?
  35. if [ $result -ne 0 ]; then
  36. echo "Build failed ($sketch) build verbose..."
  37. $arduino --verify --verbose --preserve-temp-files $sketch
  38. result=$?
  39. fi
  40. if [ $result -ne 0 ]; then
  41. echo "Build failed ($1) $sketch"
  42. return $result
  43. fi
  44. }
  45. function get_sketches_json()
  46. {
  47. local arduino=$1
  48. local srcpath=$2
  49. local platform=$3
  50. local sketches=($(find $srcpath -name *.ino))
  51. echo -en "["
  52. for sketch in "${sketches[@]}" ; do
  53. local sketchdir=$(dirname $sketch)
  54. if [[ -f "$sketchdir/.$platform.skip" ]]; then
  55. continue
  56. fi
  57. echo -en "\"$sketch\""
  58. if [[ $sketch != ${sketches[-1]} ]] ; then
  59. echo -en ","
  60. fi
  61. done
  62. echo -en "]"
  63. }
  64. function get_sketches_json_matrix()
  65. {
  66. local arduino=$1
  67. local srcpath=$2
  68. local platform=$3
  69. local ideversion=$4
  70. local board=$5
  71. local sketches=($(find $srcpath -name *.ino))
  72. for sketch in "${sketches[@]}" ; do
  73. local sketchdir=$(dirname $sketch)
  74. local sketchname=$(basename $sketch)
  75. if [[ -f "$sketchdir/.$platform.skip" ]]; then
  76. continue
  77. fi
  78. echo -en "{\"name\":\"$sketchname\",\"board\":\"$board\",\"ideversion\":\"$ideversion\",\"cpu\":\"$platform\",\"sketch\":\"$sketch\"}"
  79. if [[ $sketch != ${sketches[-1]} ]] ; then
  80. echo -en ","
  81. fi
  82. done
  83. }
  84. function get_core()
  85. {
  86. echo Setup core for $1
  87. cd $HOME/arduino_ide/hardware
  88. if [ "$1" = "esp8266" ] ; then
  89. mkdir esp8266com
  90. cd esp8266com
  91. git clone --depth 1 https://github.com/esp8266/Arduino.git esp8266
  92. cd esp8266/
  93. git submodule update --init
  94. rm -rf .git
  95. cd tools
  96. python get.py
  97. fi
  98. if [ "$1" = "esp32" ] ; then
  99. mkdir espressif
  100. cd espressif
  101. git clone --depth 1 https://github.com/espressif/arduino-esp32.git esp32
  102. cd esp32/
  103. rm -rf .git
  104. cd tools
  105. python get.py
  106. fi
  107. }
  108. function clone_library() {
  109. local url=$1
  110. echo clone $(basename $url)
  111. mkdir -p $HOME/Arduino/libraries
  112. cd $HOME/Arduino/libraries
  113. git clone --depth 1 $url
  114. rm -rf */.git
  115. rm -rf */.github
  116. rm -rf */examples
  117. }
  118. function hash_library_names() {
  119. cd $HOME/Arduino/libraries
  120. ls | sha1sum -z | cut -c1-5
  121. }