diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2017-12-26 13:18:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-26 13:18:45 +0200 |
commit | d55e98ef50782ff011f2e44d7c13886a3f6b6d05 (patch) | |
tree | 58e979e1b0884a80ff44771a83cd43c65e79a7fc | |
parent | 1904b1a976d9d389f05ed5aa9b63de6f52c1c5e5 (diff) | |
parent | 7f4f082d69bdb05ae148f81fde2d7c66897e8eb7 (diff) | |
download | meson-d55e98ef50782ff011f2e44d7c13886a3f6b6d05.zip meson-d55e98ef50782ff011f2e44d7c13886a3f6b6d05.tar.gz meson-d55e98ef50782ff011f2e44d7c13886a3f6b6d05.tar.bz2 |
Merge pull request #2581 from NickeZ/check-subproj-version
Disallow subprojects have incompatible deps
22 files changed, 158 insertions, 6 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 93f4b1a..f079079 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2131,6 +2131,8 @@ to directly access options of other subprojects.''') # Check if we've already searched for and found this dep if identifier in self.coredata.deps: cached_dep = self.coredata.deps[identifier] + mlog.log('Cached dependency', mlog.bold(name), + 'found:', mlog.green('YES')) else: # Check if exactly the same dep with different version requirements # was found already. @@ -2172,13 +2174,26 @@ to directly access options of other subprojects.''') # a higher level project, try to use it first. if 'fallback' in kwargs: dirname, varname = self.get_subproject_infos(kwargs) + required = kwargs.get('required', True) + wanted = kwargs.get('version', 'undefined') + if not isinstance(required, bool): + raise DependencyException('Keyword "required" must be a boolean.') if dirname in self.subprojects: - subproject = self.subprojects[dirname] - try: - # Never add fallback deps to self.coredata.deps - return subproject.get_variable_method([varname], {}) - except KeyError: - pass + found = self.subprojects[dirname].held_object.project_version + valid_version = wanted == 'undefined' or mesonlib.version_compare(found, wanted) + if required and not valid_version: + m = 'Version {} of {} already loaded, requested incompatible version {}' + raise DependencyException(m.format(found, dirname, wanted)) + elif valid_version: + mlog.log('Found a', mlog.green('(cached)'), 'subproject', + mlog.bold(os.path.join(self.subproject_dir, dirname)), 'for', + mlog.bold(name)) + subproject = self.subprojects[dirname] + try: + # Never add fallback deps to self.coredata.deps + return subproject.get_variable_method([varname], {}) + except KeyError: + pass # We need to actually search for this dep exception = None diff --git a/test cases/failing/68 subproj different versions/main.c b/test cases/failing/68 subproj different versions/main.c new file mode 100644 index 0000000..8793c62 --- /dev/null +++ b/test cases/failing/68 subproj different versions/main.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include "a.h" +#include "b.h" + +int main(int argc, char **argv) { + int life = a_fun() + b_fun(); + printf("%d\n", life); + return 0; +} diff --git a/test cases/failing/68 subproj different versions/meson.build b/test cases/failing/68 subproj different versions/meson.build new file mode 100644 index 0000000..7690277 --- /dev/null +++ b/test cases/failing/68 subproj different versions/meson.build @@ -0,0 +1,9 @@ +project('super', 'c') + +# A will use version 1 of C +a_dep = dependency('a', fallback: ['a', 'a_dep']) + +# B will fail becuase it requests version 2 of C +b_dep = dependency('b', fallback: ['b', 'b_dep']) + +main = executable('main', files('main.c'), dependencies: [a_dep, b_dep]) diff --git a/test cases/failing/68 subproj different versions/subprojects/a/a.c b/test cases/failing/68 subproj different versions/subprojects/a/a.c new file mode 100644 index 0000000..cd41a65 --- /dev/null +++ b/test cases/failing/68 subproj different versions/subprojects/a/a.c @@ -0,0 +1,5 @@ +#include "c.h" + +int a_fun() { + return c_fun(); +} diff --git a/test cases/failing/68 subproj different versions/subprojects/a/a.h b/test cases/failing/68 subproj different versions/subprojects/a/a.h new file mode 100644 index 0000000..8f1d49e --- /dev/null +++ b/test cases/failing/68 subproj different versions/subprojects/a/a.h @@ -0,0 +1 @@ +int a_fun(); diff --git a/test cases/failing/68 subproj different versions/subprojects/a/meson.build b/test cases/failing/68 subproj different versions/subprojects/a/meson.build new file mode 100644 index 0000000..e84182a --- /dev/null +++ b/test cases/failing/68 subproj different versions/subprojects/a/meson.build @@ -0,0 +1,11 @@ +project('a', 'c') + +c_dep = dependency('c', version:'1', fallback: ['c', 'c_dep']) + +alib = library('a', 'a.c', + dependencies: c_dep) + +a_dep = declare_dependency( + link_with: alib, + include_directories: include_directories('.'), +) diff --git a/test cases/failing/68 subproj different versions/subprojects/b/b.c b/test cases/failing/68 subproj different versions/subprojects/b/b.c new file mode 100644 index 0000000..f85f8c3 --- /dev/null +++ b/test cases/failing/68 subproj different versions/subprojects/b/b.c @@ -0,0 +1,5 @@ +#include "c.h" + +int b_fun(){ +return c_fun(); +} diff --git a/test cases/failing/68 subproj different versions/subprojects/b/b.h b/test cases/failing/68 subproj different versions/subprojects/b/b.h new file mode 100644 index 0000000..eced786 --- /dev/null +++ b/test cases/failing/68 subproj different versions/subprojects/b/b.h @@ -0,0 +1 @@ +int b_fun(); diff --git a/test cases/failing/68 subproj different versions/subprojects/b/meson.build b/test cases/failing/68 subproj different versions/subprojects/b/meson.build new file mode 100644 index 0000000..0398340 --- /dev/null +++ b/test cases/failing/68 subproj different versions/subprojects/b/meson.build @@ -0,0 +1,11 @@ +project('b', 'c') + +c_dep = dependency('c', version:'2', fallback: ['c', 'c_dep']) + +blib = library('b', 'b.c', + dependencies: c_dep) + +b_dep = declare_dependency( + link_with: blib, + include_directories: include_directories('.'), +) diff --git a/test cases/failing/68 subproj different versions/subprojects/c/c.h b/test cases/failing/68 subproj different versions/subprojects/c/c.h new file mode 100644 index 0000000..2b15f60 --- /dev/null +++ b/test cases/failing/68 subproj different versions/subprojects/c/c.h @@ -0,0 +1,3 @@ +static int c_fun(){ + return 3; +} diff --git a/test cases/failing/68 subproj different versions/subprojects/c/meson.build b/test cases/failing/68 subproj different versions/subprojects/c/meson.build new file mode 100644 index 0000000..7184933 --- /dev/null +++ b/test cases/failing/68 subproj different versions/subprojects/c/meson.build @@ -0,0 +1,5 @@ +project('c', 'c', version:'1') + +c_dep = declare_dependency( + include_directories: include_directories('.') +) diff --git a/test cases/linuxlike/12 subprojects in subprojects/main.c b/test cases/linuxlike/12 subprojects in subprojects/main.c new file mode 100644 index 0000000..8793c62 --- /dev/null +++ b/test cases/linuxlike/12 subprojects in subprojects/main.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include "a.h" +#include "b.h" + +int main(int argc, char **argv) { + int life = a_fun() + b_fun(); + printf("%d\n", life); + return 0; +} diff --git a/test cases/linuxlike/12 subprojects in subprojects/meson.build b/test cases/linuxlike/12 subprojects in subprojects/meson.build new file mode 100644 index 0000000..4014149 --- /dev/null +++ b/test cases/linuxlike/12 subprojects in subprojects/meson.build @@ -0,0 +1,9 @@ +project('super', 'c') + +# A will use version 1 of C +a_dep = dependency('a', fallback: ['a', 'a_dep']) + +# B has an optional dependency on C version 2 and will therefore work +b_dep = dependency('b', fallback: ['b', 'b_dep']) + +main = executable('main', files('main.c'), dependencies: [a_dep, b_dep]) diff --git a/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.c b/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.c new file mode 100644 index 0000000..cd41a65 --- /dev/null +++ b/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.c @@ -0,0 +1,5 @@ +#include "c.h" + +int a_fun() { + return c_fun(); +} diff --git a/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.h b/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.h new file mode 100644 index 0000000..8f1d49e --- /dev/null +++ b/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.h @@ -0,0 +1 @@ +int a_fun(); diff --git a/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/meson.build b/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/meson.build new file mode 100644 index 0000000..5f579a3 --- /dev/null +++ b/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/meson.build @@ -0,0 +1,11 @@ +project('a', 'c', version:'1.0') + +c_dep = dependency('c', version:'1', fallback: ['c', 'c_dep']) + +alib = library('a', 'a.c', + dependencies: c_dep) + +a_dep = declare_dependency( + link_with: alib, + include_directories: include_directories('.'), +) diff --git a/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.c b/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.c new file mode 100644 index 0000000..4824285 --- /dev/null +++ b/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.c @@ -0,0 +1,11 @@ +#if defined(WITH_C) +#include "c.h" +#endif + +int b_fun(){ +#if defined(WITH_C) +return c_fun(); +#else +return 0; +#endif +} diff --git a/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.h b/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.h new file mode 100644 index 0000000..eced786 --- /dev/null +++ b/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.h @@ -0,0 +1 @@ +int b_fun(); diff --git a/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/meson.build b/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/meson.build new file mode 100644 index 0000000..80903f3 --- /dev/null +++ b/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/meson.build @@ -0,0 +1,17 @@ +project('b', 'c') + +c_dep = dependency('c', version:'2', fallback: ['c', 'c_dep'], required: false) + +assert(c_dep.found() == false, 'C project has the wrong version and should not be found') + +if c_dep.found() + add_global_arguments('-DWITH_C', language: 'c') +endif + +blib = library('b', 'b.c', + dependencies: c_dep) + +b_dep = declare_dependency( + link_with: blib, + include_directories: include_directories('.'), +) diff --git a/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/c.h b/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/c.h new file mode 100644 index 0000000..2b15f60 --- /dev/null +++ b/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/c.h @@ -0,0 +1,3 @@ +static int c_fun(){ + return 3; +} diff --git a/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/meson.build b/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/meson.build new file mode 100644 index 0000000..7184933 --- /dev/null +++ b/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/meson.build @@ -0,0 +1,5 @@ +project('c', 'c', version:'1') + +c_dep = declare_dependency( + include_directories: include_directories('.') +) diff --git a/test cases/linuxlike/5 dependency versions/meson.build b/test cases/linuxlike/5 dependency versions/meson.build index d4140b7..5d9eb32 100644 --- a/test cases/linuxlike/5 dependency versions/meson.build +++ b/test cases/linuxlike/5 dependency versions/meson.build @@ -41,6 +41,11 @@ assert(somelibver.type_name() == 'internal', 'somelibver should be of type "inte somelib = dependency('somelib', version : '== 0.1', fallback : ['somelib', 'some_dep']) +# Find an internal dependency again even if required = false +somelib_reqfalse = dependency('somelib', + required: false, + fallback : ['somelib', 'some_dep']) +assert(somelib_reqfalse.found(), 'somelib should have been found') # Find an internal dependency again with the same name and incompatible version somelibver = dependency('somelib', version : '>= 0.3', |