From 8a7ac6ba4c26ace86d9291b5d937dedc9e7c7491 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 23 Mar 2017 12:44:13 +0530 Subject: [PATCH] vs: Fix custom target generated object paths The paths are already relative to the target dir. Includes a test for this which generates and builds in subdirs. If all the generation and usage is done in the build root, this bug will obviously not be triggered. --- mesonbuild/backend/vs2010backend.py | 2 +- .../meson.build | 16 ++++++++++++++++ .../obj_generator.py | 18 ++++++++++++++++++ .../objdir/meson.build | 5 +++++ .../objdir/source.c | 3 +++ .../progdir/meson.build | 1 + .../progdir/prog.c | 5 +++++ 7 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 test cases/common/139 custom target object output/meson.build create mode 100644 test cases/common/139 custom target object output/obj_generator.py create mode 100644 test cases/common/139 custom target object output/objdir/meson.build create mode 100644 test cases/common/139 custom target object output/objdir/source.c create mode 100644 test cases/common/139 custom target object output/progdir/meson.build create mode 100644 test cases/common/139 custom target object output/progdir/prog.c diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index 929fa936f..84e829650 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -918,7 +918,7 @@ class Vs2010Backend(backends.Backend): assert(isinstance(o, str)) additional_objects.append(o) for o in custom_objs: - additional_objects.append(self.relpath(o, self.get_target_dir(target))) + additional_objects.append(o) if len(additional_links) > 0: additional_links.append('%(AdditionalDependencies)') ET.SubElement(link, 'AdditionalDependencies').text = ';'.join(additional_links) diff --git a/test cases/common/139 custom target object output/meson.build b/test cases/common/139 custom target object output/meson.build new file mode 100644 index 000000000..ede165bd4 --- /dev/null +++ b/test cases/common/139 custom target object output/meson.build @@ -0,0 +1,16 @@ +project('custom target object output', 'c') + +comp = find_program('obj_generator.py') + +if host_machine.system() == 'windows' + outputname = '@BASENAME@.obj' +else + outputname = '@BASENAME@.o' +endif + +cc = meson.get_compiler('c').cmd_array().get(-1) + +subdir('objdir') +subdir('progdir') + +test('objgen', e) diff --git a/test cases/common/139 custom target object output/obj_generator.py b/test cases/common/139 custom target object output/obj_generator.py new file mode 100644 index 000000000..a33872aac --- /dev/null +++ b/test cases/common/139 custom target object output/obj_generator.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +# Mimic a binary that generates an object file (e.g. windres). + +import sys, subprocess + +if __name__ == '__main__': + if len(sys.argv) != 4: + print(sys.argv[0], 'compiler input_file output_file') + sys.exit(1) + compiler = sys.argv[1] + ifile = sys.argv[2] + ofile = sys.argv[3] + if compiler.endswith('cl'): + cmd = [compiler, '/nologo', '/MDd', '/Fo' + ofile, '/c', ifile] + else: + cmd = [compiler, '-c', ifile, '-o', ofile] + sys.exit(subprocess.call(cmd)) diff --git a/test cases/common/139 custom target object output/objdir/meson.build b/test cases/common/139 custom target object output/objdir/meson.build new file mode 100644 index 000000000..0d7f6c259 --- /dev/null +++ b/test cases/common/139 custom target object output/objdir/meson.build @@ -0,0 +1,5 @@ +# Generate an object file manually. +object = custom_target('object', + input : 'source.c', + output : outputname, + command : [comp, cc, '@INPUT@', '@OUTPUT@']) diff --git a/test cases/common/139 custom target object output/objdir/source.c b/test cases/common/139 custom target object output/objdir/source.c new file mode 100644 index 000000000..7779b332c --- /dev/null +++ b/test cases/common/139 custom target object output/objdir/source.c @@ -0,0 +1,3 @@ +int func1_in_obj() { + return 0; +} diff --git a/test cases/common/139 custom target object output/progdir/meson.build b/test cases/common/139 custom target object output/progdir/meson.build new file mode 100644 index 000000000..4216c24a6 --- /dev/null +++ b/test cases/common/139 custom target object output/progdir/meson.build @@ -0,0 +1 @@ +e = executable('prog', 'prog.c', object) diff --git a/test cases/common/139 custom target object output/progdir/prog.c b/test cases/common/139 custom target object output/progdir/prog.c new file mode 100644 index 000000000..c1ece33fb --- /dev/null +++ b/test cases/common/139 custom target object output/progdir/prog.c @@ -0,0 +1,5 @@ +int func1_in_obj(); + +int main(int argc, char **argv) { + return func1_in_obj(); +}