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