Skip to content

Commit 61dee45

Browse files
committed
Revise checking toolchain path
1 parent e9d0fbd commit 61dee45

File tree

7 files changed

+64
-45
lines changed

7 files changed

+64
-45
lines changed

tools/build.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
sys.path.insert(0, ROOT)
2828

2929

30-
from tools.toolchains import TOOLCHAINS
30+
from tools.toolchains import TOOLCHAINS, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
3131
from tools.toolchains import mbedToolchain
3232
from tools.targets import TARGET_NAMES, TARGET_MAP
3333
from tools.options import get_default_options_parser
@@ -161,6 +161,7 @@
161161
print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
162162
exit(0)
163163

164+
164165
# Get target list
165166
targets = options.mcu if options.mcu else TARGET_NAMES
166167

@@ -212,6 +213,12 @@
212213
# CPPCHECK code validation
213214
if options.cppcheck_validation:
214215
for toolchain in toolchains:
216+
if not TOOLCHAIN_CLASSES[toolchain].check_executable():
217+
if TOOLCHAIN_PATHS[toolchain] == '':
218+
TOOLCHAIN_PATHS[toolchain] = "No path set"
219+
args_error(parser, "Could not find executable for %s.\n"
220+
"Currently set search path: %s"
221+
% (toolchain, TOOLCHAIN_PATHS[toolchain]))
215222
for target in targets:
216223
try:
217224
mcu = TARGET_MAP[target]

tools/make.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import sys
2222
from time import sleep
2323
from shutil import copy
24-
from os.path import join, abspath, dirname, isfile, isdir
24+
from os.path import join, abspath, dirname, exists
25+
from distutils.spawn import find_executable
2526

2627
# Be sure that the tools directory is in the search path
2728
ROOT = abspath(join(dirname(__file__), ".."))
@@ -46,8 +47,7 @@
4647
from utils import argparse_filestring_type
4748
from utils import argparse_many
4849
from utils import argparse_dir_not_parent
49-
from argparse import ArgumentTypeError
50-
from tools.toolchains import mbedToolchain
50+
from tools.toolchains import mbedToolchain, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
5151
from tools.settings import CLI_COLOR_MAP
5252

5353
if __name__ == '__main__':
@@ -232,6 +232,13 @@
232232
else:
233233
notify = None
234234

235+
if not TOOLCHAIN_CLASSES[toolchain].check_executable():
236+
if TOOLCHAIN_PATHS[toolchain] == '':
237+
TOOLCHAIN_PATHS[toolchain] = "No path set"
238+
args_error(parser, "Could not find executable for %s.\n"
239+
"Currently set search path: %s"
240+
%(toolchain,TOOLCHAIN_PATHS[toolchain]))
241+
235242
# Test
236243
for test_no in p:
237244
test = Test(test_no)

tools/test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from tools.test_exporters import ReportExporter, ResultExporterType
3636
from utils import argparse_filestring_type, argparse_lowercase_type, argparse_many
3737
from utils import argparse_dir_not_parent
38-
from tools.toolchains import mbedToolchain
38+
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS, TOOLCHAIN_CLASSES
3939
from tools.settings import CLI_COLOR_MAP
4040

4141
if __name__ == '__main__':
@@ -115,6 +115,13 @@
115115
args_error(parser, "argument -t/--tool is required")
116116
toolchain = options.tool[0]
117117

