Skip to content

Commit 77a04a0

Browse files
committed
Initial travis pull from esp8266
1 parent 6a1e7c1 commit 77a04a0

File tree

3 files changed

+270
-0
lines changed

3 files changed

+270
-0
lines changed

.travis.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
sudo: false
2+
language: bash
3+
os:
4+
- linux
5+
6+
addons:
7+
apt:
8+
sources:
9+
- ubuntu-toolchain-r-test
10+
packages:
11+
- g++-4.8
12+
13+
script:
14+
- set -e
15+
- export CXX="g++-4.8" CC="gcc-4.8" GCOV="gcov-4.8"
16+
- echo -e "travis_fold:start:host_tests"
17+
- pushd $TRAVIS_BUILD_DIR/tests/host
18+
- make
19+
- make clean-objects
20+
- echo -e "travis_fold:end:host_tests"
21+
- echo -e "travis_fold:start:sketch_test_env_prepare"
22+
- popd
23+
- wget -O arduino.tar.xz https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz
24+
- tar xf arduino.tar.xz
25+
- mv arduino-nightly $HOME/arduino_ide
26+
- cd $HOME/arduino_ide/hardware
27+
- mkdir espressif
28+
- cd espressif
29+
- ln -s $TRAVIS_BUILD_DIR esp32
30+
- cd esp32/tools
31+
- python get.py
32+
- export PATH="$HOME/arduino_ide:$TRAVIS_BUILD_DIR/tools/xtensa-esp32-elf/bin:$PATH"
33+
- which arduino
34+
- cd $TRAVIS_BUILD_DIR
35+
- source tools/common.sh
36+
- install_libraries
37+
- echo -e "travis_fold:end:sketch_test_env_prepare"
38+
- echo -e "travis_fold:start:sketch_test"
39+
- build_sketches $HOME/arduino_ide $TRAVIS_BUILD_DIR/libraries "-l $HOME/Arduino/libraries"
40+
- echo -e "travis_fold:end:sketch_test"
41+
- echo -e "travis_fold:start:size_report"
42+
- cat size.log
43+
- echo -e "travis_fold:end:size_report"
44+
45+
notifications:
46+
email:
47+
on_success: change
48+
on_failure: change
49+
webhooks:
50+
urls:
51+
- https://webhooks.gitter.im/e/cb057279c430d91a47a8
52+
on_success: change # options: [always|never|change] default: always
53+
on_failure: always # options: [always|never|change] default: always
54+
on_start: false # default: false

tools/build.py

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
'UploadSpeed=921600'
50+
cmd += ' '
51+
cmd += '-ide-version=10607 '
52+
cmd += '-warnings={warnings} '.format(**vars(args))
53+
if args.verbose:
54+
cmd += '-verbose '
55+
cmd += sketch
56+
57+
if args.verbose:
58+
print('Building: ' + cmd, file=f)
59+
60+
cmds = cmd.split(' ')
61+
p = subprocess.Popen(cmds, stdout=f, stderr=subprocess.STDOUT)
62+
p.wait()
63+
return p.returncode
64+
65+
def parse_args():
66+
parser = argparse.ArgumentParser(description='Sketch build helper')
67+
parser.add_argument('-v', '--verbose', help='Enable verbose output',
68+
action='store_true')
69+
parser.add_argument('-i', '--ide_path', help='Arduino IDE path')
70+
parser.add_argument('-p', '--build_path', help='Build directory')
71+
parser.add_argument('-l', '--library_path', help='Additional library path',
72+
action='append')
73+
parser.add_argument('-d', '--hardware_dir', help='Additional hardware path',
74+
action='append')
75+
parser.add_argument('-b', '--board_name', help='Board name', default='esp32')
76+
parser.add_argument('-w', '--warnings', help='Compilation warnings level',
77+
default='none', choices=['none', 'all', 'more'])
78+
parser.add_argument('-o', '--output_binary', help='File name for output binary')
79+
parser.add_argument('-k', '--keep', action='store_true',
80+
help='Don\'t delete temporary build directory')
81+
parser.add_argument('--flash_freq', help='Flash frequency', default=40,
82+
type=int, choices=[40, 80])
83+
parser.add_argument('sketch_path', help='Sketch file path')
84+
return parser.parse_args()
85+
86+
def main():
87+
args = parse_args()
88+
89+
ide_path = args.ide_path
90+
if not ide_path:
91+
ide_path = os.environ.get('ARDUINO_IDE_PATH')
92+
if not ide_path:
93+
print("Please specify Arduino IDE path via --ide_path option"
94+
"or ARDUINO_IDE_PATH environment variable.", file=sys.stderr)
95+
return 2
96+
97+
sketch_path = args.sketch_path
98+
tmp_dir = args.build_path
99+
created_tmp_dir = False
100+
if not tmp_dir:
101+
tmp_dir = tempfile.mkdtemp()
102+
created_tmp_dir = True
103+
104+
tools_dir = os.path.dirname(os.path.realpath(__file__)) + '/../tools'
105+
# this is not the correct hardware folder to add.
106+
hardware_dir = os.path.dirname(os.path.realpath(__file__)) + '/../cores'
107+
108+
output_name = tmp_dir + '/' + os.path.basename(sketch_path) + '.bin'
109+
if args.verbose:
110+
print("Sketch: ", sketch_path)
111+
print("Build dir: ", tmp_dir)
112+
print("Output: ", output_name)
113+
114+
if args.verbose:
115+
f = sys.stdout
116+
else:
117+
f = open(tmp_dir + '/build.log', 'w')
118+
119+
res = compile(tmp_dir, sketch_path, tools_dir, hardware_dir, ide_path, f, args)
120+
if res != 0:
121+
return res
122+
123+
if args.output_binary is not None:
124+
shutil.copy(output_name, args.output_binary)
125+
126+
if created_tmp_dir and not args.keep:
127+
shutil.rmtree(tmp_dir, ignore_errors=True)
128+
129+
if __name__ == '__main__':
130+
sys.exit(main())

