diff --git a/tools/toolchains/__init__.py b/tools/toolchains/__init__.py index 6dd9d31c3c8..512c3476e44 100644 --- a/tools/toolchains/__init__.py +++ b/tools/toolchains/__init__.py @@ -188,6 +188,23 @@ def __str__(self): } +def check_toolchain_path(function): + """Check if the path to toolchain is valid. Exit if not. + Use this function as a decorator. Causes a system exit if the path does + not exist. Execute the function as normal if the path does exist. + + Positional arguments: + function -- the function to decorate + """ + def perform_check(self, *args, **kwargs): + if not exists(self.toolchain_path): + error_string = 'Could not find executable for %s.\n Currently ' \ + 'set search path: %s'% (self.name, self.toolchain_path) + raise Exception(error_string) + return function(self, *args, **kwargs) + return perform_check + + class mbedToolchain: # Verbose logging VERBOSE = True @@ -702,6 +719,7 @@ def get_arch_file(self, objects): # THIS METHOD IS BEING CALLED BY THE MBED ONLINE BUILD SYSTEM # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY + @check_toolchain_path def compile_sources(self, resources, build_path, inc_dirs=None): # Web IDE progress bar for project build files_to_compile = resources.s_sources + resources.c_sources + resources.cpp_sources @@ -900,6 +918,7 @@ def compile_output(self, output=[]): else: raise ToolException(_stderr) + @check_toolchain_path def build_library(self, objects, dir, name): needed_update = False lib = self.STD_LIB_NAME % name @@ -911,6 +930,7 @@ def build_library(self, objects, dir, name): return needed_update + @check_toolchain_path def link_program(self, r, tmp_path, name): needed_update = False ext = 'bin' diff --git a/tools/toolchains/arm.py b/tools/toolchains/arm.py index cb55f731446..a7ecc848a49 100644 --- a/tools/toolchains/arm.py +++ b/tools/toolchains/arm.py @@ -15,12 +15,12 @@ limitations under the License. """ import re -from os.path import join, dirname, splitext, basename, exists +from os.path import join, dirname, splitext, basename +from distutils.spawn import find_executable from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS from tools.hooks import hook_tool from tools.utils import mkdir -import copy class ARM(mbedToolchain): LINKER_EXT = '.sct' @@ -56,6 +56,11 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False, else: cpu = target.core + if not TOOLCHAIN_PATHS['ARM']: + exe = find_executable('armcc') + if exe: + TOOLCHAIN_PATHS['ARM'] = dirname(dirname(exe)) + ARM_BIN = join(TOOLCHAIN_PATHS['ARM'], "bin") ARM_INC = join(TOOLCHAIN_PATHS['ARM'], "include") @@ -81,6 +86,8 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False, self.ar = join(ARM_BIN, "armar") self.elf2bin = join(ARM_BIN, "fromelf") + self.toolchain_path = TOOLCHAIN_PATHS['ARM'] + def parse_dependencies(self, dep_path): dependencies = [] for line in open(dep_path).readlines(): diff --git a/tools/toolchains/gcc.py b/tools/toolchains/gcc.py index b9c79a8abea..add6b7e0b93 100644 --- a/tools/toolchains/gcc.py +++ b/tools/toolchains/gcc.py @@ -16,6 +16,7 @@ """ import re from os.path import join, basename, splitext, dirname, exists +from distutils.spawn import find_executable from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS from tools.hooks import hook_tool @@ -110,6 +111,11 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False, self.ar = join(tool_path, "arm-none-eabi-ar") self.elf2bin = join(tool_path, "arm-none-eabi-objcopy") + if tool_path: + self.toolchain_path = main_cc + else: + self.toolchain_path = find_executable("arm-none-eabi-gcc") or '' + def parse_dependencies(self, dep_path): dependencies = [] buff = open(dep_path).readlines() diff --git a/tools/toolchains/iar.py b/tools/toolchains/iar.py index dac3b4852d2..ca41f845b26 100644 --- a/tools/toolchains/iar.py +++ b/tools/toolchains/iar.py @@ -17,6 +17,7 @@ import re from os import remove from os.path import join, exists, dirname, splitext, exists +from distutils.spawn import find_executable from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS from tools.hooks import hook_tool @@ -50,6 +51,12 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False, cpuchoice = "Cortex-M7" else: cpuchoice = target.core + + if not TOOLCHAIN_PATHS['IAR']: + exe = find_executable('iccarm') + if exe: + TOOLCHAIN_PATHS['IAR'] = dirname(dirname(exe)) + # flags_cmd are used only by our scripts, the project files have them already defined, # using this flags results in the errors (duplication) # asm accepts --cpu Core or --fpu FPU, not like c/c++ --cpu=Core @@ -101,6 +108,8 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False, self.ar = join(IAR_BIN, "iarchive") self.elf2bin = join(IAR_BIN, "ielftool") + self.toolchain_path = TOOLCHAIN_PATHS['IAR'] + def parse_dependencies(self, dep_path): return [(self.CHROOT if self.CHROOT else '')+path.strip() for path in open(dep_path).readlines() if (path and not path.isspace())]