118+
if not TOOLCHAIN_CLASSES[toolchain].check_executable():
119+
if TOOLCHAIN_PATHS[toolchain] == '':
120+
TOOLCHAIN_PATHS[toolchain] = "No path set"
121+
args_error(parser, "Could not find executable for %s.\n"
122+
"Currently set search path: %s"
123+
% (toolchain, TOOLCHAIN_PATHS[toolchain]))
124+
118125
# Find all tests in the relevant paths
119126
for path in all_paths:
120127
all_tests.update(find_tests(path, mcu, toolchain, options.options,
@@ -196,6 +203,7 @@
196203
print "Failed to build library"
197204
else:
198205
# Build all the tests
206+
199207
test_build_success, test_build = build_tests(tests, [options.build_dir], options.build_dir, mcu, toolchain,
200208
options=options.options,
201209
clean=options.clean,

tools/toolchains/__init__.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -188,23 +188,6 @@ 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) and not exists(self.toolchain_path+'.exe'):
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-
208191
class mbedToolchain:
209192
# Verbose logging
210193
VERBOSE = True
@@ -720,7 +703,6 @@ def get_arch_file(self, objects):
720703

721704
# THIS METHOD IS BEING CALLED BY THE MBED ONLINE BUILD SYSTEM
722705
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
723-
@check_toolchain_path
724706
def compile_sources(self, resources, build_path, inc_dirs=None):
725707
# Web IDE progress bar for project build
726708
files_to_compile = resources.s_sources + resources.c_sources + resources.cpp_sources
@@ -919,7 +901,6 @@ def compile_output(self, output=[]):
919901
else:
920902
raise ToolException(_stderr)
921903

922-
@check_toolchain_path
923904
def build_library(self, objects, dir, name):
924905
needed_update = False
925906
lib = self.STD_LIB_NAME % name
@@ -931,7 +912,6 @@ def build_library(self, objects, dir, name):
931912

932913
return needed_update
933914

934-
@check_toolchain_path
935915
def link_program(self, r, tmp_path, name):
936916
needed_update = False
937917
ext = 'bin'

tools/toolchains/arm.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
limitations under the License.
1616
"""
1717
import re
18-
from os.path import join, dirname, splitext, basename
18+
from os.path import join, dirname, splitext, basename, exists
1919
from distutils.spawn import find_executable
2020

2121
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
@@ -42,6 +42,15 @@ class ARM(mbedToolchain):
4242
'ld': [],
4343
}
4444

45+
@staticmethod
46+
def check_executable():
47+
if not TOOLCHAIN_PATHS["ARM"] or not exists(TOOLCHAIN_PATHS['ARM']):
48+
exe = find_executable('armcc')
49+
if not exe:
50+
return False
51+
TOOLCHAIN_PATHS['ARM'] = dirname(dirname(exe))
52+
return True
53+
4554
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
4655
mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
4756

@@ -56,11 +65,6 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
5665
else:
5766
cpu = target.core
5867

59-
if not TOOLCHAIN_PATHS['ARM']:
60-
exe = find_executable('armcc')
61-
if exe:
62-
TOOLCHAIN_PATHS['ARM'] = dirname(dirname(exe))
63-
6468
ARM_BIN = join(TOOLCHAIN_PATHS['ARM'], "bin")
6569
ARM_INC = join(TOOLCHAIN_PATHS['ARM'], "include")
6670

@@ -86,8 +90,6 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
8690
self.ar = join(ARM_BIN, "armar")
8791
self.elf2bin = join(ARM_BIN, "fromelf")
8892

89-
self.toolchain_path = TOOLCHAIN_PATHS['ARM']
90-
9193
def parse_dependencies(self, dep_path):
9294
dependencies = []
9395
for line in open(dep_path).readlines():

tools/toolchains/gcc.py

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

114-
if tool_path:
115-
self.toolchain_path = main_cc
116-
else:
117-
self.toolchain_path = find_executable("arm-none-eabi-gcc") or ''
118-
119114
def parse_dependencies(self, dep_path):
120115
dependencies = []
121116
buff = open(dep_path).readlines()
@@ -275,6 +270,15 @@ def binary(self, resources, elf, bin):
275270

276271

277272
class GCC_ARM(GCC):
273+
@staticmethod
274+
def check_executable():
275+
if not TOOLCHAIN_PATHS["GCC_ARM"] or not exists(TOOLCHAIN_PATHS['GCC_ARM']):
276+
exe = find_executable('arm-none-eabi-gcc')
277+
if not exe:
278+
return False
279+
TOOLCHAIN_PATHS['GCC_ARM'] = dirname(exe)
280+
return True
281+
278282
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
279283
GCC.__init__(self, target, options, notify, macros, silent, TOOLCHAIN_PATHS['GCC_ARM'], extra_verbose=extra_verbose)
280284

@@ -300,6 +304,15 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
300304

301305

302306
class GCC_CR(GCC):
307+
@staticmethod
308+
def check_executable():
309+
if not TOOLCHAIN_PATHS["GCC_CR"] or not exists(TOOLCHAIN_PATHS['GCC_CR']):
310+
exe = find_executable('arm-none-eabi-gcc')
311+
if not exe:
312+
return False
313+
TOOLCHAIN_PATHS['GCC_CR'] = dirname(exe)
314+
return True
315+
303316
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
304317
GCC.__init__(self, target, options, notify, macros, silent, TOOLCHAIN_PATHS['GCC_CR'], extra_verbose=extra_verbose)
305318

tools/toolchains/iar.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,22 @@ class IAR(mbedToolchain):
4545
'ld': ["--skip_dynamic_initialization", "--threaded_lib"],
4646
}
4747

48+
@staticmethod
49+
def check_executable():
50+
if not TOOLCHAIN_PATHS["IAR"] or not exists(TOOLCHAIN_PATHS['IAR']):
51+
exe = find_executable('iccarm')
52+
if not exe:
53+
return False
54+
TOOLCHAIN_PATHS['IAR'] = dirname(dirname(exe))
55+
return True
56+
4857
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
4958
mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
5059
if target.core == "Cortex-M7F" or target.core == "Cortex-M7FD":
5160
cpuchoice = "Cortex-M7"
5261
else:
5362
cpuchoice = target.core
5463

55-
if not TOOLCHAIN_PATHS['IAR']:
56-
exe = find_executable('iccarm')
57-
if exe:
58-
TOOLCHAIN_PATHS['IAR'] = dirname(dirname(exe))
59-
6064
# flags_cmd are used only by our scripts, the project files have them already defined,
6165
# using this flags results in the errors (duplication)
6266
# asm accepts --cpu Core or --fpu FPU, not like c/c++ --cpu=Core
@@ -108,8 +112,6 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
108112
self.ar = join(IAR_BIN, "iarchive")
109113
self.elf2bin = join(IAR_BIN, "ielftool")
110114

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

0 commit comments

Comments
 (0)