My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build_all_examples 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #!/usr/bin/env bash
  2. #
  3. # Usage:
  4. #
  5. # build_all_examples [-b|--branch=<branch>]
  6. # [-c|--continue]
  7. # [-d|--debug]
  8. # [-i|--ini]
  9. # [-l|--limit=#]
  10. # [-n|--nobuild]
  11. # [-r|--resume=<path>]
  12. # [-s|--skip]
  13. #
  14. # build_all_examples [...] branch [resume-from]
  15. #
  16. set -e
  17. GITREPO=https://github.com/MarlinFirmware/Configurations.git
  18. STAT_FILE=./.pio/.buildall
  19. # Check dependencies
  20. which curl 1>/dev/null 2>&1 || { echo "curl not found! Please install it."; exit ; }
  21. which git 1>/dev/null 2>&1 || { echo "git not found! Please install it."; exit ; }
  22. SED=$(command -v gsed 2>/dev/null || command -v sed 2>/dev/null)
  23. [[ -z "$SED" ]] && { echo "No sed found, please install sed" ; exit 1 ; }
  24. SELF=`basename "$0"`
  25. HERE=`dirname "$0"`
  26. # Check if called in the right location
  27. [[ -e "Marlin/src" ]] || { echo -e "This script must be called from a Marlin working copy with:\n ./buildroot/bin/$SELF $1" ; exit ; }
  28. perror() { echo -e "$0: \033[0;31m$1 -- $2\033[0m" ; }
  29. bugout() { ((DEBUG)) && echo -e "\033[0;32m$1\033[0m" ; }
  30. usage() { echo "
  31. Usage: $SELF [-b|--branch=<branch>] [-d|--debug] [-i|--ini] [-r|--resume=<path>]
  32. $SELF [-b|--branch=<branch>] [-d|--debug] [-i|--ini] [-c|--continue]
  33. $SELF [-b|--branch=<branch>] [-d|--debug] [-i|--ini] [-s|--skip]
  34. $SELF [-b|--branch=<branch>] [-d|--debug] [-n|--nobuild]
  35. $SELF [...] branch [resume-point]
  36. "
  37. }
  38. # Assume the most recent configs
  39. BRANCH=import-2.1.x
  40. unset FIRST_CONF
  41. EXIT_USAGE=
  42. LIMIT=1000
  43. while getopts 'b:cdhil:nqr:sv-:' OFLAG; do
  44. case "${OFLAG}" in
  45. b) BRANCH=$OPTARG ; bugout "Branch: $BRANCH" ;;
  46. r) FIRST_CONF="$OPTARG" ; bugout "Resume: $FIRST_CONF" ;;
  47. c) CONTINUE=1 ; bugout "Continue" ;;
  48. s) CONTSKIP=1 ; bugout "Continue, skipping" ;;
  49. i) CREATE_INI=1 ; bugout "Generate an INI file" ;;
  50. h) EXIT_USAGE=1 ; break ;;
  51. l) LIMIT=$OPTARG ; bugout "Limit to $LIMIT configs" ;;
  52. d|v) DEBUG=1 ; bugout "Debug ON" ;;
  53. n) DRYRUN=1 ; bugout "Dry Run" ;;
  54. -) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
  55. case "$ONAM" in
  56. branch) BRANCH=$OVAL ; bugout "Branch: $BRANCH" ;;
  57. resume) FIRST_CONF="$OVAL" ; bugout "Resume: $FIRST_CONF" ;;
  58. continue) CONTINUE=1 ; bugout "Continue" ;;
  59. skip) CONTSKIP=2 ; bugout "Continue, skipping" ;;
  60. limit) LIMIT=$OVAL ; bugout "Limit to $LIMIT configs" ;;
  61. ini) CREATE_INI=1 ; bugout "Generate an INI file" ;;
  62. help) [[ -z "$OVAL" ]] || perror "option can't take value $OVAL" $ONAM ; EXIT_USAGE=1 ;;
  63. debug) DEBUG=1 ; bugout "Debug ON" ;;
  64. nobuild) DRYRUN=1 ; bugout "Dry Run" ;;
  65. *) EXIT_USAGE=2 ; echo "$SELF: unrecognized option \`--$ONAM'" ; break ;;
  66. esac
  67. ;;
  68. *) EXIT_USAGE=2 ; break ;;
  69. esac
  70. done
  71. # Extra arguments count as BRANCH, FIRST_CONF
  72. shift $((OPTIND - 1))
  73. [[ $# > 0 ]] && { BRANCH=$1 ; shift 1 ; bugout "BRANCH=$BRANCH" ; }
  74. [[ $# > 0 ]] && { FIRST_CONF=$1 ; shift 1 ; bugout "FIRST_CONF=$FIRST_CONF" ; }
  75. [[ $# > 0 ]] && { EXIT_USAGE=2 ; echo "too many arguments" ; }
  76. ((EXIT_USAGE)) && { usage ; let EXIT_USAGE-- ; exit $EXIT_USAGE ; }
  77. echo "This script downloads each Configuration and attempts to build it."
  78. echo "On failure the last-built configs will be left in your working copy."
  79. echo "Restore your configs with 'git checkout -f' or 'git reset --hard HEAD'."
  80. if [[ -f "$STAT_FILE" ]]; then
  81. IFS='*' read BRANCH FIRST_CONF <"$STAT_FILE"
  82. fi
  83. # If -c is given start from the last attempted build
  84. if ((CONTINUE)); then
  85. if [[ -z $BRANCH || -z $FIRST_CONF ]]; then
  86. echo "Nothing to continue"
  87. exit
  88. fi
  89. elif ((CONTSKIP)); then
  90. if [[ -n $BRANCH && -n $FIRST_CONF ]]; then
  91. SKIP_CONF=1
  92. else
  93. echo "Nothing to skip"
  94. exit
  95. fi
  96. fi
  97. # Check if the current repository has unmerged changes
  98. if [[ $SKIP_CONF ]]; then
  99. echo "Skipping $FIRST_CONF"
  100. elif [[ $FIRST_CONF ]]; then
  101. echo "Resuming from $FIRST_CONF"
  102. else
  103. git diff --quiet || { echo "The working copy is modified. Commit or stash changes before proceeding."; exit ; }
  104. fi
  105. # Create a temporary folder inside .pio
  106. TMP=./.pio/build-$BRANCH
  107. [[ -d "$TMP" ]] || mkdir -p $TMP
  108. # Download Configurations into the temporary folder
  109. if [[ ! -e "$TMP/README.md" ]]; then
  110. echo "Downloading Configurations from GitHub into $TMP"
  111. git clone --depth=1 --single-branch --branch "$BRANCH" $GITREPO "$TMP" || { echo "Failed to clone the configuration repository"; exit ; }
  112. else
  113. echo "Using previously downloaded Configurations at $TMP"
  114. fi
  115. echo -e "Start building now...\n====================="
  116. shopt -s nullglob
  117. IFS='
  118. '
  119. CONF_TREE=$( ls -d "$TMP"/config/examples/*/ "$TMP"/config/examples/*/*/ "$TMP"/config/examples/*/*/*/ "$TMP"/config/examples/*/*/*/*/ | grep -vE ".+\.(\w+)$" )
  120. DOSKIP=0
  121. for CONF in $CONF_TREE ; do
  122. # Get a config's directory name
  123. DIR=$( echo $CONF | sed "s|$TMP/config/examples/||" )
  124. # If looking for a config, skip others
  125. [[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && continue
  126. # Once found, stop looking
  127. unset FIRST_CONF
  128. # If skipping, don't build the found one
  129. [[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; }
  130. # ...if skipping, don't build this one
  131. compgen -G "${CONF}Con*.h" > /dev/null || continue
  132. # Remember where we are in case of failure
  133. echo "${BRANCH}*${DIR}" >"$STAT_FILE"
  134. # Build or pretend to build
  135. if [[ $DRYRUN ]]; then
  136. echo "[DRYRUN] build_example internal \"$TMP\" \"$DIR\""
  137. else
  138. # Build folder is unknown so delete all "config.ini" files
  139. [[ $CREATE_INI ]] && find ./.pio/build/ -name "config.ini" -exec rm "{}" \;
  140. ((DEBUG)) && echo "\"$HERE/build_example\" \"internal\" \"$TMP\" \"$DIR\""
  141. "$HERE/build_example" "internal" "$TMP" "$DIR" || { echo "Failed to build $DIR"; exit ; }
  142. # Build folder is unknown so copy any "config.ini"
  143. [[ $CREATE_INI ]] && find ./.pio/build/ -name "config.ini" -exec cp "{}" "$CONF" \;
  144. fi
  145. ((LIMIT--)) || { echo "Limit reached" ; break ; }
  146. done
  147. # Delete the build state
  148. rm "$STAT_FILE"
  149. # Delete the temp folder if not preserving generated INI files
  150. if [[ -e "$TMP/config/examples" ]]; then
  151. if [[ $CREATE_INI ]]; then
  152. OPEN=$( which gnome-open xdg-open open | head -n1 )
  153. $OPEN "$TMP"
  154. else
  155. rm -rf "$TMP"
  156. fi
  157. fi