diff options
11 files changed, 61 insertions, 84 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 9bfc9be23..2211f997a 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -3530,11 +3530,6 @@ class Interpreter(InterpreterBase, HoldableObject): elif isinstance(s, build.StructuredSources): self.check_for_jar_sources(s.as_list(), targetclass) - # Only permit object extraction from the same subproject - def validate_extraction(self, buildtarget: mesonlib.HoldableObject) -> None: - if self.subproject != buildtarget.subproject: - raise InterpreterException('Tried to extract objects from a different subproject.') - def is_subproject(self) -> bool: return self.subproject != '' diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py index c4f56091a..4ff7e903e 100644 --- a/mesonbuild/interpreter/interpreterobjects.py +++ b/mesonbuild/interpreter/interpreterobjects.py @@ -950,6 +950,8 @@ class BuildTargetHolder(ObjectHolder[_BuildTarget]): @typed_pos_args('extract_objects', varargs=(mesonlib.File, str, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList)) @InterpreterObject.method('extract_objects') def extract_objects_method(self, args: T.Tuple[T.List[T.Union[mesonlib.FileOrString, 'build.GeneratedTypes']]], kwargs: TYPE_nkwargs) -> build.ExtractedObjects: + if self.subproject != self.held_object.subproject: + raise InterpreterException('Tried to extract objects from a different subproject.') tobj = self._target_object unity_value = self.interpreter.coredata.get_option_for_target(tobj, "unity") is_unity = (unity_value == 'on' or (unity_value == 'subprojects' and tobj.subproject != '')) diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py index 588932cad..f40a27e31 100644 --- a/mesonbuild/interpreterbase/interpreterbase.py +++ b/mesonbuild/interpreterbase/interpreterbase.py @@ -555,12 +555,6 @@ class InterpreterBase: return Disabler() if not isinstance(obj, InterpreterObject): raise InvalidArguments(f'{object_display_name} is not callable.') - # TODO: InterpreterBase **really** shouldn't be in charge of checking this - if method_name == 'extract_objects': - if isinstance(obj, ObjectHolder): - self.validate_extraction(obj.held_object) - elif not isinstance(obj, Disabler): - raise InvalidArguments(f'Invalid operation "extract_objects" on {object_display_name} of type {type(obj).__name__}') obj.current_node = self.current_node = node res = obj.method_call(method_name, args, kwargs) return self._holderify(res) if res is not None else None @@ -675,9 +669,6 @@ class InterpreterBase: return self.variables[varname] raise InvalidCode(f'Unknown variable "{varname}".') - def validate_extraction(self, buildtarget: mesonlib.HoldableObject) -> None: - raise InterpreterException('validate_extraction is not implemented in this context (please file a bug)') - def _load_option_file(self) -> None: from .. import optinterpreter # prevent circular import diff --git a/test cases/common/22 object extraction/meson.build b/test cases/common/22 object extraction/meson.build index 37ac66dc1..cc6de6fca 100644 --- a/test cases/common/22 object extraction/meson.build +++ b/test cases/common/22 object extraction/meson.build @@ -1,50 +1,57 @@ project('object extraction', 'c') if meson.is_unity() - message('Skipping extraction test because this is a Unity build.') -else - lib1 = library('somelib', 'src/lib.c') - lib2 = library('somelib2', 'lib.c', 'header.h', 'lib2.c') - - obj1 = lib1.extract_objects('src/lib.c') - obj2 = lib2.extract_objects(['lib.c']) - obj3 = lib2.extract_objects(files('lib.c')) - obj4 = lib2.extract_objects(['lib.c', 'lib.c']) - obj5 = lib2.extract_objects(['lib.c', 'header.h']) - obj6 = lib2.extract_all_objects(recursive: true) - - e1 = executable('main1', 'main.c', objects : obj1) - e2 = executable('main2', 'main.c', objects : obj2) - e3 = executable('main3', 'main.c', objects : obj3) - e4 = executable('main4', 'main.c', objects : obj4) - e5 = executable('main5', 'main.c', objects : obj5) - e6 = executable('main6', 'main.c', objects : obj6) - - ct_src = custom_target('lib3.c', output: 'lib3.c', capture: true, - command: [find_program('create-source.py'), 'lib.c']) - lib3 = library('somelib3', ct_src) - e7 = executable('main7', 'main.c', objects: lib3.extract_objects(ct_src[0])) - e8 = executable('main8', 'main.c', objects: lib3.extract_objects(ct_src)) + error('MESON_SKIP_TEST, Skipping extraction test because this is a Unity build.') +endif - gen = generator(find_program('create-source.py'), arguments: ['@INPUT@'], - output: '@BASENAME@4.c', capture: true) - gen_src = gen.process('lib.c') - lib4 = library('somelib4', gen_src) - e9 = executable('main9', 'main.c', objects: lib4.extract_objects(gen_src)) +lib1 = library('somelib', 'src/lib.c') +lib2 = library('somelib2', 'lib.c', 'header.h', 'lib2.c') +obj1 = lib1.extract_objects('src/lib.c') +obj2 = lib2.extract_objects(['lib.c']) +obj3 = lib2.extract_objects(files('lib.c')) +obj4 = lib2.extract_objects(['lib.c', 'lib.c']) +obj5 = lib2.extract_objects(['lib.c', 'header.h']) +obj6 = lib2.extract_all_objects(recursive: true) +e1 = executable('main1', 'main.c', objects : obj1) +e2 = executable('main2', 'main.c', objects : obj2) +e3 = executable('main3', 'main.c', objects : obj3) +e4 = executable('main4', 'main.c', objects : obj4) +e5 = executable('main5', 'main.c', objects : obj5) +e6 = executable('main6', 'main.c', objects : obj6) +ct_src = custom_target('lib3.c', output: 'lib3.c', capture: true, + command: [find_program('create-source.py'), 'lib.c']) +lib3 = library('somelib3', ct_src) +e7 = executable('main7', 'main.c', objects: lib3.extract_objects(ct_src[0])) +e8 = executable('main8', 'main.c', objects: lib3.extract_objects(ct_src)) +gen = generator(find_program('create-source.py'), arguments: ['@INPUT@'], + output: '@BASENAME@4.c', capture: true) +gen_src = gen.process('lib.c') +lib4 = library('somelib4', gen_src) +e9 = executable('main9', 'main.c', objects: lib4.extract_objects(gen_src)) +custom_target('custom_target with object inputs', output: 'objs', + input: [obj1, obj2, obj3, obj5, obj6], + build_by_default: true, + command: [find_program('check-obj.py'), meson.backend(), '@INPUT@'], + capture: true) +test('extraction test 1', e1) +test('extraction test 2', e2) +test('extraction test 3', e3) +test('extraction test 4', e4) +test('extraction test 5', e5) +test('extraction test 6', e6) +test('extraction test 7', e7) +test('extraction test 8', e8) +test('extraction test 9', e9) - custom_target('custom_target with object inputs', output: 'objs', - input: [obj1, obj2, obj3, obj5, obj6], - build_by_default: true, - command: [find_program('check-obj.py'), meson.backend(), '@INPUT@'], - capture: true) +lib = subproject('sub').get_variable('lib') +testcase expect_error('Tried to extract objects from a different subproject.') + lib.extract_objects() +endtestcase - test('extraction test 1', e1) - test('extraction test 2', e2) - test('extraction test 3', e3) - test('extraction test 4', e4) - test('extraction test 5', e5) - test('extraction test 6', e6) - test('extraction test 7', e7) - test('extraction test 8', e8) - test('extraction test 9', e9) +cc = meson.get_compiler('c') +lib = cc.find_library('z', required: false) +if lib.found() + testcase expect_error('Unknown method .*', how: 're') + lib.extract_objects() + endtestcase endif diff --git a/test cases/common/22 object extraction/subprojects/sub/meson.build b/test cases/common/22 object extraction/subprojects/sub/meson.build new file mode 100644 index 000000000..e7fbb28a3 --- /dev/null +++ b/test cases/common/22 object extraction/subprojects/sub/meson.build @@ -0,0 +1,4 @@ +project('sub', 'c') + +lib = static_library('a', 'source.c') +lib.extract_objects() diff --git a/test cases/common/22 object extraction/subprojects/sub/source.c b/test cases/common/22 object extraction/subprojects/sub/source.c new file mode 100644 index 000000000..0584ef42a --- /dev/null +++ b/test cases/common/22 object extraction/subprojects/sub/source.c @@ -0,0 +1,5 @@ +int func(void); + +int func(void) { + return 1; +} diff --git a/test cases/failing/16 extract from subproject/main.c b/test cases/failing/16 extract from subproject/main.c deleted file mode 100644 index 6c8ecaea5..000000000 --- a/test cases/failing/16 extract from subproject/main.c +++ /dev/null @@ -1,5 +0,0 @@ -int sub_lib_method(void); - -int main(void) { - return 1337 - sub_lib_method(); -} diff --git a/test cases/failing/16 extract from subproject/meson.build b/test cases/failing/16 extract from subproject/meson.build deleted file mode 100644 index 286aaa191..000000000 --- a/test cases/failing/16 extract from subproject/meson.build +++ /dev/null @@ -1,9 +0,0 @@ -project('extract subproject object', 'c') - -sub = subproject('sub_project') -lib = sub.get_variable('lib') - -exe = executable('exe', 'main.c', - objects : lib.extract_objects('sub_lib.c')) - -test('extraction test', exe) diff --git a/test cases/failing/16 extract from subproject/subprojects/sub_project/meson.build b/test cases/failing/16 extract from subproject/subprojects/sub_project/meson.build deleted file mode 100644 index 0810df503..000000000 --- a/test cases/failing/16 extract from subproject/subprojects/sub_project/meson.build +++ /dev/null @@ -1,3 +0,0 @@ -project('extract subproject object -- subproject', 'c') - -lib = library('sub_lib', 'sub_lib.c') diff --git a/test cases/failing/16 extract from subproject/subprojects/sub_project/sub_lib.c b/test cases/failing/16 extract from subproject/subprojects/sub_project/sub_lib.c deleted file mode 100644 index be3c9aae2..000000000 --- a/test cases/failing/16 extract from subproject/subprojects/sub_project/sub_lib.c +++ /dev/null @@ -1,3 +0,0 @@ -int sub_lib_method() { - return 1337; -} diff --git a/test cases/failing/16 extract from subproject/test.json b/test cases/failing/16 extract from subproject/test.json deleted file mode 100644 index 161603368..000000000 --- a/test cases/failing/16 extract from subproject/test.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "stdout": [ - { - "line": "test cases/failing/16 extract from subproject/meson.build:7:32: ERROR: Tried to extract objects from a different subproject." - } - ] -} |
