|
1 | | -#! /usr/bin/env python |
2 | 1 | """ |
3 | 2 | mbed SDK |
4 | 3 | Copyright (c) 2011-2013 ARM Limited |
|
27 | 26 | ROOT = abspath(join(dirname(__file__), "..")) |
28 | 27 | sys.path.insert(0, ROOT) |
29 | 28 |
|
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 |
41 | 38 |
|
42 | 39 | OFFICIAL_MBED_LIBRARY_BUILD = get_mbed_official_release('2') |
43 | 40 |
|
44 | 41 | if __name__ == '__main__': |
45 | 42 | 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 | + ) |
54 | 70 | 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 | + ) |
66 | 95 | options, args = parser.parse_args() |
67 | | - |
68 | | - |
69 | | - |
70 | 96 | if options.list_config: |
71 | | - print json.dumps(OFFICIAL_MBED_LIBRARY_BUILD, indent=4) |
| 97 | + print(json.dumps(OFFICIAL_MBED_LIBRARY_BUILD, indent=4)) |
72 | 98 | sys.exit() |
73 | | - |
74 | 99 | start = time() |
75 | 100 | build_report = {} |
76 | 101 | build_properties = {} |
77 | | - |
78 | 102 | platforms = None |
79 | 103 | if options.platforms != "": |
80 | 104 | platforms = set(options.platforms.split(",")) |
81 | | - |
82 | 105 | status = True |
83 | | - |
84 | 106 | if options.build_tests: |
85 | 107 | # Get all paths |
86 | 108 | directories = options.build_tests.split(',') |
87 | 109 | for i in range(len(directories)): |
88 | 110 | directories[i] = normpath(join(TEST_DIR, directories[i])) |
89 | | - |
90 | 111 | test_names = [] |
91 | | - |
92 | | - for test_id in TEST_MAP.keys(): |
| 112 | + for test_id in list(TEST_MAP.keys()): |
93 | 113 | # 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): |
95 | 115 | test_path = normpath(TEST_MAP[test_id].source_dir) |
96 | 116 | for directory in directories: |
97 | 117 | if directory in test_path: |
98 | 118 | test_names.append(test_id) |
99 | | - |
100 | 119 | mut_counter = 1 |
101 | 120 | mut = {} |
102 | 121 | test_spec = { |
103 | 122 | "targets": {} |
104 | 123 | } |
105 | 124 |
|
106 | 125 | 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 | + )) |
108 | 129 |
|
109 | 130 | for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD: |
110 | 131 | 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)) |
113 | 134 | continue |
114 | 135 |
|
115 | 136 | 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 | + )) |
117 | 140 | continue |
118 | 141 |
|
119 | 142 | 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 | + ),) |
121 | 146 | else: |
122 | 147 | toolchains = toolchain_list |
123 | 148 |
|
124 | 149 | if options.toolchains: |
125 | 150 | toolchainSet = set(toolchains) |
126 | | - toolchains = toolchainSet.intersection(set((options.toolchains).split(','))) |
| 151 | + toolchains = toolchainSet.intersection( |
| 152 | + set((options.toolchains).split(',')) |
| 153 | + ) |
127 | 154 |
|
128 | 155 | mut[str(mut_counter)] = { |
129 | 156 | "mcu": target_name |
|
133 | 160 |
|
134 | 161 | test_spec["targets"][target_name] = toolchains |
135 | 162 |
|
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 | + ) |
149 | 178 | # 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() |
151 | 187 | else: |
152 | 188 | 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)) |
155 | 191 | continue |
156 | 192 |
|
157 | 193 | 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 | + )) |
159 | 197 | continue |
160 | 198 |
|
161 | 199 | 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 | + ),) |
163 | 203 | else: |
164 | 204 | toolchains = toolchain_list |
165 | 205 |
|
166 | 206 | 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 | + )) |
168 | 210 | toolchainSet = set(toolchains) |
169 | | - toolchains = toolchainSet.intersection(set((options.toolchains).split(','))) |
| 211 | + toolchains = toolchainSet.intersection( |
| 212 | + set((options.toolchains).split(',')) |
| 213 | + ) |
170 | 214 |
|
171 | 215 | for toolchain in toolchains: |
172 | 216 | built_mbed_lib = build_mbed_libs( |
|
179 | 223 | build_profile=extract_profile(parser, options, toolchain), |
180 | 224 | ) |
181 | 225 |
|
182 | | - |
183 | 226 | # 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 | + ) |
185 | 231 |
|
186 | 232 | # Write summary of the builds |
187 | 233 | 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 | + ) |
194 | 248 | status = status and print_report_exporter.report(build_report) |
195 | 249 |
|
196 | 250 | if not status: |
|
0 commit comments