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 4 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"
93 changes: 93 additions & 0 deletions recipes/perl/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import chdir, copy, get, rmdir
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps
from conan.tools.layout import basic_layout
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"

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 validate(self):
if self.settings.os == "Windows":
Copy link
Contributor

Choose a reason for hiding this comment

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

The recipe might work with MinGW. Maybe restrict it for MSVC only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I sort of just assumed it didn't work, but I didn't actually try. I'll give it a shot and see how it goes.

raise ConanInvalidConfiguration(f"{self.ref} is not supported on {self.settings.os}. "
"You may want to use strawberryperl instead.")

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 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)
Ahajha marked this conversation as resolved.
Show resolved Hide resolved
if "c" in compilers:
return compilers["c"]

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

def build(self):
# 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):
config_path = os.path.join(self.source_folder, 'Configure')
command = f"{config_path} -de -Dprefix={self.package_folder}"
Ahajha marked this conversation as resolved.
Show resolved Hide resolved
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"))
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