summaryrefslogtreecommitdiff
path: root/var
diff options
context:
space:
mode:
authorGeorge Hartzell <hartzell@alerce.com>2017-10-17 18:38:23 -0700
committerscheibelp <scheibel1@llnl.gov>2017-10-17 18:38:23 -0700
commitad5fb40d75d5e89517dc7c18b95e3ccb87e2e195 (patch)
tree09dc00605536096801dc7e652e7a2ef6300ff453 /var
parent464e558aeacfca0c4547ad24b895fc29e5f4bf5e (diff)
downloadspack-ad5fb40d75d5e89517dc7c18b95e3ccb87e2e195.tar.gz
spack-ad5fb40d75d5e89517dc7c18b95e3ccb87e2e195.tar.bz2
spack-ad5fb40d75d5e89517dc7c18b95e3ccb87e2e195.tar.xz
spack-ad5fb40d75d5e89517dc7c18b95e3ccb87e2e195.zip
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.
Diffstat (limited to 'var')
-rw-r--r--var/spack/repos/builtin/packages/perl/package.py35
1 files changed, 24 insertions, 11 deletions
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)