Skip to content

Commit

Permalink
Fixed unit test (see mesonbuild#4549)
Browse files Browse the repository at this point in the history
  • Loading branch information
mensinda committed Nov 26, 2018
1 parent 37ffff0 commit 2529d21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
35 changes: 19 additions & 16 deletions mesonbuild/dependencies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,9 @@ class CMakeDependency(ExternalDependency):
# CMake generators to try (empty for no generator)
class_cmake_generators = ['', 'Ninja', 'Unix Makefiles', 'Visual Studio 10 2010']

def _gen_exception(self, msg):
return DependencyException('Dependency {} not found: {}'.format(self.name, msg))

def __init__(self, name, environment, kwargs, language=None):
super().__init__('cmake', environment, language, kwargs)
self.name = name
Expand All @@ -911,7 +914,7 @@ def __init__(self, name, environment, kwargs, language=None):
if self.want_cross:
if 'cmake' not in environment.cross_info.config['binaries']:
if self.required:
raise DependencyException('CMake binary missing from cross file')
raise self._gen_exception('CMake binary missing from cross file')
else:
potential_cmake = ExternalProgram.from_cross_info(environment.cross_info, 'cmake')
if potential_cmake.found():
Expand All @@ -931,7 +934,7 @@ def __init__(self, name, environment, kwargs, language=None):

if not self.cmakebin:
if self.required:
raise DependencyException('CMake not found.')
raise self._gen_exception('CMake not found.')
return

modules = kwargs.get('modules', [])
Expand Down Expand Up @@ -1046,7 +1049,7 @@ def _detect_dep(self, name, modules):

# Even the old-style approach failed. Nothing else we can do here
self.is_found = False
raise DependencyException('CMake: failed to guess a CMake target for {}.\n'
raise self._gen_exception('CMake: failed to guess a CMake target for {}.\n'
'Try to explicitly specify one or more targets with the "modules" property.\n'
'Valid targets are:\n{}'.format(name, list(self.targets.keys())))

Expand All @@ -1058,7 +1061,7 @@ def _detect_dep(self, name, modules):
libraries = []
for i in modules:
if i not in self.targets:
raise DependencyException('CMake: invalid CMake target {} for {}.\n'
raise self._gen_exception('CMake: invalid CMake target {} for {}.\n'
'Try to explicitly specify one or more targets with the "modules" property.\n'
'Valid targets are:\n{}'.format(i, name, list(self.targets.keys())))

Expand Down Expand Up @@ -1169,7 +1172,7 @@ def _cmake_set(self, tline: CMakeTraceLine):
args.append(i)

if len(args) < 1:
raise DependencyException('CMake: set() requires at least one argument\n{}'.format(tline))
raise self._gen_exception('CMake: set() requires at least one argument\n{}'.format(tline))

if len(args) == 1:
# Same as unset
Expand All @@ -1182,7 +1185,7 @@ def _cmake_set(self, tline: CMakeTraceLine):
def _cmake_unset(self, tline: CMakeTraceLine):
# DOC: https://cmake.org/cmake/help/latest/command/unset.html
if len(tline.args) < 1:
raise DependencyException('CMake: unset() requires at least one argument\n{}'.format(tline))
raise self._gen_exception('CMake: unset() requires at least one argument\n{}'.format(tline))

if tline.args[0] in self.vars:
del self.vars[tline.args[0]]
Expand All @@ -1193,12 +1196,12 @@ def _cmake_add_executable(self, tline: CMakeTraceLine):

# Make sure the exe is imported
if 'IMPORTED' not in args:
raise DependencyException('CMake: add_executable() non imported executables are not supported\n{}'.format(tline))
raise self._gen_exception('CMake: add_executable() non imported executables are not supported\n{}'.format(tline))

args.remove('IMPORTED')

if len(args) < 1:
raise DependencyException('CMake: add_executable() requires at least 1 argument\n{}'.format(tline))
raise self._gen_exception('CMake: add_executable() requires at least 1 argument\n{}'.format(tline))

self.targets[args[0]] = CMakeTarget(args[0], 'EXECUTABLE', {})

Expand All @@ -1208,21 +1211,21 @@ def _cmake_add_library(self, tline: CMakeTraceLine):

# Make sure the lib is imported
if 'IMPORTED' not in args:
raise DependencyException('CMake: add_library() non imported libraries are not supported\n{}'.format(tline))
raise self._gen_exception('CMake: add_library() non imported libraries are not supported\n{}'.format(tline))

args.remove('IMPORTED')

# No only look at the first two arguments (target_name and target_type) and ignore the rest
if len(args) < 2:
raise DependencyException('CMake: add_library() requires at least 2 arguments\n{}'.format(tline))
raise self._gen_exception('CMake: add_library() requires at least 2 arguments\n{}'.format(tline))

self.targets[args[0]] = CMakeTarget(args[0], args[1], {})

def _cmake_add_custom_target(self, tline: CMakeTraceLine):
# DOC: https://cmake.org/cmake/help/latest/command/add_custom_target.html
# We only the first parameter (the target name) is interesting
if len(tline.args) < 1:
raise DependencyException('CMake: add_custom_target() requires at least one argument\n{}'.format(tline))
raise self._gen_exception('CMake: add_custom_target() requires at least one argument\n{}'.format(tline))

self.targets[tline.args[0]] = CMakeTarget(tline.args[0], 'CUSTOM', {})

Expand Down Expand Up @@ -1252,7 +1255,7 @@ def _cmake_set_property(self, tline: CMakeTraceLine):
return

if len(args) < 2:
raise DependencyException('CMake: set_property() faild to parse argument list\n{}'.format(tline))
raise self._gen_exception('CMake: set_property() faild to parse argument list\n{}'.format(tline))

propName = args[0]
propVal = list(itertools.chain(*map(lambda x: x.split(';'), args[1:])))
Expand All @@ -1263,7 +1266,7 @@ def _cmake_set_property(self, tline: CMakeTraceLine):

for i in targets:
if i not in self.targets:
raise DependencyException('CMake: set_property() TARGET {} not found\n{}'.format(i, tline))
raise self._gen_exception('CMake: set_property() TARGET {} not found\n{}'.format(i, tline))

if propName not in self.targets[i].properies:
self.targets[i].properies[propName] = []
Expand All @@ -1286,7 +1289,7 @@ def _cmake_set_target_properties(self, tline: CMakeTraceLine):
targets.append(curr)

if (len(args) % 2) != 0:
raise DependencyException('CMake: set_target_properties() uneven number of property arguments\n{}'.format(tline))
raise self._gen_exception('CMake: set_target_properties() uneven number of property arguments\n{}'.format(tline))

while len(args) > 0:
propName = args.pop(0)
Expand All @@ -1298,7 +1301,7 @@ def _cmake_set_target_properties(self, tline: CMakeTraceLine):

for i in targets:
if i not in self.targets:
raise DependencyException('CMake: set_target_properties() TARGET {} not found\n{}'.format(i, tline))
raise self._gen_exception('CMake: set_target_properties() TARGET {} not found\n{}'.format(i, tline))

self.targets[i].properies[propName] = propVal

Expand All @@ -1314,7 +1317,7 @@ def _lex_trace(self, trace):
skip_match = reg_other.match(trace, loc)
if not skip_match:
print(trace[loc:])
raise 'Failed to parse CMake trace'
raise self._gen_exception('Failed to parse CMake trace')

loc = skip_match.end()
continue
Expand Down
2 changes: 1 addition & 1 deletion run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2922,7 +2922,7 @@ class FailureTests(BasePlatformTests):
function can fail, and creating failing tests for all of them is tedious
and slows down testing.
'''
dnf = "[Dd]ependency.*not found"
dnf = "[Dd]ependency.*not found(:.*)?"
nopkg = '[Pp]kg-config not found'

def setUp(self):
Expand Down

0 comments on commit 2529d21

Please sign in to comment.