@ -23,7 +23,8 @@ from . import compilers
from . wrap import wrap , WrapMode
from . wrap import wrap , WrapMode
from . import mesonlib
from . import mesonlib
from . mesonlib import FileMode , Popen_safe , get_meson_script
from . mesonlib import FileMode , Popen_safe , get_meson_script
from . dependencies import InternalDependency , Dependency , ExternalProgram
from . dependencies import ExternalProgram
from . dependencies import InternalDependency , Dependency , DependencyException
from . interpreterbase import InterpreterBase
from . interpreterbase import InterpreterBase
from . interpreterbase import check_stringlist , noPosargs , noKwargs , stringArgs
from . interpreterbase import check_stringlist , noPosargs , noKwargs , stringArgs
from . interpreterbase import InterpreterException , InvalidArguments , InvalidCode
from . interpreterbase import InterpreterException , InvalidArguments , InvalidCode
@ -1852,12 +1853,16 @@ class Interpreter(InterpreterBase):
def func_find_library ( self , node , args , kwargs ) :
def func_find_library ( self , node , args , kwargs ) :
mlog . log ( mlog . red ( ' DEPRECATION: ' ) , ' find_library() is removed, use the corresponding method in compiler object instead. ' )
mlog . log ( mlog . red ( ' DEPRECATION: ' ) , ' find_library() is removed, use the corresponding method in compiler object instead. ' )
def func_dependency ( self , node , args , kwargs ) :
def _find_cached_dep ( self , name , kwargs ) :
self . validate_arguments ( args , 1 , [ str ] )
'''
name = args [ 0 ]
Check that there aren ' t any mismatches between the cached dep and the
if ' < ' in name or ' > ' in name or ' = ' in name :
wanted dep in terms of version and whether to use a fallback or not .
raise InvalidArguments ( ' Characters <, > and = are forbidden in dependency names. To specify '
For instance , the cached dep and the wanted dep could have mismatching
' version \n requirements use the \' version \' keyword argument instead. ' )
version requirements . The cached dep did not search for a fallback , but
the wanted dep specifies a fallback . There are many more edge - cases .
Most cases are ( or should be ) documented in :
` test cases / linuxlike / 5 dependency versions / meson . build `
'''
# Check if we want this as a cross-dep or a native-dep
# Check if we want this as a cross-dep or a native-dep
# FIXME: Not all dependencies support such a distinction right now,
# FIXME: Not all dependencies support such a distinction right now,
# and we repeat this check inside dependencies that do. We need to
# and we repeat this check inside dependencies that do. We need to
@ -1868,52 +1873,89 @@ class Interpreter(InterpreterBase):
else :
else :
want_cross = is_cross
want_cross = is_cross
identifier = dependencies . get_dep_identifier ( name , kwargs , want_cross )
identifier = dependencies . get_dep_identifier ( name , kwargs , want_cross )
# Check if we've already searched for and found this dep
cached_dep = None
cached_dep = None
# Check if we've already searched for and found this dep
if identifier in self . coredata . deps :
if identifier in self . coredata . deps :
cached_dep = self . coredata . deps [ identifier ]
cached_dep = self . coredata . deps [ identifier ]
# All other kwargs are handled in get_dep_identifier(). We have
else :
# this here as a tiny optimization to avoid searching for
# Check if exactly the same dep with different version requirements
# dependencies that we already have.
# was found already.
if ' version ' in kwargs :
# We only return early if we find a usable cached dependency since
wanted = kwargs [ ' version ' ]
# there might be multiple cached dependencies like this.
found = cached_dep . get_version ( )
w = identifier [ 1 ]
if not cached_dep . found ( ) or \
for trial , trial_dep in self . coredata . deps . items ( ) :
not mesonlib . version_compare_many ( found , wanted ) [ 0 ] :
# trial[1], identifier[1] are the version requirements
# Cached dep has the wrong version. Check if an external
if trial [ 0 ] != identifier [ 0 ] or trial [ 2 : ] != identifier [ 2 : ] :
# dependency or a fallback dependency provides it.
continue
cached_dep = None
# The version requirements are the only thing that's different.
if trial_dep . found ( ) :
# Cached dependency was found. We're close.
f = trial_dep . get_version ( )
if not w or mesonlib . version_compare_many ( f , w ) [ 0 ] :
# We either don't care about the version, or the
# cached dep version matches our requirements! Yay!
return identifier , trial_dep
elif ' fallback ' not in kwargs :
# this cached dependency matched everything but was
# not-found. Tentatively set this as the dep to use.
# If no other cached dep matches, we will use this as the
# not-found dep.
cached_dep = trial_dep
# There's a subproject fallback specified for this not-found dependency
# which might provide it, so we must check it.
if cached_dep and not cached_dep . found ( ) and ' fallback ' in kwargs :
return identifier , None
# Either no cached deps matched the dep we're looking for, or some
# not-found cached dep matched and there is no fallback specified.
# Either way, we're done.
return identifier , cached_dep
def func_dependency ( self , node , args , kwargs ) :
self . validate_arguments ( args , 1 , [ str ] )
name = args [ 0 ]
if ' < ' in name or ' > ' in name or ' = ' in name :
raise InvalidArguments ( ' Characters <, > and = are forbidden in dependency names. To specify '
' version \n requirements use the \' version \' keyword argument instead. ' )
identifier , cached_dep = self . _find_cached_dep ( name , kwargs )
if cached_dep :
if cached_dep :
if kwargs . get ( ' required ' , True ) and not cached_dep . found ( ) :
m = ' Dependency {!r} was already checked and was not found '
raise DependencyException ( m . format ( name ) )
dep = cached_dep
dep = cached_dep
else :
else :
# We need to actually search for this dep
# We need to actually search for this dep
exception = None
exception = None
dep = None
dep = None
# If the fallback has already been configured (possibly by a higher level project)
# If the dependency has already been configured, possibly by
# try to use it before using the native version
# a higher level project, try to use it first.
if ' fallback ' in kwargs :
if ' fallback ' in kwargs :
dirname , varname = self . get_subproject_infos ( kwargs )
dirname , varname = self . get_subproject_infos ( kwargs )
if dirname in self . subprojects :
if dirname in self . subprojects :
subproject = self . subprojects [ dirname ]
try :
try :
dep = self . subprojects [ dirname ] . get_variable_method ( [ varname ] , { } )
# Never add fallback deps to self.coredata.deps
dep = dep . held_object
return subproject . get_variable_method ( [ varname ] , { } )
except KeyError :
except KeyError :
pass
pass
# Search for it outside the project
if not dep :
if not dep :
try :
try :
dep = dependencies . find_external_dependency ( name , self . environment , kwargs )
dep = dependencies . find_external_dependency ( name , self . environment , kwargs )
except dependencies . DependencyException as e :
except DependencyException as e :
exception = e
exception = e
pass
pass
# Search inside the projects list
if not dep or not dep . found ( ) :
if not dep or not dep . found ( ) :
if ' fallback ' in kwargs :
if ' fallback ' in kwargs :
fallback_dep = self . dependency_fallback ( name , kwargs )
fallback_dep = self . dependency_fallback ( name , kwargs )
if fallback_dep :
if fallback_dep :
# Never add fallback deps to self.coredata.deps since we
# cannot cache them. They must always be evaluated else
# we won't actually read all the build files.
return fallback_dep
return fallback_dep
if not dep :
if not dep :
raise exception
raise exception