Skip to content

Commit ff5c8b2

Browse files
committed
Add proper travis script
1 parent c9df7cd commit ff5c8b2

File tree

4 files changed

+189
-27
lines changed

4 files changed

+189
-27
lines changed

.travis.yml

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
sudo: false
2-
language: bash
2+
3+
language: python
4+
python:
5+
- "2.7"
6+
37
os:
48
- linux
59

10+
dist:
11+
- xenial
12+
613
script:
7-
- /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16
8-
- sleep 3
9-
- export DISPLAY=:1.0
10-
- wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz
11-
- tar xf arduino-1.6.5-linux64.tar.xz
12-
- mv arduino-1.6.5 $HOME/arduino_ide
13-
- export PATH="$HOME/arduino_ide:$PATH"
14-
- which arduino
15-
- mkdir -p $HOME/Arduino/libraries
16-
- cp -r $TRAVIS_BUILD_DIR $HOME/Arduino/libraries/ESPAsyncTCP
17-
- cd $HOME/arduino_ide/hardware
18-
- mkdir esp8266com
19-
- cd esp8266com
20-
- git clone https://github.com/esp8266/Arduino.git esp8266
21-
- cd esp8266/tools
22-
- python get.py
23-
- source $TRAVIS_BUILD_DIR/travis/common.sh
24-
- arduino --board esp8266com:esp8266:generic --save-prefs
25-
- arduino --get-pref sketchbook.path
26-
- build_sketches arduino $HOME/Arduino/libraries/ESPAsyncTCP esp8266
14+
- bash $TRAVIS_BUILD_DIR/travis/build.sh
2715

2816
notifications:
2917
email:
@@ -34,4 +22,4 @@ notifications:
3422
- https://webhooks.gitter.im/e/60e65d0c78ea0a920347
3523
on_success: change # options: [always|never|change] default: always
3624
on_failure: always # options: [always|never|change] default: always
37-
on_start: false # default: false
25+
on_start: never # options: [always|never|change] default: always

travis/build.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# build.py — build a sketch using arduino-builder
5+
#
6+
# Wrapper script around arduino-builder which accepts some ESP8266-specific
7+
# options and translates them into FQBN
8+
#
9+
# Copyright © 2016 Ivan Grokhotkov
10+
#
11+
# Permission is hereby granted, free of charge, to any person obtaining a copy
12+
# of this software and associated documentation files (the "Software"), to deal
13+
# in the Software without restriction, including without limitation the rights
14+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
# copies of the Software, and to permit persons to whom the Software is
16+
# furnished to do so, subject to the following conditions:
17+
#
18+
# The above copyright notice and this permission notice shall be included in
19+
# all copies or substantial portions of the Software.
20+
#
21+
#
22+
23+
24+
from __future__ import print_function
25+
import sys
26+
import os
27+
import argparse
28+
import subprocess
29+
import tempfile
30+
import shutil
31+
32+
def compile(tmp_dir, sketch, tools_dir, hardware_dir, ide_path, f, args):
33+
cmd = ide_path + '/arduino-builder '
34+
cmd += '-compile -logger=human '
35+
cmd += '-build-path "' + tmp_dir + '" '
36+
cmd += '-tools "' + ide_path + '/tools-builder" '
37+
if args.library_path:
38+
for lib_dir in args.library_path:
39+
cmd += '-libraries "' + lib_dir + '" '
40+
cmd += '-hardware "' + ide_path + '/hardware" '
41+
if args.hardware_dir:
42+
for hw_dir in args.hardware_dir:
43+
cmd += '-hardware "' + hw_dir + '" '
44+
else:
45+
cmd += '-hardware "' + hardware_dir + '" '
46+
# Debug=Serial,DebugLevel=Core____
47+
cmd += '-fqbn=espressif:esp32:{board_name}:' \
48+
'FlashFreq={flash_freq},' \
49+
'PartitionScheme=huge_app,' \
50+
'UploadSpeed=921600'.format(**vars(args))
51+
cmd += ' '
52+
cmd += '-ide-version=10607 '
53+
cmd += '-warnings={warnings} '.format(**vars(args))
54+
if args.verbose:
55+
cmd += '-verbose '
56+
cmd += sketch
57+
58+
if args.verbose:
59+
print('Building: ' + cmd, file=f)
60+
61+
cmds = cmd.split(' ')
62+
p = subprocess.Popen(cmds, stdout=f, stderr=subprocess.STDOUT)
63+
p.wait()
64+
return p.returncode
65+
66+
def parse_args():
67+
parser = argparse.ArgumentParser(description='Sketch build helper')
68+
parser.add_argument('-v', '--verbose', help='Enable verbose output',
69+
action='store_true')
70+
parser.add_argument('-i', '--ide_path', help='Arduino IDE path')
71+
parser.add_argument('-p', '--build_path', help='Build directory')
72+
parser.add_argument('-l', '--library_path', help='Additional library path',
73+
action='append')
74+
parser.add_argument('-d', '--hardware_dir', help='Additional hardware path',
75+
action='append')
76+
parser.add_argument('-b', '--board_name', help='Board name', default='esp32')
77+
parser.add_argument('-w', '--warnings', help='Compilation warnings level',
78+
default='none', choices=['none', 'all', 'more'])
79+
parser.add_argument('-o', '--output_binary', help='File name for output binary')
80+
parser.add_argument('-k', '--keep', action='store_true',
81+
help='Don\'t delete temporary build directory')
82+
parser.add_argument('--flash_freq', help='Flash frequency', default=40,
83+
type=int, choices=[40, 80])
84+
parser.add_argument('sketch_path', help='Sketch file path')
85+
return parser.parse_args()
86+
87+
def main():
88+
args = parse_args()
89+
90+
ide_path = args.ide_path
91+
if not ide_path:
92+
ide_path = os.environ.get('ARDUINO_IDE_PATH')
93+
if not ide_path:
94+
print("Please specify Arduino IDE path via --ide_path option"
95+
"or ARDUINO_IDE_PATH environment variable.", file=sys.stderr)
96+
return 2
97+
98+
sketch_path = args.sketch_path
99+
tmp_dir = args.build_path
100+
created_tmp_dir = False
101+
if not tmp_dir:
102+
tmp_dir = tempfile.mkdtemp()
103+
created_tmp_dir = True
104+
105+
tools_dir = os.path.dirname(os.path.realpath(__file__)) + '/../tools'
106+
# this is not the correct hardware folder to add.
107+
hardware_dir = ide_path + '/hardware'
108+
109+
output_name = tmp_dir + '/' + os.path.basename(sketch_path) + '.bin'
110+
if args.verbose:
111+
print("Sketch: ", sketch_path)
112+
print("Build dir: ", tmp_dir)
113+
print("Output: ", output_name)
114+
115+
if args.verbose:
116+
f = sys.stdout
117+
else:
118+
f = open(tmp_dir + '/build.log', 'w')
119+
120+
res = compile(tmp_dir, sketch_path, tools_dir, hardware_dir, ide_path, f, args)
121+
if res != 0:
122+
return res
123+
124+
if args.output_binary is not None:
125+
shutil.copy(output_name, args.output_binary)
126+
127+
if created_tmp_dir and not args.keep:
128+
shutil.rmtree(tmp_dir, ignore_errors=True)
129+
130+
if __name__ == '__main__':
131+
sys.exit(main())

