From 943d463a2d4b604c3eac0ab3c4fb8f9938370ebe Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Wed, 20 Apr 2022 09:40:03 +0200 Subject: Configure nvhpc GCC from Spack variables (#29769) Alter the `install_components/install` script to pass the `-gcc $SPACK_CC`, `-gpp $SPACK_CXX`, and `-g77 $SPACK_F77` flags to `makelocalrc`. This ensures that nvhpc is configured to use the spack gcc spec, rather than whatever gcc is found on the path. Co-authored-by: Mikael Simberg Co-authored-by: Harmen Stoppels --- var/spack/repos/builtin/packages/nvhpc/package.py | 47 ++++++++++++++++------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/var/spack/repos/builtin/packages/nvhpc/package.py b/var/spack/repos/builtin/packages/nvhpc/package.py index 6ae56786c1..44c429817a 100644 --- a/var/spack/repos/builtin/packages/nvhpc/package.py +++ b/var/spack/repos/builtin/packages/nvhpc/package.py @@ -5,7 +5,6 @@ # # Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. -import os import platform from spack import * @@ -123,22 +122,42 @@ class Nvhpc(Package): conflicts('%intel') conflicts('%xl') - def install(self, spec, prefix): - # Enable the silent installation feature - os.environ['NVHPC_SILENT'] = "true" - os.environ['NVHPC_ACCEPT_EULA'] = "accept" - os.environ['NVHPC_INSTALL_DIR'] = prefix - - if spec.variants['install_type'].value == 'network': - os.environ['NVHPC_INSTALL_TYPE'] = "network" - os.environ['NVHPC_INSTALL_LOCAL_DIR'] = \ - "%s/%s/%s/share_objects" % \ - (prefix, 'Linux_%s' % spec.target.family, self.version) + def _version_prefix(self): + return join_path( + self.prefix, 'Linux_%s' % self.spec.target.family, self.version) + + def setup_build_environment(self, env): + env.set('NVHPC_SILENT', 'true') + env.set('NVHPC_ACCEPT_EULA', 'accept') + env.set('NVHPC_INSTALL_DIR', self.prefix) + + if self.spec.variants['install_type'].value == 'network': + local_dir = join_path(self._version_prefix(), 'share_objects') + env.set('NVHPC_INSTALL_TYPE', 'network') + env.set('NVHPC_INSTALL_LOCAL_DIR', local_dir) else: - os.environ['NVHPC_INSTALL_TYPE'] = "single" + env.set('NVHPC_INSTALL_TYPE', 'single') + + def install(self, spec, prefix): + compilers_bin = join_path(self._version_prefix(), 'compilers', 'bin') + install = Executable('./install') + makelocalrc = Executable(join_path(compilers_bin, 'makelocalrc')) + + makelocalrc_args = [ + '-gcc', self.compiler.cc, + '-gpp', self.compiler.cxx, + '-g77', self.compiler.f77, + '-x', compilers_bin + ] + if self.spec.variants['install_type'].value == 'network': + local_dir = join_path(self._version_prefix(), 'share_objects') + makelocalrc_args.extend(['-net', local_dir]) # Run install script - os.system("./install") + install() + + # Update localrc to use Spack gcc + makelocalrc(*makelocalrc_args) def setup_run_environment(self, env): prefix = Prefix(join_path(self.prefix, -- cgit v1.2.3-70-g09d2