Skip to content
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

Merged
merged 45 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
551afba
autoconf v2 ready
Sep 1, 2022
06a7499
Revert removal of PATH from env_info
jellespijker Sep 1, 2022
4add446
use unix_path instead of private import functions
jellespijker Sep 1, 2022
bd244f2
use unix_path instead of private import functions
jellespijker Sep 1, 2022
4cd02ff
pass self to unix_path
jellespijker Sep 1, 2022
ea10b5a
applied review comments
jellespijker Sep 2, 2022
ae5e36e
Add licenses to package
jellespijker Sep 2, 2022
6ae0e3d
Explicitly use an empty includedirs
jellespijker Sep 2, 2022
2108ccd
Merge branch 'conan-io:master' into autoconf-conan-v2
jellespijker Sep 5, 2022
6aeafa2
Fix setting unix_path for package_info
Sep 5, 2022
d9ee4de
simplified test_package
Sep 5, 2022
f6fc785
Revert "simplified test_package"
jellespijker Sep 6, 2022
357c078
use modern tools in test_package
Sep 6, 2022
b92480f
add conan test_v1_package
jellespijker Sep 6, 2022
f97d01d
m4 is a build requirement
Sep 6, 2022
75e7579
Ducktype Autotools `configure` and `make`
jellespijker Sep 7, 2022
2038f28
Fix paths on windows in test method
jellespijker Sep 7, 2022
f321757
Don't ducktype but inherit
jellespijker Sep 7, 2022
2187b09
use unix_path for env_info
jellespijker Sep 7, 2022
67efc0e
remove extra lin
jellespijker Sep 7, 2022
43c1014
don't use unix_path
jellespijker Sep 7, 2022
63ae4f9
fix subsystems on Windows
jellespijker Sep 8, 2022
36827a6
updated autoconf for conan v2 ready support
jellespijker Sep 10, 2022
29fe03c
Merge branch 'conan-io:master' into CURA-8831_autoconf
jellespijker Sep 10, 2022
c5b382d
autoconf bin contains shell scripts not executable
jellespijker Sep 11, 2022
e771b6f
Removed Autotools workaround from test_package
jellespijker Sep 11, 2022
9aaca05
m4 is a run requirement not a tool_req
jellespijker Sep 11, 2022
070ce49
use mingw32 for gnu tuple
jellespijker Sep 11, 2022
94149de
Run the configure command in the build_folder
jellespijker Sep 11, 2022
5f97677
Use conanbuild env as scope for testing
jellespijker Sep 13, 2022
88d5372
Ensure that M4 binary from dependency is used
jellespijker Sep 14, 2022
ad45b97
Set win_bash in configure stage
Sep 15, 2022
6e5d149
Merge branch 'conan-io:master' into CURA-8831_autoconf
jellespijker Sep 21, 2022
516a304
Merge branch 'conan-io:master' into CURA-8831_autoconf
jellespijker Oct 8, 2022
e1a1fe6
Merge branch 'conan-io:master' into CURA-8831_autoconf
jellespijker Oct 16, 2022
0000f38
Move conf keys to user space
jellespijker Oct 16, 2022
ea1b563
Use *_folder in favor of undocumented *_path
jellespijker Oct 16, 2022
1c1abb9
Reuse source files from test_package
jellespijker Oct 16, 2022
ed0ea5d
Apply suggestions from code review
jellespijker Oct 23, 2022
a2d8510
Use export_conandata_patches
jellespijker Oct 23, 2022
642c352
Removed unused conf_info values
jellespijker Oct 23, 2022
afa1246
Merge branch 'conan-io:master' into CURA-8831_autoconf
jellespijker Oct 23, 2022
53275c4
Check against empty string for conf value bash path
jellespijker Oct 29, 2022
f05d39a
Update recipes/autoconf/all/conanfile.py
jellespijker Oct 31, 2022
f76bdfe
Apply suggestions from code review
jellespijker Nov 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions recipes/autoconf/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,13 @@ sources:
patches:
"2.71":
- patch_file: "patches/2.71-0001-autom4te-relocatable.patch"
base_path: "source_subfolder"
- patch_file: "patches/2.71-0002-no-perl-path-in-shebang.patch"
base_path: "source_subfolder"
- patch_file: "patches/2.71-0003-uppercase-autom4te_perllibdir.patch"
base_path: "source_subfolder"
- patch_file: "patches/2.71-0004-no-embedded-m4-paths.patch"
base_path: "source_subfolder"
- patch_file: "patches/2.71-0005-disable-man-regeneration.patch"
base_path: "source_subfolder"
- patch_file: "patches/2.71-0006-autoconf-no-embedded-trailer_m4-path.patch"
base_path: "source_subfolder"
"2.69":
- patch_file: "patches/2.69-0001-autom4te-relocatable.patch"
base_path: "source_subfolder"
- patch_file: "patches/2.69-0002-no-perl-path-in-shebang.patch"
base_path: "source_subfolder"
- patch_file: "patches/2.69-0003-uppercase-autom4te_perllibdir.patch"
base_path: "source_subfolder"
- patch_file: "patches/2.69-0004-no-embedded-m4-paths.patch"
base_path: "source_subfolder"
185 changes: 97 additions & 88 deletions recipes/autoconf/all/conanfile.py
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 self.conf.get("tools.microsoft.bash:path", default="", check_type=str) == "":
jellespijker marked this conversation as resolved.
Show resolved Hide resolved
self.tool_requires("msys2/cci.latest")
self.tool_requires("m4/1.4.19")
Copy link
Contributor

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.

Copy link
Contributor Author

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 the settings_build if available but falls back on settings. So I believe it should work for 1 profile and a build/host profile.

Copy link
Contributor

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

Copy link
Contributor

@SpaceIm SpaceIm Oct 31, 2022

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.

Copy link
Contributor

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.


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)
62 changes: 34 additions & 28 deletions recipes/autoconf/all/test_package/conanfile.py
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need 1.53? 👀

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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, tools.microsoft.bash:path should be found in test package


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(f"autoconf --verbose", env="conanbuild")
jellespijker marked this conversation as resolved.
Show resolved Hide resolved

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
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it should be run scope

47 changes: 47 additions & 0 deletions recipes/autoconf/all/test_v1_package/conanfile.py
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)