Commit 74b7ce68 authored by Ghislain MARY's avatar Ghislain MARY

Make mac_rpath.py script compatible with Python 3.

parent 9b4413f0
...@@ -22,8 +22,8 @@ def list_files(source_dir): ...@@ -22,8 +22,8 @@ def list_files(source_dir):
# List libraries used in a file # List libraries used in a file
def list_libraries(file): def list_libraries(file):
print "Exec: /usr/bin/otool -L %s" % file print("Exec: /usr/bin/otool -L %s" % file)
ret = subprocess.check_output(["/usr/bin/otool", "-L", file]) ret = subprocess.check_output(["/usr/bin/otool", "-L", file]).decode('utf-8')
librarylist = [] librarylist = []
for a in ret.split("\n"): for a in ret.split("\n"):
...@@ -36,30 +36,30 @@ def list_libraries(file): ...@@ -36,30 +36,30 @@ def list_libraries(file):
def change_library_id(file, id): def change_library_id(file, id):
id = "@loader_path/" + id id = "@loader_path/" + id
os.chmod(file, 0o755) os.chmod(file, 0o755)
print "%s: Change id %s" % (file, id) print("%s: Change id %s" % (file, id))
ret = subprocess.check_output(["/usr/bin/install_name_tool", "-id", id, file], stderr=subprocess.STDOUT) ret = subprocess.check_output(["/usr/bin/install_name_tool", "-id", id, file], stderr=subprocess.STDOUT)
# Change path to a library in a file # Change path to a library in a file
def change_library_path(file, old, new, path = ""): def change_library_path(file, old, new, path = ""):
if len(path)> 0 and path[-1] <> '/': if len(path)> 0 and path[-1] != '/':
path = path + "/" path = path + "/"
new = "@loader_path/" + path + new new = "@loader_path/" + path + new
os.chmod(file, 0o755) os.chmod(file, 0o755)
print "%s: Replace %s -> %s" % (file, old, new) print("%s: Replace %s -> %s" % (file, old, new))
ret = subprocess.check_output(["/usr/bin/install_name_tool", "-change", old, new, file]) ret = subprocess.check_output(["/usr/bin/install_name_tool", "-change", old, new, file])
# Replace libraries used by a file # Replace libraries used by a file
def replace_libraries(file, name, libraries, path = ""): def replace_libraries(file, name, libraries, path = ""):
print "---------------------------------------------" print("---------------------------------------------")
print "Replace libraries in %s" % file print("Replace libraries in %s" % file)
change_library_id(file, name) change_library_id(file, name)
librarylist = list_libraries(file) librarylist = list_libraries(file)
for lib in libraries: for lib in libraries:
if lib <> name: if lib != name:
completelib = [s for s in librarylist if lib in s] completelib = [s for s in librarylist if lib in s]
if len(completelib) == 1: if len(completelib) == 1:
change_library_path(file, completelib[0], lib, path) change_library_path(file, completelib[0], lib, path)
print "---------------------------------------------" print("---------------------------------------------")
def main(argv=None): def main(argv=None):
if argv is None: if argv is None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment