summaryrefslogtreecommitdiff
path: root/lib/spack/docs/build_systems/rubypackage.rst
blob: ec60765eb1aeea16c0b8d8badb7252878e6375c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
.. Copyright 2013-2023 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)

.. _rubypackage:

----
Ruby
----

Like Perl, Python, and R, Ruby has its own build system for
installing Ruby gems.

^^^^^^
Phases
^^^^^^

The ``RubyBuilder`` and ``RubyPackage`` base classes provide the following phases that
can be overridden:

#. ``build`` - build everything needed to install
#. ``install`` - install everything from build directory

For packages that come with a ``*.gemspec`` file, these phases run:

.. code-block:: console

   $ gem build *.gemspec
   $ gem install *.gem


For packages that come with a ``Rakefile`` file, these phases run:

.. code-block:: console

   $ rake package
   $ gem install *.gem


For packages that come pre-packaged as a ``*.gem`` file, the build
phase is skipped and the install phase runs:

.. code-block:: console

   $ gem install *.gem


These are all standard ``gem`` commands and can be found by running:

.. code-block:: console

   $ gem help commands


For packages that only distribute ``*.gem`` files, these files can be
downloaded with the ``expand=False`` option in the ``version`` directive.
The build phase will be automatically skipped.

^^^^^^^^^^^^^^^
Important files
^^^^^^^^^^^^^^^

When building from source, Ruby packages can be identified by the
presence of any of the following files:

* ``*.gemspec``
* ``Rakefile``
* ``setup.rb`` (not yet supported)

However, not all Ruby packages are released as source code. Some are only
released as ``*.gem`` files. These files can be extracted using:

.. code-block:: console

   $ gem unpack *.gem


^^^^^^^^^^^
Description
^^^^^^^^^^^

The ``*.gemspec`` file may contain something like:

.. code-block:: ruby

   summary = "An implementation of the AsciiDoc text processor and publishing toolchain"
   description = "A fast, open source text processor and publishing toolchain for converting AsciiDoc content to HTML 5, DocBook 5, and other formats."


Either of these can be used for the description of the Spack package.

^^^^^^^^
Homepage
^^^^^^^^

The ``*.gemspec`` file may contain something like:

.. code-block:: ruby

   homepage = "https://asciidoctor.org"


This should be used as the official homepage of the Spack package.

^^^^^^^^^^^^^^^^^^^^^^^^^
Build system dependencies
^^^^^^^^^^^^^^^^^^^^^^^^^

All Ruby packages require Ruby at build and run-time. For this reason,
the base class contains:

.. code-block:: python

   extends("ruby")


The ``*.gemspec`` file may contain something like:

.. code-block:: ruby

   required_ruby_version = ">= 2.3.0"


This can be added to the Spack package using:

.. code-block:: python

   depends_on("ruby@2.3.0:", type=("build", "run"))


^^^^^^^^^^^^^^^^^
Ruby dependencies
^^^^^^^^^^^^^^^^^

When you install a package with ``gem``, it reads the ``*.gemspec``
file in order to determine the dependencies of the package.
If the dependencies are not yet installed, ``gem`` downloads them
and installs them for you. This may sound convenient, but Spack
cannot rely on this behavior for two reasons:

#. Spack needs to be able to install packages on air-gapped networks.

   If there is no internet connection, ``gem`` can't download the
   package dependencies. By explicitly listing every dependency in
   the ``package.py``, Spack knows what to download ahead of time.

#. Duplicate installations of the same dependency may occur.

   Spack supports *activation* of Ruby extensions, which involves
   symlinking the package installation prefix to the Ruby installation
   prefix. If your package is missing a dependency, that dependency
   will be installed to the installation directory of the same package.
   If you try to activate the package + dependency, it may cause a
   problem if that package has already been activated.

For these reasons, you must always explicitly list all dependencies.
Although the documentation may list the package's dependencies,
often the developers assume people will use ``gem`` and won't have to
worry about it. Always check the ``*.gemspec`` file to find the true
dependencies.

Check for the following clues in the ``*.gemspec`` file:

* ``add_runtime_dependency``

  These packages are required for installation.

* ``add_dependency``

  This is an alias for ``add_runtime_dependency``

* ``add_development_dependency``

  These packages are optional dependencies used for development.
  They should not be added as dependencies of the package.

^^^^^^^^^^^^^^^^^^^^^^
External documentation
^^^^^^^^^^^^^^^^^^^^^^

For more information on Ruby packaging, see:
https://guides.rubygems.org/