# Copyright 2013-2022 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
import os
from llnl.util.filesystem import filter_file
from spack.directives import extends
from spack.package import PackageBase, run_after
from spack.util.executable import Executable
[docs]class PerlPackage(PackageBase):
"""Specialized class for packages that are built using Perl.
This class provides four phases that can be overridden if required:
1. :py:meth:`~.PerlPackage.configure`
2. :py:meth:`~.PerlPackage.build`
3. :py:meth:`~.PerlPackage.check`
4. :py:meth:`~.PerlPackage.install`
The default methods use, in order of preference:
(1) Makefile.PL,
(2) Build.PL.
Some packages may need to override
:py:meth:`~.PerlPackage.configure_args`,
which produces a list of arguments for
:py:meth:`~.PerlPackage.configure`.
Arguments should not include the installation base directory.
"""
#: Phases of a Perl package
phases = ['configure', 'build', 'install']
#: This attribute is used in UI queries that need to know the build
#: system base class
build_system_class = 'PerlPackage'
#: Callback names for build-time test
build_time_test_callbacks = ['check']
extends('perl')
# It is possible that the shebang in the Build script that is created from
# Build.PL may be too long causing the build to fail. Patching the shebang
# does not happen until after install so set '/usr/bin/env perl' here in
# the Build script.
[docs] @run_after('configure')
def fix_shebang(self):
if self.build_method == 'Build.PL':
pattern = '#!{0}'.format(self.spec['perl'].command.path)
repl = '#!/usr/bin/env perl'
filter_file(pattern, repl, 'Build', backup=False)
[docs] def build(self, spec, prefix):
"""Builds a Perl package."""
self.build_executable()
# Ensure that tests run after build (if requested):
run_after('build')(PackageBase._run_default_build_time_test_callbacks)
[docs] def check(self):
"""Runs built-in tests of a Perl package."""
self.build_executable('test')
[docs] def install(self, spec, prefix):
"""Installs a Perl package."""
self.build_executable('install')
# Check that self.prefix is there after installation
run_after('install')(PackageBase.sanity_check_prefix)