add testcase for bad things with add_project_dependencies

Test that add_project_dependencies() can only be used before build targets
have been declared.  Also test that one cannot use override_dependency
on a superproject to inject a superproject's build products into the
subproject.  This would violate the rule that build products cannot be used
with add_project_dependencies() (similar to e.g. compiler.has_function),
so check that meson detects the situation correctly.
This commit is contained in:
Paolo Bonzini 2022-03-29 15:24:58 +02:00 committed by Eli Schwartz
parent 3a960023d3
commit 2f68aa21e8
10 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,2 @@
#pragma once
void f(void);

View File

@ -0,0 +1,3 @@
#include <stdio.h>
#include "lib.h"
void f() {puts("hello");}

View File

@ -0,0 +1,8 @@
project('super', 'c')
inc = include_directories('inc')
lib = static_library('sneaky', 'lib.c', include_directories: inc)
meson.override_dependency('sneaky',
declare_dependency(link_with: lib, include_directories: inc))
subproject('a')

View File

@ -0,0 +1,10 @@
project('a', 'c')
dep = dependency('sneaky')
# does not work
add_project_dependencies(dep, language: 'c')
executable('prog', 'prog.c')
# this would work instead:
# executable('prog', 'prog.c', dependencies: dep)

View File

@ -0,0 +1,6 @@
#include "lib.h"
int main() {
f();
return 0;
}

View File

@ -0,0 +1,7 @@
{
"stdout": [
{
"line": "test cases/failing/124 override and add_project_dependency/subprojects/a/meson.build:6:0: ERROR: Dependencies must be external dependencies"
}
]
}

View File

@ -0,0 +1,2 @@
#pragma once
void f(void);

View File

@ -0,0 +1,3 @@
#include <stdio.h>
#include "lib.h"
void f() {puts("hello");}

View File

@ -0,0 +1,5 @@
project('test', 'c')
static_library('lib', 'lib.c')
inc = include_directories('inc')
add_project_dependencies(declare_dependency(include_directories: inc), language: 'c')

View File

@ -0,0 +1,7 @@
{
"stdout": [
{
"line": "test cases/failing/125 targets before add_project_dependency/meson.build:5:0: ERROR: Tried to use 'add_project_dependencies' after a build target has been declared."
}
]
}