80 lines
2.4 KiB
Python
80 lines
2.4 KiB
Python
# Copyright Spack Project Developers. See COPYRIGHT file for details.
|
|
#
|
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
|
import glob
|
|
|
|
from spack.package import (
|
|
PackageBase,
|
|
Prefix,
|
|
Spec,
|
|
build_system,
|
|
extends,
|
|
maintainers,
|
|
register_builder,
|
|
)
|
|
|
|
from ._checks import BuilderWithDefaults
|
|
|
|
|
|
class RubyPackage(PackageBase):
|
|
"""Specialized class for building Ruby gems."""
|
|
|
|
maintainers("Kerilk")
|
|
|
|
#: This attribute is used in UI queries that need to know the build
|
|
#: system base class
|
|
build_system_class = "RubyPackage"
|
|
#: Legacy buildsystem attribute used to deserialize and install old specs
|
|
legacy_buildsystem = "ruby"
|
|
|
|
build_system("ruby")
|
|
|
|
extends("ruby", when="build_system=ruby")
|
|
|
|
|
|
@register_builder("ruby")
|
|
class RubyBuilder(BuilderWithDefaults):
|
|
"""The Ruby builder provides two phases that can be overridden if required:
|
|
|
|
#. :py:meth:`~.RubyBuilder.build`
|
|
#. :py:meth:`~.RubyBuilder.install`
|
|
"""
|
|
|
|
phases = ("build", "install")
|
|
|
|
#: Names associated with package methods in the old build-system format
|
|
legacy_methods = ()
|
|
|
|
#: Names associated with package attributes in the old build-system format
|
|
legacy_attributes = ()
|
|
|
|
def build(self, pkg: RubyPackage, spec: Spec, prefix: Prefix) -> None:
|
|
"""Build a Ruby gem."""
|
|
|
|
# ruby-rake provides both rake.gemspec and Rakefile, but only
|
|
# rake.gemspec can be built without an existing rake installation
|
|
gemspecs = glob.glob("*.gemspec")
|
|
rakefiles = glob.glob("Rakefile")
|
|
if gemspecs:
|
|
pkg.module.gem("build", "--norc", gemspecs[0])
|
|
elif rakefiles:
|
|
jobs = pkg.module.make_jobs
|
|
pkg.module.rake("package", "-j{0}".format(jobs))
|
|
else:
|
|
# Some Ruby packages only ship `*.gem` files, so nothing to build
|
|
pass
|
|
|
|
def install(self, pkg: RubyPackage, spec: Spec, prefix: Prefix) -> None:
|
|
"""Install a Ruby gem.
|
|
|
|
The ruby package sets ``GEM_HOME`` to tell gem where to install to."""
|
|
|
|
gems = glob.glob("*.gem")
|
|
if gems:
|
|
# if --install-dir is not used, GEM_PATH is deleted from the
|
|
# environement, and Gems required to build native extensions will
|
|
# not be found. Those extensions are built during `gem install`.
|
|
pkg.module.gem(
|
|
"install", "--norc", "--ignore-dependencies", "--install-dir", prefix, gems[0]
|
|
)
|