travis/build.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
echo -e "travis_fold:start:sketch_test_env_prepare"
4+
pip install pyserial
5+
wget -O arduino.tar.xz https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz
6+
tar xf arduino.tar.xz
7+
mv arduino-nightly $HOME/arduino_ide
8+
mkdir -p $HOME/Arduino/libraries
9+
cd $HOME/Arduino/libraries
10+
cp -rf $TRAVIS_BUILD_DIR AsyncTCP
11+
cd $HOME/arduino_ide/hardware
12+
mkdir espressif
13+
cd espressif
14+
git clone https://github.com/espressif/arduino-esp32.git esp32
15+
cd esp32
16+
git submodule update --init --recursive
17+
cd tools
18+
python get.py
19+
cd $TRAVIS_BUILD_DIR
20+
export PATH="$HOME/arduino_ide:$HOME/arduino_ide/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin:$PATH"
21+
source travis/common.sh
22+
echo -e "travis_fold:end:sketch_test_env_prepare"
23+
24+
echo -e "travis_fold:start:sketch_test"
25+
build_sketches $HOME/arduino_ide $HOME/Arduino/libraries/AsyncTCP/examples "-l $HOME/Arduino/libraries"
26+
if [ $? -ne 0 ]; then exit 1; fi
27+
echo -e "travis_fold:end:sketch_test"

travis/common.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,38 @@
22

33
function build_sketches()
44
{
5+
#set +e
56
local arduino=$1
67
local srcpath=$2
7-
local platform=$3
8+
local build_arg=$3
9+
local build_dir=build.tmp
10+
mkdir -p $build_dir
11+
local build_cmd="python travis/build.py -b esp32 -k -p $PWD/$build_dir $build_arg "
812
local sketches=$(find $srcpath -name *.ino)
13+
export ARDUINO_IDE_PATH=$arduino
914
for sketch in $sketches; do
15+
rm -rf $build_dir/*
1016
local sketchdir=$(dirname $sketch)
11-
if [[ -f "$sketchdir/.$platform.skip" ]]; then
12-
echo -e "\n\n ------------ Skipping $sketch ------------ \n\n";
17+
local sketchdirname=$(basename $sketchdir)
18+
local sketchname=$(basename $sketch)
19+
if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
20+
echo "Skipping $sketch, beacause it is not the main sketch file";
21+
continue
22+
fi;
23+
if [[ -f "$sketchdir/.test.skip" ]]; then
24+
echo -e "\n ------------ Skipping $sketch ------------ \n";
1325
continue
1426
fi
15-
echo -e "\n\n ------------ Building $sketch ------------ \n\n";
16-
$arduino --verify $sketch;
27+
echo -e "\n ------------ Building $sketch ------------ \n";
28+
time ($build_cmd $sketch >$build_dir/build.log)
1729
local result=$?
1830
if [ $result -ne 0 ]; then
1931
echo "Build failed ($1)"
32+
echo "Build log:"
33+
cat $build_dir/build.log
2034
return $result
2135
fi
36+
rm $build_dir/build.log
2237
done
38+
#set -e
2339
}

0 commit comments

Comments
 (0)