From 3c7f2ffc21fd4b5957df327ccf2ac09ffd8199c1 Mon Sep 17 00:00:00 2001 From: Juan Sanchez Date: Mon, 20 May 2024 13:21:45 +0200 Subject: [PATCH 1/7] fix compiler conf in meson --- conan/tools/meson/toolchain.py | 24 ++++++++++--------- .../toolchains/meson/test_mesontoolchain.py | 24 +++++++++++++++++++ 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/conan/tools/meson/toolchain.py b/conan/tools/meson/toolchain.py index 79efbf6bba0..e2734082edc 100644 --- a/conan/tools/meson/toolchain.py +++ b/conan/tools/meson/toolchain.py @@ -254,15 +254,15 @@ def __init__(self, conanfile, backend=None, native=False): #: Sets the Meson ``c`` variable, defaulting to the ``CC`` build environment value. #: If provided as a blank-separated string, it will be transformed into a list. #: Otherwise, it remains a single string. - self.c = compilers_by_conf.get("c") or build_env.get("CC") or default_comp + self.c = compilers_by_conf.get("c") or self._sanitize_format(build_env.get("CC")) or default_comp #: Sets the Meson ``cpp`` variable, defaulting to the ``CXX`` build environment value. #: If provided as a blank-separated string, it will be transformed into a list. #: Otherwise, it remains a single string. - self.cpp = compilers_by_conf.get("cpp") or build_env.get("CXX") or default_comp_cpp + self.cpp = compilers_by_conf.get("cpp") or self._sanitize_format(build_env.get("CXX")) or default_comp_cpp #: Sets the Meson ``ld`` variable, defaulting to the ``LD`` build environment value. #: If provided as a blank-separated string, it will be transformed into a list. #: Otherwise, it remains a single string. - self.ld = build_env.get("LD") + self.ld = self._sanitize_format(build_env.get("LD")) # FIXME: Should we use the new tools.build:compiler_executables and avoid buildenv? # Issue related: https://github.com/mesonbuild/meson/issues/6442 # PR related: https://github.com/mesonbuild/meson/pull/6457 @@ -420,12 +420,14 @@ def _get_env_list(v): def _filter_list_empty_fields(v): return list(filter(bool, v)) + @staticmethod + def _sanitize_format(v): + if v is None or isinstance(v, list): + return v + ret = [x.strip() for x in v.split() if x] + return f"{ret[0]}" if len(ret) == 1 else ret + def _context(self): - def _sanitize_format(v): - if v is None or isinstance(v, list): - return v - ret = [x.strip() for x in v.split() if x] - return f"'{ret[0]}'" if len(ret) == 1 else ret apple_flags = self.apple_isysroot_flag + self.apple_arch_flag + self.apple_min_version_flag extra_flags = self._get_extra_flags() @@ -464,9 +466,9 @@ def _sanitize_format(v): # https://mesonbuild.com/Builtin-options.html#directories # https://mesonbuild.com/Machine-files.html#binaries # https://mesonbuild.com/Reference-tables.html#compiler-and-linker-selection-variables - "c": _sanitize_format(self.c), - "cpp": _sanitize_format(self.cpp), - "ld": _sanitize_format(self.ld), + "c": to_meson_value(self.c), + "cpp": to_meson_value(self.cpp), + "ld": to_meson_value(self.ld), "objc": self.objc, "objcpp": self.objcpp, "c_ld": self.c_ld, diff --git a/conans/test/integration/toolchains/meson/test_mesontoolchain.py b/conans/test/integration/toolchains/meson/test_mesontoolchain.py index 21bd02c59de..b9b7f3faec7 100644 --- a/conans/test/integration/toolchains/meson/test_mesontoolchain.py +++ b/conans/test/integration/toolchains/meson/test_mesontoolchain.py @@ -4,6 +4,7 @@ import pytest +from assets.genconanfile import GenConanfile from conan.tools.files import load from conan.tools.meson import MesonToolchain from conans.test.utils.tools import TestClient @@ -517,3 +518,26 @@ def generate(self): client.save({"conanfile.py": conanfile}) client.run("install .", assert_error=True) assert "You can only pass native=True if you're cross-building" in client.out + + +@pytest.mark.skipif(platform.system() != "Windows", reason="requires Win") +def test_compiler_path_with_spaces(): + conanfile = (GenConanfile().with_name("lib").with_version("1.0").with_generator("MesonToolchain") + .with_settings("compiler")) + profile = textwrap.dedent(""" + [settings] + arch=x86 + os=Windows + compiler=msvc + compiler.version=193 + compiler.runtime=static + build_type=Release + [conf] + tools.build:compiler_executables={"c":"c compiler path with spaces", "cpp":"cpp compiler path with spaces"} + """) + client = TestClient() + client.save({"conanfile.py": conanfile, "meson-profile": profile}) + client.run("install . -pr:h=meson-profile") + conan_meson_native = client.load("conan_meson_native.ini") + assert "c = 'c compiler path with spaces'" in conan_meson_native + assert "cpp = 'cpp compiler path with spaces'" in conan_meson_native From 963d52cd28e65d55b4199867a15786603b820856 Mon Sep 17 00:00:00 2001 From: Juan Sanchez Date: Mon, 20 May 2024 14:26:58 +0200 Subject: [PATCH 2/7] fix profile in test --- .../toolchains/meson/test_mesontoolchain.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/conans/test/integration/toolchains/meson/test_mesontoolchain.py b/conans/test/integration/toolchains/meson/test_mesontoolchain.py index b9b7f3faec7..ec4e3fad160 100644 --- a/conans/test/integration/toolchains/meson/test_mesontoolchain.py +++ b/conans/test/integration/toolchains/meson/test_mesontoolchain.py @@ -4,7 +4,7 @@ import pytest -from assets.genconanfile import GenConanfile +from conans.test.assets.genconanfile import GenConanfile from conan.tools.files import load from conan.tools.meson import MesonToolchain from conans.test.utils.tools import TestClient @@ -520,18 +520,11 @@ def generate(self): assert "You can only pass native=True if you're cross-building" in client.out -@pytest.mark.skipif(platform.system() != "Windows", reason="requires Win") def test_compiler_path_with_spaces(): conanfile = (GenConanfile().with_name("lib").with_version("1.0").with_generator("MesonToolchain") .with_settings("compiler")) profile = textwrap.dedent(""" - [settings] - arch=x86 - os=Windows - compiler=msvc - compiler.version=193 - compiler.runtime=static - build_type=Release + include(default) [conf] tools.build:compiler_executables={"c":"c compiler path with spaces", "cpp":"cpp compiler path with spaces"} """) From 407a4803e56271c2714f26f704311eb7206556a6 Mon Sep 17 00:00:00 2001 From: Juan <35701596+juansblanco@users.noreply.github.com> Date: Mon, 20 May 2024 15:05:46 +0200 Subject: [PATCH 3/7] Update conan/tools/meson/toolchain.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Francisco Ramírez --- conan/tools/meson/toolchain.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/conan/tools/meson/toolchain.py b/conan/tools/meson/toolchain.py index e2734082edc..33ab0e09f41 100644 --- a/conan/tools/meson/toolchain.py +++ b/conan/tools/meson/toolchain.py @@ -421,11 +421,11 @@ def _filter_list_empty_fields(v): return list(filter(bool, v)) @staticmethod - def _sanitize_format(v): - if v is None or isinstance(v, list): - return v - ret = [x.strip() for x in v.split() if x] - return f"{ret[0]}" if len(ret) == 1 else ret + def _sanitize_env_format(value) + if value is None or isinstance(value, list): + return value + ret = [x.strip() for x in value.split() if x] + return ret[0] if len(ret) == 1 else ret def _context(self): From 98a282f7da9438487375deaeab2d39d35f85c661 Mon Sep 17 00:00:00 2001 From: Juan Sanchez Date: Mon, 20 May 2024 15:26:30 +0200 Subject: [PATCH 4/7] rename sanitize function --- conan/tools/meson/toolchain.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conan/tools/meson/toolchain.py b/conan/tools/meson/toolchain.py index 33ab0e09f41..67713d76920 100644 --- a/conan/tools/meson/toolchain.py +++ b/conan/tools/meson/toolchain.py @@ -254,15 +254,15 @@ def __init__(self, conanfile, backend=None, native=False): #: Sets the Meson ``c`` variable, defaulting to the ``CC`` build environment value. #: If provided as a blank-separated string, it will be transformed into a list. #: Otherwise, it remains a single string. - self.c = compilers_by_conf.get("c") or self._sanitize_format(build_env.get("CC")) or default_comp + self.c = compilers_by_conf.get("c") or self._sanitize_env_format(build_env.get("CC")) or default_comp #: Sets the Meson ``cpp`` variable, defaulting to the ``CXX`` build environment value. #: If provided as a blank-separated string, it will be transformed into a list. #: Otherwise, it remains a single string. - self.cpp = compilers_by_conf.get("cpp") or self._sanitize_format(build_env.get("CXX")) or default_comp_cpp + self.cpp = compilers_by_conf.get("cpp") or self._sanitize_env_format(build_env.get("CXX")) or default_comp_cpp #: Sets the Meson ``ld`` variable, defaulting to the ``LD`` build environment value. #: If provided as a blank-separated string, it will be transformed into a list. #: Otherwise, it remains a single string. - self.ld = self._sanitize_format(build_env.get("LD")) + self.ld = self._sanitize_env_format(build_env.get("LD")) # FIXME: Should we use the new tools.build:compiler_executables and avoid buildenv? # Issue related: https://github.com/mesonbuild/meson/issues/6442 # PR related: https://github.com/mesonbuild/meson/pull/6457 @@ -421,7 +421,7 @@ def _filter_list_empty_fields(v): return list(filter(bool, v)) @staticmethod - def _sanitize_env_format(value) + def _sanitize_env_format(value): if value is None or isinstance(value, list): return value ret = [x.strip() for x in value.split() if x] From fefd759d3865c5f8cf386054752b0d673f44d234 Mon Sep 17 00:00:00 2001 From: Juan <35701596+juansblanco@users.noreply.github.com> Date: Mon, 20 May 2024 16:08:50 +0200 Subject: [PATCH 5/7] Update conans/test/integration/toolchains/meson/test_mesontoolchain.py Co-authored-by: Carlos Zoido --- .../test/integration/toolchains/meson/test_mesontoolchain.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conans/test/integration/toolchains/meson/test_mesontoolchain.py b/conans/test/integration/toolchains/meson/test_mesontoolchain.py index ec4e3fad160..e2562882200 100644 --- a/conans/test/integration/toolchains/meson/test_mesontoolchain.py +++ b/conans/test/integration/toolchains/meson/test_mesontoolchain.py @@ -521,8 +521,8 @@ def generate(self): def test_compiler_path_with_spaces(): - conanfile = (GenConanfile().with_name("lib").with_version("1.0").with_generator("MesonToolchain") - .with_settings("compiler")) + conanfile = GenConanfile().with_name("lib").with_version("1.0").with_generator("MesonToolchain") + .with_settings("compiler") profile = textwrap.dedent(""" include(default) [conf] From 0972bdcf81adea9636ed657e8baaf22ce533eb34 Mon Sep 17 00:00:00 2001 From: Juan Sanchez Date: Mon, 20 May 2024 16:25:09 +0200 Subject: [PATCH 6/7] fix ident --- .../integration/toolchains/meson/test_mesontoolchain.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conans/test/integration/toolchains/meson/test_mesontoolchain.py b/conans/test/integration/toolchains/meson/test_mesontoolchain.py index e2562882200..994cf05984d 100644 --- a/conans/test/integration/toolchains/meson/test_mesontoolchain.py +++ b/conans/test/integration/toolchains/meson/test_mesontoolchain.py @@ -521,15 +521,15 @@ def generate(self): def test_compiler_path_with_spaces(): - conanfile = GenConanfile().with_name("lib").with_version("1.0").with_generator("MesonToolchain") - .with_settings("compiler") profile = textwrap.dedent(""" include(default) [conf] tools.build:compiler_executables={"c":"c compiler path with spaces", "cpp":"cpp compiler path with spaces"} """) client = TestClient() - client.save({"conanfile.py": conanfile, "meson-profile": profile}) + client.save({"conanfile.py": GenConanfile().with_name("lib").with_version("1.0") + .with_generator("MesonToolchain").with_settings("compiler"), + "meson-profile": profile}) client.run("install . -pr:h=meson-profile") conan_meson_native = client.load("conan_meson_native.ini") assert "c = 'c compiler path with spaces'" in conan_meson_native From f78967e972f8e6a91b514a70e782a5053646345b Mon Sep 17 00:00:00 2001 From: Juan Sanchez Date: Mon, 20 May 2024 18:02:35 +0200 Subject: [PATCH 7/7] reduce conanfile in test --- .../integration/toolchains/meson/test_mesontoolchain.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conans/test/integration/toolchains/meson/test_mesontoolchain.py b/conans/test/integration/toolchains/meson/test_mesontoolchain.py index 994cf05984d..3f4f01643b8 100644 --- a/conans/test/integration/toolchains/meson/test_mesontoolchain.py +++ b/conans/test/integration/toolchains/meson/test_mesontoolchain.py @@ -527,9 +527,9 @@ def test_compiler_path_with_spaces(): tools.build:compiler_executables={"c":"c compiler path with spaces", "cpp":"cpp compiler path with spaces"} """) client = TestClient() - client.save({"conanfile.py": GenConanfile().with_name("lib").with_version("1.0") - .with_generator("MesonToolchain").with_settings("compiler"), - "meson-profile": profile}) + client.save( + {"conanfile.py": GenConanfile().with_generator("MesonToolchain").with_settings("compiler"), + "meson-profile": profile}) client.run("install . -pr:h=meson-profile") conan_meson_native = client.load("conan_meson_native.ini") assert "c = 'c compiler path with spaces'" in conan_meson_native