tools/common.sh

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env bash
2+
3+
function print_size_info()
4+
{
5+
elf_file=$1
6+
7+
if [ -z "$elf_file" ]; then
8+
printf "sketch data rodata bss text irom0.text dram flash\n"
9+
return 0
10+
fi
11+
12+
elf_name=$(basename $elf_file)
13+
sketch_name="${elf_name%.*}"
14+
# echo $sketch_name
15+
declare -A segments
16+
while read -a tokens; do
17+
seg=${tokens[0]}
18+
seg=${seg//./}
19+
size=${tokens[1]}
20+
addr=${tokens[2]}
21+
if [ "$addr" -eq "$addr" -a "$addr" -ne "0" ] 2>/dev/null; then
22+
segments[$seg]=$size
23+
fi
24+
25+
26+
done < <(xtensa-esp32-elf-size --format=sysv $elf_file)
27+
28+
total_ram=$((${segments[data]} + ${segments[rodata]} + ${segments[bss]}))
29+
total_flash=$((${segments[data]} + ${segments[rodata]} + ${segments[text]} + ${segments[irom0text]}))
30+
31+
printf "%-28s %-8d %-8d %-8d %-8d %-8d %-8d %-8d\n" $sketch_name ${segments[data]} ${segments[rodata]} ${segments[bss]} ${segments[text]} ${segments[irom0text]} $total_ram $total_flash
32+
return 0
33+
}
34+
35+
function build_sketches()
36+
{
37+
set +e
38+
local arduino=$1
39+
local srcpath=$2
40+
local build_arg=$3
41+
local build_dir=build.tmp
42+
mkdir -p $build_dir
43+
local build_cmd="python tools/build.py -b generic -v -k -p $PWD/$build_dir $build_arg "
44+
local sketches=$(find $srcpath -name *.ino)
45+
print_size_info >size.log
46+
export ARDUINO_IDE_PATH=$arduino
47+
for sketch in $sketches; do
48+
rm -rf $build_dir/*
49+
local sketchdir=$(dirname $sketch)
50+
local sketchdirname=$(basename $sketchdir)
51+
local sketchname=$(basename $sketch)
52+
if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
53+
echo "Skipping $sketch, beacause it is not the main sketch file";
54+
continue
55+
fi;
56+
if [[ -f "$sketchdir/.test.skip" ]]; then
57+
echo -e "\n ------------ Skipping $sketch ------------ \n";
58+
continue
59+
fi
60+
echo -e "\n ------------ Building $sketch ------------ \n";
61+
# $arduino --verify $sketch;
62+
echo "$build_cmd $sketch"
63+
time ($build_cmd $sketch >build.log)
64+
local result=$?
65+
if [ $result -ne 0 ]; then
66+
echo "Build failed ($1)"
67+
echo "Build log:"
68+
cat build.log
69+
return $result
70+
fi
71+
rm build.log
72+
print_size_info $build_dir/*.elf >>size.log
73+
done
74+
set -e
75+
}
76+
77+
function install_libraries()
78+
{
79+
mkdir -p $HOME/Arduino/libraries
80+
pushd $HOME/Arduino/libraries
81+
82+
# install ArduinoJson library
83+
#wget https://github.com/bblanchon/ArduinoJson/releases/download/v4.6.1/ArduinoJson-v4.6.1.zip && unzip ArduinoJson-v4.6.1.zip
84+
85+
popd
86+
}

0 commit comments

Comments
 (0)