Commit 55e619d1 authored by Jérome Perrin's avatar Jérome Perrin

component/perl: Infrastructure for CPAN packages in inpendent parts

Installing everything in site_perl is not the "buildout way" and is
incompatible with the upcoming shared slapos.recipe.cmmi
parent 792425a7
......@@ -26,3 +26,93 @@ configure-command =
environment =
PATH=${patch:location}/bin:%(PATH)s
post-make-hook = ${:_profile_base_location_}/perl-create-libs-symlink.py#943453b7d3ff8d49ed12d44a7f7076ee:post_make_hook
[perl-CPAN-package]
# Macro to install a perl package from CPAN
# This macro will generate a perl wrapper as {:perl-bin} and rewrite all
# scripts installed by the package to use this perl. Executable scripts are
# installed in ${:perl-PATH}
# Inputs:
# - module name, ie. Category/Category-Name
module = (required)
# - module version
version = (required)
# - checksum of module
md5sum = (required)
# - colon (:) separated site perl of runtime dependencies, for example
# ${perl-X-Y:site_perl}:${perl-X-Z:site_perl} these paths will be included in
# the generated wrappers
inc =
# - colon (:) separated site perl of install dependencies, for example
# ${perl-X-Y:site_perl}:${perl-X-Z:site_perl} these paths will be used only
# for installation. A typical use case is to add current directory (.) for
# packages using a local version of Module::Install.
install-inc =
# - extra arguments passed to perl Makefile.PL
extra-configure-args =
# Outputs:
# - site_perl, to use in inc in dependent packages
site_perl=${:location}/lib/site_perl/${perl:version}:${:location}:${:inc}
# - a $PATH that contain the perl wrapper
perl-PATH = ${:location}/bin/
# - the path for a perl wrapper with @INC set to this CPAN package and all the
# dependencies
perl-bin = ${:perl-PATH}/perl
# Implementation
recipe = slapos.recipe.cmmi
url = https://www.cpan.org/modules/by-module/${:module}-${:version}.tar.gz
configure-command =
PERL5LIB="${:inc}:${:install-inc}" \
${perl:location}/bin/perl \
Makefile.PL \
PREFIX=${:location} \
${:extra-configure-args}
location = ${buildout:parts-directory}/${:_buildout_section_name_}
# Install scripts in "perl-bin", but create wrappers in ./bin/
make-options =
INSTALLSITESCRIPT=${:location}/perl-bin/
make-binary=
PERL5LIB="${:inc}:${:install-inc}" make
# this post-make-hook is same for all users of the macro.
post-make-hook = ${:_profile_base_location_}/../../component/perl/perl-CPAN-package-create-wrapper.py#f9314defc3b144d9f36f8cab2a013af9:post_make_hook
perl_location = ${perl:location}
[perl-wrapper]
# Macro to generate a perl wrapper with @INC set as ${:inc}
# The wrapper will be named as the section name, in buildout's bin directory.
#
# Note that this is usually not needed, because each part installed with
# perl-CPAN-package generates its own wrapper with the package and all
# dependencies available.
# This macro is useful to build a wrapper with several independent package
# available.
# It also takes care of executing perl with -I argument and not with $PERL5LIB
# environment variable, because the later is ignored when perl runs in tainted
# mode ( with -T argument )
#
# Inputs:
# - inc : colon (:) separated site perl of modules to include in @INC
# Outputs:
# - perl-bin : an executable perl
recipe = slapos.recipe.template:jinja2
template = inline:
#!/bin/sh
{% set inc = "${:inc}".split(':') %} {# XXX we could remove duplicates from inc #}
exec ${perl:location}/bin/perl \
{% for item in inc -%}{% if item %} -I "{{ item }}" \
{% endif %}{% endfor %} "$@"
mode = 0755
rendered = ${buildout:bin-directory}/${:_buildout_section_name_}
perl-bin = ${:rendered}
import os
import textwrap
import glob
def post_make_hook(options, buildout, environmet):
prefix = options['prefix']
site_perl = options['site_perl']
perl_location = options['perl_location']
bin_folder = os.path.join(prefix, 'bin')
if not os.path.isdir(bin_folder):
os.mkdir(bin_folder)
# install a ./bin/perl wrapper with @INC set
perl_wrapper_path = os.path.join(bin_folder, 'perl')
with open(perl_wrapper_path, 'w') as wrapper:
wrapper.write(textwrap.dedent('''\
#!/bin/sh
export PERL5LIB="{site_perl}:$PERL5LIB"
exec {perl_location}/bin/perl "$@"
'''.format(**locals())))
os.chmod(perl_wrapper_path, 0755)
# create a wrapper for each scripts installed in perl-bin
for script_path in glob.glob(os.path.join(prefix, 'perl-bin', '*')):
script_name = os.path.basename(script_path)
wrapper_path = os.path.join(prefix, 'bin', script_name)
with open(wrapper_path, 'w') as wrapper:
wrapper.write(textwrap.dedent('''\
#!/bin/sh
export PERL5LIB="{site_perl}:$PERL5LIB"
exec {perl_location}/bin/perl {script_path} "$@"
'''.format(**locals())))
os.chmod(wrapper_path, 0755)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment