Merge pull request #2551 from mesonbuild/fix2481

Evaluate subproject directory name correctly
pull/2555/merge
Jussi Pakkanen 7 years ago committed by GitHub
commit 3faf35ac64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      mesonbuild/interpreter.py
  2. 13
      test cases/common/163 subproject dir name collision/a.c
  3. 20
      test cases/common/163 subproject dir name collision/custom_subproject_dir/B/b.c
  4. 4
      test cases/common/163 subproject dir name collision/custom_subproject_dir/B/meson.build
  5. 14
      test cases/common/163 subproject dir name collision/custom_subproject_dir/C/c.c
  6. 2
      test cases/common/163 subproject dir name collision/custom_subproject_dir/C/meson.build
  7. 12
      test cases/common/163 subproject dir name collision/meson.build
  8. 19
      test cases/common/163 subproject dir name collision/other_subdir/custom_subproject_dir/other.c
  9. 1
      test cases/common/163 subproject dir name collision/other_subdir/meson.build

@ -2811,6 +2811,16 @@ different subdirectory.
super().run()
mlog.log('Build targets in project:', mlog.bold(str(len(self.build.targets))))
def evaluate_subproject_info(self, path_from_source_root, subproject_dirname):
depth = 0
subproj_name = ''
segs = path_from_source_root.split(os.path.sep)
while segs and segs[0] == subproject_dirname:
depth += 1
subproj_name = segs[1]
segs = segs[2:]
return (depth, subproj_name)
# Check that the indicated file is within the same subproject
# as we currently are. This is to stop people doing
# nasty things like:
@ -2832,17 +2842,16 @@ different subdirectory.
return
norm = os.path.relpath(norm, self.environment.source_dir)
assert(not os.path.isabs(norm))
segments = norm.split(os.path.sep)
num_sps = segments.count(self.subproject_dir)
(num_sps, sproj_name) = self.evaluate_subproject_info(norm, self.subproject_dir)
plain_filename = os.path.split(norm)[-1]
if num_sps == 0:
if self.subproject == '':
return
raise InterpreterException('Sandbox violation: Tried to grab file %s from a different subproject.' % segments[-1])
raise InterpreterException('Sandbox violation: Tried to grab file %s from a different subproject.' % plain_filename)
if num_sps > 1:
raise InterpreterException('Sandbox violation: Tried to grab file %s from a nested subproject.' % segments[-1])
sproj_name = segments[segments.index(self.subproject_dir) + 1]
raise InterpreterException('Sandbox violation: Tried to grab file %s from a nested subproject.' % plain_filename)
if sproj_name != self.subproject_directory_name:
raise InterpreterException('Sandbox violation: Tried to grab file %s from a different subproject.' % segments[-1])
raise InterpreterException('Sandbox violation: Tried to grab file %s from a different subproject.' % plain_filename)
def source_strings_to_files(self, sources):
results = []

@ -0,0 +1,13 @@
#include<assert.h>
char func_b();
char func_c();
int main(int argc, char **argv) {
if(func_b() != 'b') {
return 1;
}
if(func_c() != 'c') {
return 2;
}
return 0;
}

@ -0,0 +1,20 @@
#include<stdlib.h>
char func_c();
#if defined _WIN32 || defined __CYGWIN__
#define DLL_PUBLIC __declspec(dllexport)
#else
#if defined __GNUC__
#define DLL_PUBLIC __attribute__ ((visibility("default")))
#else
#pragma message ("Compiler does not support symbol visibility.")
#define DLL_PUBLIC
#endif
#endif
char DLL_PUBLIC func_b() {
if(func_c() != 'c') {
exit(3);
}
return 'b';
}

@ -0,0 +1,4 @@
project('B', 'c')
C = subproject('C')
c = C.get_variable('c')
b = shared_library('b', 'b.c', link_with : c)

@ -0,0 +1,14 @@
#if defined _WIN32 || defined __CYGWIN__
#define DLL_PUBLIC __declspec(dllexport)
#else
#if defined __GNUC__
#define DLL_PUBLIC __attribute__ ((visibility("default")))
#else
#pragma message ("Compiler does not support symbol visibility.")
#define DLL_PUBLIC
#endif
#endif
char DLL_PUBLIC func_c() {
return 'c';
}

@ -0,0 +1,12 @@
project('A', 'c', subproject_dir:'custom_subproject_dir')
B = subproject('B')
b = B.get_variable('b')
C = subproject('C')
c = C.get_variable('c')
subdir('other_subdir')
a = executable('a', 'a.c', link_with : [b, c])
test('a test', a)

@ -0,0 +1,19 @@
#include<stdlib.h>
#if defined _WIN32 || defined __CYGWIN__
#define DLL_PUBLIC __declspec(dllexport)
#else
#if defined __GNUC__
#define DLL_PUBLIC __attribute__ ((visibility("default")))
#else
#pragma message ("Compiler does not support symbol visibility.")
#define DLL_PUBLIC
#endif
#endif
char DLL_PUBLIC func_b() {
if('c' != 'c') {
exit(3);
}
return 'b';
}

@ -0,0 +1 @@
other = shared_library('other', 'custom_subproject_dir/other.c')
Loading…
Cancel
Save