Skip to content

Commit

Permalink
Speed up CI builds with caching hacks (esp8266#5539)
Browse files Browse the repository at this point in the history
  • Loading branch information
earlephilhower authored Jan 5, 2019
1 parent eaac1e8 commit 1f13c73
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
22 changes: 20 additions & 2 deletions tests/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function build_sketches()
local build_rem=$5
local lwip=$6
mkdir -p $build_dir
local build_cmd="python tools/build.py -b generic -v -w all -s 4M1M -v -k -p $PWD/$build_dir -n $lwip $build_arg "
local build_cmd="python tools/build.py -b generic -v -w all -s 4M1M -v -k --build_cache $cache_dir -p $PWD/$build_dir -n $lwip $build_arg "
local sketches=$(find $srcpath -name *.ino | sort)
print_size_info >size.log
export ARDUINO_IDE_PATH=$arduino
Expand All @@ -53,7 +53,21 @@ function build_sketches()
if [ $testcnt -ne $build_rem ]; then
continue # Not ours to do
fi
rm -rf $build_dir/*

if [ -e $cache_dir/core/*.a ]; then
# We need to preserve the build.options.json file and replace the last .ino
# with this sketch's ino file, or builder will throw everything away.
sed -i "s,^.*sketchLocation.*$, \"sketchLocation\": \"$sketch\"\,,g" $build_dir/build.options.json
# Set the time of the cached core.a file to the future so the GIT header
# we regen won't cause the builder to throw it out and rebuild from scratch.
touch -d 'now + 1 day' $cache_dir/core/*.a
fi

# Clear out the last built sketch, map, elf, bin files, but leave the compiled
# objects in the core and libraries available for use so we don't need to rebuild
# them each sketch.
rm -rf $build_dir/sketch $build_dir/*.bin $build_dir/*.map $build_dir/*.elf

local sketchdir=$(dirname $sketch)
local sketchdirname=$(basename $sketchdir)
local sketchname=$(basename $sketch)
Expand Down Expand Up @@ -221,6 +235,8 @@ if [ -z "$TRAVIS_BUILD_DIR" ]; then
echo "TRAVIS_BUILD_DIR=$TRAVIS_BUILD_DIR"
fi

cache_dir=$(mktemp -d)

if [ "$BUILD_TYPE" = "build" ]; then
install_arduino nodebug
build_sketches_with_arduino 1 0 lm2f
Expand Down Expand Up @@ -259,6 +275,8 @@ elif [ "$BUILD_TYPE" = "platformio_odd" ]; then
build_sketches_with_platformio $TRAVIS_BUILD_DIR/libraries "--board nodemcuv2 --verbose" 2 1
else
echo "BUILD_TYPE not set or invalid"
rm -rf $cache_dir
exit 1
fi

rm -rf $cache_dir
8 changes: 6 additions & 2 deletions tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import tempfile
import shutil

def compile(tmp_dir, sketch, tools_dir, hardware_dir, ide_path, f, args):
def compile(tmp_dir, sketch, cache, tools_dir, hardware_dir, ide_path, f, args):
cmd = ide_path + '/arduino-builder '
cmd += '-compile -logger=human '
cmd += '-build-path "' + tmp_dir + '" '
cmd += '-tools "' + ide_path + '/tools-builder" '
if cache != "":
cmd += '-build-cache "' + cache + '" '
if args.library_path:
for lib_dir in args.library_path:
cmd += '-libraries "' + lib_dir + '" '
Expand Down Expand Up @@ -98,6 +100,7 @@ def parse_args():
parser.add_argument('--debug_port', help='Debug port',
choices=['Serial', 'Serial1'])
parser.add_argument('--debug_level', help='Debug level')
parser.add_argument('--build_cache', help='Build directory to cache core.a', default='')
parser.add_argument('sketch_path', help='Sketch file path')
return parser.parse_args()

Expand Down Expand Up @@ -127,14 +130,15 @@ def main():
if args.verbose:
print("Sketch: ", sketch_path)
print("Build dir: ", tmp_dir)
print("Cache dir: ", args.build_cache)
print("Output: ", output_name)

if args.verbose:
f = sys.stdout
else:
f = open(tmp_dir + '/build.log', 'w')

res = compile(tmp_dir, sketch_path, tools_dir, hardware_dir, ide_path, f, args)
res = compile(tmp_dir, sketch_path, args.build_cache, tools_dir, hardware_dir, ide_path, f, args)
if res != 0:
return res

Expand Down

0 comments on commit 1f13c73

Please sign in to comment.