Merge pull request #10257 from theotherjimmy/py3-build-release

Correct Python 3 errors and lint warnings in build_release.py
pull/10393/head
Martin Kojtal 2019-04-12 14:17:31 +01:00 committed by GitHub
commit 8160c34a53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 130 additions and 76 deletions

View File

@ -1,4 +1,3 @@
#! /usr/bin/env python
""" """
mbed SDK mbed SDK
Copyright (c) 2011-2013 ARM Limited Copyright (c) 2011-2013 ARM Limited
@ -27,76 +26,96 @@ from past.builtins import basestring
ROOT = abspath(join(dirname(__file__), "..")) ROOT = abspath(join(dirname(__file__), ".."))
sys.path.insert(0, ROOT) sys.path.insert(0, ROOT)
from tools.build_api import build_mbed_libs from tools.build_api import build_mbed_libs # noqa: E402
from tools.build_api import write_build_report from tools.build_api import get_mbed_official_release # noqa: E402
from tools.build_api import get_mbed_official_release from tools.options import extract_profile # noqa: E402
from tools.options import extract_profile from tools.targets import TARGET_MAP, TARGET_NAMES # noqa: E402
from tools.targets import TARGET_MAP, TARGET_NAMES from tools.test_exporters import ReportExporter, ResultExporterType # noqa: E402, E501
from tools.test_exporters import ReportExporter, ResultExporterType from tools.test_api import SingleTestRunner # noqa: E402
from tools.test_api import SingleTestRunner from tools.paths import TEST_DIR, MBED_LIBRARIES # noqa: E402
from tools.test_api import singletest_in_cli_mode from tools.tests import TEST_MAP # noqa: E402
from tools.paths import TEST_DIR, MBED_LIBRARIES from tools.notifier.term import TerminalNotifier # noqa: E402
from tools.tests import TEST_MAP
from tools.notifier.term import TerminalNotifier
OFFICIAL_MBED_LIBRARY_BUILD = get_mbed_official_release('2') OFFICIAL_MBED_LIBRARY_BUILD = get_mbed_official_release('2')
if __name__ == '__main__': if __name__ == '__main__':
parser = OptionParser() parser = OptionParser()
parser.add_option('-o', '--official', dest="official_only", default=False, action="store_true", parser.add_option(
help="Build using only the official toolchain for each target") '-o', '--official',
parser.add_option("-j", "--jobs", type="int", dest="jobs", dest="official_only",
default=1, help="Number of concurrent jobs (default 1). Use 0 for auto based on host machine's number of CPUs") default=False,
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", action="store_true",
default=False, help="Verbose diagnostic output") help="Build using only the official toolchain for each target"
parser.add_option("-t", "--toolchains", dest="toolchains", help="Use toolchains names separated by comma") )
parser.add_option(
"-j", "--jobs",
type="int",
dest="jobs",
default=1,
help="Number of concurrent jobs (default 1)."
" Use 0 for auto based on host machine's number of CPUs"
)
parser.add_option(
"-v", "--verbose",
action="store_true",
dest="verbose",
default=False,
help="Verbose diagnostic output"
)
parser.add_option(
"-t", "--toolchains",
dest="toolchains",
help="Use toolchains names separated by comma"
)
parser.add_option("--profile", dest="profile", action="append", default=[]) parser.add_option("--profile", dest="profile", action="append", default=[])
parser.add_option(
parser.add_option("-p", "--platforms", dest="platforms", default="", help="Build only for the platform namesseparated by comma") "-p", "--platforms",
dest="platforms",
parser.add_option("-L", "--list-config", action="store_true", dest="list_config", default="",
default=False, help="List the platforms and toolchains in the release in JSON") help="Build only for the platform namesseparated by comma"
)
parser.add_option("", "--report-build", dest="report_build_file_name", help="Output the build results to an junit xml file") parser.add_option(
"-L", "--list-config",
parser.add_option("", "--build-tests", dest="build_tests", help="Build all tests in the given directories (relative to /libraries/tests)") action="store_true",
dest="list_config",
default=False,
help="List the platforms and toolchains in the release in JSON"
)
parser.add_option(
"", "--report-build",
dest="report_build_file_name",
help="Output the build results to an junit xml file"
)
parser.add_option(
"", "--build-tests",
dest="build_tests",
help="Build all tests in the given directories"
" (relative to /libraries/tests)"
)
options, args = parser.parse_args() options, args = parser.parse_args()
if options.list_config: if options.list_config:
print json.dumps(OFFICIAL_MBED_LIBRARY_BUILD, indent=4) print(json.dumps(OFFICIAL_MBED_LIBRARY_BUILD, indent=4))
sys.exit() sys.exit()
start = time() start = time()
build_report = {} build_report = {}
build_properties = {} build_properties = {}
platforms = None platforms = None
if options.platforms != "": if options.platforms != "":
platforms = set(options.platforms.split(",")) platforms = set(options.platforms.split(","))
status = True status = True
if options.build_tests: if options.build_tests:
# Get all paths # Get all paths
directories = options.build_tests.split(',') directories = options.build_tests.split(',')
for i in range(len(directories)): for i in range(len(directories)):
directories[i] = normpath(join(TEST_DIR, directories[i])) directories[i] = normpath(join(TEST_DIR, directories[i]))
test_names = [] test_names = []
for test_id in list(TEST_MAP.keys()):
for test_id in TEST_MAP.keys():
# Prevents tests with multiple source dirs from being checked # Prevents tests with multiple source dirs from being checked
if isinstance(TEST_MAP[test_id].source_dir, basestring): if isinstance(TEST_MAP[test_id].source_dir, basestring):
test_path = normpath(TEST_MAP[test_id].source_dir) test_path = normpath(TEST_MAP[test_id].source_dir)
for directory in directories: for directory in directories:
if directory in test_path: if directory in test_path:
test_names.append(test_id) test_names.append(test_id)
mut_counter = 1 mut_counter = 1
mut = {} mut = {}
test_spec = { test_spec = {
@ -104,26 +123,34 @@ if __name__ == '__main__':
} }
if options.toolchains: if options.toolchains:
print "Only building using the following toolchains: %s" % (options.toolchains) print("Only building using the following toolchains: {}".format(
options.toolchains
))
for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD: for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD:
toolchains = None toolchains = None
if platforms is not None and not target_name in platforms: if platforms is not None and target_name not in platforms:
print("Excluding %s from release" % target_name) print("Excluding {} from release".format(target_name))
continue continue
if target_name not in TARGET_NAMES: if target_name not in TARGET_NAMES:
print "Target '%s' is not a valid target. Excluding from release" print("Target '{}' is not a valid target. Excluding".format(
target_name
))
continue continue
if options.official_only: if options.official_only:
toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),) toolchains = (getattr(
TARGET_MAP[target_name], 'default_toolchain', 'ARM'
),)
else: else:
toolchains = toolchain_list toolchains = toolchain_list
if options.toolchains: if options.toolchains:
toolchainSet = set(toolchains) toolchainSet = set(toolchains)
toolchains = toolchainSet.intersection(set((options.toolchains).split(','))) toolchains = toolchainSet.intersection(
set((options.toolchains).split(','))
)
mut[str(mut_counter)] = { mut[str(mut_counter)] = {
"mcu": target_name "mcu": target_name
@ -133,7 +160,8 @@ if __name__ == '__main__':
test_spec["targets"][target_name] = toolchains test_spec["targets"][target_name] = toolchains
single_test = SingleTestRunner(_muts=mut, single_test = SingleTestRunner(
_muts=mut,
_parser=parser, _parser=parser,
_opts=options, _opts=options,
_opts_report_build_file_name=options.report_build_file_name, _opts_report_build_file_name=options.report_build_file_name,
@ -145,28 +173,44 @@ if __name__ == '__main__':
_opts_jobs=options.jobs, _opts_jobs=options.jobs,
_opts_include_non_automated=True, _opts_include_non_automated=True,
_opts_build_report=build_report, _opts_build_report=build_report,
_opts_build_properties=build_properties) _opts_build_properties=build_properties
)
# Runs test suite in CLI mode # Runs test suite in CLI mode
test_summary, shuffle_seed, test_summary_ext, test_suite_properties_ext, new_build_report, new_build_properties = single_test.execute() (
test_summary,
shuffle_seed,
test_summary_ext,
test_suite_properties_ext,
new_build_report,
new_build_properties
) = single_test.execute()
else: else:
for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD: for target_name, toolchain_list in OFFICIAL_MBED_LIBRARY_BUILD:
if platforms is not None and not target_name in platforms: if platforms is not None and target_name not in platforms:
print("Excluding %s from release" % target_name) print("Excluding {} from release".format(target_name))
continue continue
if target_name not in TARGET_NAMES: if target_name not in TARGET_NAMES:
print "Target '%s' is not a valid target. Excluding from release" print("Target '{}' is not a valid target. Excluding".format(
target_name
))
continue continue
if options.official_only: if options.official_only:
toolchains = (getattr(TARGET_MAP[target_name], 'default_toolchain', 'ARM'),) toolchains = (getattr(
TARGET_MAP[target_name], 'default_toolchain', 'ARM'
),)
else: else:
toolchains = toolchain_list toolchains = toolchain_list
if options.toolchains: if options.toolchains:
print "Only building using the following toolchains: %s" % (options.toolchains) print("Building using the following toolchains: {}".format(
options.toolchains
))
toolchainSet = set(toolchains) toolchainSet = set(toolchains)
toolchains = toolchainSet.intersection(set((options.toolchains).split(','))) toolchains = toolchainSet.intersection(
set((options.toolchains).split(','))
)
for toolchain in toolchains: for toolchain in toolchains:
built_mbed_lib = build_mbed_libs( built_mbed_lib = build_mbed_libs(
@ -179,18 +223,28 @@ if __name__ == '__main__':
build_profile=extract_profile(parser, options, toolchain), build_profile=extract_profile(parser, options, toolchain),
) )
# copy targets.json file as part of the release # copy targets.json file as part of the release
copy(join(dirname(abspath(__file__)), '..', 'targets', 'targets.json'), MBED_LIBRARIES) copy(
join(dirname(abspath(__file__)), '..', 'targets', 'targets.json'),
MBED_LIBRARIES
)
# Write summary of the builds # Write summary of the builds
if options.report_build_file_name: if options.report_build_file_name:
file_report_exporter = ReportExporter(ResultExporterType.JUNIT, package="build") file_report_exporter = ReportExporter(
file_report_exporter.report_to_file(build_report, options.report_build_file_name, test_suite_properties=build_properties) ResultExporterType.JUNIT, package="build"
)
file_report_exporter.report_to_file(
build_report,
options.report_build_file_name,
test_suite_properties=build_properties
)
print "\n\nCompleted in: (%.2f)s" % (time() - start) print("\n\nCompleted in: (%.2f)s" % (time() - start))
print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build") print_report_exporter = ReportExporter(
ResultExporterType.PRINT, package="build"
)
status = status and print_report_exporter.report(build_report) status = status and print_report_exporter.report(build_report)
if not status: if not status: