Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PATH env variable when gcc found in PATH #3895

Merged
merged 2 commits into from Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions tools/test/toolchains/api.py
Expand Up @@ -4,15 +4,15 @@
from string import printable
from copy import deepcopy
from mock import MagicMock, patch
from hypothesis import given
from hypothesis.strategies import text, lists, fixed_dictionaries
from hypothesis import given, settings
from hypothesis.strategies import text, lists, fixed_dictionaries, booleans

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

from tools.toolchains import TOOLCHAIN_CLASSES, LEGACY_TOOLCHAIN_NAMES,\
Resources
Resources, TOOLCHAIN_PATHS
from tools.targets import TARGET_MAP

def test_instantiation():
Expand Down Expand Up @@ -125,3 +125,21 @@ def test_detect_duplicates(filenames):
assert "dupe.s" in notification["message"]
assert "dupe.c" in notification["message"]
assert "dupe.cpp" in notification["message"]

@given(text(alphabet=ALPHABET + ["/"], min_size=1))
@given(booleans())
@given(booleans())
@settings(max_examples=20)
def test_path_specified_gcc(gcc_loc, exists_at_loc, exists_in_path):
with patch('tools.toolchains.gcc.exists') as _exists:
with patch('tools.toolchains.gcc.find_executable') as _find:
_exists.return_value = exists_at_loc
_find.return_value = exists_in_path
TOOLCHAIN_PATHS['GCC_ARM'] = gcc_loc
toolchain_class = TOOLCHAIN_CLASSES["GCC_ARM"]
found_p = toolchain_class.check_executable()
assert found_p == (exists_at_loc or exists_in_path)
if exists_at_loc:
assert TOOLCHAIN_PATHS['GCC_ARM'] == gcc_loc
elif exists_in_path:
assert TOOLCHAIN_PATHS['GCC_ARM'] == ''
13 changes: 11 additions & 2 deletions tools/toolchains/gcc.py
Expand Up @@ -15,7 +15,8 @@
limitations under the License.
"""
import re
from os.path import join, basename, splitext, dirname
from os.path import join, basename, splitext, dirname, exists
from distutils.spawn import find_executable

from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
from tools.hooks import hook_tool
Expand Down Expand Up @@ -285,7 +286,15 @@ def check_executable():
"""Returns True if the executable (arm-none-eabi-gcc) location
specified by the user exists OR the executable can be found on the PATH.
Returns False otherwise."""
return mbedToolchain.generic_check_executable("GCC_ARM", 'arm-none-eabi-gcc', 1)
if not TOOLCHAIN_PATHS['GCC_ARM'] or not exists(TOOLCHAIN_PATHS['GCC_ARM']):
if find_executable('arm-none-eabi-gcc'):
TOOLCHAIN_PATHS['GCC_ARM'] = ''
return True
else:
return False
else:
exec_name = join(TOOLCHAIN_PATHS['GCC_ARM'], 'arm-none-eabi-gcc')
return exists(exec_name) or exists(exec_name + '.exe')

class GCC_ARM(GCC):
pass