Skip to content

Commit a506bf9

Browse files
gartungBenedikt Hegner
authored andcommitted
making this work on OSX
1 parent 132993d commit a506bf9

1 file changed

Lines changed: 24 additions & 23 deletions

File tree

lib/spack/spack/binary_distribution.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import re
5+
import stat
56
import platform
67
from commands import getstatusoutput
78

@@ -109,14 +110,11 @@ def get_filetype(path_name):
109110
"""
110111
check the output of the file command for given string
111112
"""
112-
file_command = which("file")
113-
output = file_command("-b",
114-
path_name,
115-
output=str,
116-
fail_on_error=False,
117-
error=str)
118-
if file_command.returncode != 0:
119-
tty.warn('getting filetype of "%s" failed' % path_name)
113+
file_command = "LC_ALL=C file -b -h \"%s\"" % path_name
114+
status, output = getstatusoutput(file_command)
115+
116+
if status!= 0:
117+
tty.warn('getting filetype of "%s" failed' %path_name)
120118
return None
121119
return output.strip()
122120

@@ -149,18 +147,20 @@ def relocate_binary(path_name, topdir, new_root_dir, patchelf_executable):
149147
Change RPATHs in given file
150148
"""
151149
orig_rpath = get_existing_rpath(path_name, patchelf_executable)
152-
new_rpath = substitute_rpath(orig_rpath, topdir, new_root_dir)
153-
modify_rpath(path_name, orig_rpath, new_rpath, patchelf_executable)
150+
if orig_rpath:
151+
new_rpath = substitute_rpath(orig_rpath, topdir, new_root_dir)
152+
modify_rpath(path_name, orig_rpath, new_rpath, patchelf_executable)
154153

155154

156155
def get_existing_rpath(path_name, patchelf_executable):
157156
if platform.system() == 'Darwin':
158157
command = which('otool')
159-
output = command("-l", path_name)
158+
output = command("-l", path_name,output=str,err=str)
160159
if command.returncode != 0:
161160
tty.warn('failed reading rpath for %s.' % path_name)
162161
return False
163162
last_cmd = None
163+
path = None
164164
for line in output.split('\n'):
165165
match = re.search('( *[a-zA-Z]+ )(.*)', line)
166166
if match:
@@ -173,7 +173,10 @@ def get_existing_rpath(path_name, patchelf_executable):
173173
last_cmd = rhs
174174
if lhs == 'path' and last_cmd == 'LC_RPATH':
175175
path = rhs
176-
return path.split(':')
176+
if path == None :
177+
return False
178+
else:
179+
return path.split(':')
177180
elif platform.system() == 'Linux':
178181
command = '%s --print-rpath %s ' % (patchelf_executable, path_name)
179182
status, output = getstatusoutput(command)
@@ -198,20 +201,18 @@ def substitute_rpath(orig_rpath, topdir, new_root_path):
198201

199202

200203
def modify_rpath(path_name, orig_rpath, new_rpath, patchelf_executable):
204+
st = os.stat(path_name)
205+
wmode=os.access(path_name,os.W_OK)
206+
if not wmode : os.chmod(path_name,st.st_mode | stat.S_IWUSR)
201207
if platform.system() == 'Darwin':
202208
orig_joined = ':'.join(orig_rpath)
203209
new_joined = ':'.join(new_rpath)
204-
command = "install_name_tool -rpath '%s' '%s' '%s'" % \
205-
(orig_joined, new_joined, path_name)
206-
status, output = getstatusoutput(command)
207-
if status != 0:
208-
tty.warn('failed writing rpath for %s.' % path_name)
209210
for orig, new in zip(orig_rpath, new_rpath):
210-
command = "install_name_tool -rpath '%s' '%s' '%s'" % \
211-
(orig, new, path_name)
212-
status, output = getstatusoutput(command)
213-
if status != 0:
214-
tty.warn('failed writing rpath for %s.' % path_name)
211+
command = which("install_name_tool")
212+
output = command("-rpath", "%s" % orig,\
213+
"%s" % new, "%s" % path_name, output=str, err=str )
214+
if command.returncode != 0:
215+
tty.warn('failed writing rpath for %s.' %path_name)
215216
elif platform.system() == 'Linux':
216217
new_joined = ':'.join(new_rpath)
217218
command = "%s --force-rpath --set-rpath '%s' '%s'" % \
@@ -221,7 +222,7 @@ def modify_rpath(path_name, orig_rpath, new_rpath, patchelf_executable):
221222
tty.warn('failed writing rpath for %s.' % path_name)
222223
else:
223224
tty.die('relocation not supported for this platform')
224-
225+
os.chmod(path_name,st.st_mode)
225226

226227
def relocate_text(path_name, original_path, new_path):
227228
"""

0 commit comments

Comments
 (0)