Skip to content

Commit 1f13c73

Browse files
Speed up CI builds with caching hacks (#5539)
1 parent eaac1e8 commit 1f13c73

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

tests/common.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function build_sketches()
4343
local build_rem=$5
4444
local lwip=$6
4545
mkdir -p $build_dir
46-
local build_cmd="python tools/build.py -b generic -v -w all -s 4M1M -v -k -p $PWD/$build_dir -n $lwip $build_arg "
46+
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 "
4747
local sketches=$(find $srcpath -name *.ino | sort)
4848
print_size_info >size.log
4949
export ARDUINO_IDE_PATH=$arduino
@@ -53,7 +53,21 @@ function build_sketches()
5353
if [ $testcnt -ne $build_rem ]; then
5454
continue # Not ours to do
5555
fi
56-
rm -rf $build_dir/*
56+
57+
if [ -e $cache_dir/core/*.a ]; then
58+
# We need to preserve the build.options.json file and replace the last .ino
59+
# with this sketch's ino file, or builder will throw everything away.
60+
sed -i "s,^.*sketchLocation.*$, \"sketchLocation\": \"$sketch\"\,,g" $build_dir/build.options.json
61+
# Set the time of the cached core.a file to the future so the GIT header
62+
# we regen won't cause the builder to throw it out and rebuild from scratch.
63+
touch -d 'now + 1 day' $cache_dir/core/*.a
64+
fi
65+
66+
# Clear out the last built sketch, map, elf, bin files, but leave the compiled
67+
# objects in the core and libraries available for use so we don't need to rebuild
68+
# them each sketch.
69+
rm -rf $build_dir/sketch $build_dir/*.bin $build_dir/*.map $build_dir/*.elf
70+
5771
local sketchdir=$(dirname $sketch)
5872
local sketchdirname=$(basename $sketchdir)
5973
local sketchname=$(basename $sketch)
@@ -221,6 +235,8 @@ if [ -z "$TRAVIS_BUILD_DIR" ]; then
221235
echo "TRAVIS_BUILD_DIR=$TRAVIS_BUILD_DIR"
222236
fi
223237

238+
cache_dir=$(mktemp -d)
239+
224240
if [ "$BUILD_TYPE" = "build" ]; then
225241
install_arduino nodebug
226242
build_sketches_with_arduino 1 0 lm2f
@@ -259,6 +275,8 @@ elif [ "$BUILD_TYPE" = "platformio_odd" ]; then
259275
build_sketches_with_platformio $TRAVIS_BUILD_DIR/libraries "--board nodemcuv2 --verbose" 2 1
260276
else
261277
echo "BUILD_TYPE not set or invalid"
278+
rm -rf $cache_dir
262279
exit 1
263280
fi
264281

282+
rm -rf $cache_dir

tools/build.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
import tempfile
3030
import shutil
3131

32-
def compile(tmp_dir, sketch, tools_dir, hardware_dir, ide_path, f, args):
32+
def compile(tmp_dir, sketch, cache, tools_dir, hardware_dir, ide_path, f, args):
3333
cmd = ide_path + '/arduino-builder '
3434
cmd += '-compile -logger=human '
3535
cmd += '-build-path "' + tmp_dir + '" '
3636
cmd += '-tools "' + ide_path + '/tools-builder" '
37+
if cache != "":
38+
cmd += '-build-cache "' + cache + '" '
3739
if args.library_path:
3840
for lib_dir in args.library_path:
3941
cmd += '-libraries "' + lib_dir + '" '
@@ -98,6 +100,7 @@ def parse_args():
98100
parser.add_argument('--debug_port', help='Debug port',
99101
choices=['Serial', 'Serial1'])
100102
parser.add_argument('--debug_level', help='Debug level')
103+
parser.add_argument('--build_cache', help='Build directory to cache core.a', default='')
101104
parser.add_argument('sketch_path', help='Sketch file path')
102105
return parser.parse_args()
103106

@@ -127,14 +130,15 @@ def main():
127130
if args.verbose:
128131
print("Sketch: ", sketch_path)
129132
print("Build dir: ", tmp_dir)
133+
print("Cache dir: ", args.build_cache)
130134
print("Output: ", output_name)
131135

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

137-
res = compile(tmp_dir, sketch_path, tools_dir, hardware_dir, ide_path, f, args)
141+
res = compile(tmp_dir, sketch_path, args.build_cache, tools_dir, hardware_dir, ide_path, f, args)
138142
if res != 0:
139143
return res
140144

0 commit comments

Comments
 (0)