Skip to content

Commit

Permalink
Added support for conan v2
Browse files Browse the repository at this point in the history
Use modern Autotools toolchain and add buildenv_info

Simplified test_package No need to actually compile
something with this tool we simply need to know if it
runs.

The win_bash for the run in the test_package needs to be
set explicitly due to the conf not working properly in
the test_package see conan-io/conan#11975
  • Loading branch information
jellespijker committed Sep 5, 2022
1 parent d8863a9 commit dc309dc
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 270 deletions.
60 changes: 20 additions & 40 deletions recipes/automake/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,27 @@ sources:
sha256: "608a97523f97db32f1f5d5615c98ca69326ced2054c9f82e65bade7fc4c9dea8"
patches:
"1.16.5":
- base_path: "source_subfolder"
patch_file: "patches/0001-help2man-no-discard-stderr-0.16.4.patch"
- base_path: "source_subfolder"
patch_file: "patches/0002-no-perl-path-in-shebang-0.16.4.patch"
- base_path: "source_subfolder"
patch_file: "patches/0003-remove-embedded-datadirs-introduce-automake-conan-includes-0.16.3.patch"
- base_path: "source_subfolder"
patch_file: "patches/0004-introduce-automake_perllibdir-0.16.3.patch"
- patch_file: "patches/0001-help2man-no-discard-stderr-0.16.4.patch"
- patch_file: "patches/0002-no-perl-path-in-shebang-0.16.4.patch"
- patch_file: "patches/0003-remove-embedded-datadirs-introduce-automake-conan-includes-0.16.3.patch"
- patch_file: "patches/0004-introduce-automake_perllibdir-0.16.3.patch"
"1.16.4":
- base_path: "source_subfolder"
patch_file: "patches/0001-help2man-no-discard-stderr-0.16.4.patch"
- base_path: "source_subfolder"
patch_file: "patches/0002-no-perl-path-in-shebang-0.16.4.patch"
- base_path: "source_subfolder"
patch_file: "patches/0003-remove-embedded-datadirs-introduce-automake-conan-includes-0.16.3.patch"
- base_path: "source_subfolder"
patch_file: "patches/0004-introduce-automake_perllibdir-0.16.3.patch"
- patch_file: "patches/0001-help2man-no-discard-stderr-0.16.4.patch"
- patch_file: "patches/0002-no-perl-path-in-shebang-0.16.4.patch"
- patch_file: "patches/0003-remove-embedded-datadirs-introduce-automake-conan-includes-0.16.3.patch"
- patch_file: "patches/0004-introduce-automake_perllibdir-0.16.3.patch"
"1.16.3":
- base_path: "source_subfolder"
patch_file: "patches/0001-help2man-no-discard-stderr-0.16.3.patch"
- base_path: "source_subfolder"
patch_file: "patches/0002-no-perl-path-in-shebang-0.16.3.patch"
- base_path: "source_subfolder"
patch_file: "patches/0003-remove-embedded-datadirs-introduce-automake-conan-includes-0.16.3.patch"
- base_path: "source_subfolder"
patch_file: "patches/0004-introduce-automake_perllibdir-0.16.3.patch"
- patch_file: "patches/0001-help2man-no-discard-stderr-0.16.3.patch"
- patch_file: "patches/0002-no-perl-path-in-shebang-0.16.3.patch"
- patch_file: "patches/0003-remove-embedded-datadirs-introduce-automake-conan-includes-0.16.3.patch"
- patch_file: "patches/0004-introduce-automake_perllibdir-0.16.3.patch"
"1.16.2":
- base_path: "source_subfolder"
patch_file: "patches/0001-help2man-no-discard-stderr-0.16.2.patch"
- base_path: "source_subfolder"
patch_file: "patches/0002-no-perl-path-in-shebang-0.16.2.patch"
- base_path: "source_subfolder"
patch_file: "patches/0003-remove-embedded-datadirs-introduce-automake-conan-includes-0.16.2.patch"
- base_path: "source_subfolder"
patch_file: "patches/0004-introduce-automake_perllibdir-0.16.2.patch"
- patch_file: "patches/0001-help2man-no-discard-stderr-0.16.2.patch"
- patch_file: "patches/0002-no-perl-path-in-shebang-0.16.2.patch"
- patch_file: "patches/0003-remove-embedded-datadirs-introduce-automake-conan-includes-0.16.2.patch"
- patch_file: "patches/0004-introduce-automake_perllibdir-0.16.2.patch"
"1.16.1":
- base_path: "source_subfolder"
patch_file: "patches/0001-help2man-no-discard-stderr-0.16.1.patch"
- base_path: "source_subfolder"
patch_file: "patches/0002-no-perl-path-in-shebang-0.16.1.patch"
- base_path: "source_subfolder"
patch_file: "patches/0003-remove-embedded-datadirs-introduce-automake-conan-includes-0.16.1.patch"
- base_path: "source_subfolder"
patch_file: "patches/0004-introduce-automake_perllibdir-0.16.1.patch"
- patch_file: "patches/0001-help2man-no-discard-stderr-0.16.1.patch"
- patch_file: "patches/0002-no-perl-path-in-shebang-0.16.1.patch"
- patch_file: "patches/0003-remove-embedded-datadirs-introduce-automake-conan-includes-0.16.1.patch"
- patch_file: "patches/0004-introduce-automake_perllibdir-0.16.1.patch"
172 changes: 77 additions & 95 deletions recipes/automake/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from conans import AutoToolsBuildEnvironment, ConanFile, tools
import os
from functools import lru_cache
from os import environ, path

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.tools.files import get, apply_conandata_patches, rmdir, copy, replace_in_file
from conan.tools.gnu import Autotools
from conan.tools.layout import basic_layout
from conan.tools.microsoft import unix_path
from conan.tools.scm import Version

