Better error message when trying to use subprojects as dependencies.

This commit is contained in:
Jussi Pakkanen 2016-09-07 21:25:34 +03:00
parent 69433025ca
commit 165f8a913d
2 changed files with 10 additions and 3 deletions

View File

@ -533,7 +533,14 @@ class BuildTarget():
self.external_deps.append(dep)
self.process_sourcelist(dep.get_sources())
else:
raise InvalidArguments('Argument is not an external dependency')
# This is a bit of a hack. We do not want Build to know anything
# about the interpreter so we can't import it and use isinstance.
# This should be reliable enough.
if hasattr(dep, 'subproject'):
raise InvalidArguments('''Tried to use subproject object as a dependency.
You probably wanted to use a dependency declared in it instead. Access it
by calling get_variable() on the subproject object.''')
raise InvalidArguments('Argument is not an external dependency.')
def get_external_deps(self):
return self.external_deps

View File

@ -567,7 +567,7 @@ class SubprojectHolder(InterpreterObject):
def __init__(self, subinterpreter):
super().__init__()
self.subinterpreter = subinterpreter
self.held_object = subinterpreter
self.methods.update({'get_variable' : self.get_variable_method,
})
@ -577,7 +577,7 @@ class SubprojectHolder(InterpreterObject):
varname = args[0]
if not isinstance(varname, str):
raise InterpreterException('Get_variable takes a string argument.')
return self.subinterpreter.variables[varname]
return self.held_object.variables[varname]
class CompilerHolder(InterpreterObject):
def __init__(self, compiler, env):