diff options
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 26 | ||||
-rwxr-xr-x | run_unittests.py | 28 | ||||
-rw-r--r-- | test cases/vala/8 generated sources/meson.build | 5 |
3 files changed, 50 insertions, 9 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 6ab67fb..b9f614e 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -14,6 +14,7 @@ import os, pickle, re, shlex, subprocess, sys from collections import OrderedDict +from pathlib import PurePath from . import backends from .. import modules @@ -1141,16 +1142,31 @@ int dummy; valac_outputs = [] # All sources that are passed to valac on the commandline all_files = list(vapi_src.keys()) + # Passed as --basedir + srcbasedir = os.path.join(self.build_to_src, target.get_subdir()) for (vala_file, gensrc) in vala_src.items(): all_files.append(vala_file) # Figure out where the Vala compiler will write the compiled C 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. + # because it was generated/built by something else), and is also + # a subdir of --basedir (because the builddir is in the source + # tree, and the target subdir is the source root), the subdir + # components from the source root till the private builddir will be + # duplicated inside the private builddir. Otherwise, just the + # basename will be used. + # + # If the Vala file is outside the build directory, the paths from + # the --basedir till the subdir will be duplicated inside the + # private builddir. if isinstance(gensrc, (build.CustomTarget, build.GeneratedList)) or gensrc.is_built: vala_c_file = os.path.splitext(os.path.basename(vala_file))[0] + '.c' + # Check if the vala file is in a subdir of --basedir + abs_srcbasedir = os.path.join(self.environment.get_source_dir(), target.get_subdir()) + abs_vala_file = os.path.join(self.environment.get_build_dir(), vala_file) + if PurePath(os.path.commonpath((abs_srcbasedir, abs_vala_file))) == PurePath(abs_srcbasedir): + vala_c_subdir = PurePath(abs_vala_file).parent.relative_to(abs_srcbasedir) + vala_c_file = os.path.join(vala_c_subdir, vala_c_file) else: path_to_target = os.path.join(self.build_to_src, target.get_subdir()) if vala_file.startswith(path_to_target): @@ -1168,7 +1184,7 @@ int dummy; # means it will also preserve the directory components of Vala sources # found inside the build tree (generated sources). args += ['--directory', c_out_dir] - args += ['--basedir', os.path.join(self.build_to_src, target.get_subdir())] + args += ['--basedir', srcbasedir] if not isinstance(target, build.Executable): # Library name args += ['--library', target.name] diff --git a/run_unittests.py b/run_unittests.py index 69f467b..3a66211 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -464,10 +464,8 @@ class BasePlatformTests(unittest.TestCase): self.builddirs = [] self.new_builddir() - def new_builddir(self): - # In case the directory is inside a symlinked directory, find the real - # path otherwise we might not find the srcdir from inside the builddir. - self.builddir = os.path.realpath(tempfile.mkdtemp()) + def change_builddir(self, newdir): + self.builddir = newdir self.privatedir = os.path.join(self.builddir, 'meson-private') self.logdir = os.path.join(self.builddir, 'meson-logs') self.installdir = os.path.join(self.builddir, 'install') @@ -475,6 +473,12 @@ class BasePlatformTests(unittest.TestCase): self.mtest_command = meson_command + ['test', '-C', self.builddir] self.builddirs.append(self.builddir) + def new_builddir(self): + # In case the directory is inside a symlinked directory, find the real + # path otherwise we might not find the srcdir from inside the builddir. + newdir = os.path.realpath(tempfile.mkdtemp()) + self.change_builddir(newdir) + def _print_meson_log(self): log = os.path.join(self.logdir, 'meson-log.txt') if not os.path.isfile(log): @@ -2578,6 +2582,22 @@ endian = 'little' self.init(testdir, ['--cross-file=' + name], inprocess=True) self.wipe() + def test_vala_generated_source_buildir_inside_source_tree(self): + ''' + Test that valac outputs generated C files in the expected location when + the builddir is a subdir of the source tree. + ''' + testdir = os.path.join(self.vala_test_dir, '8 generated sources') + newdir = os.path.join(self.builddir, 'srctree') + shutil.copytree(testdir, newdir) + testdir = newdir + # New builddir + builddir = os.path.join(testdir, 'subdir/_build') + os.makedirs(builddir, exist_ok=True) + self.change_builddir(builddir) + self.init(testdir) + self.build() + class LinuxArmCrossCompileTests(BasePlatformTests): ''' diff --git a/test cases/vala/8 generated sources/meson.build b/test cases/vala/8 generated sources/meson.build index 277c943..711a93a 100644 --- a/test cases/vala/8 generated sources/meson.build +++ b/test cases/vala/8 generated sources/meson.build @@ -4,6 +4,11 @@ cd = configuration_data() cd.set('x', 'y') subdir('src') + +executable('generatedtestparent', [src, config, returncode, wrapper], + install : true, + dependencies: [dependency('glib-2.0'), dependency('gobject-2.0')]) + subdir('tools') subdir('onlygen') subdir('dependency-generated') |