dependencies: log the real reason for a dependency lookup failing

In the debug logs, always log if a dependency lookup raises a
DependencyException. In the `required: false` case, this information
would otherwise disappear forever, and we would just not even log that
we tried it -- it doesn't appear in "(tried x, y and z)".

In the `required: true` case, we would re-raise the first exception if
it failed to be detected. Update the raise message with the same
information we print to the debug logs, indicating which dependency and
which method was used in the failing attempt.
pull/10756/head
Eli Schwartz 2 years ago
parent b821a03511
commit 719dd0d2a0
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 4
      mesonbuild/dependencies/base.py
  2. 5
      mesonbuild/dependencies/detect.py
  3. 2
      test cases/failing/78 framework dependency with version/test.json
  4. 2
      test cases/failing/80 gl dependency with version/test.json
  5. 2
      test cases/failing/81 threads dependency with version/test.json

@ -406,7 +406,7 @@ class ExternalDependency(Dependency, HasNativeKwarg):
mlog.log(*found_msg)
if self.required:
m = f'Unknown version of dependency {self.name!r}, but need {self.version_reqs!r}.'
m = f'Unknown version, but need {self.version_reqs!r}.'
raise DependencyException(m)
else:
@ -423,7 +423,7 @@ class ExternalDependency(Dependency, HasNativeKwarg):
mlog.log(*found_msg)
if self.required:
m = 'Invalid version of dependency, need {!r} {!r} found {!r}.'
m = 'Invalid version, need {!r} {!r} found {!r}.'
raise DependencyException(m.format(self.name, not_found, self.version))
return

@ -113,8 +113,11 @@ def find_external_dependency(name: str, env: 'Environment', kwargs: T.Dict[str,
d._check_version()
pkgdep.append(d)
except DependencyException as e:
assert isinstance(c, functools.partial), 'for mypy'
bettermsg = f'Dependency lookup for {name} with method {c.func.log_tried()!r} failed: {e}'
mlog.debug(bettermsg)
e.args = (bettermsg,)
pkg_exc.append(e)
mlog.debug(str(e))
else:
pkg_exc.append(None)
details = d.log_details()

@ -1,7 +1,7 @@
{
"stdout": [
{
"line": "test cases/failing/78 framework dependency with version/meson.build:8:0: ERROR: Unknown version of dependency 'appleframeworks', but need ['>0']."
"line": "test cases/failing/78 framework dependency with version/meson.build:8:0: ERROR: Dependency lookup for appleframeworks with method 'framework' failed: Unknown version, but need ['>0']."
}
]
}

@ -1,7 +1,7 @@
{
"stdout": [
{
"line": "test cases/failing/80 gl dependency with version/meson.build:9:0: ERROR: Unknown version of dependency 'gl', but need ['>0']."
"line": "test cases/failing/80 gl dependency with version/meson.build:9:0: ERROR: Dependency lookup for gl with method 'system' failed: Unknown version, but need ['>0']."
}
]
}

@ -1,7 +1,7 @@
{
"stdout": [
{
"line": "test cases/failing/81 threads dependency with version/meson.build:3:0: ERROR: Unknown version of dependency 'threads', but need ['>0']."
"line": "test cases/failing/81 threads dependency with version/meson.build:3:0: ERROR: Dependency lookup for threads with method 'system' failed: Unknown version, but need ['>0']."
}
]
}

Loading…
Cancel
Save