Skip to content

Commit 99dfff4

Browse files
becker33tgamblin
authored andcommitted
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
1 parent e433a5d commit 99dfff4

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

lib/spack/spack/binary_distribution.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,6 @@ def relocate_package(workdir, spec, allow_root):
521521
old_prefix = str(buildinfo.get('spackprefix',
522522
'/not/in/buildinfo/dictionary'))
523523
rel = buildinfo.get('relative_rpaths', False)
524-
if rel:
525-
return
526524

527525
tty.msg("Relocating package from",
528526
"%s to %s." % (old_path, new_path))

lib/spack/spack/relocate.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,17 +378,21 @@ def replace_prefix_text(path_name, old_dir, new_dir):
378378
Replace old install prefix with new install prefix
379379
in text files using utf-8 encoded strings.
380380
"""
381-
382-
def replace(match):
383-
return match.group().replace(old_dir.encode('utf-8'),
384-
new_dir.encode('utf-8'))
385381
with open(path_name, 'rb+') as f:
386382
data = f.read()
387383
f.seek(0)
388-
pat = re.compile(old_dir.encode('utf-8'))
389-
if not pat.search(data):
390-
return
391-
ndata = pat.sub(replace, data)
384+
# Replace old_dir with new_dir if it appears at the beginning of a path
385+
# Negative lookbehind for a character legal in a path
386+
# Then a match group for any characters legal in a compiler flag
387+
# Then old_dir
388+
# Then characters legal in a path
389+
# Ensures we only match the old_dir if it's precedeed by a flag or by
390+
# characters not legal in a path, but not if it's preceeded by other
391+
# components of a path.
392+
old_bytes = old_dir.encode('utf-8')
393+
pat = b'(?<![\\w\\-_/])([\\w\\-_]*?)%s([\\w\\-_/]*)' % old_bytes
394+
repl = b'\\1%s\\2' % new_dir.encode('utf-8')
395+
ndata = re.sub(pat, repl, data)
392396
f.write(ndata)
393397
f.truncate()
394398

var/spack/repos/builtin/packages/perl/package.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,25 +165,43 @@ def install_cpanm(self):
165165
make()
166166
make('install')
167167

168-
def setup_dependent_environment(self, spack_env, run_env, dependent_spec):
168+
def setup_dependent_build_environment(self, env, dependent_spec):
169169
"""Set PATH and PERL5LIB to include the extension and
170170
any other perl extensions it depends on,
171171
assuming they were installed with INSTALL_BASE defined."""
172-
perl_lib_dirs = []
173-
perl_bin_dirs = []
172+
perl_lib_dirs = [join_path(self.spec.prefix.lib,
173+
str(self.spec.version))]
174+
perl_bin_dirs = [self.spec.prefix.bin]
174175
for d in dependent_spec.traverse(
175176
deptype=('build', 'run'), deptype_query='run'):
176177
if d.package.extends(self.spec):
177178
perl_lib_dirs.append(d.prefix.lib.perl5)
178179
perl_bin_dirs.append(d.prefix.bin)
179180
if perl_bin_dirs:
180181
perl_bin_path = ':'.join(perl_bin_dirs)
181-
spack_env.prepend_path('PATH', perl_bin_path)
182-
run_env.prepend_path('PATH', perl_bin_path)
182+
env.prepend_path('PATH', perl_bin_path)
183183
if perl_lib_dirs:
184184
perl_lib_path = ':'.join(perl_lib_dirs)
185-
spack_env.prepend_path('PERL5LIB', perl_lib_path)
186-
run_env.prepend_path('PERL5LIB', perl_lib_path)
185+
env.prepend_path('PERL5LIB', perl_lib_path)
186+
187+
def setup_dependent_run_environment(self, env, dependent_spec):
188+
"""Set PATH and PERL5LIB to include the extension and
189+
any other perl extensions it depends on,
190+
assuming they were installed with INSTALL_BASE defined."""
191+
perl_lib_dirs = [join_path(self.spec.prefix.lib,
192+
str(self.spec.version))]
193+
perl_bin_dirs = [self.spec.prefix.bin]
194+
for d in dependent_spec.traverse(
195+
deptype=('run',), deptype_query='run'):
196+
if d.package.extends(self.spec):
197+
perl_lib_dirs.append(d.prefix.lib.perl5)
198+
perl_bin_dirs.append(d.prefix.bin)
199+
if perl_bin_dirs:
200+
perl_bin_path = ':'.join(perl_bin_dirs)
201+
env.prepend_path('PATH', perl_bin_path)
202+
if perl_lib_dirs:
203+
perl_lib_path = ':'.join(perl_lib_dirs)
204+
env.prepend_path('PERL5LIB', perl_lib_path)
187205

188206
def setup_dependent_package(self, module, dependent_spec):
189207
"""Called before perl modules' install() methods.

0 commit comments

Comments
 (0)