2019-09-30 01:01:29 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#OSTYPE: 'linux-gnu', ARCH: 'x86_64' => linux64
|
|
|
|
#OSTYPE: 'msys', ARCH: 'x86_64' => win32
|
|
|
|
#OSTYPE: 'darwin18', ARCH: 'i386' => macos
|
|
|
|
|
|
|
|
OSBITS=`arch`
|
|
|
|
if [[ "$OSTYPE" == "linux"* ]]; then
|
|
|
|
export OS_IS_LINUX="1"
|
|
|
|
ARCHIVE_FORMAT="tar.xz"
|
|
|
|
if [[ "$OSBITS" == "i686" ]]; then
|
|
|
|
OS_NAME="linux32"
|
|
|
|
elif [[ "$OSBITS" == "x86_64" ]]; then
|
|
|
|
OS_NAME="linux64"
|
2019-10-01 21:15:13 +02:00
|
|
|
elif [[ "$OSBITS" == "armv7l" || "$OSBITS" == "aarch64" ]]; then
|
2019-09-30 01:01:29 +02:00
|
|
|
OS_NAME="linuxarm"
|
|
|
|
else
|
|
|
|
OS_NAME="$OSTYPE-$OSBITS"
|
|
|
|
echo "Unknown OS '$OS_NAME'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
|
|
|
export OS_IS_MACOS="1"
|
|
|
|
ARCHIVE_FORMAT="zip"
|
|
|
|
OS_NAME="macosx"
|
|
|
|
elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
|
|
|
|
export OS_IS_WINDOWS="1"
|
|
|
|
ARCHIVE_FORMAT="zip"
|
|
|
|
OS_NAME="windows"
|
|
|
|
else
|
|
|
|
OS_NAME="$OSTYPE-$OSBITS"
|
|
|
|
echo "Unknown OS '$OS_NAME'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
export OS_NAME
|
|
|
|
|
|
|
|
ARDUINO_BUILD_DIR="$HOME/.arduino/build.tmp"
|
|
|
|
ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp"
|
|
|
|
|
|
|
|
if [ "$OS_IS_MACOS" == "1" ]; then
|
|
|
|
export ARDUINO_IDE_PATH="/Applications/Arduino.app/Contents/Java"
|
|
|
|
export ARDUINO_USR_PATH="$HOME/Documents/Arduino"
|
2019-10-02 19:03:43 +02:00
|
|
|
elif [ "$OS_IS_WINDOWS" == "1" ]; then
|
|
|
|
export ARDUINO_IDE_PATH="$HOME/arduino_ide"
|
|
|
|
export ARDUINO_USR_PATH="$HOME/Documents/Arduino"
|
2019-09-30 01:01:29 +02:00
|
|
|
else
|
|
|
|
export ARDUINO_IDE_PATH="$HOME/arduino_ide"
|
|
|
|
export ARDUINO_USR_PATH="$HOME/Arduino"
|
|
|
|
fi
|
|
|
|
|
2020-11-03 20:12:05 +01:00
|
|
|
# Updated as of Nov 3rd 2020
|
|
|
|
ARDUINO_IDE_URL="https://github.com/espressif/arduino-esp32/releases/download/1.0.4/arduino-nightly-"
|
|
|
|
|
|
|
|
# Currently not working
|
|
|
|
#ARDUINO_IDE_URL="https://www.arduino.cc/download.php?f=/arduino-nightly-"
|
|
|
|
|
2019-09-30 01:01:29 +02:00
|
|
|
if [ ! -d "$ARDUINO_IDE_PATH" ]; then
|
2019-10-02 10:58:02 +02:00
|
|
|
echo "Installing Arduino IDE on $OS_NAME ..."
|
2020-11-03 20:12:05 +01:00
|
|
|
echo "Downloading '$ARDUINO_IDE_URL$OS_NAME.$ARCHIVE_FORMAT' to 'arduino.$ARCHIVE_FORMAT' ..."
|
2019-09-30 01:01:29 +02:00
|
|
|
if [ "$OS_IS_LINUX" == "1" ]; then
|
2020-11-03 20:12:05 +01:00
|
|
|
wget -O "arduino.$ARCHIVE_FORMAT" "$ARDUINO_IDE_URL$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1
|
2019-10-02 10:58:02 +02:00
|
|
|
echo "Extracting 'arduino.$ARCHIVE_FORMAT' ..."
|
2019-09-30 01:01:29 +02:00
|
|
|
tar xf "arduino.$ARCHIVE_FORMAT" > /dev/null
|
|
|
|
mv arduino-nightly "$ARDUINO_IDE_PATH"
|
|
|
|
else
|
2020-11-03 20:12:05 +01:00
|
|
|
curl -o "arduino.$ARCHIVE_FORMAT" -L "$ARDUINO_IDE_URL$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1
|
2019-10-02 10:58:02 +02:00
|
|
|
echo "Extracting 'arduino.$ARCHIVE_FORMAT' ..."
|
2019-09-30 01:01:29 +02:00
|
|
|
unzip "arduino.$ARCHIVE_FORMAT" > /dev/null
|
|
|
|
if [ "$OS_IS_MACOS" == "1" ]; then
|
|
|
|
mv "Arduino.app" "/Applications/Arduino.app"
|
|
|
|
else
|
|
|
|
mv arduino-nightly "$ARDUINO_IDE_PATH"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
rm -rf "arduino.$ARCHIVE_FORMAT"
|
|
|
|
|
2019-09-30 11:10:48 +02:00
|
|
|
mkdir -p "$ARDUINO_USR_PATH/libraries"
|
|
|
|
mkdir -p "$ARDUINO_USR_PATH/hardware"
|
|
|
|
|
|
|
|
echo "Arduino IDE Installed in '$ARDUINO_IDE_PATH'"
|
|
|
|
echo ""
|
|
|
|
fi
|
2019-09-30 01:01:29 +02:00
|
|
|
|
|
|
|
function build_sketch(){ # build_sketch <fqbn> <path-to-ino> [extra-options]
|
2019-09-30 11:10:48 +02:00
|
|
|
if [ "$#" -lt 2 ]; then
|
|
|
|
echo "ERROR: Illegal number of parameters"
|
|
|
|
echo "USAGE: build_sketch <fqbn> <path-to-ino> [extra-options]"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2019-09-30 01:01:29 +02:00
|
|
|
local fqbn="$1"
|
|
|
|
local sketch="$2"
|
|
|
|
local xtra_opts="$3"
|
|
|
|
local win_opts=""
|
|
|
|
if [ "$OS_IS_WINDOWS" == "1" ]; then
|
|
|
|
local ctags_version=`ls "$ARDUINO_IDE_PATH/tools-builder/ctags/"`
|
|
|
|
local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"`
|
|
|
|
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"
|
|
|
|
fi
|
|
|
|
|
2021-04-14 17:10:05 +02:00
|
|
|
#echo ""
|
|
|
|
#echo "Compiling '"$(basename "$sketch")"' ..."
|
2019-09-30 01:01:29 +02:00
|
|
|
mkdir -p "$ARDUINO_BUILD_DIR"
|
|
|
|
mkdir -p "$ARDUINO_CACHE_DIR"
|
|
|
|
$ARDUINO_IDE_PATH/arduino-builder -compile -logger=human -core-api-version=10810 \
|
|
|
|
-fqbn=$fqbn \
|
|
|
|
-warnings="all" \
|
|
|
|
-tools "$ARDUINO_IDE_PATH/tools-builder" \
|
|
|
|
-tools "$ARDUINO_IDE_PATH/tools" \
|
|
|
|
-built-in-libraries "$ARDUINO_IDE_PATH/libraries" \
|
|
|
|
-hardware "$ARDUINO_IDE_PATH/hardware" \
|
|
|
|
-hardware "$ARDUINO_USR_PATH/hardware" \
|
|
|
|
-libraries "$ARDUINO_USR_PATH/libraries" \
|
|
|
|
-build-cache "$ARDUINO_CACHE_DIR" \
|
|
|
|
-build-path "$ARDUINO_BUILD_DIR" \
|
|
|
|
$win_opts $xtra_opts "$sketch"
|
|
|
|
}
|
|
|
|
|
2021-04-05 13:23:58 +02:00
|
|
|
function count_sketches() # count_sketches <examples-path> <target-mcu>
|
2019-09-30 01:01:29 +02:00
|
|
|
{
|
|
|
|
local examples="$1"
|
2021-04-05 13:23:58 +02:00
|
|
|
local target="$2"
|
2019-10-02 10:58:02 +02:00
|
|
|
rm -rf sketches.txt
|
|
|
|
if [ ! -d "$examples" ]; then
|
|
|
|
touch sketches.txt
|
|
|
|
return 0
|
|
|
|
fi
|
2019-09-30 01:01:29 +02:00
|
|
|
local sketches=$(find $examples -name *.ino)
|
|
|
|
local sketchnum=0
|
|
|
|
for sketch in $sketches; do
|
|
|
|
local sketchdir=$(dirname $sketch)
|
|
|
|
local sketchdirname=$(basename $sketchdir)
|
|
|
|
local sketchname=$(basename $sketch)
|
2021-04-14 17:10:05 +02:00
|
|
|
if [[ "$sketchdirname.ino" != "$sketchname" ]]; then
|
2019-09-30 01:01:29 +02:00
|
|
|
continue
|
2021-04-14 17:10:05 +02:00
|
|
|
elif [[ -f "$sketchdir/.skip.$target" ]]; then
|
2019-09-30 01:01:29 +02:00
|
|
|
continue
|
2021-04-14 17:10:05 +02:00
|
|
|
else
|
|
|
|
echo $sketch >> sketches.txt
|
|
|
|
sketchnum=$(($sketchnum + 1))
|
2019-09-30 01:01:29 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
return $sketchnum
|
|
|
|
}
|
|
|
|
|
2021-04-05 13:23:58 +02:00
|
|
|
function build_sketches() # build_sketches <fqbn> <target-mcu> <examples-path> <chunk> <total-chunks> [extra-options]
|
2019-09-30 01:01:29 +02:00
|
|
|
{
|
2019-09-30 11:10:48 +02:00
|
|
|
local fqbn=$1
|
2021-04-05 13:23:58 +02:00
|
|
|
local target="$2"
|
|
|
|
local examples=$3
|
|
|
|
local chunk_idex=$4
|
|
|
|
local chunks_num=$5
|
|
|
|
local xtra_opts=$6
|
2019-09-30 01:01:29 +02:00
|
|
|
|
2021-04-05 13:23:58 +02:00
|
|
|
if [ "$#" -lt 3 ]; then
|
2019-09-30 11:10:48 +02:00
|
|
|
echo "ERROR: Illegal number of parameters"
|
2021-04-05 13:23:58 +02:00
|
|
|
echo "USAGE: build_sketches <fqbn> <target-mcu <examples-path> [<chunk> <total-chunks>] [extra-options]"
|
2019-09-30 11:10:48 +02:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2021-04-05 13:23:58 +02:00
|
|
|
if [ "$#" -lt 5 ]; then
|
2019-09-30 11:10:48 +02:00
|
|
|
chunk_idex="0"
|
|
|
|
chunks_num="1"
|
2021-04-05 13:23:58 +02:00
|
|
|
xtra_opts=$4
|
2019-09-30 11:10:48 +02:00
|
|
|
fi
|
|
|
|
|
2019-09-30 01:01:29 +02:00
|
|
|
if [ "$chunks_num" -le 0 ]; then
|
|
|
|
echo "ERROR: Chunks count must be positive number"
|
|
|
|
return 1
|
|
|
|
fi
|
2021-04-14 17:10:05 +02:00
|
|
|
if [ "$chunk_idex" -ge "$chunks_num" ] && [ "$chunks_num" -ge 2 ]; then
|
2019-09-30 01:01:29 +02:00
|
|
|
echo "ERROR: Chunk index must be less than chunks count"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2019-10-02 10:58:02 +02:00
|
|
|
set +e
|
2021-04-14 17:10:05 +02:00
|
|
|
count_sketches "$examples" "$target"
|
2019-09-30 01:01:29 +02:00
|
|
|
local sketchcount=$?
|
2019-10-02 10:58:02 +02:00
|
|
|
set -e
|
2019-09-30 01:01:29 +02:00
|
|
|
local sketches=$(cat sketches.txt)
|
|
|
|
rm -rf sketches.txt
|
|
|
|
|
|
|
|
local chunk_size=$(( $sketchcount / $chunks_num ))
|
|
|
|
local all_chunks=$(( $chunks_num * $chunk_size ))
|
|
|
|
if [ "$all_chunks" -lt "$sketchcount" ]; then
|
|
|
|
chunk_size=$(( $chunk_size + 1 ))
|
|
|
|
fi
|
|
|
|
|
2021-04-14 17:10:05 +02:00
|
|
|
local start_index=0
|
|
|
|
local end_index=0
|
|
|
|
if [ "$chunk_idex" -ge "$chunks_num" ]; then
|
|
|
|
start_index=$chunk_idex
|
2019-09-30 01:01:29 +02:00
|
|
|
end_index=$sketchcount
|
2021-04-14 17:10:05 +02:00
|
|
|
else
|
|
|
|
start_index=$(( $chunk_idex * $chunk_size ))
|
|
|
|
if [ "$sketchcount" -le "$start_index" ]; then
|
|
|
|
echo "Skipping job"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
|
|
|
|
if [ "$end_index" -gt "$sketchcount" ]; then
|
|
|
|
end_index=$sketchcount
|
|
|
|
fi
|
|
|
|
fi
|
2019-09-30 01:01:29 +02:00
|
|
|
|
|
|
|
local start_num=$(( $start_index + 1 ))
|
2021-04-14 17:10:05 +02:00
|
|
|
echo "Found $sketchcount Sketches for target '$target'";
|
|
|
|
echo "Chunk Index : $chunk_idex"
|
2019-09-30 01:01:29 +02:00
|
|
|
echo "Chunk Count : $chunks_num"
|
|
|
|
echo "Chunk Size : $chunk_size"
|
|
|
|
echo "Start Sketch: $start_num"
|
|
|
|
echo "End Sketch : $end_index"
|
|
|
|
|
|
|
|
local sketchnum=0
|
|
|
|
for sketch in $sketches; do
|
|
|
|
local sketchdir=$(dirname $sketch)
|
|
|
|
local sketchdirname=$(basename $sketchdir)
|
|
|
|
local sketchname=$(basename $sketch)
|
|
|
|
if [ "${sketchdirname}.ino" != "$sketchname" ] \
|
2021-04-05 13:23:58 +02:00
|
|
|
|| [ -f "$sketchdir/.skip.$target" ]; then
|
2019-09-30 01:01:29 +02:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
sketchnum=$(($sketchnum + 1))
|
|
|
|
if [ "$sketchnum" -le "$start_index" ] \
|
|
|
|
|| [ "$sketchnum" -gt "$end_index" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2021-04-14 17:10:05 +02:00
|
|
|
echo ""
|
|
|
|
echo "Building Sketch Index $(($sketchnum - 1)) - $sketchdirname"
|
2019-09-30 01:01:29 +02:00
|
|
|
build_sketch "$fqbn" "$sketch" "$xtra_opts"
|
|
|
|
local result=$?
|
|
|
|
if [ $result -ne 0 ]; then
|
|
|
|
return $result
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 0
|
|
|
|
}
|