Skip to content

Commit 8160c34

Browse files
authored
Merge pull request #10257 from theotherjimmy/py3-build-release
Correct Python 3 errors and lint warnings in build_release.py
2 parents 4d56b94 + 583e787 commit 8160c34

File tree

1 file changed

+132
-78
lines changed

1 file changed

+132
-78
lines changed

tools/build_release.py

Lines changed: 132 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#! /usr/bin/env python
21
"""
32
mbed SDK
43
Copyright (c) 2011-2013 ARM Limited
@@ -27,103 +26,131 @@
2726
ROOT = abspath(join(dirname(__file__), ".."))
2827
sys.path.insert(0, ROOT)
2928

30-
from tools.build_api import build_mbed_libs
31-
from tools.build_api import write_build_report
32-
from tools.build_api import get_mbed_official_release
33-
from tools.options import extract_profile
34-
from tools.targets import TARGET_MAP, TARGET_NAMES
35-
from tools.test_exporters import ReportExporter, ResultExporterType
36-
from tools.test_api import SingleTestRunner
37-
from tools.test_api import singletest_in_cli_mode
38-
from tools.paths import TEST_DIR, MBED_LIBRARIES
39-
from tools.tests import TEST_MAP
40-
from tools.notifier.term import TerminalNotifier
29+
from tools.build_api import build_mbed_libs # noqa: E402
30+
from tools.build_api import get_mbed_official_release # noqa: E402
31+
from tools.options import extract_profile # noqa: E402
32+
from tools.targets import TARGET_MAP, TARGET_NAMES # noqa: E402
33+
from tools.test_exporters import ReportExporter, ResultExporterType # noqa: E402, E501
34+
from tools.test_api import SingleTestRunner # noqa: E402
35+
from tools.paths import TEST_DIR, MBED_LIBRARIES # noqa: E402
36+
from tools.tests import TEST_MAP # noqa: E402
37+
from tools.notifier.term import TerminalNotifier # noqa: E402
4138

4239
OFFICIAL_MBED_LIBRARY_BUILD = get_mbed_official_release('2')
4340

4441
if __name__ == '__main__':
4542
parser = OptionParser()
46-
parser.add_option('-o', '--official', dest="official_only", default=False, action="store_true",
47-
help="Build using only the official toolchain for each target")
48-
parser.add_option("-j", "--jobs", type="int", dest="jobs",
49-
default=1, help="Number of concurrent jobs (default 1). Use 0 for auto based on host machine's number of CPUs")
50-
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
51-
default=False, help="Verbose diagnostic output")
52-
parser.add_option("-t", "--toolchains", dest="toolchains", help="Use toolchains names separated by comma")
53-
43+
parser.add_option(
44+
'-o', '--official',
45+
dest="official_only",
46+
default=False,
47+
action="store_true",
48+
help="Build using only the official toolchain for each target"
49+
)
50+
parser.add_option(
51+
"-j", "--jobs",
52+
type="int",
53+
dest="jobs",
54+
default=1,
55+
help="Number of concurrent jobs (default 1)."
56+
" Use 0 for auto based on host machine's number of CPUs"
57+
)
58+
parser.add_option(
59+
"-v", "--verbose",
60+
action="store_true",
61+
dest="verbose",
62+
default=False,
63+
help="Verbose diagnostic output"
64+
)
65+
parser.add_option(
66+
"-t", "--toolchains",
67+
dest="toolchains",
68+
help="Use toolchains names separated by comma"
69+
)
5470
parser.add_option("--profile", dest="profile", action="append", default=[])
55-
56-
parser.add_option("-p", "--platforms", dest="platforms", default="", help="Build only for the platform namesseparated by comma")
57-
58-
parser.add_option("-L", "--list-config", action="store_true", dest="list_config",
59-
default=False, help="List the platforms and toolchains in the release in JSON")
60-
61-
parser.add_option("", "--report-build", dest="report_build_file_name", help="Output the build results to an junit xml file")
62-
63-
parser.add_option("", "--build-tests", dest="build_tests", help="Build all tests in the given directories (relative to /libraries/tests)")
64-
65-
71+
parser.add_option(
72+
"-p", "--platforms",
73+
dest="platforms",
74+
default="",
75+
help="Build only for the platform namesseparated by comma"
76+
)
77+
parser.add_option(
78+
"-L", "--list-config",
79+
action="store_true",
80+
dest="list_config",
81+
default=False,
82+
help="List the platforms and toolchains in the release in JSON"
83+
)
84+
parser.add_option(
85+
"", "--report-build",
86+
dest="report_build_file_name",
87+
help="Output the build results to an junit xml file"
88+
)
89+
parser.add_option(
90+
"", "--build-tests",
91+
dest="build_tests",
92+
help="Build all tests in the given directories"
93+
" (relative to /libraries/tests)"
94+
)
6695
options, args = parser.parse_args()
67-
68-
69-
7096
if options.list_config:
71-
print json.dumps(OFFICIAL_MBED_LIBRARY_BUILD, indent=4)
97+
print(json.dumps(OFFICIAL_MBED_LIBRARY_BUILD, indent=4))
7298
sys.exit()
73-
7499
start = time()
75100
build_report = {}
76101
build_properties = {}
77-
78102
platforms = None
79103
if options.platforms != "":
80104
platforms = set(options.platforms.split(","))
81-
82105
status = True
83-
84106
if options.build_tests:
85107
# Get all paths
86108
directories = options.build_tests.split(',')
87109
for i in range(len(directories)):
88110
directories[i] = normpath(join(TEST_DIR, directories[i]))
89-
90111
test_names = []
91-
92-
for test_id in TEST_MAP.keys():
112+
for test_id in list(TEST_MAP.keys()):
93113
# Prevents tests with multiple source dirs from being checked
94-
if isinstance( TEST_MAP[test_id].source_dir, basestring):
114+
if isinstance(TEST_MAP[test_id].source_dir, basestring):
95115
test_path = normpath(TEST_MAP[test_id].source_dir)
96116
for directory in directories:
97117
if directory in test_path:
98118
test_names.append(test_id)
99-
100119
mut_counter = 1
101120
mut = {}
102121
test_spec = {
103122
"targets": {}
104123
}
105124

106125
if options.toolchains:
107-
print "Only building using the following toolchains: %s" % (options.toolchains)
126+
print("Only building using the following toolchains: {}".format(
127+
options.toolchains
128+
))
108129

109130
for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD:
110131
toolchains = None
111-
if platforms is not None and not target_name in platforms:
112-
print("Excluding %s from release" % target_name)
132+
if platforms is not None and target_name not in platforms:
133+
print("Excluding {} from release".format(target_name))
113134
continue
114135

115136
if target_name not in TARGET_NAMES:
116-
print "Target '%s' is not a valid target. Excluding from release"
137+
print("Target '{}' is not a valid target. Excluding".format(
138+
target_name
139+
))
117140
continue
118141

119142
if options.official_only:
120-
toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),)
143+
toolchains = (getattr(
144+
TARGET_MAP[target_name], 'default_toolchain', 'ARM'
145+
),)
121146
else:
122147
toolchains = toolchain_list
123148

124149
if options.toolchains:
125150
toolchainSet = set(toolchains)
126-
toolchains = toolchainSet.intersection(set((options.toolchains).split(',')))
151+
toolchains = toolchainSet.intersection(
152+
set((options.toolchains).split(','))
153+
)
127154

128155
mut[str(mut_counter)] = {
129156
"mcu": target_name
@@ -133,40 +160,57 @@
133160

134161
test_spec["targets"][target_name] = toolchains
135162

136-
single_test = SingleTestRunner(_muts=mut,
137-
_parser=parser,
138-
_opts=options,
139-
_opts_report_build_file_name=options.report_build_file_name,
140-
_test_spec=test_spec,
141-
_opts_test_by_names=",".join(test_names),
142-
_opts_verbose=options.verbose,
143-
_opts_only_build_tests=True,
144-
_opts_suppress_summary=True,
145-
_opts_jobs=options.jobs,
146-
_opts_include_non_automated=True,
147-
_opts_build_report=build_report,
148-
_opts_build_properties=build_properties)
163+
single_test = SingleTestRunner(
164+
_muts=mut,
165+
_parser=parser,
166+
_opts=options,
167+
_opts_report_build_file_name=options.report_build_file_name,
168+
_test_spec=test_spec,
169+
_opts_test_by_names=",".join(test_names),
170+
_opts_verbose=options.verbose,
171+
_opts_only_build_tests=True,
172+
_opts_suppress_summary=True,
173+
_opts_jobs=options.jobs,
174+
_opts_include_non_automated=True,
175+
_opts_build_report=build_report,
176+
_opts_build_properties=build_properties
177+
)
149178
# Runs test suite in CLI mode
150-
test_summary, shuffle_seed, test_summary_ext, test_suite_properties_ext, new_build_report, new_build_properties = single_test.execute()
179+
(
180+
test_summary,
181+
shuffle_seed,
182+
test_summary_ext,
183+
test_suite_properties_ext,
184+
new_build_report,
185+
new_build_properties
186+
) = single_test.execute()
151187
else:
152188
for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD:
153-
if platforms is not None and not target_name in platforms:
154-
print("Excluding %s from release" % target_name)
189+
if platforms is not None and target_name not in platforms:
190+
print("Excluding {} from release".format(target_name))
155191
continue
156192

157193
if target_name not in TARGET_NAMES:
158-
print "Target '%s' is not a valid target. Excluding from release"
194+
print("Target '{}' is not a valid target. Excluding".format(
195+
target_name
196+
))
159197
continue
160198

161199
if options.official_only:
162-
toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),)
200+
toolchains = (getattr(
201+
TARGET_MAP[target_name], 'default_toolchain', 'ARM'
202+
),)
163203
else:
164204
toolchains = toolchain_list
165205

166206
if options.toolchains:
167-
print "Only building using the following toolchains: %s" % (options.toolchains)
207+
print("Building using the following toolchains: {}".format(
208+
options.toolchains
209+
))
168210
toolchainSet = set(toolchains)
169-
toolchains = toolchainSet.intersection(set((options.toolchains).split(',')))
211+
toolchains = toolchainSet.intersection(
212+
set((options.toolchains).split(','))
213+
)
170214

171215
for toolchain in toolchains:
172216
built_mbed_lib = build_mbed_libs(
@@ -179,18 +223,28 @@
179223
build_profile=extract_profile(parser, options, toolchain),
180224
)
181225

182-
183226
# copy targets.json file as part of the release
184-
copy(join(dirname(abspath(__file__)), '..', 'targets', 'targets.json'), MBED_LIBRARIES)
227+
copy(
228+
join(dirname(abspath(__file__)), '..', 'targets', 'targets.json'),
229+
MBED_LIBRARIES
230+
)
185231

186232
# Write summary of the builds
187233
if options.report_build_file_name:
188-
file_report_exporter = ReportExporter(ResultExporterType.JUNIT, package="build")
189-
file_report_exporter.report_to_file(build_report, options.report_build_file_name, test_suite_properties=build_properties)
190-
191-
print "\n\nCompleted in: (%.2f)s" % (time() - start)
192-
193-
print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build")
234+
file_report_exporter = ReportExporter(
235+
ResultExporterType.JUNIT, package="build"
236+
)
237+
file_report_exporter.report_to_file(
238+
build_report,
239+
options.report_build_file_name,
240+
test_suite_properties=build_properties
241+
)
242+
243+
print("\n\nCompleted in: (%.2f)s" % (time() - start))
244+
245+
print_report_exporter = ReportExporter(
246+
ResultExporterType.PRINT, package="build"
247+
)
194248
status = status and print_report_exporter.report(build_report)
195249

196250
if not status:

0 commit comments

Comments
 (0)