Merge lp:~widelands-dev/widelands/fix_fix_dependencies into lp:widelands

Proposed by SirVer
Status: Merged
Merged at revision: 9071
Proposed branch: lp:~widelands-dev/widelands/fix_fix_dependencies
Merge into: lp:widelands
Diff against target: 81 lines (+18/-19)
1 file modified
utils/macos/fix_dependencies.py (+18/-19)
To merge this branch: bzr merge lp:~widelands-dev/widelands/fix_fix_dependencies
Reviewer Review Type Date Requested Status
Toni Förster Approve
Review via email: mp+366416@code.launchpad.net

Commit message

Fix the fix_dependency.py script.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4771. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/523680818.
Appveyor build 4555. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_fix_fix_dependencies-4555.

Revision history for this message
Toni Förster (stonerl) :
review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

@bunnybot merge

Revision history for this message
GunChleoc (gunchleoc) wrote :

I have copied the fix to the Build 20 branch too.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'utils/macos/fix_dependencies.py'
--- utils/macos/fix_dependencies.py 2018-12-13 07:24:01 +0000
+++ utils/macos/fix_dependencies.py 2019-04-23 20:09:09 +0000
@@ -12,12 +12,16 @@
12import os12import os
13import shutil13import shutil
14import subprocess14import subprocess
15import hashlib
1516
17def hash_file(fn):
18 return hashlib.sha1(open(fn,'rb').read()).hexdigest()
1619
17def get_dependencies(loading_binary):20def get_dependencies(loading_binary):
18 out = subprocess.check_output(['/usr/bin/otool', '-L', loading_binary])21 out = subprocess.check_output(['/usr/bin/otool', '-L', loading_binary])
19 interesting_lines = (l.strip()22 interesting_lines = (l.strip()
20 for l in out.splitlines() if l.startswith('\t'))23 for l in out.splitlines() if l.startswith('\t'))
24 binary_hash = hash_file(loading_binary)
21 dependencies = []25 dependencies = []
22 for line in interesting_lines:26 for line in interesting_lines:
23 if '.framework' in line: # We cannot handle frameworks27 if '.framework' in line: # We cannot handle frameworks
@@ -26,31 +30,23 @@
26 continue30 continue
27 if '@executable_path' in line:31 if '@executable_path' in line:
28 continue32 continue
29 dependencies.append(line[:line.find('(')].strip())33 dependency = line[:line.find('(')].strip()
34 dependencies.append(dependency)
30 dep_dict = {}35 dep_dict = {}
31 for dep in dependencies:36 for dep in dependencies:
32 file_name = dep.replace('@loader_path', p.dirname(loading_binary))37 file_name = dep.replace('@loader_path', p.dirname(loading_binary))
38 dependency_hash = hash_file(file_name)
39 if binary_hash == file_name:
40 # This is a dylib and the first line is not a dependency, but the
41 # ID of this dependency. We ignore it.
42 continue
33 dep_dict[dep] = os.path.realpath(file_name)43 dep_dict[dep] = os.path.realpath(file_name)
34 return dep_dict44 return dep_dict
3545
3646
37def fix_dependencies(top_level_binary):47def change_id(binary):
38 top_level_binary = p.realpath(top_level_binary)48 subprocess.check_call(['/usr/bin/install_name_tool', '-id',
39 todo = {(top_level_binary, top_level_binary)}49 '@executable_path/' + p.basename(binary), binary])
40 done = set()
41 path = p.dirname(top_level_binary)
42 while todo:
43 (binary_in_path, binary_in_system) = todo.pop()
44 print('Fixing %s' % binary_in_path)
45 done.add(binary_in_path)
46 dependencies = get_dependencies(binary_in_system)
47 for (dep_name, dep_file) in dependencies.items():
48 in_directory = p.join(path, p.basename(dep_file))
49 todo.add((in_directory, dep_file))
50 shutil.copy(dep_file, in_directory)
51 os.chmod(in_directory, 0644)
52 subprocess.check_call(['/usr/bin/install_name_tool', '-change',
53 dep_name, '@executable_path/' + p.basename(dep_file), binary_in_path])
5450
5551
56def parse_args():52def parse_args():
@@ -74,7 +70,8 @@
74 if b in done:70 if b in done:
75 continue71 continue
76 done.add(b)72 done.add(b)
77 for (dep_name, dep_path) in get_dependencies(b).items():73 dependencies = get_dependencies(b)
74 for (dep_name, dep_path) in dependencies.items():
78 if dep_name in all_dependencies and all_dependencies[dep_name] != dep_path:75 if dep_name in all_dependencies and all_dependencies[dep_name] != dep_path:
79 raise RuntimeError('{} was already seen with a different path: {} != {}' % (76 raise RuntimeError('{} was already seen with a different path: {} != {}' % (
80 dep_name, dep_path, all_dependencies[dep_name]))77 dep_name, dep_path, all_dependencies[dep_name]))
@@ -91,6 +88,8 @@
9188
92 for binary in to_fix:89 for binary in to_fix:
93 print('Fixing binary: %s' % binary)90 print('Fixing binary: %s' % binary)
91 if binary.endswith(".dylib"):
92 change_id(binary)
94 for (dep_name, dep_path) in all_dependencies.items():93 for (dep_name, dep_path) in all_dependencies.items():
95 subprocess.check_call(['/usr/bin/install_name_tool', '-change',94 subprocess.check_call(['/usr/bin/install_name_tool', '-change',
96 dep_name, '@executable_path/' + p.basename(dep_path), binary])95 dep_name, '@executable_path/' + p.basename(dep_path), binary])

Subscribers

People subscribed via source and target branches

to status/vote changes: