Skip to content

Commit

Permalink
Use plugin to codesign Darwin runtime library
Browse files Browse the repository at this point in the history
  • Loading branch information
jondy committed May 12, 2023
1 parent b05ab04 commit 63befaf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
raise ModuleNotFoundError('no pyarmor_runtime extension found')
'''

runtime_package_template3 = '''# Pyarmor $rev, $timestamp
from importlib.machinery import ExtensionFileLoader
from sysconfig import get_platform
__pyarmor__ = ExtensionFileLoader(
'.pyarmor_runtime', __file__.replace('__init__.py', 'pyarmor_runtime.so')
).load_module().__pyarmor__
'''


def format_platform(plat, arch):
from struct import calcsize
Expand Down
2 changes: 1 addition & 1 deletion src/cli/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ outer_keyname = pyarmor.rkey
inline_plugin = 1

;; Default plugins
plugins = PycPlugin
plugins = PycPlugin CodesignPlugin

;; Using shared runtime package
; use_runtime = /path/to/runtime
Expand Down
19 changes: 19 additions & 0 deletions src/cli/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,22 @@ def post_build(ctx, inputs, outputs, pack):
if x.endswith('.pyc'):
pycname = os.path.join(path, x)
os.rename(pycname, pycname[:-1])


class CodesignPlugin:

@staticmethod
def post_runtime(ctx, source, dest, platform):
if platform.startswith('darwin'):
from subprocess import Popen, PIPE
identity = '-'
cmdlist = ['codesign', '-s', identity, '--force',
'--all-architectures', '--timestamp', dest]
p = Popen(cmdlist, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
if p.returncode != 0:
logger.warning(
'codesign command (%r) failed with error code %d!\n'
'stdout: %r\n'
'stderr: %r',
cmdlist, p.returncode, stdout, stderr)

0 comments on commit 63befaf

Please sign in to comment.