Skip to content

Commit 0e4b841

Browse files
committed
Removing need for memap to printed through toolchains
1 parent 655c377 commit 0e4b841

File tree

3 files changed

+79
-56
lines changed

3 files changed

+79
-56
lines changed

tools/build_api.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,26 @@ def build_project(src_paths, build_path, target, toolchain_name,
455455
# Link Program
456456
res, _ = toolchain.link_program(resources, build_path, name)
457457

458+
memap_instance = getattr(toolchain, 'memap_instance', None)
459+
memap_table = ''
460+
if memap_instance:
461+
# Write output to stdout in text (pretty table) format
462+
memap_table = memap_instance.generate_output('table', silent=silent)
463+
464+
# Write output to file in JSON format
465+
map_out = join(build_path, name + "_map.json")
466+
memap_instance.generate_output('json', map_out)
467+
468+
# Write output to file in CSV format for the CI
469+
map_csv = join(build_path, name + "_map.csv")
470+
memap_instance.generate_output('csv-ci', map_csv)
471+
458472
resources.detect_duplicates(toolchain)
459473

460474
if report != None:
461475
end = time()
462476
cur_result["elapsed_time"] = end - start
463-
cur_result["output"] = toolchain.get_output()
477+
cur_result["output"] = toolchain.get_output() + memap_table
464478
cur_result["result"] = "OK"
465479
cur_result["memory_usage"] = toolchain.map_outputs
466480

tools/test_api.py

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,8 +2097,16 @@ def build_test_worker(*args, **kwargs):
20972097
ret['bin_file'] = bin_file
20982098
ret['kwargs'] = kwargs
20992099

2100+
except NotSupportedException, e:
2101+
ret['reason'] = e
2102+
except ToolException, e:
2103+
ret['reason'] = e
2104+
except KeyboardInterrupt, e:
2105+
ret['reason'] = e
21002106
except:
2101-
ret['reason'] = sys.exc_info()[1]
2107+
# Print unhandled exceptions here
2108+
import traceback
2109+
traceback.print_exc(file=sys.stdout)
21022110

21032111
return ret
21042112

@@ -2132,7 +2140,6 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
21322140

21332141
jobs_count = int(jobs if jobs else cpu_count())
21342142
p = Pool(processes=jobs_count)
2135-
21362143
results = []
21372144
for test_name, test_path in tests.iteritems():
21382145
test_build_path = os.path.join(build_path, test_path)
@@ -2166,51 +2173,61 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
21662173
p.terminate()
21672174
p.join()
21682175
raise ToolException("Compile did not finish in 10 minutes")
2176+
else:
2177+
sleep(0.01)
2178+
pending = 0
2179+
for r in results:
2180+
if r.ready() is True:
2181+
try:
2182+
worker_result = r.get()
2183+
results.remove(r)
21692184

2170-
sleep(0.01)
2171-
pending = 0
2172-
for r in results:
2173-
if r.ready() is True:
2174-
try:
2175-
worker_result = r.get()
2176-
results.remove(r)
2177-
2178-
# Take report from the kwargs and merge it into existing report
2179-
report_entry = worker_result['kwargs']['report'][target_name][toolchain_name]
2180-
for test_key in report_entry.keys():
2181-
report[target_name][toolchain_name][test_key] = report_entry[test_key]
2182-
2183-
# Set the overall result to a failure if a build failure occurred
2184-
if not worker_result['result'] and not isinstance(worker_result['reason'], NotSupportedException):
2185-
result = False
2186-
2187-
# Adding binary path to test build result
2188-
if worker_result['result'] and 'bin_file' in worker_result:
2189-
bin_file = norm_relative_path(worker_result['bin_file'], execution_directory)
2190-
2191-
test_build['tests'][worker_result['kwargs']['project_id']] = {
2192-
"binaries": [
2193-
{
2194-
"path": bin_file
2195-
}
2196-
]
2197-
}
2185+
# Take report from the kwargs and merge it into existing report
2186+
report_entry = worker_result['kwargs']['report'][target_name][toolchain_name]
2187+
for test_key in report_entry.keys():
2188+
report[target_name][toolchain_name][test_key] = report_entry[test_key]
21982189

2199-
test_key = worker_result['kwargs']['project_id'].upper()
2200-
print report[target_name][toolchain_name][test_key][0][0]['output'].rstrip()
2201-
print 'Image: %s\n' % bin_file
2202-
2203-
except ToolException, err:
2204-
if p._taskqueue.queue:
2205-
p._taskqueue.queue.clear()
2206-
sleep(0.5)
2207-
p.terminate()
2208-
p.join()
2209-
raise ToolException(err)
2210-
else:
2211-
pending += 1
2212-
if pending >= jobs_count:
2213-
break
2190+
# Set the overall result to a failure if a build failure occurred
2191+
if not worker_result['result'] and not isinstance(worker_result['reason'], NotSupportedException):
2192+
result = False
2193+
break
2194+
2195+
# Adding binary path to test build result
2196+
if worker_result['result'] and 'bin_file' in worker_result:
2197+
bin_file = norm_relative_path(worker_result['bin_file'], execution_directory)
2198+
2199+
test_build['tests'][worker_result['kwargs']['project_id']] = {
2200+
"binaries": [
2201+
{
2202+
"path": bin_file
2203+
}
2204+
]
2205+
}
2206+
2207+
test_key = worker_result['kwargs']['project_id'].upper()
2208+
print report[target_name][toolchain_name][test_key][0][0]['output'].rstrip()
2209+
print 'Image: %s\n' % bin_file
2210+
2211+
except:
2212+
if p._taskqueue.queue:
2213+
p._taskqueue.queue.clear()
2214+
sleep(0.5)
2215+
p.terminate()
2216+
p.join()
2217+
raise
2218+
else:
2219+
pending += 1
2220+
if pending >= jobs_count:
2221+
break
2222+
2223+
# Break as soon as possible if there is a failure and we are not
2224+
# continuing on build failures
2225+
if not result and not continue_on_build_fail:
2226+
if p._taskqueue.queue:
2227+
p._taskqueue.queue.clear()
2228+
sleep(0.5)
2229+
p.terminate()
2230+
break
22142231

22152232
p.join()
22162233

tools/toolchains/__init__.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,16 +1075,8 @@ def mem_stats(self, map):
10751075
self.info("Unknown toolchain for memory statistics %s" % toolchain)
10761076
return None
10771077

1078-
# Write output to stdout in text (pretty table) format
1079-
self.info(memap.generate_output('table', silent=True))
1080-
1081-
# Write output to file in JSON format
1082-
map_out = splitext(map)[0] + "_map.json"
1083-
memap.generate_output('json', map_out)
1084-
1085-
# Write output to file in CSV format for the CI
1086-
map_csv = splitext(map)[0] + "_map.csv"
1087-
memap.generate_output('csv-ci', map_csv)
1078+
# Store the memap instance for later use
1079+
self.memap_instance = memap
10881080

10891081
# Here we return memory statistics structure (constructed after
10901082
# call to generate_output) which contains raw data in bytes

0 commit comments

Comments
 (0)