From ec2e4a1d6a41b2e97b40a8617accdbcc47d1acc1 Mon Sep 17 00:00:00 2001 From: Brian Daniels Date: Thu, 12 May 2016 19:00:40 +0100 Subject: [PATCH 1/2] Adding default id for the build report if no id is provided --- tools/build_api.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/build_api.py b/tools/build_api.py index a8d5287cfa..4394d9aaa9 100644 --- a/tools/build_api.py +++ b/tools/build_api.py @@ -109,8 +109,10 @@ def build_project(src_path, build_path, target, toolchain_name, if report != None: start = time() - id_name = project_id.upper() - description = project_description + + # If project_id is specified, use that over the default name + id_name = project_id.upper() if project_id else name.upper() + description = project_description if project_description else name vendor_label = target.extra_labels[0] cur_result = None prep_report(report, target.name, toolchain_name, id_name) @@ -190,7 +192,8 @@ def build_project(src_path, build_path, target, toolchain_name, def build_library(src_paths, build_path, target, toolchain_name, dependencies_paths=None, options=None, name=None, clean=False, archive=True, notify=None, verbose=False, macros=None, inc_dirs=None, inc_dirs_ext=None, - jobs=1, silent=False, report=None, properties=None, extra_verbose=False): + jobs=1, silent=False, report=None, properties=None, extra_verbose=False, + project_id=None): """ src_path: the path of the source directory build_path: the path of the build directory target: ['LPC1768', 'LPC11U24', 'LPC2368'] @@ -213,7 +216,9 @@ def build_library(src_paths, build_path, target, toolchain_name, if report != None: start = time() - id_name = name.upper() + + # If project_id is specified, use that over the default name + id_name = project_id.upper() if project_id else name.upper() description = name vendor_label = target.extra_labels[0] cur_result = None From bc86aa92a06c17134ce637a4b0ee1496e756554f Mon Sep 17 00:00:00 2001 From: Brian Daniels Date: Thu, 12 May 2016 19:01:32 +0100 Subject: [PATCH 2/2] Adding JUnit build reporting option to test.py --- tools/test.py | 17 +++++++++++++++++ tools/test_exporters.py | 6 +++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/test.py b/tools/test.py index e79c1dc6ac..f9f659c554 100644 --- a/tools/test.py +++ b/tools/test.py @@ -30,6 +30,7 @@ from tools.options import get_default_options_parser from tools.build_api import build_project, build_library from tools.targets import TARGET_MAP from tools.utils import mkdir +from tools.test_exporters import ReportExporter, ResultExporterType if __name__ == '__main__': try: @@ -66,6 +67,9 @@ if __name__ == '__main__': parser.add_option("--test-spec", dest="test_spec", default=None, help="Destination path for a test spec file that can be used by the Greentea automated test tool") + parser.add_option("--build-report-junit", dest="build_report_junit", + default=None, help="Destination path for a build report in the JUnit xml format") + parser.add_option("-v", "--verbose", action="store_true", dest="verbose", @@ -118,16 +122,25 @@ if __name__ == '__main__': target = TARGET_MAP[options.mcu] + build_report = {} + build_properties = {} + + # Build sources lib_build_res = build_library(base_source_paths, options.build_dir, target, options.tool, options=options.options, jobs=options.jobs, clean=options.clean, + report=build_report, + properties=build_properties, + name="mbed-os", archive=False) # Build all the tests test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool, options=options.options, clean=options.clean, + report=build_report, + properties=build_properties, jobs=options.jobs) # If a path to a test spec is provided, write it to a file @@ -147,6 +160,10 @@ if __name__ == '__main__': print "[ERROR] Error writing test spec to file" print e + # If a path to a JUnit build report spec is provided, write it to a file + if options.build_report_junit: + report_exporter = ReportExporter(ResultExporterType.JUNIT) + report_exporter.report_to_file(build_report, options.build_report_junit, test_suite_properties=build_properties) sys.exit() except KeyboardInterrupt, e: diff --git a/tools/test_exporters.py b/tools/test_exporters.py index 16c5e47409..a65fd29fb1 100644 --- a/tools/test_exporters.py +++ b/tools/test_exporters.py @@ -17,7 +17,8 @@ limitations under the License. Author: Przemyslaw Wirkus """ -from tools.utils import construct_enum +from tools.utils import construct_enum, mkdir +import os ResultExporterType = construct_enum(HTML='Html_Exporter', @@ -97,6 +98,9 @@ class ReportExporter(): def write_to_file(self, report, file_name): if report is not None: + dirname = os.path.dirname(file_name) + if dirname: + mkdir(dirname) with open(file_name, 'w') as f: f.write(report)