required_conan_version = ">=1.50.0"


class AutomakeConan(ConanFile):
Expand All @@ -12,20 +19,11 @@ class AutomakeConan(ConanFile):
topics = ("conan", "automake", "configure", "build")
license = ("GPL-2.0-or-later", "GPL-3.0-or-later")
settings = "os", "arch", "compiler", "build_type"
generators = "AutotoolsDeps", "AutotoolsToolchain", "VirtualBuildEnv"
win_bash = True

exports_sources = "patches/*"

_autotools = None

@property
def _source_subfolder(self):
return os.path.join(self.source_folder, "source_subfolder")

@property
def _version_major_minor(self):
[major, minor, _] = self.version.split(".", 2)
return '{}.{}'.format(major, minor)

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
Expand All @@ -34,107 +32,91 @@ def configure(self):
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx

def requirements(self):
self.requires("autoconf/2.71")
# automake requires perl-Thread-Queue package

def build_requirements(self):
if hasattr(self, "settings_build"):
self.build_requires("autoconf/2.71")
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")
self.tool_requires("autoconf/2.71")
if self._settings_build.os == "Windows" and not environ.get("CONAN_BASH_PATH"):
self.tool_requires("msys2/cci.latest")

def package_id(self):
del self.info.settings.arch
del self.info.settings.compiler
del self.info.settings.build_type

def layout(self):
basic_layout(self, src_folder="source")
self.cpp.package.includedirs = [] # KB-H071: It is a tool that doesn't contain headers, removing the include directory.

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

@property
def _datarootdir(self):
return os.path.join(self.package_folder, "res")
return path.join(self.package_folder, "bin", "share")

@property
def _automake_libdir(self):
return os.path.join(self._datarootdir, "automake-{}".format(self._version_major_minor))

def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
conf_args = [
"--datarootdir={}".format(tools.unix_path(self._datarootdir)),
"--prefix={}".format(tools.unix_path(self.package_folder)),
]
self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder)
return self._autotools

def _patch_files(self):
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)
if self.settings.os == "Windows":
# tracing using m4 on Windows returns Windows paths => use cygpath to convert to unix paths
tools.replace_in_file(os.path.join(self._source_subfolder, "bin", "aclocal.in"),
" $map_traced_defs{$arg1} = $file;",
" $file = `cygpath -u $file`;\n"
" $file =~ s/^\\s+|\\s+$//g;\n"
" $map_traced_defs{$arg1} = $file;")
version = Version(self.version)
return path.join(self._datarootdir, f"automake-{version.major}.{version.minor}")

def build(self):
self._patch_files()
autotools = self._configure_autotools()
autotools.make()

def package(self):
self.copy("COPYING*", src=self._source_subfolder, dst="licenses")
autotools = self._configure_autotools()
autotools.install()
tools.rmdir(os.path.join(self._datarootdir, "info"))
tools.rmdir(os.path.join(self._datarootdir, "man"))
tools.rmdir(os.path.join(self._datarootdir, "doc"))
@lru_cache(1)
def _autotools(self):
autotool = Autotools(self)
autotool.configure()
autotool.make()
return autotool

def build(self):
apply_conandata_patches(self)
if self.settings.os == "Windows":
binpath = os.path.join(self.package_folder, "bin")
for filename in os.listdir(binpath):
fullpath = os.path.join(binpath, filename)
if not os.path.isfile(fullpath):
continue
os.rename(fullpath, fullpath + ".exe")

def package_info(self):
self.cpp_info.libdirs = []
self.cpp_info.includedirs = []

bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable:: {}".format(bin_path))
self.env_info.PATH.append(bin_path)

bin_ext = ".exe" if self.settings.os == "Windows" else ""

aclocal = tools.unix_path(os.path.join(self.package_folder, "bin", "aclocal" + bin_ext))
self.output.info("Appending ACLOCAL environment variable with: {}".format(aclocal))
self.env_info.ACLOCAL.append(aclocal)

automake_datadir = tools.unix_path(self._datarootdir)
self.output.info("Setting AUTOMAKE_DATADIR to {}".format(automake_datadir))
self.env_info.AUTOMAKE_DATADIR = automake_datadir
# tracing using m4 on Windows returns Windows paths => use cygpath to convert to unix paths
replace_in_file(self, path.join(self.source_path, "bin", "aclocal.in"),
" $map_traced_defs{$arg1} = $file;",
" $file = `cygpath -u $file`;\n"
" $file =~ s/^\\s+|\\s+$//g;\n"
" $map_traced_defs{$arg1} = $file;")

automake_libdir = tools.unix_path(self._automake_libdir)
self.output.info("Setting AUTOMAKE_LIBDIR to {}".format(automake_libdir))
self.env_info.AUTOMAKE_LIBDIR = automake_libdir
_ = self._autotools()

automake_perllibdir = tools.unix_path(self._automake_libdir)
self.output.info("Setting AUTOMAKE_PERLLIBDIR to {}".format(automake_perllibdir))
self.env_info.AUTOMAKE_PERLLIBDIR = automake_perllibdir
def package(self):
autotools = self._autotools()
# KB-H013 we're packaging an application, place everything under bin
autotools.install(args=[f"DESTDIR={unix_path(self, path.join(self.package_folder, 'bin'))}"])

automake = tools.unix_path(os.path.join(self.package_folder, "bin", "automake" + bin_ext))
self.output.info("Setting AUTOMAKE to {}".format(automake))
self.env_info.AUTOMAKE = automake
copy(self, "COPYING*", src=self.source_folder, dst=path.join(self.package_folder, "licenses"))
rmdir(self, path.join(self._datarootdir, "info"))
rmdir(self, path.join(self._datarootdir, "man"))
rmdir(self, path.join(self._datarootdir, "doc"))

self.output.info("Append M4 include directories to AUTOMAKE_CONAN_INCLUDES environment variable")
def _set_env(self, var_name, var_path):
self.output.info(f"Setting {var_name} to {var_path}")
self.buildenv_info.define_path(var_name, var_path)
setattr(self.env_info, var_name, unix_path(self, var_path))

self.user_info.compile = os.path.join(self._automake_libdir, "compile")
self.user_info.ar_lib = os.path.join(self._automake_libdir, "ar-lib")
def package_info(self):
# KB-H013 we're packaging an application, hence the nested bin
bin_dir = path.join(self.package_folder, "bin", "bin")
self.output.info(f"Appending PATH environment variable:: {bin_dir}")
self.buildenv_info.prepend_path("PATH", bin_dir)
self.env_info.PATH.append(bin_dir)

for var in [("ACLOCAL", path.join(self.package_folder, "bin", "aclocal")),
("AUTOMAKE_DATADIR", self._datarootdir),
("AUTOMAKE_LIBDIR", self._automake_libdir),
("AUTOMAKE_PERLLIBDIR", self._automake_libdir),
("AUTOMAKE", path.join(self.package_folder, "bin", "automake"))]:
self._set_env(*var)

