Skip to content

[Exporters][morph export-build] Adds build tests for make exporters and suppresses TargetNotSupported traceback #3134

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

Closed
wants to merge 1 commit into from
Closed
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
51 changes: 49 additions & 2 deletions tools/export/makefile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
"""
from os.path import splitext, basename, relpath, join, abspath, dirname,\
exists
from os import curdir, getcwd
import sys
from subprocess import check_output, CalledProcessError, Popen, PIPE
import subprocess
from jinja2.exceptions import TemplateNotFound
from tools.export.exporters import Exporter
from tools.export.exporters import Exporter, FailedBuildException
from tools.utils import NotSupportedException
from tools.targets import TARGET_MAP

Expand Down Expand Up @@ -102,6 +104,51 @@ def generate(self):
else:
raise NotSupportedException("This make tool is in development")

def build(self):
""" Build Make project """
# > Make -C [project directory] -j
if self.zipfile:
proj_file = splitext(self.zipfile)[0]
else:
proj_file = join(self.export_dir, "Makefile")

ret_dict = {
0: 'Normal exit with no errors.',
1: 'General purpose error if no other explicit error is known.',
2: 'There was an error in the makefile.',
3: 'A shell line had a non-zero status.',
4: 'Make ran out of memory.',
5: 'The program specified on the shell line was not executable.',
6: 'The shell line was longer than the command processor allowed.',
7: 'The program specified on the shell line could not be found.',
8: 'There was not enough memory to execute the shell line.',
9: 'The shell line produced a device error.',
10: 'The program specified on the shell line became resident.',
11: 'The shell line producedan unknown error.',
15: 'There was a problem with the memory miser.',
16: 'The user hit CTRL+C or CTRL+BREAK..'}
cmd = ["make", "-C", proj_file, "-j"]
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
ret = p.communicate()
out, err = ret[0], ret[1]
ret_code = p.returncode
with open(join(self.export_dir, 'build_log.txt'), 'w') as f:
f.write("=" * 10 + "OUT" + "=" * 10 + "\n")
f.write(out)
f.write("=" * 10 + "ERR" + "=" * 10 + "\n")
f.write(err)
if ret_code == 0:
f.write("SUCCESS")
else:
f.write("FAILURE")
if ret_code != 0:
# Seems like something went wrong.
raise FailedBuildException("Project: %s build failed with the status: %s" % (
self.project_name, ret_dict.get(ret_code, "Unknown")))
else:
return "Project: %s build succeeded with the status: %s" % (
self.project_name, ret_dict[0])


class GccArm(Makefile):
"""GCC ARM specific makefile target"""
Expand Down
4 changes: 1 addition & 3 deletions tools/export/uvision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ def generate_flash_dll(self):
'''
fl_count = 0
def get_mem_no_x(mem_str):
mem_reg = "\dx(\w+)"
m = re.search(mem_reg, mem_str)
return m.group(1) if m else None
return mem_str[2:]

RAMS = [(get_mem_no_x(info["start"]), get_mem_no_x(info["size"]))
for mem, info in self.target_info["memory"].items() if "RAM" in mem]
Expand Down
6 changes: 5 additions & 1 deletion tools/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from tools.paths import EXPORT_DIR, MBED_HAL, MBED_LIBRARIES
from tools.export import EXPORTERS, mcu_ide_matrix
from tools.export.exporters import TargetNotSupportedException
from tools.tests import TESTS, TEST_MAP
from tools.tests import test_known, test_name_known, Test
from tools.targets import TARGET_NAMES
Expand Down Expand Up @@ -234,10 +235,13 @@ def main():
# Export to selected toolchain
_, toolchain_name = get_exporter_toolchain(options.ide)
profile = extract_profile(parser, options, toolchain_name)
export(options.mcu, options.ide, build=options.build,
try:
export(options.mcu, options.ide, build=options.build,
src=options.source_dir, macros=options.macros,
project_id=options.program, clean=options.clean,
zip_proj=zip_proj, build_profile=profile)
except TargetNotSupportedException:
print "Your target is not supported for the selected IDE."


if __name__ == "__main__":
Expand Down
12 changes: 8 additions & 4 deletions tools/project_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,14 @@ def export_project(src_paths, export_path, target, ide,
macros=macros)
files.append(config_header)
if zip_proj:
if isinstance(zip_proj, basestring):
zip_export(join(export_path, zip_proj), name, resource_dict, files, inc_repos)
else:
zip_export(zip_proj, name, resource_dict, files, inc_repos)
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
if isinstance(zip_proj, basestring):
zip_export(join(export_path, zip_proj), name, resource_dict, files, inc_repos)
exporter.zipfile = (join(export_path, zip_proj))
else:
zip_export(zip_proj, name, resource_dict, files, inc_repos)

return exporter

Expand Down
18 changes: 13 additions & 5 deletions tools/test/export/build_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from shutil import rmtree
from collections import namedtuple
from copy import copy
import zipfile


from tools.paths import EXPORT_DIR
Expand Down Expand Up @@ -96,6 +97,7 @@ def test_case(case):
return TestCase(**case)

def handle_log(self,log):
print log
try:
with open(log, 'r') as in_log:
print in_log.read()
Expand Down Expand Up @@ -126,6 +128,10 @@ def batch_tests(self, clean=False):
test_case.ide,
test_case.name))
try:
if test_case.zip:
name_str = ('%s_%s_%s') % (test_case.mcu, test_case.ide, test_case.name)
with zipfile.ZipFile(exporter.zipfile, "r") as zip_file:
zip_file.extractall(path=join(EXPORT_DIR, name_str))
exporter.build()
except FailedBuildException:
self.failures.append("%s::%s\t%s" % (test_case.mcu,
Expand Down Expand Up @@ -161,8 +167,9 @@ def perform_exports(self, test_case):
try:
_, toolchain = get_exporter_toolchain(test_case.ide)
profile = extract_profile(self.parser, self.options, toolchain)
zip_name = name_str+'.zip' if test_case.zip else None
exporter = export(test_case.mcu, test_case.ide,
project_id=test_case.id, zip_proj=None,
project_id=test_case.id, zip_proj=zip_name,
clean=True, src=test_case.src,
export_path=join(EXPORT_DIR,name_str),
silent=True, build_profile=profile)
Expand Down Expand Up @@ -203,7 +210,7 @@ def check_version(version):
def main():
"""Entry point"""

ide_list = ["iar", "uvision"]
ide_list = ["iar", "uvision", "make_gcc_arm", "make_iar", "make_armc5"]

default_v2 = [test_name_known("MBED_BLINKY")]
default_v5 = [check_valid_mbed_os('tests-mbedmicro-rtos-mbed-basic')]
Expand Down Expand Up @@ -274,13 +281,14 @@ def main():
v2_tests = options.programs or default_v2

tests = []
default_test = {key:None for key in ['ide', 'mcu', 'name', 'id', 'src', 'log']}
default_test = {key:None for key in ['ide', 'mcu', 'name', 'id', 'src', 'log', 'zip']}
for mcu in test_targets:
for ide in options.ides:
log = "build_log.txt" if ide == 'iar' \
log = "build_log.txt" if ide != 'uvision' \
else join('build', 'build_log.txt')
# add each test case to the tests array
default_test.update({'mcu': mcu, 'ide': ide, 'log':log})
zip = True if "make" in ide else False
default_test.update({'mcu': mcu, 'ide': ide, 'log':log, 'zip':zip})
for test in v2_tests:
default_test.update({'name':TESTS[test]["id"], 'id':test})
tests.append(copy(default_test))
Expand Down