From f42d0f506331290869506b0405e7f4f1862d9c48 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Tue, 27 Sep 2016 01:08:35 +0530 Subject: [PATCH 1/2] Add a vala test for generated sources in subdirs Modified from a test case provided by @benwaffle on https://github.com/mesonbuild/meson/issues/815 --- test cases/vala/8 generated source/installed_files.txt | 1 + test cases/vala/8 generated source/meson.build | 7 +++++++ test cases/vala/8 generated source/src/config.vala.in | 3 +++ test cases/vala/8 generated source/src/meson.build | 5 +++++ test cases/vala/8 generated source/src/test.vala | 3 +++ test cases/vala/8 generated source/tools/meson.build | 3 +++ 6 files changed, 22 insertions(+) create mode 100644 test cases/vala/8 generated source/installed_files.txt create mode 100644 test cases/vala/8 generated source/meson.build create mode 100644 test cases/vala/8 generated source/src/config.vala.in create mode 100644 test cases/vala/8 generated source/src/meson.build create mode 100644 test cases/vala/8 generated source/src/test.vala create mode 100644 test cases/vala/8 generated source/tools/meson.build diff --git a/test cases/vala/8 generated source/installed_files.txt b/test cases/vala/8 generated source/installed_files.txt new file mode 100644 index 000000000..a4c37f6ed --- /dev/null +++ b/test cases/vala/8 generated source/installed_files.txt @@ -0,0 +1 @@ +usr/bin/generatedtest diff --git a/test cases/vala/8 generated source/meson.build b/test cases/vala/8 generated source/meson.build new file mode 100644 index 000000000..7271821da --- /dev/null +++ b/test cases/vala/8 generated source/meson.build @@ -0,0 +1,7 @@ +project('mytest', 'vala', 'c') + +cd = configuration_data() +cd.set('x', 'y') + +subdir('src') +subdir('tools') diff --git a/test cases/vala/8 generated source/src/config.vala.in b/test cases/vala/8 generated source/src/config.vala.in new file mode 100644 index 000000000..a5196fdf1 --- /dev/null +++ b/test cases/vala/8 generated source/src/config.vala.in @@ -0,0 +1,3 @@ +namespace Config { + public static const string x = "@x@"; +} diff --git a/test cases/vala/8 generated source/src/meson.build b/test cases/vala/8 generated source/src/meson.build new file mode 100644 index 000000000..9096c678c --- /dev/null +++ b/test cases/vala/8 generated source/src/meson.build @@ -0,0 +1,5 @@ +config = configure_file(input: 'config.vala.in', + output: 'config.vala', + configuration: cd) + +src = files('test.vala') diff --git a/test cases/vala/8 generated source/src/test.vala b/test cases/vala/8 generated source/src/test.vala new file mode 100644 index 000000000..98d6821f7 --- /dev/null +++ b/test cases/vala/8 generated source/src/test.vala @@ -0,0 +1,3 @@ +void main() { + print (Config.x); +} diff --git a/test cases/vala/8 generated source/tools/meson.build b/test cases/vala/8 generated source/tools/meson.build new file mode 100644 index 000000000..834ec1a8e --- /dev/null +++ b/test cases/vala/8 generated source/tools/meson.build @@ -0,0 +1,3 @@ +executable('generatedtest', [src, config], + install : true, + dependencies: [dependency('glib-2.0'), dependency('gobject-2.0')]) From 1e3d03cc09240390894bbf9ad7ced05bcde181f1 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Tue, 27 Sep 2016 01:10:52 +0530 Subject: [PATCH 2/2] ninja: Fix C file name for generated Vala sources The Vala compiler preserves the path components of a Vala source file if the source file is in a subdir. Fixes https://github.com/mesonbuild/meson/issues/815 --- mesonbuild/backend/ninjabackend.py | 36 +++++++++++++++++++----------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index a84de0e1a..14aa496aa 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -820,14 +820,14 @@ int dummy; outfile.write('\n') def split_vala_sources(self, sources): - src = [] + other_src = [] vapi_src = [] for s in sources: if s.endswith('.vapi'): vapi_src.append(s) else: - src.append(s) - return (src, vapi_src) + other_src.append(s) + return (other_src, vapi_src) def determine_dep_vapis(self, target): result = [] @@ -845,14 +845,10 @@ int dummy; def generate_vala_compile(self, target, outfile): """Vala is compiled into C. Set up all necessary build steps here.""" valac = target.compilers['vala'] - (src, vapi_src) = self.split_vala_sources(target.get_sources()) + (other_src, vapi_src) = self.split_vala_sources(target.get_sources()) vapi_src = [x.rel_to_builddir(self.build_to_src) for x in vapi_src] extra_dep_files = [] - vala_input_files = [] - for s in src: - if s.endswith('.vala'): - vala_input_files.append(s.rel_to_builddir(self.build_to_src)) - if len(src) == 0: + if len(other_src) == 0: raise InvalidArguments('Vala library has no Vala source files.') namebase = target.name base_h = namebase + '.h' @@ -872,9 +868,23 @@ int dummy; args += ['-H', hname] args += ['--library=' + target.name] args += ['--vapi=' + os.path.join('..', base_vapi)] - for src in vala_input_files: - namebase = os.path.splitext(os.path.split(src)[1])[0] + '.c' - full_c = os.path.join(self.get_target_private_dir(target), namebase) + vala_src = [] + for s in other_src: + if not s.endswith('.vala'): + continue + vala_file = s.rel_to_builddir(self.build_to_src) + vala_src.append(vala_file) + # Figure out where the Vala compiler will write the compiled C file + dirname, basename = os.path.split(vala_file) + # If the Vala file is in a subdir of the build dir (in our case + # because it was generated/built by something else), the subdir path + # components will be preserved in the output path. But if the Vala + # file is outside the build directory, the path components will be + # stripped and just the basename will be used. + c_file = os.path.splitext(basename)[0] + '.c' + if s.is_built: + c_file = os.path.join(dirname, c_file) + full_c = os.path.join(self.get_target_private_dir(target), c_file) generated_c_files.append(full_c) outputs.append(full_c) if self.environment.coredata.get_builtin_option('werror'): @@ -900,7 +910,7 @@ int dummy; args += dependency_vapis element = NinjaBuildElement(self.all_outputs, outputs, valac.get_language() + '_COMPILER', - vala_input_files + vapi_src) + vala_src + vapi_src) element.add_item('ARGS', args) element.add_dep(extra_dep_files) element.write(outfile)