diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2024-03-13 12:48:06 -0700 |
|---|---|---|
| committer | Eli Schwartz <eschwartz93@gmail.com> | 2024-09-23 19:26:23 -0400 |
| commit | b7bf61e33e76705e6dd9a0e59e48ac9f3b97e765 (patch) | |
| tree | fa2b918f4f51983bc5117b7794a6a720ef1d2775 /test cases/common | |
| parent | 6e98767c31dcc23229edee4c5609d65eaf3646a8 (diff) | |
| download | meson-b7bf61e33e76705e6dd9a0e59e48ac9f3b97e765.tar.gz | |
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: #12967
Diffstat (limited to 'test cases/common')
6 files changed, 67 insertions, 3 deletions
diff --git a/test cases/common/183 partial dependency/declare_dependency/meson.build b/test cases/common/183 partial dependency/declare_dependency/meson.build index 3783f6694..8c62d1082 100644 --- a/test cases/common/183 partial dependency/declare_dependency/meson.build +++ b/test cases/common/183 partial dependency/declare_dependency/meson.build @@ -1,4 +1,4 @@ -# Copyright © 2018 Intel Corporation +# Copyright © 2018-2024 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,4 +29,12 @@ dec_exe = executable( dependencies : sub_dep, ) +# Ensure that two partial dependencies of the same dependency are applied, as +# they may provide different values. +dec2_exe = executable( + 'declare_dep2', + files('main.c', 'other.c'), + dependencies : [sub_dep.partial_dependency(), sub_dep], +) + test('Declare Dependency', dec_exe) diff --git a/test cases/common/183 partial dependency/external_dependency/header_only.c b/test cases/common/183 partial dependency/external_dependency/header_only.c new file mode 100644 index 000000000..ecdd58bec --- /dev/null +++ b/test cases/common/183 partial dependency/external_dependency/header_only.c @@ -0,0 +1,8 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright © 2024 Intel Corporation + */ + +#include <zlib.h> + +int main(void) { return 0; } diff --git a/test cases/common/183 partial dependency/external_dependency/link.c b/test cases/common/183 partial dependency/external_dependency/link.c new file mode 100644 index 000000000..dae5561e1 --- /dev/null +++ b/test cases/common/183 partial dependency/external_dependency/link.c @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright © 2024 Intel Corporation + */ + +#include <zlib.h> +#include <string.h> + +int main(void) { + const char * zver = zlibVersion(); + return strcmp(zver, ZLIB_VERSION); +} diff --git a/test cases/common/183 partial dependency/external_dependency/meson.build b/test cases/common/183 partial dependency/external_dependency/meson.build new file mode 100644 index 000000000..4194bb76e --- /dev/null +++ b/test cases/common/183 partial dependency/external_dependency/meson.build @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright © 2024 Intel Corporation + +# TODO: don't use compile whenever we get includes and compile args separated +dep_zlib_sub = dep_zlib.partial_dependency(compile_args : true, includes : true) + +executable( + 'zlib header only test', + 'header_only.c', + dependencies : dep_zlib_sub, +) + +executable( + 'zlib link test', + 'link.c', + dependencies : [dep_zlib_sub, dep_zlib], +) diff --git a/test cases/common/183 partial dependency/meson.build b/test cases/common/183 partial dependency/meson.build index e908487f1..c492cc3d4 100644 --- a/test cases/common/183 partial dependency/meson.build +++ b/test cases/common/183 partial dependency/meson.build @@ -1,4 +1,4 @@ -# Copyright © 2018 Intel Corporation +# Copyright © 2018-2024 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,3 +15,6 @@ project('partial dependency', ['c', 'cpp']) subdir('declare_dependency') + +dep_zlib = dependency('zlib', required : false) +subdir('external_dependency', if_found : dep_zlib) diff --git a/test cases/common/98 subproject subdir/meson.build b/test cases/common/98 subproject subdir/meson.build index ef053d86c..d2bafedf5 100644 --- a/test cases/common/98 subproject subdir/meson.build +++ b/test cases/common/98 subproject subdir/meson.build @@ -1,3 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2016-2023 The Meson Developers +# Copyright © 2024 Intel Corporation + project('proj', 'c') subproject('sub') libSub = dependency('sub', fallback: ['sub', 'libSub']) @@ -6,7 +10,19 @@ exe = executable('prog', 'prog.c', dependencies: libSub) test('subproject subdir', exe) # Verify the subproject has placed dependency override. -dependency('sub-1.0') +d = dependency('sub-1.0') + +# verify that the name is the overridden name +assert(d.name() == 'sub-1.0', 'name was not properly set, should have been "sub-1.0", but was @0@'.format(d.name())) + +# Verify that when a dependency object is used for two overrides, the correct +# name is used +meson.override_dependency('new-dep', d) +d2 = dependency('new-dep') +assert(d2.name() == 'new-dep', 'name was not properly set, should have been "new-dep", but was @0@'.format(d2.name())) + +# And that the old dependency wasn't changed +assert(d.name() == 'sub-1.0', 'original dependency was mutated.') # Verify we can now take 'sub' dependency without fallback, but only version 1.0. dependency('sub') |
