diff --git a/tools/toolchains/gcc.py b/tools/toolchains/gcc.py index d05a2ea297..22c0e3c72c 100644 --- a/tools/toolchains/gcc.py +++ b/tools/toolchains/gcc.py @@ -22,7 +22,8 @@ from distutils.version import LooseVersion from tools.targets import CORE_ARCH from tools.toolchains.mbed_toolchain import mbedToolchain, TOOLCHAIN_PATHS -from tools.utils import run_cmd, NotSupportedException +from tools.utils import run_cmd + class GCC(mbedToolchain): OFFICIALLY_SUPPORTED = True @@ -37,15 +38,21 @@ class GCC(mbedToolchain): def __init__(self, target, notify=None, macros=None, build_profile=None, build_dir=None): - mbedToolchain.__init__(self, target, notify, macros, - build_profile=build_profile, build_dir=build_dir) + mbedToolchain.__init__( + self, + target, + notify, + macros, + build_profile=build_profile, + build_dir=build_dir + ) - tool_path=TOOLCHAIN_PATHS['GCC_ARM'] + tool_path = TOOLCHAIN_PATHS['GCC_ARM'] # Add flags for current size setting default_lib = "std" if hasattr(target, "default_lib"): default_lib = target.default_lib - elif hasattr(target, "default_build"): # Legacy + elif hasattr(target, "default_build"): default_lib = target.default_build if default_lib == "small": @@ -109,8 +116,8 @@ class GCC(mbedToolchain): main_cc = join(tool_path, "arm-none-eabi-gcc") main_cppc = join(tool_path, "arm-none-eabi-g++") self.asm = [main_cc] + self.flags['asm'] + self.flags["common"] - self.cc = [main_cc] - self.cppc =[main_cppc] + self.cc = [main_cc] + self.cppc = [main_cppc] self.cc += self.flags['c'] + self.flags['common'] self.cppc += self.flags['cxx'] + self.flags['common'] @@ -129,9 +136,13 @@ class GCC(mbedToolchain): stdout, _, retcode = run_cmd([self.cc[0], "--version"], redirect=True) msg = None match = self.GCC_VERSION_RE.search(stdout.encode("utf-8")) - found_version = LooseVersion(match.group(0).decode('utf-8')) if match else None + if match: + found_version = LooseVersion(match.group(0).decode('utf-8')) + else: + found_version = None min_ver, max_ver = self.GCC_RANGE - if found_version and (found_version < min_ver or found_version >= max_ver): + if found_version and (found_version < min_ver + or found_version >= max_ver): msg = ("Compiler version mismatch: Have {}; " "expected version >= {} and < {}" .format(found_version, min_ver, max_ver)) @@ -196,7 +207,9 @@ class GCC(mbedToolchain): def assemble(self, source, object, includes): # Build assemble command - cmd = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-o", object, source] + cmd = self.asm + self.get_compile_options( + self.get_symbols(True), includes + ) + ["-o", object, source] # Return command array, don't execute return [cmd] @@ -230,15 +243,23 @@ class GCC(mbedToolchain): # Preprocess if mem_map: preproc_output = join(dirname(output), ".link_script.ld") - cmd = (self.preproc + [mem_map] + self.ld[1:] + - [ "-o", preproc_output]) + cmd = ( + self.preproc + [mem_map] + self.ld[1:] + ["-o", preproc_output] + ) self.notify.cc_verbose("Preproc: %s" % ' '.join(cmd)) self.default_cmd(cmd) mem_map = preproc_output # Build linker command map_file = splitext(output)[0] + ".map" - cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"] + cmd = ( + self.ld + + ["-o", output, "-Wl,-Map=%s" % map_file] + + objects + + ["-Wl,--start-group"] + + libs + + ["-Wl,--end-group"] + ) if mem_map: cmd.extend(['-T', mem_map]) @@ -291,9 +312,12 @@ class GCC(mbedToolchain): @staticmethod def check_executable(): """Returns True if the executable (arm-none-eabi-gcc) location - specified by the user exists OR the executable can be found on the PATH. - Returns False otherwise.""" - if not TOOLCHAIN_PATHS['GCC_ARM'] or not exists(TOOLCHAIN_PATHS['GCC_ARM']): + specified by the user exists OR the executable can be found on the + PATH. Returns False otherwise.""" + if ( + not TOOLCHAIN_PATHS['GCC_ARM'] or + not exists(TOOLCHAIN_PATHS['GCC_ARM']) + ): if find_executable('arm-none-eabi-gcc'): TOOLCHAIN_PATHS['GCC_ARM'] = '' return True @@ -303,5 +327,6 @@ class GCC(mbedToolchain): exec_name = join(TOOLCHAIN_PATHS['GCC_ARM'], 'arm-none-eabi-gcc') return exists(exec_name) or exists(exec_name + '.exe') + class GCC_ARM(GCC): pass