Skip to content

Commit f4c4110

Browse files
authored
Merge pull request #5 from gu0keno0/unsign_py
Add --unsign / --no-unsign cmdline options to allow unsigning relocat…
2 parents 8bce58e + 3e9ef6a commit f4c4110

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

locallibs/fix.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@
1919

2020
import os
2121
import shutil
22+
import subprocess
2223
import sys
2324

25+
26+
UNSIGN_TOOL = "/usr/bin/codesign"
27+
28+
2429
def ensure_current_version_link(framework_path, short_version):
2530
'''Make sure the framework has Versions/Current'''
2631
versions_current_path = os.path.join(framework_path, "Versions/Current")
@@ -119,3 +124,17 @@ def fix_other_things(framework_path, short_version):
119124
future'''
120125
return (ensure_current_version_link(framework_path, short_version) and
121126
fix_script_shebangs(framework_path, short_version))
127+
128+
129+
def fix_broken_signatures(files_relocatablized):
130+
"""
131+
Unsign the binaries and libraries that were relocatablized to avoid
132+
them having corrupted signatures.
133+
"""
134+
for file in files_relocatablized:
135+
print("Unsigning %s to avoid broken signature." % file)
136+
subprocess.check_call([
137+
UNSIGN_TOOL,
138+
"--remove-signature",
139+
file,
140+
])

locallibs/relocatablizer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,11 @@ def relocatablize(framework_path):
247247
)
248248
fix_modes(full_framework_path)
249249
framework_data = analyze(full_framework_path)
250+
files_changed = set()
250251
for dylib in framework_data["dylibs"]:
251252
old_install_name = dylib["install_name"]
252253
new_install_name = relativize_install_name(dylib["path"])
254+
files_changed.add(dylib["path"])
253255
# update other files with new install_name
254256
if old_install_name != new_install_name:
255257
files = (
@@ -260,7 +262,11 @@ def relocatablize(framework_path):
260262
for item in files:
261263
if old_install_name in item["dependencies"]:
262264
fix_dep(item["path"], old_install_name, new_install_name)
265+
files_changed.add(item["path"])
263266
print()
264267
# add rpaths to executables
265268
for item in framework_data["executables"]:
266269
add_rpath(item["path"])
270+
files_changed.add(item["path"])
271+
272+
return files_changed

make_relocatable_python_framework.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import optparse
2222

2323
from locallibs import get
24-
from locallibs.fix import fix_other_things
24+
from locallibs.fix import fix_broken_signatures, fix_other_things
2525
from locallibs.install import install_extras
2626
from locallibs.relocatablizer import relocatablize
2727

@@ -61,6 +61,13 @@ def main():
6161
"Python modules to be installed. If not provided, certain useful "
6262
"modules for macOS will be installed.",
6363
)
64+
parser.add_option(
65+
"--no-unsign",
66+
dest="unsign",
67+
action="store_false",
68+
help="Do not unsign binaries and libraries after they are relocatablized."
69+
)
70+
parser.set_defaults(unsign=True)
6471
options, _arguments = parser.parse_args()
6572

6673
framework_path = get.FrameworkGetter(
@@ -70,7 +77,9 @@ def main():
7077
).download_and_extract(destination=options.destination)
7178

7279
if framework_path:
73-
relocatablize(framework_path)
80+
files_relocatablized = relocatablize(framework_path)
81+
if options.unsign:
82+
fix_broken_signatures(files_relocatablized)
7483
short_version = ".".join(options.python_version.split(".")[0:2])
7584
install_extras(
7685
framework_path,

0 commit comments

Comments
 (0)