Skip to content

Commit

Permalink
use full path of cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas committed Dec 15, 2017
1 parent df957b4 commit c9170fa
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 3 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
language: python
python:
- "2.7_with_system_site_packages"
- "3.3"
- "3.5"
sudo: false
# group: deprecated-2017Q4
# command to install dependencies
install:
# fetch "normal" debian python for 3.3
- if [ "$TRAVIS_PYTHON_VERSION" == "3.3" ]; then sudo add-apt-repository -y ppa:fkrull/deadsnakes && sudo apt-get -y update && sudo apt-get install python3.3 python3.3-dev && virtualenv -p /usr/bin/python3.3 ~/virtualenvs/3.3_debian && source ~/virtualenvs/3.3_debian/bin/activate; fi
# - if [ "$TRAVIS_PYTHON_VERSION" == "3.3" ]; then sudo add-apt-repository -y ppa:fkrull/deadsnakes && sudo apt-get -y update && sudo apt-get install python3.3 python3.3-dev && virtualenv -p /usr/bin/python3.3 ~/virtualenvs/3.3_debian && source ~/virtualenvs/3.3_debian/bin/activate; fi
- pip install argparse catkin-pkg empy mock nose
# command to run tests
script:
Expand Down
2 changes: 2 additions & 0 deletions test/unit_tests/test_environment_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_appends_windows(self):
self.assertEqual(['set foo=bar'], code)

def test_generate_environment_script(self):
old_environ = os.environ
try:
fake_environ = os.environ.copy()
fake_environ['FOO'] = '/bar'
Expand All @@ -80,5 +81,6 @@ def test_generate_environment_script(self):
self.assertTrue('export BAR="/bar"' in result, result)
self.assertEqual('#!/usr/bin/env sh', result[0])
finally:
os.environ = old_environ
catkin.environment_cache.os.environ = os.environ
shutil.rmtree(rootdir)
2 changes: 2 additions & 0 deletions test/unit_tests/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class WorkspaceTest(unittest.TestCase):

def test_get_workspaces(self):
old_environ = os.environ
try:
root_dir = tempfile.mkdtemp()
ws1 = os.path.join(root_dir, 'ws1')
Expand All @@ -38,6 +39,7 @@ def test_get_workspaces(self):
self.assertEqual([ws2, ws1], get_workspaces())
finally:
shutil.rmtree(root_dir)
os.environ = old_environ
catkin.workspace.os.environ = os.environ

def test_get_source_paths(self):
Expand Down
7 changes: 6 additions & 1 deletion test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import unittest
import tempfile

from test.which import which

CMAKE_EXECUTABLE = which('cmake')

# import platform
# ubuntudist = platform.dist()[2]

Expand Down Expand Up @@ -191,7 +195,8 @@ def cmake(self,

if not os.path.isdir(this_builddir):
os.makedirs(this_builddir)
cmd = ["cmake", this_srcdir] + args
assert CMAKE_EXECUTABLE is not None
cmd = [CMAKE_EXECUTABLE, this_srcdir] + args
o = expect(cmd, cwd=this_builddir)
if (expect == succeed):
self.assertTrue(os.path.isfile(this_builddir + "/CMakeCache.txt"))
Expand Down
79 changes: 79 additions & 0 deletions test/which.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import os
import sys

try:
from shutil import which as _which
except ImportError:
_which = None


def _which_backport(cmd, mode=os.F_OK | os.X_OK, path=None):
# Check that a given file can be accessed with the correct mode.
# Additionally check that `file` is not a directory, as on Windows
# directories pass the os.access check.
def _access_check(fn, mode):
return (os.path.exists(fn) and os.access(fn, mode) and
not os.path.isdir(fn))

# If we're given a path with a directory part, look it up directly rather
# than referring to PATH directories. This includes checking relative
# to the current directory, e.g. ./script
if os.path.dirname(cmd):
if _access_check(cmd, mode):
return cmd
return None

if path is None:
path = os.environ.get('PATH', os.defpath)
if not path:
return None
path = path.split(os.pathsep)

if sys.platform == 'win32':
# The current directory takes precedence on Windows.
if os.curdir not in path:
path.insert(0, os.curdir)

# PATHEXT is necessary to check on Windows.
pathext = os.environ.get('PATHEXT', '').split(os.pathsep)
# See if the given file matches any of the expected path extensions.
# This will allow us to short circuit when given "python.exe".
# If it does match, only test that one, otherwise we have to try
# others.
if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
files = [cmd]
else:
files = [cmd + ext for ext in pathext]
else:
# On other platforms you don't have things like PATHEXT to tell you
# what file suffixes are executable, so just pass on cmd as-is.
files = [cmd]

seen = set()
for directory in path:
normdir = os.path.normcase(directory)
if normdir not in seen:
seen.add(normdir)
for thefile in files:
name = os.path.join(directory, thefile)
if _access_check(name, mode):
return name
return None


def which(cmd, mode=os.F_OK | os.X_OK, path=None, **kwargs):
"""Given a command, mode, and a PATH string, return the path which
conforms to the given mode on the PATH, or None if there is no such
file.
`mode` defaults to ``os.F_OK | os.X_OK``. `path` defaults to the result
of ``os.environ.get("PATH")``, or can be overridden with a custom search
path.
Backported from :py:func:`shutil.which`
(`<https://docs.python.org/3.3/library/shutil.html#shutil.which>`_),
available in Python 3.3.
"""
kwargs.update({'mode': mode, 'path': path})
global _which
if _which is not None:
return _which(cmd, **kwargs)
return _which_backport(cmd, **kwargs)

0 comments on commit c9170fa

Please sign in to comment.