dependency: Cleanup code by avoiding nested if blocks
@@ -2979,39 +2979,28 @@ external dependencies (including libraries) must go to "dependencies".''')
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)
+ identifier, cached_dep = self._find_cached_dep(name, kwargs)
if cached_dep:
if required and not cached_dep.found():
m = 'Dependency {!r} was already checked and was not found'
raise DependencyException(m.format(display_name))
- dep = cached_dep
- else:
+ return DependencyHolder(cached_dep, self.subproject)
+
# If the dependency has already been configured, possibly by
# a higher level project, try to use it first.
if has_fallback:
dirname, varname = self.get_subproject_infos(kwargs)
if dirname in self.subprojects:
- return self.get_subproject_dep(display_name, dirname, varname, kwargs)
+ return self.get_subproject_dep(name, dirname, varname, kwargs)
- # We need to actually search for this dep
- dep = NotFoundDependency(self.environment)
-
- # Unless a fallback exists and is forced ...
- if self.coredata.get_builtin_option('wrap_mode') == WrapMode.forcefallback and has_fallback:
- pass
- # ... search for it outside the project
- elif name != '':
+ wrap_mode = self.coredata.get_builtin_option('wrap_mode')
+ forcefallback = wrap_mode == WrapMode.forcefallback and has_fallback
+ if name != '' and not forcefallback:
self._handle_featurenew_dependencies(name)
kwargs['required'] = required and not has_fallback
dep = dependencies.find_external_dependency(name, self.environment, kwargs)
kwargs['required'] = required
-
- # Search inside the projects list
- if not dep.found():
- if has_fallback:
- return self.dependency_fallback(display_name, kwargs)
-
# Only store found-deps in the cache
# Never add fallback deps to self.coredata.deps since we
# cannot cache them. They must always be evaluated else
@@ -3020,6 +3009,11 @@ external dependencies (including libraries) must go to "dependencies".''')
self.coredata.deps[identifier] = dep
return DependencyHolder(dep, self.subproject)
+ if has_fallback:
+ return self.dependency_fallback(display_name, kwargs)
+
+ return self.notfound_dependency()
+
@FeatureNew('disabler', '0.44.0')
@noKwargs
@noPosargs
