summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGreg Becker <becker33@llnl.gov>2019-11-04 23:03:35 -0600
committerTodd Gamblin <tgamblin@llnl.gov>2019-11-18 14:13:42 -0700
commit99dfff447509a68d672a82812e5abfbc463b6d26 (patch)
tree1dd04bfa2ab55c9e8b681fde804145c7ef03053c /lib
parente433a5dc0b8a98a13cfaee43f57787be6ead4292 (diff)
downloadspack-99dfff447509a68d672a82812e5abfbc463b6d26.tar.gz
spack-99dfff447509a68d672a82812e5abfbc463b6d26.tar.bz2
spack-99dfff447509a68d672a82812e5abfbc463b6d26.tar.xz
spack-99dfff447509a68d672a82812e5abfbc463b6d26.zip
binary distribution: relocate text files properly in relative binaries (#13578)
* Make relative binaries relocate text files properly * rb strings aren't valid in python 2 * move perl to new interface for setup_environment family methods
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/binary_distribution.py2
-rw-r--r--lib/spack/spack/relocate.py20
2 files changed, 12 insertions, 10 deletions
diff --git a/lib/spack/spack/binary_distribution.py b/lib/spack/spack/binary_distribution.py
index 3effc3c71f..3b10cca180 100644
--- a/lib/spack/spack/binary_distribution.py
+++ b/lib/spack/spack/binary_distribution.py
@@ -521,8 +521,6 @@ def relocate_package(workdir, spec, allow_root):
old_prefix = str(buildinfo.get('spackprefix',
'/not/in/buildinfo/dictionary'))
rel = buildinfo.get('relative_rpaths', False)
- if rel:
- return
tty.msg("Relocating package from",
"%s to %s." % (old_path, new_path))
diff --git a/lib/spack/spack/relocate.py b/lib/spack/spack/relocate.py
index 8b1f3422d2..d899b372e7 100644
--- a/lib/spack/spack/relocate.py
+++ b/lib/spack/spack/relocate.py
@@ -378,17 +378,21 @@ def replace_prefix_text(path_name, old_dir, new_dir):
Replace old install prefix with new install prefix
in text files using utf-8 encoded strings.
"""
-
- def replace(match):
- return match.group().replace(old_dir.encode('utf-8'),
- new_dir.encode('utf-8'))
with open(path_name, 'rb+') as f:
data = f.read()
f.seek(0)
- pat = re.compile(old_dir.encode('utf-8'))
- if not pat.search(data):
- return
- ndata = pat.sub(replace, data)
+ # Replace old_dir with new_dir if it appears at the beginning of a path
+ # Negative lookbehind for a character legal in a path
+ # Then a match group for any characters legal in a compiler flag
+ # Then old_dir
+ # Then characters legal in a path
+ # Ensures we only match the old_dir if it's precedeed by a flag or by
+ # characters not legal in a path, but not if it's preceeded by other
+ # components of a path.
+ old_bytes = old_dir.encode('utf-8')
+ pat = b'(?<![\\w\\-_/])([\\w\\-_]*?)%s([\\w\\-_/]*)' % old_bytes
+ repl = b'\\1%s\\2' % new_dir.encode('utf-8')
+ ndata = re.sub(pat, repl, data)
f.write(ndata)
f.truncate()