Skip to content

Commit

Permalink
update code_sign (#2457)
Browse files Browse the repository at this point in the history
  • Loading branch information
lixun910 committed Oct 10, 2023
1 parent 3a47ac2 commit c546046
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ internationalization/.vscode/launch.json
internationalization/pofiles/new_zh_CN.mo
internationalization/.vscode/settings.json
internationalization/~$zh_CN.xlsx

GeoDamake.opt
internationalization/credentials.json
internationalization/token.json

GeoDamake.opt
build/
38 changes: 30 additions & 8 deletions BuildTools/macosx/code_sign.py
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:
Expand Down Expand Up @@ -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:
Expand All @@ -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)")

0 comments on commit c546046

Please sign in to comment.