@@ -188,6 +188,23 @@ def __str__(self):
188188}
189189
190190
191+ def check_toolchain_path (function ):
192+ """Check if the path to toolchain is valid. Exit if not.
193+ Use this function as a decorator. Causes a system exit if the path does
194+ not exist. Execute the function as normal if the path does exist.
195+
196+ Positional arguments:
197+ function -- the function to decorate
198+ """
199+ def perform_check (self , * args , ** kwargs ):
200+ if not exists (self .toolchain_path ):
201+ error_string = 'Could not find executable for %s.\n Currently ' \
202+ 'set search path: %s' % (self .name , self .toolchain_path )
203+ raise Exception (error_string )
204+ return function (self , * args , ** kwargs )
205+ return perform_check
206+
207+
191208class mbedToolchain :
192209 # Verbose logging
193210 VERBOSE = True
@@ -702,6 +719,7 @@ def get_arch_file(self, objects):
702719
703720 # THIS METHOD IS BEING CALLED BY THE MBED ONLINE BUILD SYSTEM
704721 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
722+ @check_toolchain_path
705723 def compile_sources (self , resources , build_path , inc_dirs = None ):
706724 # Web IDE progress bar for project build
707725 files_to_compile = resources .s_sources + resources .c_sources + resources .cpp_sources
@@ -900,6 +918,7 @@ def compile_output(self, output=[]):
900918 else :
901919 raise ToolException (_stderr )
902920
921+ @check_toolchain_path
903922 def build_library (self , objects , dir , name ):
904923 needed_update = False
905924 lib = self .STD_LIB_NAME % name
@@ -911,6 +930,7 @@ def build_library(self, objects, dir, name):
911930
912931 return needed_update
913932
933+ @check_toolchain_path
914934 def link_program (self , r , tmp_path , name ):
915935 needed_update = False
916936 ext = 'bin'
0 commit comments