From 1bcca6d30e4ec7f728b0647f725cd3ff675d4eeb Mon Sep 17 00:00:00 2001 From: Joseph Hughes Date: Sun, 9 Aug 2026 21:02:43 -0500 Subject: [PATCH] fix: write a meson build file with a forward slash separator A meson build file is read as text, so a Windows separator starts an escape sequence. The source directory written for mt3dms became a tab, the one for vs2dt became a vertical tab, and the one for gridgen became a backspace, and none of the three built with meson on Windows. triangle built because a backslash followed by an s is not an escape. Write a path to a meson build file with a forward slash, which meson accepts on every platform, and build the four targets with meson on Windows. This is the same change made for the makefile in #271. --- autotest/test_build.py | 4 +--- pymake/utils/_meson_build.py | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/autotest/test_build.py b/autotest/test_build.py index 6ca844e..fa26bd1 100644 --- a/autotest/test_build.py +++ b/autotest/test_build.py @@ -15,9 +15,7 @@ targets_exclude = [] test_ostag = get_ostag() test_fc_env = os.environ.get("FC") -if "win" in test_ostag: - meson_exclude = ["mt3dms", "vs2dt", "triangle", "gridgen"] -elif "win" not in test_ostag and test_fc_env in ("ifort",): +if "win" not in test_ostag and test_fc_env in ("ifort",): meson_exclude = ["mf2000", "mf2005", "swtv4", "mflgr"] else: meson_exclude = [] diff --git a/pymake/utils/_meson_build.py b/pymake/utils/_meson_build.py index cefe691..2a24651 100644 --- a/pymake/utils/_meson_build.py +++ b/pymake/utils/_meson_build.py @@ -421,6 +421,27 @@ def _meson_build( ) +def _meson_path(pth): + """Format a path so that it can be written to a meson build file. + + A meson build file is read as text, so a Windows separator starts an + escape sequence, and a source directory such as 'true-binary' becomes a + tab. Meson accepts a forward slash on every platform. + + Parameters + ---------- + pth : str or Path + path to format + + Returns + ------- + pth : str + path with a forward slash separator + + """ + return Path(pth).as_posix() + + def _create_main_meson_build( mesondir, target, @@ -496,7 +517,7 @@ def _create_main_meson_build( c/cpp compiler that meson will use. None if no c/cpp source files """ - appdir = os.path.relpath(os.path.dirname(target), mesondir) + appdir = _meson_path(os.path.relpath(os.path.dirname(target), mesondir)) target = os.path.splitext(os.path.basename(target))[0] osname = _get_osname() @@ -668,7 +689,7 @@ def _create_main_meson_build( # add source directories line = "" for key, value in source_path_dict.items(): - pth = os.path.relpath(value, mesondir) + pth = _meson_path(os.path.relpath(value, mesondir)) line += f"subdir('{pth}')\n" line += "\n" f.write(line) @@ -681,7 +702,7 @@ def _create_main_meson_build( for root, dirs, files in os.walk(value): for file in files: if file.endswith(".h") or file.endswith(".hpp"): - pth = os.path.relpath(root, mesondir) + pth = _meson_path(os.path.relpath(root, mesondir)) include_dirs.append(pth) break if len(include_dirs) > 0: