-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[autoconf] conan v2 #12896
[autoconf] conan v2 #12896
Changes from all commits
551afba
06a7499
4add446
bd244f2
4cd02ff
ea10b5a
ae5e36e
6ae0e3d
2108ccd
6aeafa2
d9ee4de
f6fc785
357c078
b92480f
f97d01d
75e7579
2038f28
f321757
2187b09
67efc0e
43c1014
63ae4f9
36827a6
29fe03c
c5b382d
e771b6f
9aaca05
070ce49
94149de
5f97677
88d5372
ad45b97
6e5d149
516a304
e1a1fe6
0000f38
ea1b563
1c1abb9
ed0ea5d
a2d8510
642c352
afa1246
53275c4
f05d39a
f76bdfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,131 @@ | ||
from conans import AutoToolsBuildEnvironment, ConanFile, tools | ||
import contextlib | ||
import os | ||
from os import path | ||
|
||
required_conan_version = ">=1.33.0" | ||
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.layout import basic_layout | ||
from conan.tools.microsoft import unix_path, is_msvc | ||
|
||
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" | ||
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/" | ||
description = "Autoconf is an extensible package of M4 macros that produce shell scripts to automatically configure software source code packages" | ||
topics = ("autoconf", "configure", "build") | ||
license = ("GPL-2.0-or-later", "GPL-3.0-or-later") | ||
settings = "os", "arch", "compiler", "build_type" | ||
|
||
exports_sources = "patches/*" | ||
|
||
_autotools = None | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return os.path.join(self.source_folder, "source_subfolder") | ||
|
||
@property | ||
def _settings_build(self): | ||
# TODO: Remove for Conan v2 | ||
return getattr(self, "settings_build", self.settings) | ||
|
||
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") | ||
|
||
def requirements(self): | ||
self.requires("m4/1.4.19") | ||
|
||
def build_requirements(self): | ||
if hasattr(self, "settings_build"): | ||
self.build_requires("m4/1.4.19") | ||
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"): | ||
self.build_requires("msys2/cci.latest") | ||
|
||
def package_id(self): | ||
self.info.header_only() | ||
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") | ||
|
||
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], | ||
destination=self.source_folder, strip_root=True) | ||
|
||
@property | ||
def _datarootdir(self): | ||
return os.path.join(self.package_folder, "bin", "share") | ||
def generate(self): | ||
tc = AutotoolsToolchain(self) | ||
tc.configure_args.extend([ | ||
"--datarootdir=${prefix}/res", | ||
]) | ||
|
||
@property | ||
def _autoconf_datarootdir(self): | ||
return os.path.join(self._datarootdir, "autoconf") | ||
|
||
def _configure_autotools(self): | ||
if self._autotools: | ||
return self._autotools | ||
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) | ||
datarootdir = self._datarootdir | ||
prefix = self.package_folder | ||
if self.settings.os == "Windows": | ||
datarootdir = tools.unix_path(datarootdir) | ||
prefix = tools.unix_path(prefix) | ||
conf_args = [ | ||
"--datarootdir={}".format(datarootdir), | ||
"--prefix={}".format(prefix), | ||
] | ||
self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder) | ||
return self._autotools | ||
|
||
def _patch_files(self): | ||
for patch in self.conan_data.get("patches", {}).get(self.version, []): | ||
tools.patch(**patch) | ||
|
||
@contextlib.contextmanager | ||
def _build_context(self): | ||
with tools.environment_append(tools.RunEnvironment(self).vars): | ||
yield | ||
if is_msvc(self): | ||
build = "{}-{}-{}".format( | ||
"x86_64" if self._settings_build.arch == "x86_64" else "i686", | ||
"pc" if self._settings_build.arch == "x86" else "win64", | ||
"mingw32") | ||
host = "{}-{}-{}".format( | ||
"x86_64" if self.settings.arch == "x86_64" else "i686", | ||
"pc" if self.settings.arch == "x86" else "win64", | ||
"mingw32") | ||
tc.configure_args.append(f"--build={build}") | ||
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'))) | ||
tc.generate(env) | ||
|
||
deps = AutotoolsDeps(self) | ||
deps.generate() | ||
|
||
ms = VirtualBuildEnv(self) | ||
ms.generate(scope="build") | ||
|
||
def build(self): | ||
self._patch_files() | ||
with self._build_context(): | ||
autotools = self._configure_autotools() | ||
autotools.make() | ||
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") | ||
|
||
autotools = Autotools(self) | ||
autotools.configure() | ||
autotools.make() | ||
|
||
def package(self): | ||
self.copy("COPYING*", src=self._source_subfolder, dst="licenses") | ||
with self._build_context(): | ||
autotools = self._configure_autotools() | ||
autotools.install() | ||
tools.rmdir(os.path.join(self.package_folder, "bin", "share", "info")) | ||
tools.rmdir(os.path.join(self.package_folder, "bin", "share", "man")) | ||
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 | ||
|
||
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")) | ||
|
||
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 env var with : {}".format(bin_path)) | ||
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) | ||
|
||
ac_macrodir = self._autoconf_datarootdir | ||
self.output.info("Setting AC_MACRODIR to {}".format(ac_macrodir)) | ||
self.env_info.AC_MACRODIR = ac_macrodir | ||
|
||
autoconf = tools.unix_path(os.path.join(self.package_folder, "bin", "autoconf")) | ||
self.output.info("Setting AUTOCONF to {}".format(autoconf)) | ||
self.env_info.AUTOCONF = autoconf | ||
|
||
autoreconf = tools.unix_path(os.path.join(self.package_folder, "bin", "autoreconf")) | ||
self.output.info("Setting AUTORECONF to {}".format(autoreconf)) | ||
self.env_info.AUTORECONF = autoreconf | ||
|
||
autoheader = tools.unix_path(os.path.join(self.package_folder, "bin", "autoheader")) | ||
self.output.info("Setting AUTOHEADER to {}".format(autoheader)) | ||
self.env_info.AUTOHEADER = autoheader | ||
|
||
autom4te = tools.unix_path(os.path.join(self.package_folder, "bin", "autom4te")) | ||
self.output.info("Setting AUTOM4TE to {}".format(autom4te)) | ||
self.env_info.AUTOM4TE = autom4te | ||
|
||
autom4te_perllibdir = self._autoconf_datarootdir | ||
self.output.info("Setting AUTOM4TE_PERLLIBDIR to {}".format(autom4te_perllibdir)) | ||
self.env_info.AUTOM4TE_PERLLIBDIR = autom4te_perllibdir | ||
dataroot_path = 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") | ||
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") | ||
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") | ||
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") | ||
self.output.info(f"Defining AUTOM4TE environment variable: {autom4te_bin}") | ||
self.env_info.AUTOM4TE = autom4te_bin | ||
self.buildenv_info.define_path("AUTOM4TE", autom4te_bin) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,53 @@ | ||
from conans import AutoToolsBuildEnvironment, ConanFile, tools | ||
from conan.tools.microsoft import is_msvc | ||
import contextlib | ||
import os | ||
import shutil | ||
from os import path | ||
|
||
required_conan_version = ">=1.45.0" | ||
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" | ||
|
||
|
||
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" | ||
test_type = "explicit" | ||
|
||
@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 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") | ||
|
||
@contextlib.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 | ||
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) | ||
|
||
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 | ||
Comment on lines
+33
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't be merged in this state where windows is not tested, needs conan 1.53.0 in c3i There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this need 1.53? 👀 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. conan-io/conan#12095. So currently test is skipped on Windows, not good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jellespijker please remove this condition, now that conan 1.53.0 is dsployed, |
||
|
||
for src in self.exports_sources: | ||
shutil.copy(os.path.join(self.source_folder, src), self.build_folder) | ||
self.run("{} --verbose".format(os.environ["AUTOCONF"]), | ||
win_bash=tools.os_info.is_windows, run_environment=True) | ||
self.run("{} --help".format(os.path.join(self.build_folder, "configure").replace("\\", "/")), | ||
win_bash=tools.os_info.is_windows, run_environment=True) | ||
autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) | ||
with self._build_context(): | ||
autotools.configure() | ||
autotools.make() | ||
shutil.copy(path.join(self.source_folder, src), self.build_folder) | ||
|
||
self.run("autoconf --verbose") | ||
|
||
autotools = Autotools(self) | ||
autotools.configure(build_script_folder=self.build_folder) | ||
autotools.make() | ||
|
||
def test(self): | ||
if not tools.cross_building(self): | ||
self.run(os.path.join(".", "test_package"), run_environment=True) | ||
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 | ||
|
||
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") | ||
Comment on lines
+49
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not need to protect with can_run, since it's executed in build scope. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be run scope? Seems odd to be using build scope in a "can the test run" scenario 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it should be run scope |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from conans import AutoToolsBuildEnvironment, ConanFile, tools | ||
from conan.tools.microsoft import is_msvc, unix_path | ||
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", | ||
test_type = "explicit" | ||
|
||
@property | ||
def _settings_build(self): | ||
return getattr(self, "settings_build", self.settings) | ||
|
||
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") | ||
|
||
@contextlib.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 | ||
|
||
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) | ||
self.run("{} --help".format(os.path.join(self.build_folder, "configure").replace("\\", "/")), | ||
win_bash=tools.os_info.is_windows, run_environment=True) | ||
autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) | ||
with self._build_context(): | ||
autotools.configure() | ||
autotools.make() | ||
|
||
def test(self): | ||
if not tools.cross_building(self): | ||
self.run(os.path.join(".", "test_package"), run_environment=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't work with
if hasattr(self, "settings_build"):
? It's important to avoid issues with 1 profile.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SpaceIm I'm not sure what you mean with this comment;
self._settings_build
returns either thesettings_build
if available but falls back onsettings
. So I believe it should work for 1 profile and a build/host profile.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 profile is deprecated, this will help alter consumers to upgrade their usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with this strategy. It's not a good user experience to break such things brutally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still using
-pr
only, as I have problems with some packages and-pr:b and -pr:h
,so if one package won't with with -pr, and others won't work with -pr:b and -pr:h then we have a gridlock situation.
I'd instead suggest a warning in the conan client with a link to an issue where people can report problematic recipes that they discover using the dual-profiles...
I can start testing again with the dual profiles and look for errors.