From ad5fb40d75d5e89517dc7c18b95e3ccb87e2e195 Mon Sep 17 00:00:00 2001 From: George Hartzell Date: Tue, 17 Oct 2017 18:38:23 -0700 Subject: perl: add write permissions to update config files (#5746) Perl installs a couple of config files that need to be munged so that they don't refer to the spack compiler. These files are installed read-only. Behind the scenes 'filter_file' moves its file to a safe place, and tries to create a working file that is both O_WRONLY and has the perms of the original file. On an NFSv4 filesystem, the combination of 'r--r--r--' and O_WRONLY throws a permissions error. This commit adds a simple context manager that temporarily makes the files writable. --- var/spack/repos/builtin/packages/perl/package.py | 35 ++++++++++++++++-------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'var') diff --git a/var/spack/repos/builtin/packages/perl/package.py b/var/spack/repos/builtin/packages/perl/package.py index cb7cbe07fc..d354332b16 100644 --- a/var/spack/repos/builtin/packages/perl/package.py +++ b/var/spack/repos/builtin/packages/perl/package.py @@ -32,6 +32,7 @@ # from spack import * import os +from contextlib import contextmanager class Perl(Package): # Perl doesn't use Autotools, it should subclass Package @@ -186,7 +187,9 @@ class Perl(Package): # Perl doesn't use Autotools, it should subclass Package def filter_config_dot_pm(self): """Run after install so that Config.pm records the compiler that Spack built the package with. If this isn't done, $Config{cc} will - be set to Spack's cc wrapper script. + be set to Spack's cc wrapper script. These files are read-only, which + frustrates filter_file on some filesystems (NFSv4), so make them + temporarily writable. """ kwargs = {'ignore_absent': True, 'backup': False, 'string': False} @@ -196,18 +199,28 @@ class Perl(Package): # Perl doesn't use Autotools, it should subclass Package config_dot_pm = perl('-MModule::Loaded', '-MConfig', '-e', 'print is_loaded(Config)', output=str) - match = 'cc *=>.*' - substitute = "cc => '{cc}',".format(cc=self.compiler.cc) - filter_file(match, substitute, config_dot_pm, **kwargs) + with self.make_briefly_writable(config_dot_pm): + match = 'cc *=>.*' + substitute = "cc => '{cc}',".format(cc=self.compiler.cc) + filter_file(match, substitute, config_dot_pm, **kwargs) # And the path Config_heavy.pl d = os.path.dirname(config_dot_pm) config_heavy = join_path(d, 'Config_heavy.pl') - match = '^cc=.*' - substitute = "cc='{cc}'".format(cc=self.compiler.cc) - filter_file(match, substitute, config_heavy, **kwargs) - - match = '^ld=.*' - substitute = "ld='{ld}'".format(ld=self.compiler.cc) - filter_file(match, substitute, config_heavy, **kwargs) + with self.make_briefly_writable(config_heavy): + match = '^cc=.*' + substitute = "cc='{cc}'".format(cc=self.compiler.cc) + filter_file(match, substitute, config_heavy, **kwargs) + + match = '^ld=.*' + substitute = "ld='{ld}'".format(ld=self.compiler.cc) + filter_file(match, substitute, config_heavy, **kwargs) + + @contextmanager + def make_briefly_writable(self, path): + """Temporarily make a file writable, then reset""" + perm = os.stat(path).st_mode + os.chmod(path, perm | 0o200) + yield + os.chmod(path, perm) -- cgit v1.2.3-60-g2f50