Skip to content

Commit e24c9d7

Browse files
committed
interpreter: when overriding a dependency make its name match
Otherwise internal dependencies have auto-generated names that are not human readable. Instead, use the name that the dependency overrides. For example: ```meson meson.override_dependency('zlib', declare_dependency()) dep_zlib = dependency('zlib') assert(dep_zlib.name() == 'zlib') ``` Fixes: mesonbuild#12967
1 parent 31a81f9 commit e24c9d7

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

mesonbuild/interpreter/mesonmain.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# Copyright 2012-2021 The Meson development team
3-
# Copyright © 2021 Intel Corporation
3+
# Copyright © 2021-2024 Intel Corporation
44
from __future__ import annotations
55

6+
import copy
67
import os
78
import typing as T
89

@@ -347,6 +348,16 @@ def override_dependency_method(self, args: T.Tuple[str, dependencies.Dependency]
347348
if not name:
348349
raise InterpreterException('First argument must be a string and cannot be empty')
349350

351+
# Make a copy since we're going to mutate.
352+
#
353+
# dep = declare_dependency()
354+
# meson.override_dependency('foo', dep)
355+
# meson.override_dependency('foo-1.0', dep)
356+
# dep = dependency('foo')
357+
# dep.name() # == 'foo-1.0'
358+
dep = copy.copy(dep)
359+
dep.name = name
360+
350361
optkey = OptionKey('default_library', subproject=self.interpreter.subproject)
351362
default_library = self.interpreter.coredata.get_option(optkey)
352363
assert isinstance(default_library, str), 'for mypy'

test cases/common/98 subproject subdir/meson.build

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright 2016-2023 The Meson Developers
3+
# Copyright © 2024 Intel Corporation
4+
15
project('proj', 'c')
26
subproject('sub')
37
libSub = dependency('sub', fallback: ['sub', 'libSub'])
@@ -6,7 +10,19 @@ exe = executable('prog', 'prog.c', dependencies: libSub)
610
test('subproject subdir', exe)
711

812
# Verify the subproject has placed dependency override.
9-
dependency('sub-1.0')
13+
d = dependency('sub-1.0')
14+
15+
# verify that the name is the overridden name
16+
assert(d.name() == 'sub-1.0', 'name was not properly set, should have been "sub-1.0", but was @0@'.format(d.name()))
17+
18+
# Verify that when a dependency object is used for two overrides, the correct
19+
# name is used
20+
meson.override_dependency('new-dep', d)
21+
d2 = dependency('new-dep')
22+
assert(d2.name() == 'new-dep', 'name was not properly set, should have been "new-dep", but was @0@'.format(d2.name()))
23+
24+
# And that the old dependency wasn't changed
25+
assert(d.name() == 'sub-1.0', 'original dependency was mutated.')
1026

1127
# Verify we can now take 'sub' dependency without fallback, but only version 1.0.
1228
dependency('sub')

0 commit comments

Comments
 (0)