compile_bin = path.join(self._automake_libdir, "compile")
self.output.info(f"Define path to `compile` binary in user_info as: {compile_bin}")
self.user_info.compile = compile_bin
compile_conf_key = "user.automake:compile"
self.output.info(f"Defining path to `compile` binary in configuration as `{compile_conf_key}` with value: {compile_bin}")
self.conf_info.define(compile_conf_key, compile_bin)

ar_lib_bin = path.join(self._automake_libdir, "ar-lib")
self.output.info(f"Define path to `ar_lib` binary in user_info as: {ar_lib_bin}")
self.user_info.ar_lib = ar_lib_bin
ar_lib_conf_key = "user.automake:ar-lib"
self.output.info(f"Defining path to `ar-lib` binary in configuration as `{ar_lib_conf_key}` with value: {ar_lib_bin}")
self.conf_info.define(ar_lib_conf_key, ar_lib_bin)
4 changes: 0 additions & 4 deletions recipes/automake/all/test_package/Makefile.am

This file was deleted.

86 changes: 13 additions & 73 deletions recipes/automake/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,89 +1,29 @@
from conans import AutoToolsBuildEnvironment, ConanFile, tools
from conan.tools.microsoft import is_msvc
from contextlib import contextmanager
import os
import shutil
from os import environ

required_conan_version = ">=1.45.0"
from conan import ConanFile
from conan.tools.build import can_run

required_conan_version = ">=1.50.0"


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
exports_sources = "configure.ac", "Makefile.am", "test_package_1.c", "test_package.cpp"
# DON'T COPY extra.m4 TO BUILD FOLDER!!!
generators = "VirtualBuildEnv"
test_type = "explicit"
win_bash = True

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

def requirements(self):
self.requires(self.tested_reference_str)

def build_requirements(self):
self.build_requires(self.tested_reference_str)
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")

@contextmanager
def _build_context(self):
if is_msvc(self):
with tools.vcvars(self):
with tools.environment_append({"CC": "cl -nologo", "CXX": "cl -nologo",}):
yield
else:
yield

_default_cc = {
"gcc": "gcc",
"clang": "clang",
"Visual Studio": "cl -nologo",
"apple-clang": "clang",
}

@property
def _system_cc(self):
system_cc = os.environ.get("CC", None)
if not system_cc:
system_cc = self._default_cc.get(str(self.settings.compiler))
return system_cc

@property
def _user_info(self):
return getattr(self, "user_info_build", self.deps_user_info)

def _build_scripts(self):
"""Test compile script of automake"""
compile_script = self._user_info["automake"].compile
ar_script = self._user_info["automake"].ar_lib
assert os.path.isfile(ar_script)
assert os.path.isfile(compile_script)

if self._system_cc:
with tools.vcvars(self) if is_msvc(self) else tools.no_op():
self.run("{} {} test_package_1.c -o script_test".format(tools.unix_path(compile_script), self._system_cc), win_bash=tools.os_info.is_windows)

def _build_autotools(self):
"""Test autoreconf + configure + make"""
with tools.environment_append({"AUTOMAKE_CONAN_INCLUDES": [tools.unix_path(self.source_folder)]}):
self.run("{} -fiv".format(os.environ["AUTORECONF"]), 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)
autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
with self._build_context():
autotools.configure()
autotools.make()
self.tool_requires(self.tested_reference_str)
if self._settings_build.os == "Windows" and not environ.get("CONAN_BASH_PATH"):
self.tool_requires("msys2/cci.latest")

def build(self):
for src in self.exports_sources:
shutil.copy(os.path.join(self.source_folder, src), self.build_folder)

self._build_scripts()
self._build_autotools()
pass

def test(self):
if self._system_cc:
if not tools.cross_building(self):
self.run(os.path.join(".", "script_test"), run_environment=True)

if not tools.cross_building(self):
self.run(os.path.join(".", "test_package"), run_environment=True)
if can_run(self):
self.run("automake --version", run_environment=True, env="conanbuild", win_bash=self.settings.os == "Windows")
Loading

0 comments on commit dc309dc

Please sign in to comment.