Skip to content

Commit 3b71e13

Browse files
authored
Builder scripts update (#3300)
1 parent 1c77790 commit 3b71e13

12 files changed

+469
-619
lines changed

.github/workflows/main.yml

+30-350
Large diffs are not rendered by default.

.travis.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ jobs:
2121
- name: "Build Arduino 0"
2222
if: tag IS blank AND (type = pull_request OR (type = push AND branch = master))
2323
stage: build
24-
script: $TRAVIS_BUILD_DIR/tools/ci/build-tests.sh 0 4
24+
script: $TRAVIS_BUILD_DIR/tools/ci/on-push.sh 0 4
2525

2626
- name: "Build Arduino 1"
2727
if: tag IS blank AND (type = pull_request OR (type = push AND branch = master))
2828
stage: build
29-
script: $TRAVIS_BUILD_DIR/tools/ci/build-tests.sh 1 4
29+
script: $TRAVIS_BUILD_DIR/tools/ci/on-push.sh 1 4
3030

3131
- name: "Build Arduino 2"
3232
if: tag IS blank AND (type = pull_request OR (type = push AND branch = master))
3333
stage: build
34-
script: $TRAVIS_BUILD_DIR/tools/ci/build-tests.sh 2 4
34+
script: $TRAVIS_BUILD_DIR/tools/ci/on-push.sh 2 4
3535

3636
- name: "Build Arduino 3"
3737
if: tag IS blank AND (type = pull_request OR (type = push AND branch = master))
3838
stage: build
39-
script: $TRAVIS_BUILD_DIR/tools/ci/build-tests.sh 3 4
39+
script: $TRAVIS_BUILD_DIR/tools/ci/on-push.sh 3 4
4040

4141
- name: "Build PlatformIO"
4242
if: tag IS blank AND (type = pull_request OR (type = push AND branch = master))
4343
stage: build
44-
script: $TRAVIS_BUILD_DIR/tools/ci/build-tests.sh 4 4
44+
script: $TRAVIS_BUILD_DIR/tools/ci/on-push.sh 4 4
4545

4646
- name: "Package & Deploy"
4747
if: tag IS present

tools/ci/build-tests.sh

-64
This file was deleted.

tools/ci/check-cmakelists.sh

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
set -e
1010

11-
cd "`dirname $0`/.." # cd to arduino-esp32 root
12-
1311
# pull all submodules
1412
git submodule update --init --recursive
1513

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
if [ ! -d "$ARDUINO_USR_PATH/hardware/espressif/esp32" ]; then
4+
echo "Installing ESP32 Arduino Core in '$ARDUINO_USR_PATH/hardware/espressif/esp32'..."
5+
script_init_path="$PWD"
6+
mkdir -p "$ARDUINO_USR_PATH/hardware/espressif" && \
7+
cd "$ARDUINO_USR_PATH/hardware/espressif"
8+
if [ $? -ne 0 ]; then exit 1; fi
9+
10+
if [ "$GITHUB_REPOSITORY" == "espressif/arduino-esp32" ]; then
11+
echo "Linking Core..." && \
12+
ln -s $GITHUB_WORKSPACE esp32
13+
else
14+
echo "Cloning Core Repository..." && \
15+
git clone https://github.com/espressif/arduino-esp32.git esp32 > /dev/null 2>&1
16+
if [ $? -ne 0 ]; then echo "ERROR: GIT clone failed"; exit 1; fi
17+
fi
18+
19+
cd esp32 && \
20+
echo "Updating submodules..." && \
21+
git submodule update --init --recursive > /dev/null 2>&1
22+
if [ $? -ne 0 ]; then echo "ERROR: Submodule update failed"; exit 1; fi
23+
24+
echo "Installing Python Serial..." && \
25+
pip install pyserial > /dev/null
26+
if [ $? -ne 0 ]; then echo "ERROR: Install failed"; exit 1; fi
27+
28+
if [ "$OS_IS_WINDOWS" == "1" ]; then
29+
echo "Installing Python Requests..."
30+
pip install requests > /dev/null
31+
if [ $? -ne 0 ]; then echo "ERROR: Install failed"; exit 1; fi
32+
fi
33+
34+
echo "Downloading the tools and the toolchain..."
35+
cd tools && python get.py > /dev/null
36+
if [ $? -ne 0 ]; then echo "ERROR: Download failed"; exit 1; fi
37+
cd $script_init_path
38+
39+
echo "ESP32 Arduino has been installed in '$ARDUINO_USR_PATH/hardware/espressif/esp32'"
40+
echo ""
41+
fi

tools/ci/install-arduino-ide.sh

+203
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
#!/bin/bash
2+
3+
#OSTYPE: 'linux-gnu', ARCH: 'x86_64' => linux64
4+
#OSTYPE: 'msys', ARCH: 'x86_64' => win32
5+
#OSTYPE: 'darwin18', ARCH: 'i386' => macos
6+
7+
OSBITS=`arch`
8+
if [[ "$OSTYPE" == "linux"* ]]; then
9+
export OS_IS_LINUX="1"
10+
ARCHIVE_FORMAT="tar.xz"
11+
if [[ "$OSBITS" == "i686" ]]; then
12+
OS_NAME="linux32"
13+
elif [[ "$OSBITS" == "x86_64" ]]; then
14+
OS_NAME="linux64"
15+
elif [[ "$OSBITS" == "armv7l" ]]; then
16+
OS_NAME="linuxarm"
17+
else
18+
OS_NAME="$OSTYPE-$OSBITS"
19+
echo "Unknown OS '$OS_NAME'"
20+
exit 1
21+
fi
22+
elif [[ "$OSTYPE" == "darwin"* ]]; then
23+
export OS_IS_MACOS="1"
24+
ARCHIVE_FORMAT="zip"
25+
OS_NAME="macosx"
26+
elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
27+
export OS_IS_WINDOWS="1"
28+
ARCHIVE_FORMAT="zip"
29+
OS_NAME="windows"
30+
else
31+
OS_NAME="$OSTYPE-$OSBITS"
32+
echo "Unknown OS '$OS_NAME'"
33+
exit 1
34+
fi
35+
export OS_NAME
36+
37+
ARDUINO_BUILD_DIR="$HOME/.arduino/build.tmp"
38+
ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp"
39+
40+
if [ "$OS_IS_MACOS" == "1" ]; then
41+
export ARDUINO_IDE_PATH="/Applications/Arduino.app/Contents/Java"
42+
export ARDUINO_USR_PATH="$HOME/Documents/Arduino"
43+
else
44+
export ARDUINO_IDE_PATH="$HOME/arduino_ide"
45+
export ARDUINO_USR_PATH="$HOME/Arduino"
46+
fi
47+
48+
echo "Installing Arduino IDE on $OS_NAME..."
49+
50+
if [ ! -d "$ARDUINO_IDE_PATH" ]; then
51+
echo "Downloading 'arduino-nightly-$OS_NAME.$ARCHIVE_FORMAT' to 'arduino.$ARCHIVE_FORMAT'..."
52+
if [ "$OS_IS_LINUX" == "1" ]; then
53+
wget -O "arduino.$ARCHIVE_FORMAT" "https://www.arduino.cc/download.php?f=/arduino-nightly-$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1
54+
if [ $? -ne 0 ]; then echo "ERROR: Download failed"; exit 1; fi
55+
echo "Extracting 'arduino.$ARCHIVE_FORMAT'..."
56+
tar xf "arduino.$ARCHIVE_FORMAT" > /dev/null
57+
if [ $? -ne 0 ]; then exit 1; fi
58+
mv arduino-nightly "$ARDUINO_IDE_PATH"
59+
else
60+
curl -o "arduino.$ARCHIVE_FORMAT" -L "https://www.arduino.cc/download.php?f=/arduino-nightly-$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1
61+
if [ $? -ne 0 ]; then echo "ERROR: Download failed"; exit 1; fi
62+
echo "Extracting 'arduino.$ARCHIVE_FORMAT'..."
63+
unzip "arduino.$ARCHIVE_FORMAT" > /dev/null
64+
if [ $? -ne 0 ]; then exit 1; fi
65+
if [ "$OS_IS_MACOS" == "1" ]; then
66+
mv "Arduino.app" "/Applications/Arduino.app"
67+
else
68+
mv arduino-nightly "$ARDUINO_IDE_PATH"
69+
fi
70+
fi
71+
if [ $? -ne 0 ]; then exit 1; fi
72+
rm -rf "arduino.$ARCHIVE_FORMAT"
73+
fi
74+
75+
mkdir -p "$ARDUINO_USR_PATH/libraries"
76+
mkdir -p "$ARDUINO_USR_PATH/hardware"
77+
78+
function build_sketch(){ # build_sketch <fqbn> <path-to-ino> [extra-options]
79+
local fqbn="$1"
80+
local sketch="$2"
81+
local xtra_opts="$3"
82+
local win_opts=""
83+
if [ "$OS_IS_WINDOWS" == "1" ]; then
84+
local ctags_version=`ls "$ARDUINO_IDE_PATH/tools-builder/ctags/"`
85+
local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"`
86+
win_opts="-prefs=runtime.tools.ctags.path=$ARDUINO_IDE_PATH/tools-builder/ctags/$ctags_version -prefs=runtime.tools.arduino-preprocessor.path=$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/$preprocessor_version"
87+
fi
88+
89+
echo ""
90+
echo "Compiling '"$(basename "$sketch")"'..."
91+
mkdir -p "$ARDUINO_BUILD_DIR"
92+
mkdir -p "$ARDUINO_CACHE_DIR"
93+
$ARDUINO_IDE_PATH/arduino-builder -compile -logger=human -core-api-version=10810 \
94+
-fqbn=$fqbn \
95+
-warnings="all" \
96+
-tools "$ARDUINO_IDE_PATH/tools-builder" \
97+
-tools "$ARDUINO_IDE_PATH/tools" \
98+
-built-in-libraries "$ARDUINO_IDE_PATH/libraries" \
99+
-hardware "$ARDUINO_IDE_PATH/hardware" \
100+
-hardware "$ARDUINO_USR_PATH/hardware" \
101+
-libraries "$ARDUINO_USR_PATH/libraries" \
102+
-build-cache "$ARDUINO_CACHE_DIR" \
103+
-build-path "$ARDUINO_BUILD_DIR" \
104+
$win_opts $xtra_opts "$sketch"
105+
}
106+
107+
function count_sketches() # count_sketches <examples-path>
108+
{
109+
local examples="$1"
110+
local sketches=$(find $examples -name *.ino)
111+
local sketchnum=0
112+
rm -rf sketches.txt
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" ]]; then
118+
continue
119+
fi;
120+
if [[ -f "$sketchdir/.test.skip" ]]; then
121+
continue
122+
fi
123+
echo $sketch >> sketches.txt
124+
sketchnum=$(($sketchnum + 1))
125+
done
126+
return $sketchnum
127+
}
128+
129+
function build_sketches() # build_sketches <examples-path> <fqbn> <chunk> <total-chunks> [extra-options]
130+
{
131+
local examples=$1
132+
local fqbn=$2
133+
local chunk_idex=$3
134+
local chunks_num=$4
135+
local xtra_opts=$5
136+
137+
if [ "$chunks_num" -le 0 ]; then
138+
echo "ERROR: Chunks count must be positive number"
139+
return 1
140+
fi
141+
if [ "$chunk_idex" -ge "$chunks_num" ]; then
142+
echo "ERROR: Chunk index must be less than chunks count"
143+
return 1
144+
fi
145+
146+
count_sketches "$examples"
147+
local sketchcount=$?
148+
local sketches=$(cat sketches.txt)
149+
rm -rf sketches.txt
150+
151+
local chunk_size=$(( $sketchcount / $chunks_num ))
152+
local all_chunks=$(( $chunks_num * $chunk_size ))
153+
if [ "$all_chunks" -lt "$sketchcount" ]; then
154+
chunk_size=$(( $chunk_size + 1 ))
155+
fi
156+
157+
local start_index=$(( $chunk_idex * $chunk_size ))
158+
if [ "$sketchcount" -le "$start_index" ]; then
159+
echo "Skipping job"
160+
return 0
161+
fi
162+
163+
local end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
164+
if [ "$end_index" -gt "$sketchcount" ]; then
165+
end_index=$sketchcount
166+
fi
167+
168+
local start_num=$(( $start_index + 1 ))
169+
echo "Found $sketchcount Sketches";
170+
echo "Chunk Count : $chunks_num"
171+
echo "Chunk Size : $chunk_size"
172+
echo "Start Sketch: $start_num"
173+
echo "End Sketch : $end_index"
174+
175+
local sketchnum=0
176+
for sketch in $sketches; do
177+
local sketchdir=$(dirname $sketch)
178+
local sketchdirname=$(basename $sketchdir)
179+
local sketchname=$(basename $sketch)
180+
if [ "${sketchdirname}.ino" != "$sketchname" ] \
181+
|| [ -f "$sketchdir/.test.skip" ]; then
182+
continue
183+
fi
184+
sketchnum=$(($sketchnum + 1))
185+
if [ "$sketchnum" -le "$start_index" ] \
186+
|| [ "$sketchnum" -gt "$end_index" ]; then
187+
continue
188+
fi
189+
build_sketch "$fqbn" "$sketch" "$xtra_opts"
190+
local result=$?
191+
if [ $result -ne 0 ]; then
192+
return $result
193+
fi
194+
done
195+
return 0
196+
}
197+
198+
echo "Arduino IDE Installed in '$ARDUINO_IDE_PATH'"
199+
# echo "You can install boards in '$ARDUINO_IDE_PATH/hardware' or in '$ARDUINO_USR_PATH/hardware'"
200+
# echo "User libraries should be installed in '$ARDUINO_USR_PATH/libraries'"
201+
# echo "Then you can call 'build_sketch <fqbn> <path-to-ino> [extra-options]' to build your sketches"
202+
echo ""
203+

0 commit comments

Comments
 (0)