diff --git a/recipes/autoconf/all/conanfile.py b/recipes/autoconf/all/conanfile.py index 2653000a17820..ceb06b4b4a4be 100644 --- a/recipes/autoconf/all/conanfile.py +++ b/recipes/autoconf/all/conanfile.py @@ -1,18 +1,21 @@ -from os import path - from conan import ConanFile from conan.tools.env import VirtualBuildEnv from conan.tools.files import copy, get, rmdir, apply_conandata_patches, replace_in_file, export_conandata_patches -from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps +from conan.tools.gnu import Autotools, AutotoolsToolchain from conan.tools.layout import basic_layout from conan.tools.microsoft import unix_path, is_msvc +from conans import tools as tools_legacy +import os required_conan_version = ">=1.52.0" class AutoconfConan(ConanFile): name = "autoconf" - description = "Autoconf is an extensible package of M4 macros that produce shell scripts to automatically configure software source code packages" + description = ( + "Autoconf is an extensible package of M4 macros that produce shell " + "scripts to automatically configure software source code packages" + ) license = ("GPL-2.0-or-later", "GPL-3.0-or-later") url = "https://github.com/conan-io/conan-center-index" homepage = "https://www.gnu.org/software/autoconf/" @@ -27,9 +30,6 @@ def _settings_build(self): def export_sources(self): export_conandata_patches(self) - def configure(self): - self.win_bash = self._settings_build.os == "Windows" - def layout(self): basic_layout(self, src_folder="src") @@ -40,15 +40,20 @@ def package_id(self): self.info.clear() def build_requirements(self): - if self._settings_build.os == "Windows" and not self.conf.get("tools.microsoft.bash:path", check_type=str): - self.tool_requires("msys2/cci.latest") self.tool_requires("m4/1.4.19") + if self._settings_build.os == "Windows": + self.win_bash = True + if not self.conf.get("tools.microsoft.bash:path", check_type=str): + self.tool_requires("msys2/cci.latest") def source(self): get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) def generate(self): + env = VirtualBuildEnv(self) + env.generate() + tc = AutotoolsToolchain(self) tc.configure_args.extend([ "--datarootdir=${prefix}/res", @@ -68,64 +73,66 @@ def generate(self): tc.configure_args.append(f"--host={host}") env = tc.environment() - env.define("INSTALL", unix_path(self, path.join(self.source_folder, 'build-aux', 'install-sh'))) + env.define_path("INSTALL", unix_path(self, os.path.join(self.source_folder, "build-aux", "install-sh"))) tc.generate(env) - deps = AutotoolsDeps(self) - deps.generate() - - ms = VirtualBuildEnv(self) - ms.generate(scope="build") - - def build(self): + def _patch_sources(self): apply_conandata_patches(self) - replace_in_file(self, path.join(self.source_folder, "Makefile.in"), "M4 = /usr/bin/env m4", "#M4 = /usr/bin/env m4") + replace_in_file(self, os.path.join(self.source_folder, "Makefile.in"), + "M4 = /usr/bin/env m4", "#M4 = /usr/bin/env m4") + def build(self): + self._patch_sources() autotools = Autotools(self) autotools.configure() autotools.make() def package(self): autotools = Autotools(self) - autotools.install(args=[f"DESTDIR={unix_path(self, self.package_folder)}"]) # Need to specify the `DESTDIR` as a Unix path, aware of the subsystem + # TODO: can be replaced by autotools.install() if required_conan_version = ">=1.54.0" + autotools.install(args=[f"DESTDIR={unix_path(self, self.package_folder)}"]) - copy(self, "COPYING*", src=self.source_folder, dst=path.join(self.package_folder, "licenses")) - rmdir(self, path.join(self.package_folder, "res", "info")) - rmdir(self, path.join(self.package_folder, "res", "man")) + copy(self, "COPYING*", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + rmdir(self, os.path.join(self.package_folder, "res", "info")) + rmdir(self, os.path.join(self.package_folder, "res", "man")) def package_info(self): self.cpp_info.libdirs = [] self.cpp_info.includedirs = [] + self.cpp_info.resdirs = ["res"] - bin_path = path.join(self.package_folder, "bin") - self.output.info(f"Appending PATH environment variable: {bin_path}") - self.env_info.PATH.append(bin_path) + # TODO: use legacy unix_path for the moment (see https://github.com/conan-io/conan/issues/12499) - dataroot_path = path.join(self.package_folder, "res", "autoconf") + dataroot_path = tools_legacy.unix_path(os.path.join(self.package_folder, "res", "autoconf")) self.output.info(f"Defining AC_MACRODIR environment variable: {dataroot_path}") - self.env_info.AC_MACRODIR = dataroot_path self.buildenv_info.define_path("AC_MACRODIR", dataroot_path) self.output.info(f"Defining AUTOM4TE_PERLLIBDIR environment variable: {dataroot_path}") - self.env_info.AUTOM4TE_PERLLIBDIR = dataroot_path self.buildenv_info.define_path("AUTOM4TE_PERLLIBDIR", dataroot_path) - autoconf_bin = path.join(bin_path, "autoconf") + bin_path = os.path.join(self.package_folder, "bin") + + autoconf_bin = tools_legacy.unix_path(os.path.join(bin_path, "autoconf")) self.output.info(f"Defining AUTOCONF environment variable: {autoconf_bin}") - self.env_info.AUTOCONF = autoconf_bin self.buildenv_info.define_path("AUTOCONF", autoconf_bin) - autoreconf_bin = path.join(bin_path, "autoreconf") + autoreconf_bin = tools_legacy.unix_path(os.path.join(bin_path, "autoreconf")) self.output.info(f"Defining AUTORECONF environment variable: {autoreconf_bin}") - self.env_info.AUTORECONF = autoreconf_bin self.buildenv_info.define_path("AUTORECONF", autoreconf_bin) - autoheader_bin = path.join(bin_path, "autoheader") + autoheader_bin = tools_legacy.unix_path(os.path.join(bin_path, "autoheader")) self.output.info(f"Defining AUTOHEADER environment variable: {autoheader_bin}") - self.env_info.AUTOHEADER = autoheader_bin self.buildenv_info.define_path("AUTOHEADER", autoheader_bin) - autom4te_bin = path.join(bin_path, "autom4te") + autom4te_bin = tools_legacy.unix_path(os.path.join(bin_path, "autom4te")) self.output.info(f"Defining AUTOM4TE environment variable: {autom4te_bin}") - self.env_info.AUTOM4TE = autom4te_bin self.buildenv_info.define_path("AUTOM4TE", autom4te_bin) + + # TODO: to remove in conan v2 + self.env_info.PATH.append(bin_path) + self.env_info.AC_MACRODIR = dataroot_path + self.env_info.AUTOM4TE_PERLLIBDIR = dataroot_path + self.env_info.AUTOCONF = autoconf_bin + self.env_info.AUTORECONF = autoreconf_bin + self.env_info.AUTOHEADER = autoheader_bin + self.env_info.AUTOM4TE = autom4te_bin diff --git a/recipes/autoconf/all/test_package/conanfile.py b/recipes/autoconf/all/test_package/conanfile.py index 737e921d3c222..bb22349ed9696 100644 --- a/recipes/autoconf/all/test_package/conanfile.py +++ b/recipes/autoconf/all/test_package/conanfile.py @@ -1,53 +1,51 @@ -import shutil -from os import path - from conan import ConanFile from conan.tools.build import can_run -from conan.tools.gnu import Autotools -from conan.tools.microsoft import unix_path - -required_conan_version = ">=1.50.0" +from conan.tools.env import Environment, VirtualBuildEnv +from conan.tools.files import copy +from conan.tools.gnu import Autotools, AutotoolsToolchain +from conan.tools.layout import basic_layout +from conan.tools.microsoft import is_msvc +import os class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - exports_sources = "configure.ac", "config.h.in", "Makefile.in", "test_package_c.c", "test_package_cpp.cpp", - generators = "AutotoolsDeps", "AutotoolsToolchain", "VirtualBuildEnv" + settings = "os", "arch", "compiler", "build_type" test_type = "explicit" + win_bash = True @property def _settings_build(self): - # TODO: Remove for Conan v2 return getattr(self, "settings_build", self.settings) - @property - def win_bash(self): - return self._settings_build.os == "Windows" + def layout(self): + basic_layout(self) def build_requirements(self): - if self._settings_build.os == "Windows" and not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool): - self.tool_requires("msys2/cci.latest") # The conf `tools.microsoft.bash:path` and `tools.microsoft.bash:subsystem` aren't injected for test_package self.tool_requires(self.tested_reference_str) + if self._settings_build.os == "Windows" and not self.conf.get("tools.microsoft.bash:path", check_type=str): + self.tool_requires("msys2/cci.latest") + + def generate(self): + env = VirtualBuildEnv(self) + env.generate() + tc = AutotoolsToolchain(self) + tc.generate() + if is_msvc(self): + env = Environment() + env.define("CC", "cl -nologo") + env.define("CXX", "cl -nologo") + env.vars(self).save_script("conanbuild_msvc") def build(self): - if self._settings_build.os == "Windows" and not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool): - return # autoconf needs a bash if there isn't a bash no need to build - - for src in self.exports_sources: - shutil.copy(path.join(self.source_folder, src), self.build_folder) - + for src in ("configure.ac", "config.h.in", "Makefile.in", "test_package_c.c", "test_package_cpp.cpp"): + copy(self, src, self.source_folder, self.build_folder) self.run("autoconf --verbose") - autotools = Autotools(self) autotools.configure(build_script_folder=self.build_folder) autotools.make() def test(self): - if self._settings_build.os == "Windows" and not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool): - return # autoconf needs a bash if there isn't a bash no need to build - + self.win_bash = None if can_run(self): - ext = ".exe" if self.settings.os == "Windows" else "" - test_cmd = unix_path(self, path.join(self.build_folder, f"test_package{ext}")) - - self.run(test_cmd, env="conanbuild") + bin_path = os.path.join(self.build_folder, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/autoconf/all/test_v1_package/conanfile.py b/recipes/autoconf/all/test_v1_package/conanfile.py index 251a0dd0da2d6..422d5f44c10cf 100644 --- a/recipes/autoconf/all/test_v1_package/conanfile.py +++ b/recipes/autoconf/all/test_v1_package/conanfile.py @@ -1,15 +1,12 @@ from conans import AutoToolsBuildEnvironment, ConanFile, tools -from conan.tools.microsoft import is_msvc, unix_path +from conan.tools.files import copy +from conan.tools.microsoft import is_msvc import contextlib import os -import shutil - -required_conan_version = ">=1.45.0" class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - exports_sources = "../test_package/configure.ac", "../test_package/config.h.in", "../test_package/Makefile.in", "../test_package/test_package_c.c", "../test_package/test_package_cpp.cpp", + settings = "os", "arch", "compiler", "build_type" test_type = "explicit" @property @@ -31,12 +28,11 @@ def _build_context(self): yield def build(self): - for src in self.exports_sources: - shutil.copy(os.path.join(self.source_folder, src), self.build_folder) - self.run("autoconf --verbose", - win_bash=tools.os_info.is_windows, run_environment=True) + for src in ("configure.ac", "config.h.in", "Makefile.in", "test_package_c.c", "test_package_cpp.cpp"): + copy(self, src, os.path.join(self.source_folder, os.pardir, "test_package"), self.build_folder) + self.run("autoconf --verbose", win_bash=tools.os_info.is_windows) self.run("{} --help".format(os.path.join(self.build_folder, "configure").replace("\\", "/")), - win_bash=tools.os_info.is_windows, run_environment=True) + win_bash=tools.os_info.is_windows) autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) with self._build_context(): autotools.configure()