Skip to content

Commit 8082799

Browse files
committed
Add --build-data flag to mbed test
1 parent aeb6109 commit 8082799

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

tools/build_api.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
from types import ListType
2222
from shutil import rmtree
2323
from os.path import join, exists, dirname, basename, abspath, normpath, splitext
24+
from os.path import relpath
2425
from os import linesep, remove, makedirs
2526
from time import time
2627
from intelhex import IntelHex
28+
from json import load, dump
2729

2830
from tools.utils import mkdir, run_cmd, run_cmd_ext, NotSupportedException,\
2931
ToolException, InvalidReleaseTargetException, intelhex_offset
@@ -1365,3 +1367,22 @@ def write_build_report(build_report, template_filename, filename):
13651367
placeholder.write(template.render(
13661368
failing_builds=build_report_failing,
13671369
passing_builds=build_report_passing))
1370+
1371+
1372+
def merge_build_data(filename, toolchain_report):
1373+
path_to_file = dirname(abspath(filename))
1374+
try:
1375+
build_data = load(open(filename))
1376+
except (IOError, ValueError):
1377+
build_data = {'builds': []}
1378+
for tgt in toolchain_report.values():
1379+
for tc in tgt.values():
1380+
for project in tc.values():
1381+
for build in project:
1382+
try:
1383+
build[0]['elf'] = relpath(build[0]['elf'], path_to_file)
1384+
build[0]['bin'] = relpath(build[0]['bin'], path_to_file)
1385+
except KeyError:
1386+
pass
1387+
build_data['builds'].append(build[0])
1388+
dump(build_data, open(filename, "wb"), indent=4, separators=(',', ': '))

tools/make.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,13 @@
4949
from tools.build_api import mcu_toolchain_matrix
5050
from tools.build_api import mcu_toolchain_list
5151
from tools.build_api import mcu_target_list
52+
from tools.build_api import merge_build_data
5253
from utils import argparse_filestring_type
5354
from utils import argparse_many
5455
from utils import argparse_dir_not_parent
5556
from tools.toolchains import mbedToolchain, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
5657
from tools.settings import CLI_COLOR_MAP
5758

58-
def merge_build_data(filename, toolchain_report):
59-
try:
60-
build_data = load(open(filename))
61-
except (IOError, ValueError):
62-
build_data = {'builds': []}
63-
for tgt in toolchain_report.values():
64-
for tc in tgt.values():
65-
for project in tc.values():
66-
for build in project:
67-
build_data['builds'].append(build[0])
68-
dump(build_data, open(filename, "wb"), indent=4, separators=(',', ': '))
69-
7059
if __name__ == '__main__':
7160
# Parse Options
7261
parser = get_default_options_parser(add_app_config=True)

tools/test.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from tools.options import get_default_options_parser, extract_profile
3232
from tools.build_api import build_project, build_library
3333
from tools.build_api import print_build_memory_usage
34+
from tools.build_api import merge_build_data
3435
from tools.targets import TARGET_MAP
3536
from tools.utils import mkdir, ToolException, NotSupportedException, args_error
3637
from tools.test_exporters import ReportExporter, ResultExporterType
@@ -88,6 +89,10 @@
8889

8990
parser.add_argument("--build-report-junit", dest="build_report_junit",
9091
default=None, help="Destination path for a build report in the JUnit xml format")
92+
parser.add_argument("--build-data",
93+
dest="build_data",
94+
default=None,
95+
help="Dump build_data to this file")
9196

9297
parser.add_argument("-v", "--verbose",
9398
action="store_true",
@@ -175,17 +180,13 @@
175180
profile = extract_profile(parser, options, toolchain)
176181
try:
177182
# Build sources
178-
build_library(base_source_paths, options.build_dir, mcu, toolchain,
179-
jobs=options.jobs,
180-
clean=options.clean,
181-
report=build_report,
182-
properties=build_properties,
183-
name="mbed-build",
184-
macros=options.macros,
185-
verbose=options.verbose,
186-
notify=notify,
187-
archive=False,
188-
app_config=options.app_config,
183+
build_library(base_source_paths, options.build_dir, mcu,
184+
toolchain, jobs=options.jobs,
185+
clean=options.clean, report=build_report,
186+
properties=build_properties, name="mbed-build",
187+
macros=options.macros, verbose=options.verbose,
188+
notify=notify, archive=False,
189+
app_config=options.app_config,
189190
build_profile=profile)
190191

191192
library_build_success = True
@@ -245,6 +246,8 @@
245246

246247
print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build")
247248
status = print_report_exporter.report(build_report)
249+
if options.build_data:
250+
merge_build_data(options.build_data, build_report)
248251

249252
if status:
250253
sys.exit(0)

0 commit comments

Comments
 (0)