Merge pull request #2581 from NickeZ/check-subproj-version

Disallow subprojects have incompatible deps
pull/2832/head
Jussi Pakkanen 7 years ago committed by GitHub
commit d55e98ef50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      mesonbuild/interpreter.py
  2. 9
      test cases/failing/68 subproj different versions/main.c
  3. 9
      test cases/failing/68 subproj different versions/meson.build
  4. 5
      test cases/failing/68 subproj different versions/subprojects/a/a.c
  5. 1
      test cases/failing/68 subproj different versions/subprojects/a/a.h
  6. 11
      test cases/failing/68 subproj different versions/subprojects/a/meson.build
  7. 5
      test cases/failing/68 subproj different versions/subprojects/b/b.c
  8. 1
      test cases/failing/68 subproj different versions/subprojects/b/b.h
  9. 11
      test cases/failing/68 subproj different versions/subprojects/b/meson.build
  10. 3
      test cases/failing/68 subproj different versions/subprojects/c/c.h
  11. 5
      test cases/failing/68 subproj different versions/subprojects/c/meson.build
  12. 9
      test cases/linuxlike/12 subprojects in subprojects/main.c
  13. 9
      test cases/linuxlike/12 subprojects in subprojects/meson.build
  14. 5
      test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.c
  15. 1
      test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.h
  16. 11
      test cases/linuxlike/12 subprojects in subprojects/subprojects/a/meson.build
  17. 11
      test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.c
  18. 1
      test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.h
  19. 17
      test cases/linuxlike/12 subprojects in subprojects/subprojects/b/meson.build
  20. 3
      test cases/linuxlike/12 subprojects in subprojects/subprojects/c/c.h
  21. 5
      test cases/linuxlike/12 subprojects in subprojects/subprojects/c/meson.build
  22. 5
      test cases/linuxlike/5 dependency versions/meson.build

@ -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

@ -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;
}

@ -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])

@ -0,0 +1,5 @@
#include "c.h"
int a_fun() {
return c_fun();
}

@ -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('.'),
)

@ -0,0 +1,5 @@
#include "c.h"
int b_fun(){
return c_fun();
}

@ -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('.'),
)

@ -0,0 +1,5 @@
project('c', 'c', version:'1')
c_dep = declare_dependency(
include_directories: include_directories('.')
)

@ -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;
}

@ -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])

@ -0,0 +1,5 @@
#include "c.h"
int a_fun() {
return c_fun();
}

@ -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('.'),
)

@ -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
}

@ -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('.'),
)

@ -0,0 +1,5 @@
project('c', 'c', version:'1')
c_dep = declare_dependency(
include_directories: include_directories('.')
)

@ -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',

Loading…
Cancel
Save