Python2+3: mbed test --compile

pull/5848/head
Jimmy Brisson 2018-01-12 16:46:26 -06:00
parent c93a2bfa4c
commit 1dd39fbe80
3 changed files with 24 additions and 22 deletions

View File

@ -18,6 +18,7 @@ limitations under the License.
TEST BUILD & RUN TEST BUILD & RUN
""" """
from __future__ import print_function, division, absolute_import
import sys import sys
import os import os
import json import json
@ -36,8 +37,8 @@ from tools.build_api import merge_build_data
from tools.targets import TARGET_MAP from tools.targets import TARGET_MAP
from tools.utils import mkdir, ToolException, NotSupportedException, args_error from tools.utils import mkdir, ToolException, NotSupportedException, args_error
from tools.test_exporters import ReportExporter, ResultExporterType from tools.test_exporters import ReportExporter, ResultExporterType
from utils import argparse_filestring_type, argparse_lowercase_type, argparse_many from tools.utils import argparse_filestring_type, argparse_lowercase_type, argparse_many
from utils import argparse_dir_not_parent from tools.utils import argparse_dir_not_parent
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS, TOOLCHAIN_CLASSES from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS, TOOLCHAIN_CLASSES
from tools.settings import CLI_COLOR_MAP from tools.settings import CLI_COLOR_MAP
@ -164,7 +165,8 @@ if __name__ == '__main__':
if fnmatch.fnmatch(testname, name): if fnmatch.fnmatch(testname, name):
tests[testname] = test tests[testname] = test
else: else:
print "[Warning] Test with name '%s' was not found in the available tests" % (name) print("[Warning] Test with name '%s' was not found in the "
"available tests" % (name))
else: else:
tests = all_tests tests = all_tests
@ -211,18 +213,18 @@ if __name__ == '__main__':
build_profile=profile) build_profile=profile)
library_build_success = True library_build_success = True
except ToolException, e: except ToolException as e:
# ToolException output is handled by the build log # ToolException output is handled by the build log
pass pass
except NotSupportedException, e: except NotSupportedException as e:
# NotSupportedException is handled by the build log # NotSupportedException is handled by the build log
pass pass
except Exception, e: except Exception as e:
# Some other exception occurred, print the error message # Some other exception occurred, print the error message
print e print(e)
if not library_build_success: if not library_build_success:
print "Failed to build library" print("Failed to build library")
else: else:
# Build all the tests # Build all the tests
@ -252,9 +254,9 @@ if __name__ == '__main__':
try: try:
with open(options.test_spec, 'w') as f: with open(options.test_spec, 'w') as f:
f.write(json.dumps(test_spec_data, indent=2)) f.write(json.dumps(test_spec_data, indent=2))
except IOError, e: except IOError as e:
print "[ERROR] Error writing test spec to file" print("[ERROR] Error writing test spec to file")
print e print(e)
# If a path to a JUnit build report spec is provided, write it to a file # If a path to a JUnit build report spec is provided, write it to a file
if options.build_report_junit: if options.build_report_junit:
@ -264,7 +266,7 @@ if __name__ == '__main__':
# Print memory map summary on screen # Print memory map summary on screen
if build_report: if build_report:
print print
print print_build_memory_usage(build_report) print(print_build_memory_usage(build_report))
print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build") print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build")
status = print_report_exporter.report(build_report) status = print_report_exporter.report(build_report)
@ -276,13 +278,13 @@ if __name__ == '__main__':
else: else:
sys.exit(1) sys.exit(1)
except KeyboardInterrupt, e: except KeyboardInterrupt as e:
print "\n[CTRL+c] exit" print("\n[CTRL+c] exit")
except ConfigException, e: except ConfigException as e:
# Catching ConfigException here to prevent a traceback # Catching ConfigException here to prevent a traceback
print "[ERROR] %s" % str(e) print("[ERROR] %s" % str(e))
except Exception,e: except Exception as e:
import traceback import traceback
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)
print "[ERROR] %s" % str(e) print("[ERROR] %s" % str(e))
sys.exit(1) sys.exit(1)

View File

@ -29,6 +29,7 @@ import argparse
import datetime import datetime
import threading import threading
import ctypes import ctypes
import functools
from colorama import Fore, Back, Style from colorama import Fore, Back, Style
from prettytable import PrettyTable from prettytable import PrettyTable
from copy import copy from copy import copy
@ -52,7 +53,7 @@ from tools.utils import ToolException
from tools.utils import NotSupportedException from tools.utils import NotSupportedException
from tools.utils import construct_enum from tools.utils import construct_enum
from tools.memap import MemapParser from tools.memap import MemapParser
from tools.targets import TARGET_MAP from tools.targets import TARGET_MAP, Target
import tools.test_configs as TestConfig import tools.test_configs as TestConfig
from tools.test_db import BaseDBAccess from tools.test_db import BaseDBAccess
from tools.build_api import build_project, build_mbed_libs, build_lib from tools.build_api import build_project, build_mbed_libs, build_lib
@ -2216,7 +2217,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
execution_directory = "." execution_directory = "."
base_path = norm_relative_path(build_path, execution_directory) base_path = norm_relative_path(build_path, execution_directory)
target_name = target if isinstance(target, str) else target.name target_name = target.name if isinstance(target, Target) else target
cfg, _, _ = get_config(base_source_paths, target_name, toolchain_name) cfg, _, _ = get_config(base_source_paths, target_name, toolchain_name)
baud_rate = 9600 baud_rate = 9600

View File

@ -795,7 +795,7 @@ class mbedToolchain:
def copy_files(self, files_paths, trg_path, resources=None, rel_path=None): def copy_files(self, files_paths, trg_path, resources=None, rel_path=None):
# Handle a single file # Handle a single file
if isinstance(files_paths, list): if not isinstance(files_paths, list):
files_paths = [files_paths] files_paths = [files_paths]
for source in files_paths: for source in files_paths:
@ -1291,7 +1291,6 @@ class mbedToolchain:
self.config_file = None # this means "config file not present" self.config_file = None # this means "config file not present"
changed = True changed = True
elif crt_data != prev_data: # different content of config file elif crt_data != prev_data: # different content of config file
print("changed!")
with open(self.config_file, "w") as f: with open(self.config_file, "w") as f:
f.write(crt_data) f.write(crt_data)
changed = True changed = True