| 2 |
raymond |
1 |
#!/bin/bash
|
|
|
2 |
|
|
|
3 |
echo "Installing Python Wheel ..."
|
|
|
4 |
pip install wheel > /dev/null 2>&1
|
|
|
5 |
|
|
|
6 |
echo "Installing PlatformIO ..."
|
|
|
7 |
pip install -U platformio > /dev/null 2>&1
|
|
|
8 |
|
|
|
9 |
echo "PlatformIO has been installed"
|
|
|
10 |
echo ""
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
function build_pio_sketch(){ # build_pio_sketch <board> <path-to-ino>
|
|
|
14 |
if [ "$#" -lt 2 ]; then
|
|
|
15 |
echo "ERROR: Illegal number of parameters"
|
|
|
16 |
echo "USAGE: build_pio_sketch <board> <path-to-ino>"
|
|
|
17 |
return 1
|
|
|
18 |
fi
|
|
|
19 |
|
|
|
20 |
local board="$1"
|
|
|
21 |
local sketch="$2"
|
|
|
22 |
local sketch_dir=$(dirname "$sketch")
|
|
|
23 |
echo ""
|
|
|
24 |
echo "Compiling '"$(basename "$sketch")"' ..."
|
|
|
25 |
python -m platformio ci -l '.' --board "$board" "$sketch_dir" --project-option="board_build.partitions = huge_app.csv" --project-option="lib_compat_mode = strict" --project-option="lib_ldf_mode = chain"
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
function count_sketches() # count_sketches <examples-path>
|
|
|
29 |
{
|
|
|
30 |
local examples="$1"
|
|
|
31 |
rm -rf sketches.txt
|
|
|
32 |
if [ ! -d "$examples" ]; then
|
|
|
33 |
touch sketches.txt
|
|
|
34 |
return 0
|
|
|
35 |
fi
|
|
|
36 |
local sketches=$(find $examples -name *.ino)
|
|
|
37 |
local sketchnum=0
|
|
|
38 |
for sketch in $sketches; do
|
|
|
39 |
local sketchdir=$(dirname $sketch)
|
|
|
40 |
local sketchdirname=$(basename $sketchdir)
|
|
|
41 |
local sketchname=$(basename $sketch)
|
|
|
42 |
if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
|
|
|
43 |
continue
|
|
|
44 |
fi;
|
|
|
45 |
if [[ -f "$sketchdir/.test.skip" ]]; then
|
|
|
46 |
continue
|
|
|
47 |
fi
|
|
|
48 |
echo $sketch >> sketches.txt
|
|
|
49 |
sketchnum=$(($sketchnum + 1))
|
|
|
50 |
done
|
|
|
51 |
return $sketchnum
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
function build_pio_sketches() # build_pio_sketches <board> <examples-path> <chunk> <total-chunks>
|
|
|
55 |
{
|
|
|
56 |
if [ "$#" -lt 2 ]; then
|
|
|
57 |
echo "ERROR: Illegal number of parameters"
|
|
|
58 |
echo "USAGE: build_pio_sketches <board> <examples-path> [<chunk> <total-chunks>]"
|
|
|
59 |
return 1
|
|
|
60 |
fi
|
|
|
61 |
|
|
|
62 |
local board=$1
|
|
|
63 |
local examples=$2
|
|
|
64 |
local chunk_idex=$3
|
|
|
65 |
local chunks_num=$4
|
|
|
66 |
|
|
|
67 |
if [ "$#" -lt 4 ]; then
|
|
|
68 |
chunk_idex="0"
|
|
|
69 |
chunks_num="1"
|
|
|
70 |
fi
|
|
|
71 |
|
|
|
72 |
if [ "$chunks_num" -le 0 ]; then
|
|
|
73 |
echo "ERROR: Chunks count must be positive number"
|
|
|
74 |
return 1
|
|
|
75 |
fi
|
|
|
76 |
if [ "$chunk_idex" -ge "$chunks_num" ]; then
|
|
|
77 |
echo "ERROR: Chunk index must be less than chunks count"
|
|
|
78 |
return 1
|
|
|
79 |
fi
|
|
|
80 |
|
|
|
81 |
set +e
|
|
|
82 |
count_sketches "$examples"
|
|
|
83 |
local sketchcount=$?
|
|
|
84 |
set -e
|
|
|
85 |
local sketches=$(cat sketches.txt)
|
|
|
86 |
rm -rf sketches.txt
|
|
|
87 |
|
|
|
88 |
local chunk_size=$(( $sketchcount / $chunks_num ))
|
|
|
89 |
local all_chunks=$(( $chunks_num * $chunk_size ))
|
|
|
90 |
if [ "$all_chunks" -lt "$sketchcount" ]; then
|
|
|
91 |
chunk_size=$(( $chunk_size + 1 ))
|
|
|
92 |
fi
|
|
|
93 |
|
|
|
94 |
local start_index=$(( $chunk_idex * $chunk_size ))
|
|
|
95 |
if [ "$sketchcount" -le "$start_index" ]; then
|
|
|
96 |
echo "Skipping job"
|
|
|
97 |
return 0
|
|
|
98 |
fi
|
|
|
99 |
|
|
|
100 |
local end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
|
|
|
101 |
if [ "$end_index" -gt "$sketchcount" ]; then
|
|
|
102 |
end_index=$sketchcount
|
|
|
103 |
fi
|
|
|
104 |
|
|
|
105 |
local start_num=$(( $start_index + 1 ))
|
|
|
106 |
echo "Found $sketchcount Sketches";
|
|
|
107 |
echo "Chunk Count : $chunks_num"
|
|
|
108 |
echo "Chunk Size : $chunk_size"
|
|
|
109 |
echo "Start Sketch: $start_num"
|
|
|
110 |
echo "End Sketch : $end_index"
|
|
|
111 |
|
|
|
112 |
local sketchnum=0
|
|
|
113 |
for sketch in $sketches; do
|
|
|
114 |
local sketchdir=$(dirname $sketch)
|
|
|
115 |
local sketchdirname=$(basename $sketchdir)
|
|
|
116 |
local sketchname=$(basename $sketch)
|
|
|
117 |
if [ "${sketchdirname}.ino" != "$sketchname" ] \
|
|
|
118 |
|| [ -f "$sketchdir/.test.skip" ]; then
|
|
|
119 |
continue
|
|
|
120 |
fi
|
|
|
121 |
sketchnum=$(($sketchnum + 1))
|
|
|
122 |
if [ "$sketchnum" -le "$start_index" ] \
|
|
|
123 |
|| [ "$sketchnum" -gt "$end_index" ]; then
|
|
|
124 |
continue
|
|
|
125 |
fi
|
|
|
126 |
build_pio_sketch "$board" "$sketch"
|
|
|
127 |
local result=$?
|
|
|
128 |
if [ $result -ne 0 ]; then
|
|
|
129 |
return $result
|
|
|
130 |
fi
|
|
|
131 |
done
|
|
|
132 |
return 0
|
|
|
133 |
}
|