5454ssh darwin 'cd /tmp && /usr/local/bin/python3 -u -' <gen_native_cfg.py >../graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixConstantsDarwin.java
5555"""
5656
57- import argparse
5857import datetime
5958import os
6059import subprocess
@@ -550,7 +549,8 @@ class PosixConstants{platform} {{
550549 static void getConstants(PosixConstants.Registry constants) {{
551550{output}
552551 }}
553- }}'''
552+ }}
553+ '''
554554
555555Constant = namedtuple ('Constant' , ['name' , 'optional' , 'type' , 'format' ])
556556Struct = namedtuple ('Struct' , ['name' , 'members' , 'unix_only' ])
@@ -576,11 +576,8 @@ def parse_defs():
576576 current_group = []
577577 groups [m .group (1 )] = current_group
578578 else :
579- d = type_defs [m .group (3 )]
580- optional = m .group (2 ) == '*' or (m .group (2 ) and sys .platform .capitalize () == 'Win32' )
581- if sys .platform .capitalize () == 'Win32' :
582- optional = m .group (2 )
583- c = Constant (m .group (4 ), optional , * d )
579+ c_type , c_format = type_defs [m .group (3 )]
580+ c = Constant (name = m .group (4 ), optional = m .group (2 ), type = c_type , format = c_format )
584581 current_group .append (c )
585582 constants .append (c )
586583
@@ -646,7 +643,7 @@ def generate_platform():
646643 f .write (f'#ifdef { c .name } \n ' )
647644 f .write (f' printf(" constants.put(\\ "{ c .name } \\ ", { c .format } );\\ n", { c .name } );\n ' )
648645 if c .optional :
649- if c .optional not in [ "*" , True ] :
646+ if c .optional != '*' :
650647 f .write ('#else\n ' )
651648 if c .optional == "u" :
652649 f .write (f' printf(" constants.put(\\ "{ c .name } \\ ", { c .format } );\\ n", _{ c .name } );\n ' )
@@ -666,7 +663,10 @@ def generate_platform():
666663 output = subprocess .run (f'./{ c_executable_file } ' , shell = False , check = True , stdout = subprocess .PIPE , universal_newlines = True ).stdout [:- 1 ]
667664 uname = " " .join (tuple (plat .uname ()))
668665
669- print (platform_template .format (java_copyright = java_copyright , script_name = script_name , timestamp = datetime .datetime .now (), uname = uname , platform = platform , output = output ))
666+ out_path = DIR / f'graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixConstants{ platform } .java'
667+
668+ with open (out_path , 'w' ) as f :
669+ f .write (platform_template .format (java_copyright = java_copyright , script_name = script_name , timestamp = datetime .datetime .now (), uname = uname , platform = platform , output = output ))
670670
671671
672672def load_existing_parts (path ):
@@ -714,7 +714,7 @@ def generate_posix_constants(constants, groups):
714714 defs = []
715715
716716 def add_constant (opt , typ , name ):
717- prefix = 'Optional' if opt else 'Mandatory'
717+ prefix = 'Optional' if opt == '*' else 'Mandatory'
718718 decls .append (f' public static final { prefix } { typ } Constant { name } ;\n ' )
719719 defs .append (f' { name } = reg.create{ prefix } { typ } ("{ name } ");\n ' )
720720
@@ -771,13 +771,8 @@ def generate_native_constants(layouts):
771771
772772
773773def main ():
774- parser = argparse .ArgumentParser ()
775- parser .add_argument ('--common' , action = 'store_true' )
776- args = parser .parse_args ()
777- if args .common :
778- generate_common ()
779- return
780774 try :
775+ generate_common ()
781776 generate_platform ()
782777 finally :
783778 delete_if_exists (c_source_file )
0 commit comments