Skip to content

Commit dfb3e2a

Browse files
committed
dependencies/detect: simplify logging tried methods
Avoid extra method calls and repeating ourselves.
1 parent 0718934 commit dfb3e2a

File tree

7 files changed

+11
-17
lines changed

7 files changed

+11
-17
lines changed

mesonbuild/dependencies/detect.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def find_external_dependency(name: str, env: 'Environment', kwargs: DependencyOb
112112
pkg_exc: T.List[DependencyException] = []
113113
pkgdep: T.List[ExternalDependency] = []
114114
details = ''
115+
tried_methods: T.List[str] = []
115116

116117
for c in candidates:
117118
# try this dependency method
@@ -139,7 +140,6 @@ def find_external_dependency(name: str, env: 'Environment', kwargs: DependencyOb
139140

140141
# if the dependency was found
141142
if d.found():
142-
143143
info: mlog.TV_LoggableList = []
144144
if d.version:
145145
info.append(mlog.normal_cyan(d.version))
@@ -151,16 +151,11 @@ def find_external_dependency(name: str, env: 'Environment', kwargs: DependencyOb
151151
mlog.log(type_text, mlog.bold(display_name), details + 'found:', mlog.green('YES'), *info)
152152

153153
return d
154+
tried_methods.append(c.method)
154155

155156
# otherwise, the dependency could not be found
156-
tried_methods = [d.log_tried() for d in pkgdep if d.log_tried()]
157-
if tried_methods:
158-
tried = mlog.format_list(tried_methods)
159-
else:
160-
tried = ''
161-
162-
mlog.log(type_text, mlog.bold(display_name), details + 'found:', mlog.red('NO'),
163-
f'(tried {tried})' if tried else '')
157+
tried = ' (tried {})'.format(mlog.format_list(tried_methods)) if tried_methods else ''
158+
mlog.log(type_text, mlog.bold(display_name), details + 'found:', mlog.red('NO'), tried)
164159

165160
if required:
166161
# if an exception occurred with the first detection method, re-raise it
@@ -171,8 +166,7 @@ def find_external_dependency(name: str, env: 'Environment', kwargs: DependencyOb
171166

172167
# we have a list of failed ExternalDependency objects, so we can report
173168
# the methods we tried to find the dependency
174-
raise DependencyException(f'Dependency "{name}" not found' +
175-
(f', tried {tried}' if tried else ''))
169+
raise DependencyException(f'Dependency "{name}" not found' + tried)
176170

177171
return NotFoundDependency(name, env)
178172

test cases/failing/101 no fallback/test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"stdout": [
33
{
44
"match": "re",
5-
"line": ".*/meson\\.build:2:11: ERROR: (Pkg-config binary for machine MachineChoice\\.HOST not found\\. Giving up\\.|Dependency \"foob\" not found, tried .*)"
5+
"line": ".*/meson\\.build:2:11: ERROR: (Pkg-config binary for machine MachineChoice\\.HOST not found\\. Giving up\\.|Dependency \"foob\" not found \\(tried .*\\))"
66
}
77
]
88
}

test cases/failing/34 dependency not-required then required/test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"stdout": [
33
{
44
"match": "re",
5-
"line": ".*/meson\\.build:4:10: ERROR: (Pkg-config binary for machine MachineChoice\\.HOST not found\\. Giving up\\.|Dependency \"foo\\-bar\\-xyz\\-12\\.3\" not found, tried .*)"
5+
"line": ".*/meson\\.build:4:10: ERROR: (Pkg-config binary for machine MachineChoice\\.HOST not found\\. Giving up\\.|Dependency \"foo\\-bar\\-xyz\\-12\\.3\" not found \\(tried .*\\))"
66
}
77
]
88
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"stdout": [
33
{
4-
"line": "test cases/failing/63 wrong boost module/meson.build:9:10: ERROR: Dependency \"boost\" not found, tried system"
4+
"line": "test cases/failing/63 wrong boost module/meson.build:9:10: ERROR: Dependency \"boost\" not found (tried system)"
55
}
66
]
77
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"stdout": [
33
{
4-
"line": "test cases/failing/80 dub library/meson.build:11:0: ERROR: Dependency \"dubtestproject\" not found"
4+
"line": "test cases/failing/80 dub library/meson.build:11:0: ERROR: Dependency \"dubtestproject\" not found (tried dub)"
55
}
66
]
77
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"stdout": [
33
{
4-
"line": "test cases/failing/81 dub executable/meson.build:11:0: ERROR: Dependency \"dubtestproject:test1\" not found"
4+
"line": "test cases/failing/81 dub executable/meson.build:11:0: ERROR: Dependency \"dubtestproject:test1\" not found (tried dub)"
55
}
66
]
77
}

test cases/failing/82 dub compiler/test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"stdout": [
1515
{
16-
"line": "test cases/failing/82 dub compiler/meson.build:17:0: ERROR: Dependency \"dubtestproject:test2\" not found"
16+
"line": "test cases/failing/82 dub compiler/meson.build:17:0: ERROR: Dependency \"dubtestproject:test2\" not found (tried dub)"
1717
}
1818
]
1919
}

0 commit comments

Comments
 (0)