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

perl: add recipe #24078

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions recipes/perl/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"5.38.2":
url: "https://www.cpan.org/src/5.0/perl-5.38.2.tar.gz"
sha256: "a0a31534451eb7b83c7d6594a497543a54d488bc90ca00f5e34762577f40655e"
123 changes: 123 additions & 0 deletions recipes/perl/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
from conan import ConanFile
from conan.tools.files import chdir, copy, get, replace_in_file, rmdir
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps
from conan.tools.layout import basic_layout
from conan.tools.microsoft import msvs_toolset
import os


required_conan_version = ">=1.54.0"

class PerlConan(ConanFile):
name = "perl"
description = "A high-level, general-purpose, interpreted, dynamic programming language"
license = "GPL-1.0-only"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.perl.org/"
topics = ("scripting", "programming", "language")
package_type = "application"
settings = "os", "arch", "compiler", "build_type"

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

def configure(self):
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

def layout(self):
basic_layout(self, src_folder="src")

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

def requirements(self):
self.requires("bzip2/1.0.8")
self.requires("zlib/[>=1.2.11 <2]")

def build_requirements(self):
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 generate(self):
tc = AutotoolsToolchain(self)
tc.generate()

deps = AutotoolsDeps(self)
deps.generate()

@property
def _compiler(self):
compilers = self.conf.get("tools.build:compiler_executables", default={}, check_type=dict)
if "c" in compilers:
return compilers["c"]

# Otherwise it will use the system "cc" command - assuming the profile reflects this.
return None

@property
def _cctype(self):
return f"MSVC{msvs_toolset(self)}"

def build(self):
if self.settings.os == "Windows":
# TODO: MinGW, maybe look into GNUMakefile in the same directory
makefile_dir = os.path.join(self.source_folder, "win32")
makefile = os.path.join(makefile_dir, "Makefile")
# Fix calls to 'rename' giving wrong syntax. 'ren' on Windows is synonymous with 'rename',
# 'rename' in bash is something completely different.
replace_in_file(self, makefile, "rename", "ren")
# Specify installation directory: These are set with equals in the makefile so
# they must be modified else any provided value will be overwritten.
replace_in_file(self, makefile, "INST_DRV\t= c:", f"INST_DRV\t= {self.package_folder}")
replace_in_file(self, makefile, "INST_TOP\t= $(INST_DRV)\perl", f"INST_TOP\t= {self.package_folder}")

Check warning on line 76 in recipes/perl/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Anomalous backslash in string: '\p'. String constant might be missing an r prefix.

with chdir(self, os.path.join(self.source_folder, "win32")):
# Errors if info about the MSVC version isn't given.
os.environ["CCTYPE"] = self._cctype
# Must use nmake, otherwise the build hangs
self.run("nmake")
else:
# Can't use configure() since Perl uses "Configure" instead of "configure". Renaming the file does not seem to work.
with chdir(self, self.source_folder):
command = f"./Configure -de -Dprefix={self.package_folder}"
compiler = self._compiler
if compiler:
command += f" -Dcc={compiler}"
self.run(command)
autotools = Autotools(self)
autotools.make()

def package(self):
copy(self, "Copying", self.source_folder, os.path.join(self.package_folder, "licenses"))
if self.settings.os == "Windows":
with chdir(self, os.path.join(self.source_folder, "win32")):
os.environ["CCTYPE"] = self._cctype
self.run(f"nmake install")

Check warning on line 99 in recipes/perl/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Using an f-string that does not have any interpolated variables
else:
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.install(args=["DESTDIR="])

rmdir(self, os.path.join(self.package_folder, "man"))

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

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m", "rt"]

Comment on lines +113 to +115
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m", "rt"]

There are no libraries to be linked, so the system_libs are unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a few libraries in the package, I presume C extensions that link to the system libraries. The hooks complain, so this is mainly to satisfy that.

self.runenv_info.define_path("PERL5LIB", os.path.join(self.package_folder, "lib"))

# TODO: Legacy, to be removed in Conan 2.0
self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))
self.env_info.PERL5LIB = os.path.join(self.package_folder, "lib")

def package_id(self):
del self.info.settings.compiler
47 changes: 47 additions & 0 deletions recipes/perl/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from conan import ConanFile, conan_version
from conan.errors import ConanException
from conan.tools.build import can_run
from conan.tools.layout import basic_layout
import os
from io import StringIO


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "VirtualRunEnv"
test_type = "explicit"

def layout(self):
basic_layout(self)

def requirements(self):
self.requires(self.tested_reference_str, run=True)

def build(self):
pass

@property
def _version(self):
if conan_version.major >= 2:
return self.dependencies["perl"].ref.version
else:
return self.deps_cpp_info["perl"].version

def test(self):
if can_run(self):
buffer = StringIO()
# Magic syntax for getting the perl version: $^V
# `perl --version` doesn't give a cleanly parsable output.
self.run('perl -e "print $^V"', buffer, env="conanrun")
# Produces something like "v5.38.2"
self.output.info(buffer.getvalue())
if str(self._version) not in buffer.getvalue():
raise ConanException(
f"perl reported wrong version. Expected {self._version}, got {buffer.getvalue()}."
)

self.run(f'perl {os.path.join(self.source_folder, "test_package.pl")}', env="conanrun")

# Check that the extensions requiring dependencies were built
self.run('perl -e "use IO::Compress::Bzip2"', env="conanrun")
self.run('perl -e "use Compress::Zlib"', env="conanrun")
7 changes: 7 additions & 0 deletions recipes/perl/all/test_package/test_package.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Basic test to ensure standard library modules are loadable

use File::Basename;

my $dirname = dirname("hello_conan/goodbye_conan");

print($dirname)
3 changes: 3 additions & 0 deletions recipes/perl/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"5.38.2":
folder: all
Loading