|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +CHUNK_INDEX=$1 |
| 4 | +CHUNKS_CNT=$2 |
| 5 | +if [ "$#"-lt 2 ];then |
| 6 | +echo"Building all sketches" |
| 7 | + CHUNK_INDEX=0 |
| 8 | + CHUNKS_CNT=1 |
| 9 | +fi |
| 10 | +if [ "$CHUNKS_CNT"-le 0 ];then |
| 11 | +echo"Chunks count must be positive number" |
| 12 | +exit 1 |
| 13 | +fi |
| 14 | +if [ "$CHUNK_INDEX"-ge"$CHUNKS_CNT" ];then |
| 15 | +echo"Chunk index must be less than chunks count" |
| 16 | +exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +export ARDUINO_IDE_PATH=$HOME/arduino_ide |
| 20 | +export ARDUINO_LIB_PATH=$HOME/Arduino/libraries |
| 21 | +export EXAMPLES_PATH=$TRAVIS_BUILD_DIR/libraries |
| 22 | +export EXAMPLES_BUILD_DIR=$TRAVIS_BUILD_DIR/build.tmp |
| 23 | +export EXAMPLES_BUILD_CMD="python tools/build.py -b esp32 -v -k -p $EXAMPLES_BUILD_DIR -l $ARDUINO_LIB_PATH" |
| 24 | +export EXAMPLES_SIZE_BIN=$TRAVIS_BUILD_DIR/tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-size |
| 25 | + |
| 26 | +functionprint_size_info() |
| 27 | +{ |
| 28 | + elf_file=$1 |
| 29 | + |
| 30 | +if [ -z"$elf_file" ];then |
| 31 | +printf"sketch iram0.text flash.text flash.rodata dram0.data dram0.bss dram flash\n" |
| 32 | +return 0 |
| 33 | +fi |
| 34 | + |
| 35 | + elf_name=$(basename $elf_file) |
| 36 | + sketch_name="${elf_name%.*}" |
| 37 | +# echo $sketch_name |
| 38 | +declare -A segments |
| 39 | +whileread -a tokens;do |
| 40 | + seg=${tokens[0]} |
| 41 | + seg=${seg//./} |
| 42 | + size=${tokens[1]} |
| 43 | + addr=${tokens[2]} |
| 44 | +if [ "$addr"-eq"$addr"-a"$addr"-ne"0" ] 2>/dev/null;then |
| 45 | + segments[$seg]=$size |
| 46 | +fi |
| 47 | +done<<($EXAMPLES_SIZE_BIN --format=sysv $elf_file) |
| 48 | + |
| 49 | + total_ram=$((${segments[dram0data]}+${segments[dram0bss]})) |
| 50 | + total_flash=$((${segments[iram0text]}+${segments[flashtext]}+${segments[dram0data]}+${segments[flashrodata]})) |
| 51 | +printf"%-32s %-8d %-8d %-8d %-8d %-8d %-8d %-8d\n"$sketch_name${segments[iram0text]}${segments[flashtext]}${segments[flashrodata]}${segments[dram0data]}${segments[dram0bss]}$total_ram$total_flash |
| 52 | +return 0 |
| 53 | +} |
| 54 | + |
| 55 | +functionbuild_sketch() |
| 56 | +{ |
| 57 | +local sketch=$1 |
| 58 | +echo -e "\n------------ Building $sketch ------------\n"; |
| 59 | + rm -rf $EXAMPLES_BUILD_DIR/* |
| 60 | +time ($EXAMPLES_BUILD_CMD$sketch>build.log) |
| 61 | +local result=$? |
| 62 | +if [ $result-ne 0 ];then |
| 63 | +echo"Build failed ($1)" |
| 64 | +echo"Build log:" |
| 65 | + cat build.log |
| 66 | +return$result |
| 67 | +fi |
| 68 | + rm build.log |
| 69 | +return 0 |
| 70 | +} |
| 71 | + |
| 72 | +functioncount_sketches() |
| 73 | +{ |
| 74 | +local sketches=$(find $EXAMPLES_PATH -name *.ino) |
| 75 | +local sketchnum=0 |
| 76 | + rm -rf sketches.txt |
| 77 | +forsketchin$sketches;do |
| 78 | +local sketchdir=$(dirname $sketch) |
| 79 | +local sketchdirname=$(basename $sketchdir) |
| 80 | +local sketchname=$(basename $sketch) |
| 81 | +if [[ "${sketchdirname}.ino"!="$sketchname" ]];then |
| 82 | +continue |
| 83 | +fi; |
| 84 | +if [[ -f"$sketchdir/.test.skip" ]];then |
| 85 | +continue |
| 86 | +fi |
| 87 | +echo$sketch>> sketches.txt |
| 88 | + sketchnum=$(($sketchnum+1)) |
| 89 | +done |
| 90 | +return$sketchnum |
| 91 | +} |
| 92 | + |
| 93 | +functionbuild_sketches() |
| 94 | +{ |
| 95 | + mkdir -p $EXAMPLES_BUILD_DIR |
| 96 | +local chunk_idex=$1 |
| 97 | +local chunks_num=$2 |
| 98 | + count_sketches |
| 99 | +local sketchcount=$? |
| 100 | +local sketches=$(cat sketches.txt) |
| 101 | + |
| 102 | +local chunk_size=$(($sketchcount/$chunks_num)) |
| 103 | +local all_chunks=$(($chunks_num*$chunk_size)) |
| 104 | +if [ "$all_chunks"-lt"$sketchcount" ];then |
| 105 | + chunk_size=$(($chunk_size+1)) |
| 106 | +fi |
| 107 | + |
| 108 | +local start_index=$(($chunk_idex*$chunk_size)) |
| 109 | +if [ "$sketchcount"-le"$start_index" ];then |
| 110 | +echo"Skipping job" |
| 111 | +return 0 |
| 112 | +fi |
| 113 | + |
| 114 | +local end_index=$(( $(( $chunk_idex+1))*$chunk_size )) |
| 115 | +if [ "$end_index"-gt"$sketchcount" ];then |
| 116 | + end_index=$sketchcount |
| 117 | +fi |
| 118 | + |
| 119 | +local start_num=$(($start_index+1)) |
| 120 | +#echo -e "Sketches: \n$sketches\n" |
| 121 | +echo"Found $sketchcount Sketches"; |
| 122 | +echo"Chunk Count : $chunks_num" |
| 123 | +echo"Chunk Size : $chunk_size" |
| 124 | +echo"Start Sketch: $start_num" |
| 125 | +echo"End Sketch : $end_index" |
| 126 | + |
| 127 | +local sketchnum=0 |
| 128 | + print_size_info >size.log |
| 129 | +forsketchin$sketches;do |
| 130 | +local sketchdir=$(dirname $sketch) |
| 131 | +local sketchdirname=$(basename $sketchdir) |
| 132 | +local sketchname=$(basename $sketch) |
| 133 | +if [[ "${sketchdirname}.ino"!="$sketchname" ]];then |
| 134 | +#echo "Skipping $sketch, beacause it is not the main sketch file"; |
| 135 | +continue |
| 136 | +fi; |
| 137 | +if [[ -f"$sketchdir/.test.skip" ]];then |
| 138 | +#echo "Skipping $sketch marked"; |
| 139 | +continue |
| 140 | +fi |
| 141 | + sketchnum=$(($sketchnum+1)) |
| 142 | +if [ "$sketchnum"-le"$start_index" ];then |
| 143 | +#echo "Skipping $sketch index low" |
| 144 | +continue |
| 145 | +fi |
| 146 | +if [ "$sketchnum"-gt"$end_index" ];then |
| 147 | +#echo "Skipping $sketch index high" |
| 148 | +continue |
| 149 | +fi |
| 150 | + build_sketch $sketch |
| 151 | +local result=$? |
| 152 | +if [ $result-ne 0 ];then |
| 153 | +return$result |
| 154 | +fi |
| 155 | + print_size_info $EXAMPLES_BUILD_DIR/*.elf >>size.log |
| 156 | +done |
| 157 | +return 0 |
| 158 | +} |
| 159 | + |
| 160 | +build_sketches $CHUNK_INDEX$CHUNKS_CNT |
| 161 | + |
| 162 | +if [ $?-ne 0 ];thenexit 1;fi |
0 commit comments