Skip to content

Commit ae10ca8

Browse files
authored
Merge pull request #3895 from theotherjimmy/find-exec-in-path
Use PATH env variable when gcc found in PATH
2 parents 213626d + 4408c01 commit ae10ca8

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

tools/test/toolchains/api.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
from string import printable
55
from copy import deepcopy
66
from mock import MagicMock, patch
7-
from hypothesis import given
8-
from hypothesis.strategies import text, lists, fixed_dictionaries
7+
from hypothesis import given, settings
8+
from hypothesis.strategies import text, lists, fixed_dictionaries, booleans
99

1010
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..",
1111
".."))
1212
sys.path.insert(0, ROOT)
1313

1414
from tools.toolchains import TOOLCHAIN_CLASSES, LEGACY_TOOLCHAIN_NAMES,\
15-
Resources
15+
Resources, TOOLCHAIN_PATHS
1616
from tools.targets import TARGET_MAP
1717

1818
def test_instantiation():
@@ -125,3 +125,21 @@ def test_detect_duplicates(filenames):
125125
assert "dupe.s" in notification["message"]
126126
assert "dupe.c" in notification["message"]
127127
assert "dupe.cpp" in notification["message"]
128+
129+
@given(text(alphabet=ALPHABET + ["/"], min_size=1))
130+
@given(booleans())
131+
@given(booleans())
132+
@settings(max_examples=20)
133+
def test_path_specified_gcc(gcc_loc, exists_at_loc, exists_in_path):
134+
with patch('tools.toolchains.gcc.exists') as _exists:
135+
with patch('tools.toolchains.gcc.find_executable') as _find:
136+
_exists.return_value = exists_at_loc
137+
_find.return_value = exists_in_path
138+
TOOLCHAIN_PATHS['GCC_ARM'] = gcc_loc
139+
toolchain_class = TOOLCHAIN_CLASSES["GCC_ARM"]
140+
found_p = toolchain_class.check_executable()
141+
assert found_p == (exists_at_loc or exists_in_path)
142+
if exists_at_loc:
143+
assert TOOLCHAIN_PATHS['GCC_ARM'] == gcc_loc
144+
elif exists_in_path:
145+
assert TOOLCHAIN_PATHS['GCC_ARM'] == ''

tools/toolchains/gcc.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
limitations under the License.
1616
"""
1717
import re
18-
from os.path import join, basename, splitext, dirname
18+
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
@@ -286,7 +287,15 @@ def check_executable():
286287
"""Returns True if the executable (arm-none-eabi-gcc) location
287288
specified by the user exists OR the executable can be found on the PATH.
288289
Returns False otherwise."""
289-
return mbedToolchain.generic_check_executable("GCC_ARM", 'arm-none-eabi-gcc', 1)
290+
if not TOOLCHAIN_PATHS['GCC_ARM'] or not exists(TOOLCHAIN_PATHS['GCC_ARM']):
291+
if find_executable('arm-none-eabi-gcc'):
292+
TOOLCHAIN_PATHS['GCC_ARM'] = ''
293+
return True
294+
else:
295+
return False
296+
else:
297+
exec_name = join(TOOLCHAIN_PATHS['GCC_ARM'], 'arm-none-eabi-gcc')
298+
return exists(exec_name) or exists(exec_name + '.exe')
290299

291300
class GCC_ARM(GCC):
292301
pass

0 commit comments

Comments
 (0)