Skip to content

Speed up CI builds with caching hacks #5539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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