From ac8d5f215640179c6135a87f1e089587ae7fb102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Sun, 1 Oct 2017 15:45:08 +0200 Subject: [PATCH 1/4] Allow different directories for Vala files --- mesonbuild/backend/ninjabackend.py | 10 ++++++++-- .../22 same target in directories/Subdir/Test.vala | 5 +++++ .../vala/22 same target in directories/Test.vala | 5 +++++ .../vala/22 same target in directories/meson.build | 11 +++++++++++ .../vala/22 same target in directories/prog.vala | 9 +++++++++ 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 test cases/vala/22 same target in directories/Subdir/Test.vala create mode 100644 test cases/vala/22 same target in directories/Test.vala create mode 100644 test cases/vala/22 same target in directories/meson.build create mode 100644 test cases/vala/22 same target in directories/prog.vala diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 2e6e351c9..e00dd5eea 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1131,9 +1131,14 @@ int dummy; # file is outside the build directory, the path components will be # stripped and just the basename will be used. if isinstance(gensrc, (build.CustomTarget, build.GeneratedList)) or gensrc.is_built: - vala_c_file = os.path.splitext(vala_file)[0] + '.c' - else: vala_c_file = os.path.splitext(os.path.basename(vala_file))[0] + '.c' + else: + realpath = os.path.abspath(os.path.join(self.environment.get_build_dir(), vala_file)) + if (realpath.startswith(os.path.join(self.environment.get_source_dir(), target.get_subdir()))): + relpath = os.path.relpath(realpath, os.path.join(self.environment.get_source_dir(), target.get_subdir())) + vala_c_file = os.path.join(os.path.dirname(relpath), os.path.splitext(os.path.basename(vala_file))[0] + '.c') + else: + vala_c_file = os.path.splitext(os.path.basename(vala_file))[0] + '.c' # All this will be placed inside the c_out_dir vala_c_file = os.path.join(c_out_dir, vala_c_file) vala_c_src.append(vala_c_file) @@ -1145,6 +1150,7 @@ int dummy; # means it will also preserve the directory components of Vala sources # found inside the build tree (generated sources). args += ['-d', c_out_dir] + args += ['-b', os.path.join(self.environment.get_source_dir(), target.get_subdir())] if not isinstance(target, build.Executable): # Library name args += ['--library=' + target.name] diff --git a/test cases/vala/22 same target in directories/Subdir/Test.vala b/test cases/vala/22 same target in directories/Subdir/Test.vala new file mode 100644 index 000000000..3a311f4dc --- /dev/null +++ b/test cases/vala/22 same target in directories/Subdir/Test.vala @@ -0,0 +1,5 @@ +public class Subdir.Test : GLib.Object { + construct { + stdout.printf("Test from subdir.\n"); + } +} diff --git a/test cases/vala/22 same target in directories/Test.vala b/test cases/vala/22 same target in directories/Test.vala new file mode 100644 index 000000000..1b57dd96d --- /dev/null +++ b/test cases/vala/22 same target in directories/Test.vala @@ -0,0 +1,5 @@ +public class Test : GLib.Object { + construct { + stdout.printf("Test from main directory.\n"); + } +} diff --git a/test cases/vala/22 same target in directories/meson.build b/test cases/vala/22 same target in directories/meson.build new file mode 100644 index 000000000..25250da1a --- /dev/null +++ b/test cases/vala/22 same target in directories/meson.build @@ -0,0 +1,11 @@ +project('valatest', 'vala', 'c') + +valadeps = [dependency('glib-2.0'), dependency('gobject-2.0')] +valafiles = files([ + 'prog.vala', + 'Test.vala', + 'Subdir/Test.vala' +]) + +e = executable('multidir_prog', valafiles, dependencies : valadeps) +test('valatest', e) diff --git a/test cases/vala/22 same target in directories/prog.vala b/test cases/vala/22 same target in directories/prog.vala new file mode 100644 index 000000000..f3ac09977 --- /dev/null +++ b/test cases/vala/22 same target in directories/prog.vala @@ -0,0 +1,9 @@ +class MainProg : GLib.Object { + + public static int main(string[] args) { + var test1 = new Test (); + var test2 = new Subdir.Test (); + stdout.printf("Vala is working.\n"); + return 0; + } +} From f13887b64a9d535682668960493158ae15bfbb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Tue, 3 Oct 2017 18:25:07 +0200 Subject: [PATCH 2/4] Reduce code complexity, fix nested array in files instruction --- mesonbuild/backend/ninjabackend.py | 7 +++---- test cases/vala/22 same target in directories/meson.build | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index e00dd5eea..5d02991f9 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1133,10 +1133,9 @@ int dummy; if isinstance(gensrc, (build.CustomTarget, build.GeneratedList)) or gensrc.is_built: vala_c_file = os.path.splitext(os.path.basename(vala_file))[0] + '.c' else: - realpath = os.path.abspath(os.path.join(self.environment.get_build_dir(), vala_file)) - if (realpath.startswith(os.path.join(self.environment.get_source_dir(), target.get_subdir()))): - relpath = os.path.relpath(realpath, os.path.join(self.environment.get_source_dir(), target.get_subdir())) - vala_c_file = os.path.join(os.path.dirname(relpath), os.path.splitext(os.path.basename(vala_file))[0] + '.c') + path_to_target = os.path.join(self.build_to_src, target.get_subdir()) + if vala_file.startswith(path_to_target): + vala_c_file = os.path.splitext(os.path.relpath(vala_file, path_to_target))[0] + '.c' else: vala_c_file = os.path.splitext(os.path.basename(vala_file))[0] + '.c' # All this will be placed inside the c_out_dir diff --git a/test cases/vala/22 same target in directories/meson.build b/test cases/vala/22 same target in directories/meson.build index 25250da1a..144e31085 100644 --- a/test cases/vala/22 same target in directories/meson.build +++ b/test cases/vala/22 same target in directories/meson.build @@ -1,11 +1,11 @@ project('valatest', 'vala', 'c') valadeps = [dependency('glib-2.0'), dependency('gobject-2.0')] -valafiles = files([ +valafiles = files( 'prog.vala', 'Test.vala', 'Subdir/Test.vala' -]) +) e = executable('multidir_prog', valafiles, dependencies : valadeps) test('valatest', e) From 6483a0d8466635ae01373bb469fa98ec44c212e9 Mon Sep 17 00:00:00 2001 From: Alistair Thomas Date: Tue, 3 Oct 2017 13:17:58 +0100 Subject: [PATCH 3/4] Add additional directory depth tests to Vala test case 22 --- .../Subdir/Subdir2/Test.vala | 5 +++++ .../Subdir/Test.vala | 2 +- .../Subdir2/Test.vala | 5 +++++ .../vala/22 same target in directories/Test.vala | 2 +- .../22 same target in directories/meson.build | 4 +++- .../vala/22 same target in directories/prog.vala | 15 +++++++-------- 6 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 test cases/vala/22 same target in directories/Subdir/Subdir2/Test.vala create mode 100644 test cases/vala/22 same target in directories/Subdir2/Test.vala diff --git a/test cases/vala/22 same target in directories/Subdir/Subdir2/Test.vala b/test cases/vala/22 same target in directories/Subdir/Subdir2/Test.vala new file mode 100644 index 000000000..94e5cbc31 --- /dev/null +++ b/test cases/vala/22 same target in directories/Subdir/Subdir2/Test.vala @@ -0,0 +1,5 @@ +public class Subdir.Subdir2.Test : GLib.Object { + construct { + stdout.printf("Test from Subdir/Subdir2/\n"); + } +} diff --git a/test cases/vala/22 same target in directories/Subdir/Test.vala b/test cases/vala/22 same target in directories/Subdir/Test.vala index 3a311f4dc..02143c4ff 100644 --- a/test cases/vala/22 same target in directories/Subdir/Test.vala +++ b/test cases/vala/22 same target in directories/Subdir/Test.vala @@ -1,5 +1,5 @@ public class Subdir.Test : GLib.Object { construct { - stdout.printf("Test from subdir.\n"); + stdout.printf("Test from Subdir/\n"); } } diff --git a/test cases/vala/22 same target in directories/Subdir2/Test.vala b/test cases/vala/22 same target in directories/Subdir2/Test.vala new file mode 100644 index 000000000..4a2d61f27 --- /dev/null +++ b/test cases/vala/22 same target in directories/Subdir2/Test.vala @@ -0,0 +1,5 @@ +public class Subdir2.Test : GLib.Object { + construct { + stdout.printf("Test from Subdir2/\n"); + } +} diff --git a/test cases/vala/22 same target in directories/Test.vala b/test cases/vala/22 same target in directories/Test.vala index 1b57dd96d..9154e2286 100644 --- a/test cases/vala/22 same target in directories/Test.vala +++ b/test cases/vala/22 same target in directories/Test.vala @@ -1,5 +1,5 @@ public class Test : GLib.Object { construct { - stdout.printf("Test from main directory.\n"); + stdout.printf("Test from main directory\n"); } } diff --git a/test cases/vala/22 same target in directories/meson.build b/test cases/vala/22 same target in directories/meson.build index 144e31085..6785f7377 100644 --- a/test cases/vala/22 same target in directories/meson.build +++ b/test cases/vala/22 same target in directories/meson.build @@ -4,7 +4,9 @@ valadeps = [dependency('glib-2.0'), dependency('gobject-2.0')] valafiles = files( 'prog.vala', 'Test.vala', - 'Subdir/Test.vala' + 'Subdir/Test.vala', + 'Subdir/Subdir2/Test.vala', + 'Subdir2/Test.vala', ) e = executable('multidir_prog', valafiles, dependencies : valadeps) diff --git a/test cases/vala/22 same target in directories/prog.vala b/test cases/vala/22 same target in directories/prog.vala index f3ac09977..37cbf7a90 100644 --- a/test cases/vala/22 same target in directories/prog.vala +++ b/test cases/vala/22 same target in directories/prog.vala @@ -1,9 +1,8 @@ -class MainProg : GLib.Object { - - public static int main(string[] args) { - var test1 = new Test (); - var test2 = new Subdir.Test (); - stdout.printf("Vala is working.\n"); - return 0; - } +int main() { + var test1 = new Test (); + var test2 = new Subdir.Test (); + var test3 = new Subdir2.Test (); + var test4 = new Subdir.Subdir2.Test (); + stdout.printf("Vala is working.\n"); + return 0; } From d551dbff9a1c5948d4de036f4c7e2cab12a9476c Mon Sep 17 00:00:00 2001 From: Alistair Thomas Date: Tue, 3 Oct 2017 19:14:43 +0100 Subject: [PATCH 4/4] Use long form of valac options and make --basedir use relative path --- mesonbuild/backend/ninjabackend.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 5d02991f9..bb281e15f 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1148,14 +1148,14 @@ int dummy; # Tell Valac to output everything in our private directory. Sadly this # means it will also preserve the directory components of Vala sources # found inside the build tree (generated sources). - args += ['-d', c_out_dir] - args += ['-b', os.path.join(self.environment.get_source_dir(), target.get_subdir())] + args += ['--directory', c_out_dir] + args += ['--basedir', os.path.join(self.build_to_src, target.get_subdir())] if not isinstance(target, build.Executable): # Library name - args += ['--library=' + target.name] + args += ['--library', target.name] # Outputted header hname = os.path.join(self.get_target_dir(target), target.vala_header) - args += ['-H', hname] + args += ['--header', hname] if self.is_unity(target): # Without this the declarations will get duplicated in the .c # files and cause a build failure when all of them are