aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2015-06-17 20:16:28 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2015-06-17 20:16:28 +0300
commitec74616bbd7b16b3ce0b953e02e83c50252c73db (patch)
tree350d5ad00423a0dd53409668b98f60c81d5c22c8
parent83aa2262e36b596173fc310b4f22971391dc1083 (diff)
downloadmeson-ec74616bbd7b16b3ce0b953e02e83c50252c73db.zip
meson-ec74616bbd7b16b3ce0b953e02e83c50252c73db.tar.gz
meson-ec74616bbd7b16b3ce0b953e02e83c50252c73db.tar.bz2
Prevent extraction of objects from subprojects.
-rw-r--r--interpreter.py13
-rw-r--r--test cases/failing/16 extract object subdir/meson.build4
-rw-r--r--test cases/failing/16 extract object subdir/src/first/lib_first.c3
-rw-r--r--test cases/failing/16 extract object subdir/src/first/meson.build1
-rw-r--r--test cases/failing/16 extract object subdir/src/meson.build1
-rw-r--r--test cases/failing/16 extract object subdir/tst/first/exe_first.c5
-rw-r--r--test cases/failing/16 extract object subdir/tst/first/meson.build4
-rw-r--r--test cases/failing/16 extract object subdir/tst/meson.build1
8 files changed, 31 insertions, 1 deletions
diff --git a/interpreter.py b/interpreter.py
index 54a3882..5db9717 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 0000000..6db4290
--- /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 0000000..01e06b6
--- /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 0000000..b97aef4
--- /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 0000000..3f5ec32
--- /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 0000000..4f714df
--- /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 0000000..a6fa7da
--- /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 0000000..3f5ec32
--- /dev/null
+++ b/test cases/failing/16 extract object subdir/tst/meson.build
@@ -0,0 +1 @@
+subdir('first')