3434from codecs import BOM_UTF8
3535from glob import glob
3636from json import dumps as json_dumps , loads as json_loads
37- from subprocess import Popen , check_output
37+ from subprocess import PIPE , Popen , check_output
3838from time import gmtime , strftime
3939from zipfile import ZipFile
4040
@@ -607,8 +607,6 @@ def copy3(src, dst, onlycopy=False):
607607
608608 logging .info ('Patch library %s' , target )
609609 data = _patch_extension (target , keylist , suffix , supermode = False )
610- with open (target , 'wb' ) as f :
611- f .write (data )
612610 checklist .append (sum (bytearray (data )))
613611
614612 if not platforms :
@@ -1456,8 +1454,6 @@ def write_integer(data, offset, value):
14561454 data [offset :offset + size ] = keylist [j ]
14571455 offset += size
14581456
1459- logging .info ('Patch library file OK' )
1460-
14611457 if suffix :
14621458 marker = bytes (b'_vax_000000' )
14631459 k = len (marker )
@@ -1471,6 +1467,12 @@ def write_integer(data, offset, value):
14711467 raise RuntimeError ('Failed to add symbol suffix for library %s'
14721468 % filename )
14731469
1470+ with open (filename , 'wb' ) as f :
1471+ f .write (data )
1472+
1473+ sign_binary (filename )
1474+
1475+ logging .info ('Patch library file OK' )
14741476 return data
14751477
14761478
@@ -1537,9 +1539,6 @@ def _make_super_runtime(capsule, output, platforms, licfile=None, suffix=''):
15371539
15381540 logging .info ('Patch extension %s' , target )
15391541 data = _patch_extension (target , keylist , suffix )
1540-
1541- with open (target , 'wb' ) as f :
1542- f .write (data )
15431542 checklist .append (sum (bytearray (data )))
15441543
15451544 logging .info ('Generate runtime files OK' )
@@ -1570,9 +1569,6 @@ def _package_super_runtime(output, platforms, filelist, keylist, suffix):
15701569
15711570 logging .info ('Patch extension %s' , target )
15721571 data = _patch_extension (target , keylist , suffix )
1573-
1574- with open (target , 'wb' ) as f :
1575- f .write (data )
15761572 checklist .append (sum (bytearray (data )))
15771573
15781574 logging .info ('Generate super runtime package OK' )
@@ -1782,3 +1778,26 @@ def get_sppmode_files(timeout=None):
17821778 logging .info ('Download sppmode library "%s" OK' , platid )
17831779
17841780 return libname , licfile
1781+
1782+
1783+ def sign_binary (filename ):
1784+ if not sys .platform .startswith ('darwin' ):
1785+ return
1786+
1787+ # Maybe cross platform
1788+ output = check_output (['file' , filename ])
1789+ if output .find (b' Mach-O ' ) == - 1 :
1790+ return
1791+
1792+ logging .info ("Signing file %s" , filename )
1793+ identity = '-'
1794+ cmdlist = ['codesign' , '-s' , identity , '--force' , '--all-architectures' ,
1795+ '--timestamp' , filename ]
1796+ p = Popen (cmdlist , stdout = PIPE , stderr = PIPE )
1797+ stdout , stderr = p .communicate ()
1798+ if p .returncode != 0 :
1799+ logging .warning ("codesign command (%r) failed with error code %d!\n "
1800+ "stdout: %r\n "
1801+ "stderr: %r" ,
1802+ cmdlist , p .returncode , stdout , stderr )
1803+ raise SystemError ("codesign failure!" )
0 commit comments