Skip to content

Commit

Permalink
Refine multi-platform runtime package template
Browse files Browse the repository at this point in the history
  • Loading branch information
jondy committed May 12, 2023
1 parent ce6ac71 commit c8e38f1
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions src/cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,44 @@
from .pyarmor_runtime import __pyarmor__
'''

multi_runtime_package_template = '''# Pyarmor $rev, $timestamp
def __pyarmor__()
from platform import system, machine
from struct import calcsize
def format_system():
plat = system().lower()
return 'windows' if plat.startswith('cygwin') else \
'linux' if plat.startswith('linux') else plat
def format_machine(plat):
mach = machine().lower()
arch_table = (
('x86', ('i386', 'i486', 'i586', 'i686')),
('x86_64', ('x64', 'x86_64', 'amd64', 'intel')),
('arm', ('armv5',)),
('armv6', ('armv6l',)),
('armv7', ('armv7l',)),
('aarch32', ('aarch32',)),
('aarch64', ('aarch64', 'arm64'))
)
for alias, archlist in arch_table:
if x in archlist:
mach = alias
break
return mach
plat, mach = format_system(), format_machine()
if plat == 'windows' and mach == 'x86_64':
bitness = calcsize('P'.encode()) * 8
if bitness == 32:
mach = 'x86'
name = '.'.join(['', '_'.join([plat, mach]), 'pyarmor_runtime'])
return __import__(name, globals(), locals(), ['__pyarmor__'])
__pyarmor__ = __pyarmor__().__pyarmor__
'''

runtime_package_template2 = '''# Pyarmor $rev, $timestamp
for suffix in '', '_a1', '_a2', '_a3':
try:
Expand Down Expand Up @@ -115,10 +153,6 @@ def __init__(self, home, gpath='', lpath='', rpath='', encoding=None):
self.runtime_keyfile = '.pyarmor.ikey'

self.bootstrap_template = bootstrap_template
self.runtime_package_templates = (
runtime_package_template,
runtime_package_template2,
)

# Alias format for duplicated input names
self.alias_suffix = '{0}-{1}'
Expand Down Expand Up @@ -559,6 +593,10 @@ def runtime_messages(self):
if cfg.has_section('runtime.message'):
return cfg

def runtime_package_template(self, platforms):
return runtime_package_template if len(platforms) == 1 else \
multi_runtime_package_template

#
# RFT settings
#
Expand Down

0 comments on commit c8e38f1

Please sign in to comment.