Merge pull request #1343 from glennpj/r_unfilter

R extension dependencies with compiler wrapper
This commit is contained in:
becker33 2016-08-01 13:51:13 -07:00 committed by GitHub
commit b892cebe8a

View File

@ -22,10 +22,9 @@
# License along with this program; if not, write to the Free Software # License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
import os
from spack import * from spack import *
from spack.util.environment import * from spack.util.environment import *
import shutil
class R(Package): class R(Package):
@ -74,6 +73,10 @@ class R(Package):
depends_on('pcre') depends_on('pcre')
depends_on('jdk') depends_on('jdk')
@property
def etcdir(self):
return join_path(prefix, 'rlib', 'R', 'etc')
def install(self, spec, prefix): def install(self, spec, prefix):
rlibdir = join_path(prefix, 'rlib') rlibdir = join_path(prefix, 'rlib')
configure_args = ['--prefix=%s' % prefix, configure_args = ['--prefix=%s' % prefix,
@ -88,6 +91,12 @@ def install(self, spec, prefix):
make() make()
make('install') make('install')
# Make a copy of Makeconf because it will be needed to properly build R
# dependencies in Spack.
src_makeconf = join_path(self.etcdir, 'Makeconf')
dst_makeconf = join_path(self.etcdir, 'Makeconf.spack')
shutil.copy(src_makeconf, dst_makeconf)
self.filter_compilers(spec, prefix) self.filter_compilers(spec, prefix)
def filter_compilers(self, spec, prefix): def filter_compilers(self, spec, prefix):
@ -98,18 +107,16 @@ def filter_compilers(self, spec, prefix):
cc and c++. We want them to be bound to whatever compiler cc and c++. We want them to be bound to whatever compiler
they were built with.""" they were built with."""
etcdir = join_path(prefix, 'rlib', 'R', 'etc')
kwargs = {'ignore_absent': True, 'backup': False, 'string': True} kwargs = {'ignore_absent': True, 'backup': False, 'string': True}
filter_file(env['CC'], self.compiler.cc, filter_file(env['CC'], self.compiler.cc,
join_path(etcdir, 'Makeconf'), **kwargs) join_path(self.etcdir, 'Makeconf'), **kwargs)
filter_file(env['CXX'], self.compiler.cxx, filter_file(env['CXX'], self.compiler.cxx,
join_path(etcdir, 'Makeconf'), **kwargs) join_path(self.etcdir, 'Makeconf'), **kwargs)
filter_file(env['F77'], self.compiler.f77, filter_file(env['F77'], self.compiler.f77,
join_path(etcdir, 'Makeconf'), **kwargs) join_path(self.etcdir, 'Makeconf'), **kwargs)
filter_file(env['FC'], self.compiler.fc, filter_file(env['FC'], self.compiler.fc,
join_path(etcdir, 'Makeconf'), **kwargs) join_path(self.etcdir, 'Makeconf'), **kwargs)
# ======================================================================== # ========================================================================
# Set up environment to make install easy for R extensions. # Set up environment to make install easy for R extensions.
@ -117,7 +124,7 @@ def filter_compilers(self, spec, prefix):
@property @property
def r_lib_dir(self): def r_lib_dir(self):
return os.path.join('rlib', 'R', 'library') return join_path('rlib', 'R', 'library')
def setup_dependent_environment(self, spack_env, run_env, extension_spec): def setup_dependent_environment(self, spack_env, run_env, extension_spec):
# Set R_LIBS to include the library dir for the # Set R_LIBS to include the library dir for the
@ -125,15 +132,21 @@ def setup_dependent_environment(self, spack_env, run_env, extension_spec):
r_libs_path = [] r_libs_path = []
for d in extension_spec.traverse(deptype=nolink, deptype_query='run'): for d in extension_spec.traverse(deptype=nolink, deptype_query='run'):
if d.package.extends(self.spec): if d.package.extends(self.spec):
r_libs_path.append(os.path.join(d.prefix, self.r_lib_dir)) r_libs_path.append(join_path(d.prefix, self.r_lib_dir))
r_libs_path = ':'.join(r_libs_path) r_libs_path = ':'.join(r_libs_path)
spack_env.set('R_LIBS', r_libs_path) spack_env.set('R_LIBS', r_libs_path)
spack_env.set('R_MAKEVARS_SITE',
join_path(self.etcdir, 'Makeconf.spack'))
# Use the number of make_jobs set in spack. The make program will
# determine how many jobs can actually be started.
spack_env.set('MAKEFLAGS', '-j{0}'.format(make_jobs))
# For run time environment set only the path for extension_spec and # For run time environment set only the path for extension_spec and
# prepend it to R_LIBS # prepend it to R_LIBS
if extension_spec.package.extends(self.spec): if extension_spec.package.extends(self.spec):
run_env.prepend_path('R_LIBS', os.path.join( run_env.prepend_path('R_LIBS', join_path(
extension_spec.prefix, self.r_lib_dir)) extension_spec.prefix, self.r_lib_dir))
def setup_environment(self, spack_env, run_env): def setup_environment(self, spack_env, run_env):
@ -147,13 +160,14 @@ def setup_environment(self, spack_env, run_env):
def setup_dependent_package(self, module, ext_spec): def setup_dependent_package(self, module, ext_spec):
"""Called before R modules' install() methods. In most cases, """Called before R modules' install() methods. In most cases,
extensions will only need to have one line: extensions will only need to have one line:
R('CMD', 'INSTALL', '--library=%s' % self.module.r_lib_dir, '%s' % R('CMD', 'INSTALL', '--library={0}'.format(self.module.r_lib_dir),
self.stage.source_path)""" self.stage.source_path)"""
# R extension builds can have a global R executable function # R extension builds can have a global R executable function
module.R = Executable(join_path(self.spec.prefix.bin, 'R')) module.R = Executable(join_path(self.spec.prefix.bin, 'R'))
# Add variable for library directry # Add variable for library directry
module.r_lib_dir = os.path.join(ext_spec.prefix, self.r_lib_dir) module.r_lib_dir = join_path(ext_spec.prefix, self.r_lib_dir)
# Make the site packages directory for extensions, if it does not exist # Make the site packages directory for extensions, if it does not exist
# already. # already.