From ec74616bbd7b16b3ce0b953e02e83c50252c73db Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Wed, 17 Jun 2015 20:16:28 +0300 Subject: [PATCH] Prevent extraction of objects from subprojects. --- interpreter.py | 13 ++++++++++++- .../failing/16 extract object subdir/meson.build | 4 ++++ .../16 extract object subdir/src/first/lib_first.c | 3 +++ .../16 extract object subdir/src/first/meson.build | 1 + .../16 extract object subdir/src/meson.build | 1 + .../16 extract object subdir/tst/first/exe_first.c | 5 +++++ .../16 extract object subdir/tst/first/meson.build | 4 ++++ .../16 extract object subdir/tst/meson.build | 1 + 8 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test cases/failing/16 extract object subdir/meson.build create mode 100644 test cases/failing/16 extract object subdir/src/first/lib_first.c create mode 100644 test cases/failing/16 extract object subdir/src/first/meson.build create mode 100644 test cases/failing/16 extract object subdir/src/meson.build create mode 100644 test cases/failing/16 extract object subdir/tst/first/exe_first.c create mode 100644 test cases/failing/16 extract object subdir/tst/first/meson.build create mode 100644 test cases/failing/16 extract object subdir/tst/meson.build diff --git a/interpreter.py b/interpreter.py index 54a388210..5db9717f8 100644 --- a/interpreter.py +++ b/interpreter.py @@ -1650,7 +1650,7 @@ class Interpreter(): elif targetholder is JarHolder: targetclass = build.Jar else: - print(targetholder) + mlog.debug('Unknown target type:', str(targetholder)) raise RuntimeError('Unreachable code') target = targetclass(name, self.subdir, is_cross, sources, objs, self.environment, kwargs) l = targetholder(target) @@ -1770,8 +1770,19 @@ class Interpreter(): if not isinstance(obj, InterpreterObject): raise InvalidArguments('Variable "%s" is not callable.' % object_name) (args, kwargs) = self.reduce_arguments(args) + if method_name == 'extract_objects': + self.validate_extraction(obj.held_object) return obj.method_call(method_name, args, kwargs) + def validate_extraction(self, buildtarget): + if self.subproject_dir == '': + if buildtarget.subdir.startswith(self.subproject_dir): + raise InterpreterException('Tried to extract objects from a subproject target.') + else: + lead = '/'.join(self.subdir.split('/')[0:2]) + if not buildtarget.subdir.startswith(lead): + raise InterpreterException('Tried to extract objects from a different subproject target.') + def array_method_call(self, obj, method_name, args): if method_name == 'contains': return self.check_contains(obj, args) diff --git a/test cases/failing/16 extract object subdir/meson.build b/test cases/failing/16 extract object subdir/meson.build new file mode 100644 index 000000000..6db429053 --- /dev/null +++ b/test cases/failing/16 extract object subdir/meson.build @@ -0,0 +1,4 @@ +project('Extract objects from subdirs.', 'c') + +subdir('src') +subdir('tst') diff --git a/test cases/failing/16 extract object subdir/src/first/lib_first.c b/test cases/failing/16 extract object subdir/src/first/lib_first.c new file mode 100644 index 000000000..01e06b62f --- /dev/null +++ b/test cases/failing/16 extract object subdir/src/first/lib_first.c @@ -0,0 +1,3 @@ +int first() { + return 1001; +} diff --git a/test cases/failing/16 extract object subdir/src/first/meson.build b/test cases/failing/16 extract object subdir/src/first/meson.build new file mode 100644 index 000000000..b97aef44e --- /dev/null +++ b/test cases/failing/16 extract object subdir/src/first/meson.build @@ -0,0 +1 @@ +first_lib = shared_library('first_lib', 'lib_first.c') diff --git a/test cases/failing/16 extract object subdir/src/meson.build b/test cases/failing/16 extract object subdir/src/meson.build new file mode 100644 index 000000000..3f5ec3200 --- /dev/null +++ b/test cases/failing/16 extract object subdir/src/meson.build @@ -0,0 +1 @@ +subdir('first') diff --git a/test cases/failing/16 extract object subdir/tst/first/exe_first.c b/test cases/failing/16 extract object subdir/tst/first/exe_first.c new file mode 100644 index 000000000..4f714df2c --- /dev/null +++ b/test cases/failing/16 extract object subdir/tst/first/exe_first.c @@ -0,0 +1,5 @@ +int first(void); + +int main() { + return first() - 1001; +} diff --git a/test cases/failing/16 extract object subdir/tst/first/meson.build b/test cases/failing/16 extract object subdir/tst/first/meson.build new file mode 100644 index 000000000..a6fa7da1b --- /dev/null +++ b/test cases/failing/16 extract object subdir/tst/first/meson.build @@ -0,0 +1,4 @@ +first_exe = executable('first_exe', 'exe_first.c', + objects : first_lib.extract_objects('lib_first.c')) + +test('first_test', first_exe) diff --git a/test cases/failing/16 extract object subdir/tst/meson.build b/test cases/failing/16 extract object subdir/tst/meson.build new file mode 100644 index 000000000..3f5ec3200 --- /dev/null +++ b/test cases/failing/16 extract object subdir/tst/meson.build @@ -0,0 +1 @@ +subdir('first')