Skip to content

Commit 1445886

Browse files
committed
Readable error when toolchain paths not set.
Fixes #2360. New error: [Error] Toolchain path does not exist for IAR. Current value: /default/path/that/doesnt/exist (System exit before any build system calls)
1 parent 52658e5 commit 1445886

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

tools/toolchains/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
print('[ERROR] Toolchain path does not exist for %s.\n'
202+
'Current value: %s' % (self.name, self.toolchain_path))
203+
sys.exit()
204+
return function(self, *args, **kwargs)
205+
return perform_check
206+
207+
191208
class 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'

tools/toolchains/arm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
8181
self.ar = join(ARM_BIN, "armar")
8282
self.elf2bin = join(ARM_BIN, "fromelf")
8383

84+
self.toolchain_path = TOOLCHAIN_PATHS['ARM']
85+
8486
def parse_dependencies(self, dep_path):
8587
dependencies = []
8688
for line in open(dep_path).readlines():

tools/toolchains/gcc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
110110
self.ar = join(tool_path, "arm-none-eabi-ar")
111111
self.elf2bin = join(tool_path, "arm-none-eabi-objcopy")
112112

113+
self.toolchain_path = tool_path
114+
113115
def parse_dependencies(self, dep_path):
114116
dependencies = []
115117
buff = open(dep_path).readlines()

tools/toolchains/iar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
101101
self.ar = join(IAR_BIN, "iarchive")
102102
self.elf2bin = join(IAR_BIN, "ielftool")
103103

104+
self.toolchain_path = TOOLCHAIN_PATHS['IAR']
105+
104106
def parse_dependencies(self, dep_path):
105107
return [(self.CHROOT if self.CHROOT else '')+path.strip() for path in open(dep_path).readlines()
106108
if (path and not path.isspace())]

0 commit comments

Comments
 (0)