Skip to content

Commit ea3526d

Browse files
authored
Merge pull request #2418 from sarahmarshy/path_error_rev
Readable error when toolchain paths not set. Allow IAR and ARM toolchains to be set in user's PATH.
2 parents 39127f8 + cd229ba commit ea3526d

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
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+
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+
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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
limitations under the License.
1616
"""
1717
import re
18-
from os.path import join, dirname, splitext, basename, exists
18+
from os.path import join, dirname, splitext, basename
19+
from distutils.spawn import find_executable
1920

2021
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2122
from tools.hooks import hook_tool
2223
from tools.utils import mkdir
23-
import copy
2424

2525
class ARM(mbedToolchain):
2626
LINKER_EXT = '.sct'
@@ -56,6 +56,11 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
5656
else:
5757
cpu = target.core
5858

59+
if not TOOLCHAIN_PATHS['ARM']:
60+
exe = find_executable('armcc')
61+
if exe:
62+
TOOLCHAIN_PATHS['ARM'] = dirname(dirname(exe))
63+
5964
ARM_BIN = join(TOOLCHAIN_PATHS['ARM'], "bin")
6065
ARM_INC = join(TOOLCHAIN_PATHS['ARM'], "include")
6166

@@ -81,6 +86,8 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
8186
self.ar = join(ARM_BIN, "armar")
8287
self.elf2bin = join(ARM_BIN, "fromelf")
8388

89+
self.toolchain_path = TOOLCHAIN_PATHS['ARM']
90+
8491
def parse_dependencies(self, dep_path):
8592
dependencies = []
8693
for line in open(dep_path).readlines():

tools/toolchains/gcc.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""
1717
import re
1818
from os.path import join, basename, splitext, dirname, exists
19+
from distutils.spawn import find_executable
1920

2021
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2122
from tools.hooks import hook_tool
@@ -110,6 +111,11 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
110111
self.ar = join(tool_path, "arm-none-eabi-ar")
111112
self.elf2bin = join(tool_path, "arm-none-eabi-objcopy")
112113

114+
if tool_path:
115+
self.toolchain_path = main_cc
116+
else:
117+
self.toolchain_path = find_executable("arm-none-eabi-gcc") or ''
118+
113119
def parse_dependencies(self, dep_path):
114120
dependencies = []
115121
buff = open(dep_path).readlines()

tools/toolchains/iar.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import re
1818
from os import remove
1919
from os.path import join, exists, dirname, splitext, exists
20+
from distutils.spawn import find_executable
2021

2122
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2223
from tools.hooks import hook_tool
@@ -50,6 +51,12 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
5051
cpuchoice = "Cortex-M7"
5152
else:
5253
cpuchoice = target.core
54+
55+
if not TOOLCHAIN_PATHS['IAR']:
56+
exe = find_executable('iccarm')
57+
if exe:
58+
TOOLCHAIN_PATHS['IAR'] = dirname(dirname(exe))
59+
5360
# flags_cmd are used only by our scripts, the project files have them already defined,
5461
# using this flags results in the errors (duplication)
5562
# 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,
101108
self.ar = join(IAR_BIN, "iarchive")
102109
self.elf2bin = join(IAR_BIN, "ielftool")
103110

111+
self.toolchain_path = TOOLCHAIN_PATHS['IAR']
112+
104113
def parse_dependencies(self, dep_path):
105114
return [(self.CHROOT if self.CHROOT else '')+path.strip() for path in open(dep_path).readlines()
106115
if (path and not path.isspace())]

0 commit comments

Comments
 (0)