From d50f2df0b50547f7aed546d55a25e8537af380ee Mon Sep 17 00:00:00 2001 From: Noah Massey Date: Thu, 2 Nov 2023 11:06:22 -0400 Subject: [PATCH 1/4] Add autotools win_bash test for configured make_program --- .../toolchains/gnu/autotools/test_win_bash.py | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/conans/test/functional/toolchains/gnu/autotools/test_win_bash.py b/conans/test/functional/toolchains/gnu/autotools/test_win_bash.py index 28d0972a2d7..4c27065ed18 100644 --- a/conans/test/functional/toolchains/gnu/autotools/test_win_bash.py +++ b/conans/test/functional/toolchains/gnu/autotools/test_win_bash.py @@ -104,3 +104,66 @@ def build(self): client.save({"conanfile.py": conanfile}) client.run("create .") assert "ar.exe" in client.out + +@pytest.mark.skipif(platform.system() != "Windows", reason="Requires Windows") +def test_autotools_support_custom_make(): + """ Check that the conf setting `tools.gnu:make_program` works when set with + windows native paths. For example, when set programatically by a package + """ + client = TestClient(path_with_spaces=False) + bash_path = None + make_path = None + try: + bash_path = tools_locations["msys2"]["system"]["path"]["Windows"] + "/bash.exe" + make_path = tools_locations["msys2"]["system"]["path"]["Windows"] + "/make.exe" + except KeyError: + pytest.skip("msys2 path not defined") + if not os.path.exists(make_path): + pytest.skip("msys2 make not installed") + + make_path = make_path.replace("/", "\\") + assert os.path.exists(make_path) + + save(client.cache.new_config_path, textwrap.dedent(""" + tools.microsoft.bash:subsystem=msys2 + tools.microsoft.bash:path={} + tools.gnu:make_program={} + tools.build:compiler_executables={{"c": "cl", "cpp": "cl"}} + """.format(bash_path, make_path))) + + main = gen_function_cpp(name="main") + # The autotools support for "cl" compiler (VS) is very limited, linking with deps doesn't + # work but building a simple app do + makefile_am = gen_makefile_am(main="main", main_srcs="main.cpp") + configure_ac = gen_configure_ac() + + conanfile = textwrap.dedent(""" + from conans import ConanFile + from conan.tools.gnu import Autotools + + class TestConan(ConanFile): + settings = "os", "compiler", "arch", "build_type" + exports_sources = "configure.ac", "Makefile.am", "main.cpp" + generators = "AutotoolsToolchain" + win_bash = True + + def build(self): + # These commands will run in bash activating first the vcvars and + # then inside the bash activating the + self.run("aclocal") + self.run("autoconf") + self.run("automake --add-missing --foreign") + autotools = Autotools(self) + autotools.configure() + autotools.make() + autotools.install() + """) + + client.save({"conanfile.py": conanfile, + "configure.ac": configure_ac, + "Makefile.am": makefile_am, + "main.cpp": main}) + client.run("install . -s:b os=Windows -s:h os=Windows") + client.run("build .") + client.run_command("main.exe") + check_exe_run(client.out, "main", "msvc", None, "Release", "x86_64", None) From 4d4de48dc1ad166bffd050fd02324fac3e0051ab Mon Sep 17 00:00:00 2001 From: Noah Massey Date: Thu, 2 Nov 2023 11:09:09 -0400 Subject: [PATCH 2/4] AutoTools.make(): encode path to make_program appropriately Autotools expects to be run in a unix-like environment. So the correct encoding for paths to execute is unix-like. --- conan/tools/gnu/autotools.py | 1 + 1 file changed, 1 insertion(+) diff --git a/conan/tools/gnu/autotools.py b/conan/tools/gnu/autotools.py index a3a7e744934..15230983275 100644 --- a/conan/tools/gnu/autotools.py +++ b/conan/tools/gnu/autotools.py @@ -46,6 +46,7 @@ def make(self, target=None, args=None): make_program = self._conanfile.conf.get("tools.gnu:make_program", default="mingw32-make" if self._use_win_mingw() else "make") + make_program = unix_path(self._conanfile, make_program) str_args = self._make_args str_extra_args = " ".join(args) if args is not None else "" jobs = "" From 5b33028889dc3aa322bd976204e3cfd71e810c84 Mon Sep 17 00:00:00 2001 From: memsharded Date: Fri, 3 Nov 2023 12:52:23 +0100 Subject: [PATCH 3/4] simplified test --- .../toolchains/gnu/autotools/test_win_bash.py | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/conans/test/functional/toolchains/gnu/autotools/test_win_bash.py b/conans/test/functional/toolchains/gnu/autotools/test_win_bash.py index 4c27065ed18..59f2c923fe2 100644 --- a/conans/test/functional/toolchains/gnu/autotools/test_win_bash.py +++ b/conans/test/functional/toolchains/gnu/autotools/test_win_bash.py @@ -4,7 +4,7 @@ import pytest -from conans.test.assets.autotools import gen_makefile_am, gen_configure_ac +from conans.test.assets.autotools import gen_makefile_am, gen_configure_ac, gen_makefile from conans.test.assets.sources import gen_function_cpp from conans.test.conftest import tools_locations from conans.test.functional.utils import check_exe_run @@ -105,6 +105,7 @@ def build(self): client.run("create .") assert "ar.exe" in client.out + @pytest.mark.skipif(platform.system() != "Windows", reason="Requires Windows") def test_autotools_support_custom_make(): """ Check that the conf setting `tools.gnu:make_program` works when set with @@ -131,11 +132,9 @@ def test_autotools_support_custom_make(): tools.build:compiler_executables={{"c": "cl", "cpp": "cl"}} """.format(bash_path, make_path))) - main = gen_function_cpp(name="main") # The autotools support for "cl" compiler (VS) is very limited, linking with deps doesn't # work but building a simple app do - makefile_am = gen_makefile_am(main="main", main_srcs="main.cpp") - configure_ac = gen_configure_ac() + makefile = gen_makefile() conanfile = textwrap.dedent(""" from conans import ConanFile @@ -143,27 +142,20 @@ def test_autotools_support_custom_make(): class TestConan(ConanFile): settings = "os", "compiler", "arch", "build_type" - exports_sources = "configure.ac", "Makefile.am", "main.cpp" generators = "AutotoolsToolchain" win_bash = True def build(self): # These commands will run in bash activating first the vcvars and # then inside the bash activating the - self.run("aclocal") - self.run("autoconf") - self.run("automake --add-missing --foreign") autotools = Autotools(self) - autotools.configure() autotools.make() - autotools.install() """) client.save({"conanfile.py": conanfile, - "configure.ac": configure_ac, - "Makefile.am": makefile_am, - "main.cpp": main}) + "Makefile": makefile}) client.run("install . -s:b os=Windows -s:h os=Windows") client.run("build .") - client.run_command("main.exe") - check_exe_run(client.out, "main", "msvc", None, "Release", "x86_64", None) + # This used to crash, because ``make_program`` was not unix_path + assert "conanfile.py: Calling build()" in client.out + From 922cb85ba10b36e136a940882458a3f2aeff25c4 Mon Sep 17 00:00:00 2001 From: Noah Massey Date: Tue, 7 Nov 2023 12:16:27 -0500 Subject: [PATCH 4/4] Convert make_program path appropriately for selected subsystem --- conan/tools/gnu/autotools.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/conan/tools/gnu/autotools.py b/conan/tools/gnu/autotools.py index 15230983275..f4470446641 100644 --- a/conan/tools/gnu/autotools.py +++ b/conan/tools/gnu/autotools.py @@ -46,7 +46,8 @@ def make(self, target=None, args=None): make_program = self._conanfile.conf.get("tools.gnu:make_program", default="mingw32-make" if self._use_win_mingw() else "make") - make_program = unix_path(self._conanfile, make_program) + subsystem = deduce_subsystem(self._conanfile, scope="build") + make_program = subsystem_path(subsystem, make_program) str_args = self._make_args str_extra_args = " ".join(args) if args is not None else "" jobs = ""