Skip to content

Commit db4c380

Browse files
committed
Python2+3: build_travis.py and Travis tests
1 parent 424ad85 commit db4c380

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

.travis.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env:
1010
--data @- << DATA\n{
1111
"state": "$0",
1212
"description": "$1",
13-
"context": "travis-ci/$NAME",
13+
"context": "travis-ci/$NAME/$(python --version)",
1414
"target_url": "https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID"
1515
}\nDATA'
1616
@@ -73,6 +73,10 @@ matrix:
7373
7474
- env:
7575
- NAME=tools
76+
python:
77+
- '2.7'
78+
- '3.5'
79+
- '3.6'
7680
install:
7781
# Install dependencies
7882
- sudo apt-get install gcc-arm-embedded
@@ -175,7 +179,7 @@ matrix:
175179
- mkdir BUILD
176180
script:
177181
# Run local mbed 2 testing
178-
- python2 -u tools/build_travis.py --vendor "${NAME#mbed2-}"
182+
- python -u tools/build_travis.py --vendor "${NAME#mbed2-}"
179183
- <<: *mbed-2
180184
env: NAME=mbed2-STM
181185
- <<: *mbed-2
@@ -190,3 +194,8 @@ matrix:
190194
env: NAME=mbed2-NUVOTON
191195
- <<: *mbed-2
192196
env: NAME=mbed2-RENESAS
197+
# Change python version here only because 3x the other jobs does not add any more coverage
198+
python:
199+
- '2.7'
200+
- '3.5'
201+
- '3.6'

tools/build.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
1818
LIBRARIES BUILD
1919
"""
20+
from __future__ import print_function, division, absolute_import
21+
2022
import sys
2123
from time import time
2224
from os.path import join, abspath, dirname
@@ -130,7 +132,7 @@
130132

131133
# Only prints matrix of supported toolchains
132134
if options.supported_toolchains:
133-
print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
135+
print(mcu_toolchain_matrix(platform_filter=options.general_filter_regex))
134136
exit(0)
135137

136138

@@ -184,7 +186,7 @@
184186
tt_id = "%s::%s" % (toolchain, target)
185187
if toolchain not in TARGET_MAP[target].supported_toolchains:
186188
# Log this later
187-
print "%s skipped: toolchain not supported" % tt_id
189+
print("%s skipped: toolchain not supported" % tt_id)
188190
skipped.append(tt_id)
189191
else:
190192
try:
@@ -224,26 +226,24 @@
224226
successes.append(tt_id)
225227
else:
226228
skipped.append(tt_id)
227-
except Exception, e:
229+
except Exception as e:
228230
if options.verbose:
229231
import traceback
230232
traceback.print_exc(file=sys.stdout)
231233
sys.exit(1)
232234
failures.append(tt_id)
233-
print e
235+
print(e)
234236

235237

236238
# Write summary of the builds
237-
print
238-
print "Completed in: (%.2f)s" % (time() - start)
239-
print
239+
print("\nCompleted in: (%.2f)s\n" % (time() - start))
240240

241241
for report, report_name in [(successes, "Build successes:"),
242242
(skipped, "Build skipped:"),
243243
(failures, "Build failures:"),
244244
]:
245245
if report:
246-
print print_build_results(report, report_name),
246+
print(print_build_results(report, report_name))
247247

248248
if failures:
249249
sys.exit(1)

tools/build_travis.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
See the License for the specific language governing permissions and
1919
limitations under the License.
2020
"""
21+
from __future__ import print_function, division, absolute_import
2122

2223
import os
2324
import sys
@@ -382,11 +383,12 @@ def run_builds(dry_run, vendor):
382383
toolchain_list = build["toolchains"]
383384
if type(toolchain_list) != type([]): toolchain_list = [toolchain_list]
384385
for toolchain in toolchain_list:
385-
cmdline = "python tools/build.py -m %s -t %s -c --silent "% (build["target"], toolchain)
386+
cmdline = ("%s tools/build.py -m %s -t %s -c --silent "%
387+
(sys.executable, build["target"], toolchain))
386388
libs = build.get("libs", [])
387389
if libs:
388390
cmdline = cmdline + " ".join(["--" + l for l in libs])
389-
print "Executing: " + cmdline
391+
print("Executing: %s" % cmdline)
390392
if not dry_run:
391393
if os.system(cmdline) != 0:
392394
sys.exit(1)
@@ -408,8 +410,11 @@ def run_test_linking(dry_run, vendor):
408410
for test_lib in tests:
409411
test_names = tests[test_lib]
410412
test_lib_switch = "--" + test_lib if test_lib else ""
411-
cmdline = "python tools/make.py -m %s -t %s -c --silent %s -n %s " % (link["target"], toolchain, test_lib_switch, ",".join(test_names))
412-
print "Executing: " + cmdline
413+
cmdline = ("%s tools/make.py -m %s -t %s -c --silent %s "
414+
"-n %s" % (sys.executable, link["target"],
415+
toolchain, test_lib_switch,
416+
",".join(test_names)))
417+
print("Executing: %s" % cmdline)
413418
if not dry_run:
414419
if os.system(cmdline) != 0:
415420
sys.exit(1)

tools/toolchains/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ def get_link_file(self, cmd):
865865
# ARM, GCC, IAR cross compatible
866866
def get_arch_file(self, objects):
867867
archive_file = join(self.build_dir, ".archive_files.txt")
868-
with open(archive_file, "wb") as f:
868+
with open(archive_file, "w") as f:
869869
o_list = []
870870
for o in objects:
871871
o_list.append('"%s"' % o)

0 commit comments

Comments
 (0)