Blame SOURCES/macros.perl

276c98
# Sensible Perl-specific RPM build macros.
276c98
#
276c98
# Note that these depend on the generic filtering system being in place in
276c98
# rpm core; but won't cause a build to fail if they're not present.
276c98
#
276c98
# Chris Weyl <cweyl@alumni.drew.edu> 2009
276c98
# Marcela Mašláňová <mmaslano@redhat.com> 2011
276c98
276c98
# This macro unsets several common vars used to control how Makefile.PL (et
276c98
# al) build and install packages.  We also set a couple to help some of the
276c98
# common systems be less interactive.  This was blatantly stolen from
276c98
# cpanminus, and helps building rpms locally when one makes extensive use of
276c98
# local::lib, etc.
276c98
#
276c98
# Usage, in %build, before "%{__perl} Makefile.PL ..."
276c98
#
276c98
#   %{?perl_ext_env_unset}
276c98
276c98
%@scl@perl_ext_env_unset %{expand:
276c98
unset PERL_MM_OPT MODULEBUILDRC PERL5INC
276c98
export PERL_AUTOINSTALL="--defaultdeps"
276c98
export PERL_MM_USE_DEFAULT=1
276c98
}
276c98
276c98
#############################################################################
276c98
# Filtering macro incantations
276c98
276c98
# keep track of what "revision" of the filtering we're at.  Each time we
276c98
# change the filter we should increment this.
276c98
276c98
%@scl@perl_default_filter_revision 3
276c98
276c98
# Perl provides/requeries are generated by external generators.
276c98
%global @scl@__perl_provides /usr/lib/rpm/perl.prov
276c98
%global @scl@__perl_requires /usr/lib/rpm/perl.req
276c98
276c98
# By default, for perl packages we want to filter all files in _docdir from 
276c98
# req/prov scanning.
276c98
# Filtering out any provides caused by private libs in vendorarch/archlib
276c98
# (vendor/core) is done by rpmbuild since Fedora 20
276c98
# <https://fedorahosted.org/fpc/ticket/353>.
276c98
#
276c98
# Note that this must be invoked in the spec file, preferably as 
276c98
# "%{?perl_default_filter}", before any %description block.
276c98
276c98
%@scl@perl_default_filter %{expand: \
276c98
%global __provides_exclude_from %{?__provides_exclude_from:%__provides_exclude_from|}^%{_docdir}
276c98
%global __requires_exclude_from %{?__requires_exclude_from:%__requires_exclude_from|}^%{_docdir}
276c98
%global __provides_exclude %{?__provides_exclude:%__provides_exclude|}^%{?scl_prefix}perl\\\\(VMS|^%{?scl_prefix}perl\\\\(Win32|^%{?scl_prefix}perl\\\\(DB\\\\)|^%{?scl_prefix}perl\\\\(UNIVERSAL\\\\)
276c98
%global __requires_exclude %{?__requires_exclude:%__requires_exclude|}^%{?scl_prefix}perl\\\\(VMS|^%{?scl_prefix}perl\\\\(Win32
276c98
}
276c98
276c98
#############################################################################
276c98
# Macros to assist with generating a "-tests" subpackage in a semi-automatic
276c98
# manner.
276c98
#
276c98
# The following macros are still in a highly experimental stage and users
276c98
# should be aware that the interface and behaviour may change. 
276c98
#
276c98
# PLEASE, PLEASE CONDITIONALIZE THESE MACROS IF YOU USE THEM.
276c98
#
276c98
# See http://gist.github.com/284409
276c98
276c98
# These macros should be invoked as above, right before the first %description
276c98
# section, and conditionalized.  e.g., for the common case where all our tests
276c98
# are located under t/, the correct usage is:
276c98
#
276c98
#   %{?perl_default_subpackage_tests}
276c98
#
276c98
# If custom files/directories need to be specified, this can be done as such:
276c98
#
276c98
#   %{?perl_subpackage_tests:%perl_subpackage_tests t/ one/ three.sql}
276c98
#
276c98
# etc, etc.
276c98
276c98
%@scl@perl_version   %(eval "`%{__perl} -V:version`"; echo $version)
276c98
%@scl@perl_testdir   %{_libexecdir}/perl5-tests
276c98
%@scl@cpan_dist_name %(eval echo %{name} | %{__sed} -e 's/^perl-//')
276c98
276c98
# easily mark something as required by -tests and BR to the main package
276c98
%@scl@tests_req() %{expand:\
276c98
BuildRequires: %*\
276c98
%%@scl@tests_subpackage_requires %*\
276c98
}
276c98
276c98
# macro %%{__perl} contains the definition of LD_LIBRARY_PATH and it could
276c98
# not be used for shbang
276c98
%@scl@__perl %{?_scl_root}/usr/bin/perl
276c98
276c98
# fixup (and create if needed) the shbang lines in tests, so they work and
276c98
# rpmlint doesn't (correctly) have a fit
276c98
%@scl@fix_shbang_line() \
276c98
TMPHEAD=`mktemp`\
276c98
TMPBODY=`mktemp`\
276c98
for file in %* ; do \
276c98
    head -1 $file > $TMPHEAD\
276c98
    tail -n +2 $file > $TMPBODY\
276c98
    %{__perl} -pi -e '$f = /^#!/ ? "" : "#!%{@scl@__perl}$/"; $_="$f$_"' $TMPHEAD\
276c98
    cat $TMPHEAD $TMPBODY > $file\
276c98
done\
276c98
%{__perl} -MExtUtils::MakeMaker -e "ExtUtils::MM_Unix->fixin(qw{%*})"\
276c98
%{__rm} $TMPHEAD $TMPBODY\
276c98
%{nil}
276c98
276c98
# additional -tests subpackage requires, if any
276c98
%@scl@tests_subpackage_requires() %{expand: \
276c98
%global @scl@__tests_spkg_req %{?@scl@__tests_spkg_req} %* \
276c98
}
276c98
276c98
# additional -tests subpackage provides, if any
276c98
%@scl@tests_subpackage_provides() %{expand: \
276c98
%global @scl@__tests_spkg_prov %{?@scl@__tests_spkg_prov} %* \
276c98
}
276c98
276c98
#
276c98
# Runs after the body of %check completes.
276c98
#
276c98
276c98
%@scl@__perl_check_pre %{expand: \
276c98
%{?__spec_check_pre} \
276c98
pushd %{buildsubdir} \
276c98
%define @scl@perl_br_testdir %{buildroot}%{@scl@perl_testdir}/%{@scl@cpan_dist_name} \
276c98
%{__mkdir_p} %{@scl@perl_br_testdir} \
276c98
%{__tar} -cf - %{__perl_test_dirs} | ( cd %{@scl@perl_br_testdir} && %{__tar} -xf - ) \
276c98
find . -maxdepth 1 -type f -name '*META*' -exec %{__cp} -vp {} %{@scl@perl_br_testdir} ';' \
276c98
find %{@scl@perl_br_testdir} -type f -exec %{__chmod} -c -x {} ';' \
276c98
T_FILES=`find %{@scl@perl_br_testdir} -type f -name '*.t'` \
276c98
%@scl@fix_shbang_line $T_FILES \
276c98
%{__chmod} +x $T_FILES \
276c98
%{_fixperms} %{@scl@perl_br_testdir} \
276c98
popd \
276c98
}
276c98
276c98
#
276c98
# The actual invoked macro
276c98
#
276c98
276c98
%@scl@perl_subpackage_tests() %{expand: \
276c98
%global __perl_package 1\
276c98
%global __perl_test_dirs %* \
276c98
%global __spec_check_pre %{expand:%{@scl@__perl_check_pre}} \
276c98
%package tests\
276c98
Summary: Test suite for package %{name}\
276c98
Group: Development/Debug\
276c98
Requires: %{name} = %{?epoch:%{epoch}:}%{version}-%{release}\
276c98
Requires: %{?_scl_root}/usr/bin/prove \
276c98
%{?@scl@__tests_spkg_req:Requires: %@scl@__tests_spkg_req}\
276c98
%{?@scl@__tests_spkg_prov:Provides: %@scl@__tests_spkg_prov}\
276c98
AutoReqProv: 0 \
276c98
%description tests\
276c98
This package provides the test suite for package %{name}.\
276c98
%files tests\
276c98
%defattr(-,root,root,-)\
276c98
%{@scl@perl_testdir}\
276c98
}
276c98
276c98
# shortcut sugar
276c98
%@scl@perl_default_subpackage_tests %@scl@perl_subpackage_tests t/
276c98