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
1=== modified file 'utils/macos/fix_dependencies.py'
2--- utils/macos/fix_dependencies.py 2018-12-13 07:24:01 +0000
3+++ utils/macos/fix_dependencies.py 2019-04-23 20:09:09 +0000
4@@ -12,12 +12,16 @@
5 import os
6 import shutil
7 import subprocess
8+import hashlib
9
10+def hash_file(fn):
11+ return hashlib.sha1(open(fn,'rb').read()).hexdigest()
12
13 def get_dependencies(loading_binary):
14 out = subprocess.check_output(['/usr/bin/otool', '-L', loading_binary])
15 interesting_lines = (l.strip()
16 for l in out.splitlines() if l.startswith('\t'))
17+ binary_hash = hash_file(loading_binary)
18 dependencies = []
19 for line in interesting_lines:
20 if '.framework' in line: # We cannot handle frameworks
21@@ -26,31 +30,23 @@
22 continue
23 if '@executable_path' in line:
24 continue
25- dependencies.append(line[:line.find('(')].strip())
26+ dependency = line[:line.find('(')].strip()
27+ dependencies.append(dependency)
28 dep_dict = {}
29 for dep in dependencies:
30 file_name = dep.replace('@loader_path', p.dirname(loading_binary))
31+ dependency_hash = hash_file(file_name)
32+ if binary_hash == file_name:
33+ # This is a dylib and the first line is not a dependency, but the
34+ # ID of this dependency. We ignore it.
35+ continue
36 dep_dict[dep] = os.path.realpath(file_name)
37 return dep_dict
38
39
40-def fix_dependencies(top_level_binary):
41- top_level_binary = p.realpath(top_level_binary)
42- todo = {(top_level_binary, top_level_binary)}
43- done = set()
44- path = p.dirname(top_level_binary)
45- while todo:
46- (binary_in_path, binary_in_system) = todo.pop()
47- print('Fixing %s' % binary_in_path)
48- done.add(binary_in_path)
49- dependencies = get_dependencies(binary_in_system)
50- for (dep_name, dep_file) in dependencies.items():
51- in_directory = p.join(path, p.basename(dep_file))
52- todo.add((in_directory, dep_file))
53- shutil.copy(dep_file, in_directory)
54- os.chmod(in_directory, 0644)
55- subprocess.check_call(['/usr/bin/install_name_tool', '-change',
56- dep_name, '@executable_path/' + p.basename(dep_file), binary_in_path])
57+def change_id(binary):
58+ subprocess.check_call(['/usr/bin/install_name_tool', '-id',
59+ '@executable_path/' + p.basename(binary), binary])
60
61
62 def parse_args():
63@@ -74,7 +70,8 @@
64 if b in done:
65 continue
66 done.add(b)
67- for (dep_name, dep_path) in get_dependencies(b).items():
68+ dependencies = get_dependencies(b)
69+ for (dep_name, dep_path) in dependencies.items():
70 if dep_name in all_dependencies and all_dependencies[dep_name] != dep_path:
71 raise RuntimeError('{} was already seen with a different path: {} != {}' % (
72 dep_name, dep_path, all_dependencies[dep_name]))
73@@ -91,6 +88,8 @@
74
75 for binary in to_fix:
76 print('Fixing binary: %s' % binary)
77+ if binary.endswith(".dylib"):
78+ change_id(binary)
79 for (dep_name, dep_path) in all_dependencies.items():
80 subprocess.check_call(['/usr/bin/install_name_tool', '-change',
81 dep_name, '@executable_path/' + p.basename(dep_path), binary])

Subscribers

People subscribed via source and target branches

to status/vote changes: