Skip to content

Commit 5dd149c

Browse files
committed
Fix formatting erros in arm.py
except for the extremely long regex
1 parent a2fcdba commit 5dd149c

File tree

1 file changed

+135
-56
lines changed

1 file changed

+135
-56
lines changed

tools/toolchains/arm.py

Lines changed: 135 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
limitations under the License.
1616
"""
1717
from __future__ import print_function, absolute_import
18-
from builtins import str
18+
from builtins import str # noqa: F401
1919

2020
import re
2121
from copy import copy
22-
from os.path import join, dirname, splitext, basename, exists, relpath, isfile
23-
from os import makedirs, write, curdir, remove
22+
from os.path import join, dirname, splitext, basename, exists, isfile
23+
from os import makedirs, write, remove
2424
from tempfile import mkstemp
2525
from shutil import rmtree
2626
from distutils.version import LooseVersion
@@ -29,17 +29,20 @@
2929
from tools.toolchains.mbed_toolchain import mbedToolchain, TOOLCHAIN_PATHS
3030
from tools.utils import mkdir, NotSupportedException, run_cmd
3131

32+
3233
class ARM(mbedToolchain):
3334
LINKER_EXT = '.sct'
3435
LIBRARY_EXT = '.ar'
3536

3637
STD_LIB_NAME = "%s.ar"
37-
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+)( \(column (?P<column>\d+)\)|): (?P<severity>Warning|Error|Fatal error): (?P<message>.+)')
38-
INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
38+
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+)( \(column (?P<column>\d+)\)|): (?P<severity>Warning|Error|Fatal error): (?P<message>.+)')
39+
INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
3940
DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
4041
SHEBANG = "#! armcc -E"
41-
SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
42-
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD", "Cortex-A9"]
42+
SUPPORTED_CORES = [
43+
"Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4", "Cortex-M4F",
44+
"Cortex-M7", "Cortex-M7F", "Cortex-M7FD", "Cortex-A9"
45+
]
4346
ARMCC_RANGE = (LooseVersion("5.06"), LooseVersion("5.07"))
4447
ARMCC_VERSION_RE = re.compile(b"Component: ARM Compiler (\d+\.\d+)")
4548

@@ -81,15 +84,17 @@ def __init__(self, target, notify=None, macros=None,
8184
cpu = target.core
8285

8386
ARM_BIN = join(TOOLCHAIN_PATHS['ARM'], "bin")
84-
ARM_INC = join(TOOLCHAIN_PATHS['ARM'], "include")
8587

8688
main_cc = join(ARM_BIN, "armcc")
8789

8890
self.flags['common'] += ["--cpu=%s" % cpu]
8991

9092
self.asm = [main_cc] + self.flags['common'] + self.flags['asm']
9193
self.cc = [main_cc] + self.flags['common'] + self.flags['c']
92-
self.cppc = [main_cc] + self.flags['common'] + self.flags['c'] + self.flags['cxx']
94+
self.cppc = (
95+
[main_cc] + self.flags['common'] +
96+
self.flags['c'] + self.flags['cxx']
97+
)
9398

9499
self.ld = [join(ARM_BIN, "armlink")] + self.flags['ld']
95100

@@ -103,9 +108,13 @@ def version_check(self):
103108
msg = None
104109
min_ver, max_ver = self.ARMCC_RANGE
105110
match = self.ARMCC_VERSION_RE.search(stdout.encode("utf-8"))
106-
found_version = LooseVersion(match.group(1).decode("utf-8")) if match else None
111+
if match:
112+
found_version = LooseVersion(match.group(1).decode("utf-8"))
113+
else:
114+
found_version = None
107115
min_ver, max_ver = self.ARMCC_RANGE
108-
if found_version and (found_version < min_ver or found_version >= max_ver):
116+
if found_version and (found_version < min_ver
117+
or found_version >= max_ver):
109118
msg = ("Compiler version mismatch: Have {}; "
110119
"expected version >= {} and < {}"
111120
.format(found_version, min_ver, max_ver))
@@ -134,8 +143,11 @@ def parse_dependencies(self, dep_path):
134143
for line in open(dep_path).readlines():
135144
match = ARM.DEP_PATTERN.match(line)
136145
if match is not None:
137-
#we need to append chroot, because when the .d files are generated the compiler is chrooted
138-
dependencies.append((self.CHROOT if self.CHROOT else '') + match.group('file'))
146+
# we need to append chroot, because when the .d files are
147+
# generated the compiler is chrooted
148+
dependencies.append(
149+
(self.CHROOT if self.CHROOT else '') + match.group('file')
150+
)
139151
return dependencies
140152

141153
def parse_output(self, output):
@@ -150,14 +162,18 @@ def parse_output(self, output):
150162
'severity': match.group('severity').lower(),
151163
'file': match.group('file'),
152164
'line': match.group('line'),
153-
'col': match.group('column') if match.group('column') else 0,
154165
'message': match.group('message'),
155166
'text': '',
156167
'target_name': self.target.name,
157168
'toolchain_name': self.name
158169
}
170+
if match.group('column'):
171+
msg['col'] = match.group('column')
172+
else:
173+
msg['col'] = 0
159174
elif msg is not None:
160-
# Determine the warning/error column by calculating the ^ position
175+
# Determine the warning/error column by calculating the '^'
176+
# position
161177
match = ARM.INDEX_PATTERN.match(line)
162178
if match is not None:
163179
msg['col'] = len(match.group('col'))
@@ -244,7 +260,7 @@ def correct_scatter_shebang(self, scatter_file, cur_dir_name=None):
244260
with open(scatter_file, "r") as input:
245261
lines = input.readlines()
246262
if (lines[0].startswith(self.SHEBANG) or
247-
not lines[0].startswith("#!")):
263+
not lines[0].startswith("#!")):
248264
return scatter_file
249265
else:
250266
new_scatter = join(self.build_dir, ".link_script.sct")
@@ -290,7 +306,8 @@ def archive(self, objects, lib_path):
290306

291307
def binary(self, resources, elf, bin):
292308
_, fmt = splitext(bin)
293-
# On .hex format, combine multiple .hex files (for multiple load regions) into one
309+
# On .hex format, combine multiple .hex files (for multiple load
310+
# regions) into one
294311
bin_arg = {".bin": "--bin", ".hex": "--i32combined"}[fmt]
295312
cmd = [self.elf2bin, bin_arg, '-o', bin, elf]
296313

@@ -322,46 +339,95 @@ def redirect_symbol(source, sync, build_dir):
322339

323340

324341
class ARM_STD(ARM):
342+
325343
OFFICIALLY_SUPPORTED = True
326-
def __init__(self, target, notify=None, macros=None,
327-
build_profile=None, build_dir=None):
328-
ARM.__init__(self, target, notify, macros, build_dir=build_dir,
329-
build_profile=build_profile)
344+
345+
def __init__(
346+
self,
347+
target,
348+
notify=None,
349+
macros=None,
350+
build_profile=None,
351+
build_dir=None
352+
):
353+
ARM.__init__(
354+
self,
355+
target,
356+
notify,
357+
macros,
358+
build_dir=build_dir,
359+
build_profile=build_profile
360+
)
330361
if int(target.build_tools_metadata["version"]) > 0:
331-
#check only for ARMC5 because ARM_STD means using ARMC5, and thus supported_toolchains must include ARMC5
362+
#check only for ARMC5 because ARM_STD means using ARMC5, and thus
363+
# supported_toolchains must include ARMC5
332364
if "ARMC5" not in target.supported_toolchains:
333-
raise NotSupportedException("ARM compiler 5 support is required for ARM build")
365+
raise NotSupportedException(
366+
"ARM compiler 5 support is required for ARM build"
367+
)
334368
else:
335-
if not set(("ARM", "uARM")).intersection(set(target.supported_toolchains)):
336-
raise NotSupportedException("ARM/uARM compiler support is required for ARM build")
369+
if not set(("ARM", "uARM")).intersection(set(
370+
target.supported_toolchains
371+
)):
372+
raise NotSupportedException(
373+
"ARM/uARM compiler support is required for ARM build"
374+
)
337375

338376
class ARM_MICRO(ARM):
377+
339378
PATCHED_LIBRARY = False
379+
340380
OFFICIALLY_SUPPORTED = True
341-
def __init__(self, target, notify=None, macros=None,
342-
silent=False, extra_verbose=False, build_profile=None,
343-
build_dir=None):
344-
target.default_toolchain = "uARM"
345381

382+
def __init__(
383+
self,
384+
target,
385+
notify=None,
386+
macros=None,
387+
silent=False,
388+
extra_verbose=False,
389+
build_profile=None,
390+
build_dir=None
391+
):
392+
target.default_toolchain = "uARM"
346393
if int(target.build_tools_metadata["version"]) > 0:
347-
#At this point we already know that we want to use ARMC5+Microlib, so check for if they are supported
348-
#For, AC6+Microlib we still use ARMC6 class
349-
if not set(("ARMC5","uARM")).issubset(set(target.supported_toolchains)):
350-
raise NotSupportedException("ARM/uARM compiler support is required for ARM build")
394+
# At this point we already know that we want to use ARMC5+Microlib
395+
# so check for if they are supported For, AC6+Microlib we still
396+
# use ARMC6 class
397+
if not set(("ARMC5","uARM")).issubset(set(
398+
target.supported_toolchains
399+
)):
400+
raise NotSupportedException(
401+
"ARM/uARM compiler support is required for ARM build"
402+
)
351403
else:
352-
if not set(("ARM", "uARM")).intersection(set(target.supported_toolchains)):
353-
raise NotSupportedException("ARM/uARM compiler support is required for ARM build")
354-
ARM.__init__(self, target, notify, macros, build_dir=build_dir,
355-
build_profile=build_profile)
404+
if not set(("ARM", "uARM")).intersection(set(
405+
target.supported_toolchains
406+
)):
407+
raise NotSupportedException(
408+
"ARM/uARM compiler support is required for ARM build"
409+
)
410+
ARM.__init__(
411+
self,
412+
target,
413+
notify,
414+
macros,
415+
build_dir=build_dir,
416+
build_profile=build_profile
417+
)
418+
356419

357420
class ARMC6(ARM_STD):
358-
OFFICIALLY_SUPPORTED = True
421+
422+
OFFICIALLY_SUPPORTED = False
359423
SHEBANG = "#! armclang -E --target=arm-arm-none-eabi -x c"
360-
SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
361-
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD",
362-
"Cortex-M23", "Cortex-M23-NS", "Cortex-M33", "Cortex-M33F",
363-
"Cortex-M33-NS", "Cortex-M33F-NS", "Cortex-M33FE-NS", "Cortex-M33FE",
364-
"Cortex-A9"]
424+
SUPPORTED_CORES = [
425+
"Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
426+
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD",
427+
"Cortex-M23", "Cortex-M23-NS", "Cortex-M33", "Cortex-M33F",
428+
"Cortex-M33-NS", "Cortex-M33F-NS", "Cortex-M33FE-NS", "Cortex-M33FE",
429+
"Cortex-A9"
430+
]
365431
ARMCC_RANGE = (LooseVersion("6.10"), LooseVersion("7.0"))
366432

367433
@staticmethod
@@ -375,12 +441,20 @@ def __init__(self, target, *args, **kwargs):
375441
"this compiler does not support the core %s" % target.core)
376442

377443
if int(target.build_tools_metadata["version"]) > 0:
378-
if not set(("ARM", "ARMC6", "uARM")).intersection(set(target.supported_toolchains)):
379-
raise NotSupportedException("ARM/ARMC6 compiler support is required for ARMC6 build")
444+
if not set(("ARM", "ARMC6", "uARM")).intersection(set(
445+
target.supported_toolchains
446+
)):
447+
raise NotSupportedException(
448+
"ARM/ARMC6 compiler support is required for ARMC6 build"
449+
)
380450
else:
381-
if not set(("ARM", "ARMC6")).intersection(set(target.supported_toolchains)):
382-
raise NotSupportedException("ARM/ARMC6 compiler support is required for ARMC6 build")
383-
451+
if not set(("ARM", "ARMC6")).intersection(set(
452+
target.supported_toolchains
453+
)):
454+
raise NotSupportedException(
455+
"ARM/ARMC6 compiler support is required for ARMC6 build"
456+
)
457+
384458
if getattr(target, "default_toolchain", "ARMC6") == "uARM":
385459
if "-DMBED_RTOS_SINGLE_THREAD" not in self.flags['common']:
386460
self.flags['common'].append("-DMBED_RTOS_SINGLE_THREAD")
@@ -389,15 +463,16 @@ def __init__(self, target, *args, **kwargs):
389463
if "--library_type=microlib" not in self.flags['ld']:
390464
self.flags['ld'].append("--library_type=microlib")
391465
if "-Wl,--library_type=microlib" not in self.flags['c']:
392-
self.flags['c'].append("-Wl,--library_type=microlib")
466+
self.flags['c'].append("-Wl,--library_type=microlib")
393467
if "-Wl,--library_type=microlib" not in self.flags['cxx']:
394-
self.flags['cxx'].append("-Wl,--library_type=microlib")
468+
self.flags['cxx'].append("-Wl,--library_type=microlib")
395469
if "--library_type=microlib" not in self.flags['asm']:
396-
self.flags['asm'].append("--library_type=microlib")
470+
self.flags['asm'].append("--library_type=microlib")
397471

398472
core = target.core
399473
if CORE_ARCH[target.core] == 8:
400-
if (not target.core.endswith("-NS")) and kwargs.get('build_dir', False):
474+
if ((not target.core.endswith("-NS")) and
475+
kwargs.get('build_dir', False)):
401476
# Create Secure library
402477
build_dir = kwargs['build_dir']
403478
secure_file = join(build_dir, "cmse_lib.o")
@@ -464,8 +539,10 @@ def __init__(self, target, *args, **kwargs):
464539
self.flags['common'] + self.flags['c'])
465540
self.cppc = ([join(TOOLCHAIN_PATHS["ARMC6"], "armclang")] +
466541
self.flags['common'] + self.flags['cxx'])
467-
self.asm = [join(TOOLCHAIN_PATHS["ARMC6"], "armasm")] + self.flags['asm']
468-
self.ld = [join(TOOLCHAIN_PATHS["ARMC6"], "armlink")] + self.flags['ld']
542+
self.asm = [join(TOOLCHAIN_PATHS["ARMC6"], "armasm")]
543+
self.asm += self.flags['asm']
544+
self.ld = [join(TOOLCHAIN_PATHS["ARMC6"], "armlink")]
545+
self.ld += self.flags['ld']
469546
self.ar = join(TOOLCHAIN_PATHS["ARMC6"], "armar")
470547
self.elf2bin = join(TOOLCHAIN_PATHS["ARMC6"], "fromelf")
471548

@@ -499,8 +576,10 @@ def get_compile_options(self, defines, includes, for_asm=False):
499576
if config_header:
500577
opts.extend(self.get_config_option(config_header))
501578
if for_asm:
502-
return ["--cpreproc",
503-
"--cpreproc_opts=%s" % ",".join(self.flags['common'] + opts)]
579+
return [
580+
"--cpreproc",
581+
"--cpreproc_opts=%s" % ",".join(self.flags['common'] + opts)
582+
]
504583
return opts
505584

506585
def assemble(self, source, object, includes):

0 commit comments

Comments
 (0)