Skip to content

Commit b892ceb

Browse files
authored
Merge pull request spack#1343 from glennpj/r_unfilter
R extension dependencies with compiler wrapper
2 parents 49e4796 + 8dc26bb commit b892ceb

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

var/spack/repos/builtin/packages/R/package.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
# License along with this program; if not, write to the Free Software
2323
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2424
##############################################################################
25-
import os
26-
2725
from spack import *
2826
from spack.util.environment import *
27+
import shutil
2928

3029

3130
class R(Package):
@@ -74,6 +73,10 @@ class R(Package):
7473
depends_on('pcre')
7574
depends_on('jdk')
7675

76+
@property
77+
def etcdir(self):
78+
return join_path(prefix, 'rlib', 'R', 'etc')
79+
7780
def install(self, spec, prefix):
7881
rlibdir = join_path(prefix, 'rlib')
7982
configure_args = ['--prefix=%s' % prefix,
@@ -88,6 +91,12 @@ def install(self, spec, prefix):
8891
make()
8992
make('install')
9093

94+
# Make a copy of Makeconf because it will be needed to properly build R
95+
# dependencies in Spack.
96+
src_makeconf = join_path(self.etcdir, 'Makeconf')
97+
dst_makeconf = join_path(self.etcdir, 'Makeconf.spack')
98+
shutil.copy(src_makeconf, dst_makeconf)
99+
91100
self.filter_compilers(spec, prefix)
92101

93102
def filter_compilers(self, spec, prefix):
@@ -98,42 +107,46 @@ def filter_compilers(self, spec, prefix):
98107
cc and c++. We want them to be bound to whatever compiler
99108
they were built with."""
100109

101-
etcdir = join_path(prefix, 'rlib', 'R', 'etc')
102-
103110
kwargs = {'ignore_absent': True, 'backup': False, 'string': True}
104111

105-
filter_file(env['CC'], self.compiler.cc,
106-
join_path(etcdir, 'Makeconf'), **kwargs)
112+
filter_file(env['CC'], self.compiler.cc,
113+
join_path(self.etcdir, 'Makeconf'), **kwargs)
107114
filter_file(env['CXX'], self.compiler.cxx,
108-
join_path(etcdir, 'Makeconf'), **kwargs)
115+
join_path(self.etcdir, 'Makeconf'), **kwargs)
109116
filter_file(env['F77'], self.compiler.f77,
110-
join_path(etcdir, 'Makeconf'), **kwargs)
117+
join_path(self.etcdir, 'Makeconf'), **kwargs)
111118
filter_file(env['FC'], self.compiler.fc,
112-
join_path(etcdir, 'Makeconf'), **kwargs)
119+
join_path(self.etcdir, 'Makeconf'), **kwargs)
113120

114121
# ========================================================================
115122
# Set up environment to make install easy for R extensions.
116123
# ========================================================================
117124

118125
@property
119126
def r_lib_dir(self):
120-
return os.path.join('rlib', 'R', 'library')
127+
return join_path('rlib', 'R', 'library')
121128

122129
def setup_dependent_environment(self, spack_env, run_env, extension_spec):
123130
# Set R_LIBS to include the library dir for the
124131
# extension and any other R extensions it depends on.
125132
r_libs_path = []
126133
for d in extension_spec.traverse(deptype=nolink, deptype_query='run'):
127134
if d.package.extends(self.spec):
128-
r_libs_path.append(os.path.join(d.prefix, self.r_lib_dir))
135+
r_libs_path.append(join_path(d.prefix, self.r_lib_dir))
129136

130137
r_libs_path = ':'.join(r_libs_path)
131138
spack_env.set('R_LIBS', r_libs_path)
139+
spack_env.set('R_MAKEVARS_SITE',
140+
join_path(self.etcdir, 'Makeconf.spack'))
141+
142+
# Use the number of make_jobs set in spack. The make program will
143+
# determine how many jobs can actually be started.
144+
spack_env.set('MAKEFLAGS', '-j{0}'.format(make_jobs))
132145

133146
# For run time environment set only the path for extension_spec and
134147
# prepend it to R_LIBS
135148
if extension_spec.package.extends(self.spec):
136-
run_env.prepend_path('R_LIBS', os.path.join(
149+
run_env.prepend_path('R_LIBS', join_path(
137150
extension_spec.prefix, self.r_lib_dir))
138151

139152
def setup_environment(self, spack_env, run_env):
@@ -147,13 +160,14 @@ def setup_environment(self, spack_env, run_env):
147160
def setup_dependent_package(self, module, ext_spec):
148161
"""Called before R modules' install() methods. In most cases,
149162
extensions will only need to have one line:
150-
R('CMD', 'INSTALL', '--library=%s' % self.module.r_lib_dir, '%s' %
151-
self.stage.source_path)"""
163+
R('CMD', 'INSTALL', '--library={0}'.format(self.module.r_lib_dir),
164+
self.stage.source_path)"""
165+
152166
# R extension builds can have a global R executable function
153167
module.R = Executable(join_path(self.spec.prefix.bin, 'R'))
154168

155169
# Add variable for library directry
156-
module.r_lib_dir = os.path.join(ext_spec.prefix, self.r_lib_dir)
170+
module.r_lib_dir = join_path(ext_spec.prefix, self.r_lib_dir)
157171

158172
# Make the site packages directory for extensions, if it does not exist
159173
# already.

0 commit comments

Comments
 (0)