-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import subprocess | ||
import os, sys, re | ||
import os | ||
import sys | ||
import re | ||
from shutil import copyfile | ||
from pathlib import Path | ||
|
||
processed_items = {} | ||
|
||
def ProcessDependency(dylib_path, cid): | ||
|
||
def ProcessDependency(dylib_path, cid, current_item=None): | ||
if dylib_path in processed_items: | ||
return | ||
else: | ||
|
@@ -49,10 +53,14 @@ def ProcessDependency(dylib_path, cid): | |
dylib_path = '/usr/local/opt/openexr/lib/libOpenEXR-3_1.30.dylib' | ||
if dylib_path == '@rpath/libOpenEXRCore-3_1.30.dylib': | ||
dylib_path = '/usr/local/opt/openexr/lib/libOpenEXRCore-3_1.30.dylib' | ||
|
||
m = re.search('@rpath/(libabsl.*)', dylib_path) | ||
if m: | ||
dylib_path = '/usr/local/opt/abseil/lib/' + m.group(1) | ||
elif dylib_path.startswith('@rpath'): | ||
item_filename = os.path.basename(dylib_path) | ||
copy_dir = str(Path(current_item).parent) | ||
dylib_path = f'{copy_dir}/{item_filename}' | ||
|
||
m = re.search('@rpath/(libaws.*)', dylib_path) | ||
if m: | ||
|
@@ -62,21 +70,35 @@ def ProcessDependency(dylib_path, cid): | |
if m: | ||
dylib_path = '/usr/local/' + m.group(1) | ||
|
||
|
||
if dylib_path.startswith('@loader_path'): | ||
item_filename = os.path.basename(dylib_path) | ||
upper_levels = dylib_path.count('../') | ||
copy_dir = str(Path(current_item).parent) | ||
if upper_levels - 1 >= 0: | ||
current_dir = Path(current_item).parents[upper_levels - 1] | ||
copy_dir = str(current_dir) | ||
item_filename = dylib_path[dylib_path.rindex('../') + 3:] | ||
dylib_path = f'{copy_dir}/{item_filename}' | ||
elif upper_levels == 0: | ||
dylib_path = f'{copy_dir}/{item_filename}' | ||
|
||
print("Process:", dylib_path) | ||
#cmd = "codesign -f -s - " | ||
# cmd = "codesign -f -s - " | ||
cmd = '/usr/bin/codesign --force --sign "{}" '.format(cid) | ||
os.system(cmd + dylib_path) | ||
|
||
dep_libs = subprocess.check_output(['otool', '-L', dylib_path]).decode('utf-8') | ||
dep_libs = subprocess.check_output( | ||
['otool', '-L', dylib_path]).decode('utf-8') | ||
items = dep_libs.split('\n')[2:-1] | ||
for item in items: | ||
item = item.strip().split(" ")[0] | ||
if item.startswith('/usr/lib') == False and item.startswith('/System') == False: | ||
# process item | ||
ProcessDependency(item, cid) | ||
ProcessDependency(item, cid, dylib_path) | ||
|
||
|
||
# e.g. | ||
# python3 code_sign.py /opt/homebrew/opt/gdal/lib/libgdal.29.dylib "Apple Development: [email protected] (AN5USPSZF6)" | ||
# python3 code_sign.py /opt/homebrew/opt/gdal/lib/libgdal.32.dylib "Apple Development: [email protected] (AN5USPSZF6)" | ||
ProcessDependency(sys.argv[1], sys.argv[2]) | ||
#ProcessDependency(sys.argv[1], sys.argv[2]) | ||
#ProcessDependency('/opt/homebrew/Cellar/gdal/3.7.2/lib/libgdal.33.3.7.2.dylib', "Apple Development: [email protected] (AN5USPSZF6)") |