Skip to content

Commit ab92a5a

Browse files
committed
Toolchain check generic in mbedToolchain
1 parent 8b74c5b commit ab92a5a

File tree

5 files changed

+47
-32
lines changed

5 files changed

+47
-32
lines changed

tools/make.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
import sys
2222
from time import sleep
2323
from shutil import copy
24-
from os.path import join, abspath, dirname, exists
25-
from distutils.spawn import find_executable
24+
from os.path import join, abspath, dirname
2625

2726
# Be sure that the tools directory is in the search path
2827
ROOT = abspath(join(dirname(__file__), ".."))

tools/toolchains/__init__.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from copy import deepcopy
2828
from tools.config import Config
2929
from abc import ABCMeta, abstractmethod
30+
from distutils.spawn import find_executable
3031

3132
from multiprocessing import Pool, cpu_count
3233
from tools.utils import run_cmd, mkdir, rel_path, ToolException, NotSupportedException, split_path, compile_worker
@@ -1091,6 +1092,44 @@ def get_config_header(self):
10911092
self.config_processed = True
10921093
return self.config_file
10931094

1095+
@staticmethod
1096+
def generic_check_executable(tool_key, executable_name, levels_up,
1097+
nested_dir=None):
1098+
"""
1099+
Positional args:
1100+
tool_key: the key to index TOOLCHAIN_PATHS
1101+
executable_name: the toolchain's named executable (ex. armcc)
1102+
levels_up: each toolchain joins the toolchain_path, some
1103+
variable directories (bin, include), and the executable name,
1104+
so the TOOLCHAIN_PATH value must be appropriately distanced
1105+
1106+
Keyword args:
1107+
nested_dir: the directory within TOOLCHAIN_PATHS where the executable
1108+
is found (ex: 'bin' for ARM\bin\armcc (necessary to check for path
1109+
that will be used by toolchain's compile)
1110+
1111+
Returns True if the executable location specified by the user
1112+
exists and is valid OR the executable can be found on the PATH.
1113+
Returns False otherwise.
1114+
"""
1115+
# Search PATH if user did not specify a path or specified path doesn't
1116+
# exist.
1117+
if not TOOLCHAIN_PATHS[tool_key] or not exists(TOOLCHAIN_PATHS[tool_key]):
1118+
exe = find_executable(executable_name)
1119+
if not exe:
1120+
return False
1121+
for level in range(levels_up):
1122+
# move up the specified number of directories
1123+
exe = dirname(exe)
1124+
TOOLCHAIN_PATHS[tool_key] = exe
1125+
if nested_dir:
1126+
subdir = join(TOOLCHAIN_PATHS[tool_key], nested_dir,
1127+
executable_name)
1128+
else:
1129+
subdir = join(TOOLCHAIN_PATHS[tool_key],executable_name)
1130+
# User could have specified a path that exists but does not contain exe
1131+
return exists(subdir) or exists(subdir +'.exe')
1132+
10941133
@abstractmethod
10951134
def get_config_option(self, config_header):
10961135
"""Generate the compiler option that forces the inclusion of the configuration

tools/toolchains/arm.py

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

2120
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2221
from tools.hooks import hook_tool
@@ -47,12 +46,7 @@ def check_executable():
4746
"""Returns True if the executable (armcc) location specified by the
4847
user exists OR the executable can be found on the PATH.
4948
Returns False otherwise."""
50-
if not TOOLCHAIN_PATHS["ARM"] or not exists(TOOLCHAIN_PATHS['ARM']):
51-
exe = find_executable('armcc')
52-
if not exe:
53-
return False
54-
TOOLCHAIN_PATHS['ARM'] = dirname(dirname(exe))
55-
return True
49+
return mbedToolchain.generic_check_executable("ARM", 'armcc', 2, 'bin')
5650

5751
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
5852
mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)

tools/toolchains/gcc.py

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

2120
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2221
from tools.hooks import hook_tool
@@ -275,12 +274,7 @@ def check_executable():
275274
"""Returns True if the executable (arm-none-eabi-gcc) location
276275
specified by the user exists OR the executable can be found on the PATH.
277276
Returns False otherwise."""
278-
if not TOOLCHAIN_PATHS["GCC_ARM"] or not exists(TOOLCHAIN_PATHS['GCC_ARM']):
279-
exe = find_executable('arm-none-eabi-gcc')
280-
if not exe:
281-
return False
282-
TOOLCHAIN_PATHS['GCC_ARM'] = dirname(exe)
283-
return True
277+
return mbedToolchain.generic_check_executable("GCC_ARM", 'arm-none-eabi-gcc', 1)
284278

285279
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
286280
GCC.__init__(self, target, options, notify, macros, silent, TOOLCHAIN_PATHS['GCC_ARM'], extra_verbose=extra_verbose)
@@ -312,12 +306,7 @@ def check_executable():
312306
"""Returns True if the executable (arm-none-eabi-gcc) location
313307
specified by the user exists OR the executable can be found on the PATH.
314308
Returns False otherwise."""
315-
if not TOOLCHAIN_PATHS["GCC_CR"] or not exists(TOOLCHAIN_PATHS['GCC_CR']):
316-
exe = find_executable('arm-none-eabi-gcc')
317-
if not exe:
318-
return False
319-
TOOLCHAIN_PATHS['GCC_CR'] = dirname(exe)
320-
return True
309+
return mbedToolchain.generic_check_executable("GCC_CR", 'arm-none-eabi-gcc', 1)
321310

322311
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
323312
GCC.__init__(self, target, options, notify, macros, silent, TOOLCHAIN_PATHS['GCC_CR'], extra_verbose=extra_verbose)

tools/toolchains/iar.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"""
1717
import re
1818
from os import remove
19-
from os.path import join, exists, dirname, splitext, exists
20-
from distutils.spawn import find_executable
19+
from os.path import join, splitext
2120

2221
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2322
from tools.hooks import hook_tool
@@ -50,12 +49,7 @@ def check_executable():
5049
"""Returns True if the executable (arm-none-eabi-gcc) location
5150
specified by the user exists OR the executable can be found on the PATH.
5251
Returns False otherwise."""
53-
if not TOOLCHAIN_PATHS["IAR"] or not exists(TOOLCHAIN_PATHS['IAR']):
54-
exe = find_executable('iccarm')
55-
if not exe:
56-
return False
57-
TOOLCHAIN_PATHS['IAR'] = dirname(dirname(exe))
58-
return True
52+
return mbedToolchain.generic_check_executable("IAR", 'iccarm', 2, "bin")
5953

6054
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
6155
mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)

0 commit comments

Comments
 (0)