Commit 5907c415 authored by André Anjos's avatar André Anjos 💬
Browse files

Fix tests and behavior

parent 86ad5e59
Pipeline #3710 passed with stages
in 27 minutes and 59 seconds
......@@ -52,12 +52,21 @@ class EnvironmentWrapper(object):
# set the pkg-config paths to look at, environment settings in front
prefixes = prefixes if prefixes else []
if 'CMAKE_PREFIX_PATH' in self.environ:
prefixes = self.environ['CMAKE_PREFIX_PATH'].split(os.pathsep) + prefixes
if 'CMAKE_PREFIX_PATH' in os.environ:
prefixes = os.environ['CMAKE_PREFIX_PATH'].split(os.pathsep) + prefixes
if 'BOB_PREFIX_PATH' in self.environ:
prefixes = self.environ['BOB_PREFIX_PATH'].split(os.pathsep) + prefixes
if 'BOB_PREFIX_PATH' in os.environ:
prefixes = os.environ['BOB_PREFIX_PATH'].split(os.pathsep) + prefixes
pkgcfg += [os.path.join(k, 'lib', 'pkgconfig') for k in prefixes]
pkgcfg += [os.path.join(k, 'lib64', 'pkgconfig') for k in prefixes]
pkgcfg += [os.path.join(k, 'lib32', 'pkgconfig') for k in prefixes]
def __remove_environ(key):
if key in self.environ: del self.environ[key]
def __append_to_environ(key, value, sep=' '):
if self.environ.get(key):
if value:
......@@ -68,19 +77,15 @@ class EnvironmentWrapper(object):
# joins all paths, respecting potential environment variables set by the
# user, with priority
self.environ['BOB_PREFIX_PATH'] = None
__append_to_environ('BOB_PREFIX_PATH', os.environ.get('BOB_PREFIX_PATH'),
os.pathsep)
__remove_environ('BOB_PREFIX_PATH')
__append_to_environ('BOB_PREFIX_PATH', os.pathsep.join(prefixes),
os.pathsep)
self.environ['CMAKE_PREFIX_PATH'] = None
__append_to_environ('CMAKE_PREFIX_PATH',
os.environ.get('CMAKE_PREFIX_PATH'), os.pathsep)
__remove_environ('CMAKE_PREFIX_PATH')
__append_to_environ('CMAKE_PREFIX_PATH', os.pathsep.join(prefixes),
os.pathsep)
self.environ['PKG_CONFIG_PATH'] = None
__remove_environ('PKG_CONFIG_PATH')
__append_to_environ('PKG_CONFIG_PATH', os.environ.get('PKG_CONFIG_PATH'),
os.pathsep)
__append_to_environ('PKG_CONFIG_PATH', os.pathsep.join(pkgcfg), os.pathsep)
......@@ -94,28 +99,29 @@ class EnvironmentWrapper(object):
def _order_flags(key, internal=None):
if internal:
# prepend internal
buildout_cflags = self.environ.get(key)
self.environ[key] = None
saved = self.environ.get(key)
__remove_environ(key)
__append_to_environ(key, internal)
__append_to_environ(key, buildout_cflags)
__append_to_environ(key, saved)
__append_to_environ(key, os.environ.get(key))
# for these environment variables, values set on the environment come last
# so they can override, values set on the buildout recipe or our internal
# settings
_order_flags('CFLAGS', cflags)
_order_flags('CXXFLAGS', cflags)
_order_flags('LDFLAGS', EnvironmentWrapper.LDFLAGS)
# sets the MacOSX deployment target, if the user has not yet set it on
# their environment
if platform.system() == 'Darwin':
if os.environ.get('MACOSX_DEPLOYMENT_TARGET'):
self.environ['MACOSX_DEPLOYMENT_TARGET'] = \
os.environ['MACOSX_DEPLOYMENT_TARGET']
else:
self.environ['MACOSX_DEPLOYMENT_TARGET'] = \
EnvironmentWrapper.MACOSX_DEPLOYMENT_TARGET
if cflags is not None:
_order_flags('CFLAGS', cflags)
_order_flags('CXXFLAGS', cflags)
_order_flags('LDFLAGS', EnvironmentWrapper.LDFLAGS)
# sets the MacOSX deployment target, if the user has not yet set it on
# their environment
if platform.system() == 'Darwin':
if os.environ.get('MACOSX_DEPLOYMENT_TARGET'):
self.environ['MACOSX_DEPLOYMENT_TARGET'] = \
os.environ['MACOSX_DEPLOYMENT_TARGET']
else:
self.environ['MACOSX_DEPLOYMENT_TARGET'] = \
EnvironmentWrapper.MACOSX_DEPLOYMENT_TARGET
def set(self):
"""Sets the current environment for variables needed for the setup of the
......
......@@ -8,6 +8,7 @@
import os
import logging
import nose.tools
import platform
from .envwrapper import EnvironmentWrapper
......@@ -34,7 +35,8 @@ def test_default():
def cleanup():
'''Removes weird variables from the user environment just for the tests'''
remove = ['CFLAGS', 'CXXFLAGS', 'BOB_PREFIX_PATH', 'PKG_CONFIG_PATH']
remove = ['CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'BOB_PREFIX_PATH',
'PKG_CONFIG_PATH', 'CMAKE_PREFIX_PATH', 'MACOSX_DEPLOYMENT_TARGET']
for key in remove:
if key in os.environ: del os.environ[key]
......@@ -50,13 +52,28 @@ def test_set_debug_true():
before = dict(os.environ)
e.set()
nose.tools.eq_(len(os.environ) - len(before), 2)
if platform.system() == 'Darwin':
nose.tools.eq_(len(os.environ) - len(before), 4)
else:
# Linux
nose.tools.eq_(len(os.environ) - len(before), 2)
assert 'CFLAGS' in os.environ
assert os.environ['CFLAGS'].find(EnvironmentWrapper.DEBUG_FLAGS) >= 0
assert os.environ['CFLAGS'].find(EnvironmentWrapper.RELEASE_FLAGS) < 0
assert os.environ['CFLAGS'].find(EnvironmentWrapper.DEBUG_CFLAGS) >= 0
assert os.environ['CFLAGS'].find(EnvironmentWrapper.RELEASE_CFLAGS) < 0
assert 'CXXFLAGS' in os.environ
assert os.environ['CXXFLAGS'].find(EnvironmentWrapper.DEBUG_FLAGS) >= 0
assert os.environ['CXXFLAGS'].find(EnvironmentWrapper.RELEASE_FLAGS) < 0
assert os.environ['CXXFLAGS'].find(EnvironmentWrapper.DEBUG_CFLAGS) >= 0
assert os.environ['CXXFLAGS'].find(EnvironmentWrapper.RELEASE_CFLAGS) < 0
if platform.system() == 'Darwin':
assert 'LDFLAGS' in os.environ
assert os.environ['LDFLAGS'].find(EnvironmentWrapper.LDFLAGS) >= 0
assert 'MACOSX_DEPLOYMENT_TARGET' in os.environ
assert os.environ['MACOSX_DEPLOYMENT_TARGET'] == \
EnvironmentWrapper.MACOSX_DEPLOYMENT_TARGET
e.unset()
for key in before:
......@@ -77,15 +94,30 @@ def test_set_debug_false():
before = dict(os.environ)
e.set()
nose.tools.eq_(len(os.environ) - len(before), 2)
if platform.system() == 'Darwin':
nose.tools.eq_(len(os.environ) - len(before), 4)
else:
# Linux
nose.tools.eq_(len(os.environ) - len(before), 2)
assert 'CFLAGS' in os.environ
assert 'CXXFLAGS' in os.environ
nose.tools.eq_(os.environ['CFLAGS'], e.environ['CFLAGS'])
assert os.environ['CFLAGS'].find(EnvironmentWrapper.DEBUG_FLAGS) < 0
assert os.environ['CFLAGS'].find(EnvironmentWrapper.RELEASE_FLAGS) >= 0
assert os.environ['CFLAGS'].find(EnvironmentWrapper.DEBUG_CFLAGS) < 0
assert os.environ['CFLAGS'].find(EnvironmentWrapper.RELEASE_CFLAGS) >= 0
nose.tools.eq_(os.environ['CXXFLAGS'], e.environ['CXXFLAGS'])
assert os.environ['CXXFLAGS'].find(EnvironmentWrapper.DEBUG_FLAGS) < 0
assert os.environ['CXXFLAGS'].find(EnvironmentWrapper.RELEASE_FLAGS) >= 0
assert os.environ['CXXFLAGS'].find(EnvironmentWrapper.DEBUG_CFLAGS) < 0
assert os.environ['CXXFLAGS'].find(EnvironmentWrapper.RELEASE_CFLAGS) >= 0
if platform.system() == 'Darwin':
assert 'LDFLAGS' in os.environ
assert os.environ['LDFLAGS'].find(EnvironmentWrapper.LDFLAGS) >= 0
assert 'MACOSX_DEPLOYMENT_TARGET' in os.environ
assert os.environ['MACOSX_DEPLOYMENT_TARGET'] == \
EnvironmentWrapper.MACOSX_DEPLOYMENT_TARGET
e.unset()
for key in before:
......@@ -111,6 +143,8 @@ def test_set_prefixes():
nose.tools.eq_(os.environ['PKG_CONFIG_PATH'], e.environ['PKG_CONFIG_PATH'])
assert 'BOB_PREFIX_PATH' in os.environ
nose.tools.eq_(os.environ['BOB_PREFIX_PATH'], os.pathsep.join(prefixes))
assert 'CMAKE_PREFIX_PATH' in os.environ
nose.tools.eq_(os.environ['CMAKE_PREFIX_PATH'], os.pathsep.join(prefixes))
e.unset()
for key in before:
......@@ -132,6 +166,7 @@ def test_set_environment():
before = dict(os.environ)
e.set()
nose.tools.eq_(len(os.environ) - len(before), 1)
assert varname in os.environ
nose.tools.eq_(os.environ[varname], varvalue)
......@@ -179,7 +214,8 @@ def test_set_multiple():
CFLAGS='-DNDEBUG',
CXXFLAGS='${CFLAGS}',
PKG_CONFIG_PATH='/a/b/lib/pkgconfig',
BOB_PREFIX_PATH='/c/d'
BOB_PREFIX_PATH='/c/d',
CMAKE_PREFIX_PATH='/d/f',
)
e = EnvironmentWrapper(logging.getLogger(), debug=True, environ=environ)
......@@ -187,10 +223,18 @@ def test_set_multiple():
before = dict(os.environ)
e.set()
nose.tools.eq_(len(os.environ) - len(before), 4)
nose.tools.eq_(os.environ['CFLAGS'], EnvironmentWrapper.DEBUG_FLAGS + ' ' + environ['CFLAGS'])
if platform.system() == 'Darwin':
nose.tools.eq_(len(os.environ) - len(before), 7)
else:
# Linux
nose.tools.eq_(len(os.environ) - len(before), 5)
nose.tools.eq_(os.environ['CFLAGS'], EnvironmentWrapper.DEBUG_CFLAGS + ' ' + environ['CFLAGS'])
nose.tools.eq_(os.environ['CXXFLAGS'], os.environ['CFLAGS'])
nose.tools.eq_(os.environ['BOB_PREFIX_PATH'], environ['BOB_PREFIX_PATH'])
assert os.environ['BOB_PREFIX_PATH'].startswith(environ['BOB_PREFIX_PATH'])
assert os.environ['BOB_PREFIX_PATH'].endswith(environ['CMAKE_PREFIX_PATH'])
assert os.environ['CMAKE_PREFIX_PATH'] == os.environ['BOB_PREFIX_PATH']
assert os.environ['PKG_CONFIG_PATH'].startswith(environ['PKG_CONFIG_PATH'])
assert os.environ['PKG_CONFIG_PATH'].find(environ['BOB_PREFIX_PATH']) >= 0
......@@ -217,7 +261,13 @@ def test_preserve_user():
before = dict(os.environ)
e.set()
nose.tools.eq_(len(os.environ) - len(before), 1)
if platform.system() == 'Darwin':
nose.tools.eq_(len(os.environ) - len(before), 3)
else:
# Linux
nose.tools.eq_(len(os.environ) - len(before), 1)
assert os.environ['CFLAGS'].endswith('-BUILDOUT-TEST-STRING')
e.unset()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment