@@ -70,6 +70,14 @@ def setUp(self):
70
70
def ccompile (self , name ):
71
71
from distutils .core import setup , Extension
72
72
source_file = '%s/%s.c' % (__dir__ , name )
73
+
74
+ try :
75
+ stat_result = os .stat (source_file )
76
+ if stat_result [6 ] == 0 :
77
+ raise SystemError ("empty source file %s" % (source_file ,))
78
+ except FileNotFoundError :
79
+ raise SystemError ("source file %s not available" % (source_file ,))
80
+
73
81
module = Extension (name , sources = [source_file ])
74
82
args = ['--quiet' , 'build' , 'install_lib' , '-f' , '--install-dir=%s' % __dir__ ]
75
83
setup (
@@ -81,12 +89,25 @@ def ccompile(self, name):
81
89
ext_modules = [module ]
82
90
)
83
91
# ensure file was really written
92
+ binary_file_llvm = '%s/%s.bc' % (__dir__ , name )
93
+ binary_file_gcc = '%s/%s.so' % (__dir__ , name )
94
+
95
+ tries = 0
96
+ while tries < 3 and not file_not_empty (binary_file_llvm ) and not file_not_empty (binary_file_gcc ):
97
+ tries += 1
98
+
99
+ if tries >= 3 :
100
+ raise SystemError ("binary file %s/%s.(bc|so) not available" % (__dir__ , name ))
101
+
102
+
103
+ def file_not_empty (path ):
84
104
try :
85
- stat_result = os .stat (source_file )
105
+ stat_result = os .stat (path )
86
106
if stat_result [6 ] == 0 :
87
- raise SystemError ( "empty source file %s" % ( source_file ,))
107
+ return False
88
108
except FileNotFoundError :
89
- raise SystemError ("source file %s not available" % (source_file ,))
109
+ return False
110
+ return True
90
111
91
112
92
113
c_template = """
@@ -502,11 +523,21 @@ def CPyExtType(name, code, **kwargs):
502
523
kwargs .setdefault ("ready_code" , "" )
503
524
c_source = UnseenFormatter ().format (template , ** kwargs )
504
525
505
- with open ("%s/%s.c" % (__dir__ , name ), "wb" , buffering = 0 ) as f :
526
+ source_file = "%s/%s.c" % (__dir__ , name )
527
+ with open (source_file , "wb" , buffering = 0 ) as f :
506
528
if GRAALPYTHON :
507
529
f .write (c_source )
508
530
else :
509
531
f .write (bytes (c_source , 'utf-8' ))
532
+
533
+ # ensure file was really written
534
+ try :
535
+ stat_result = os .stat (source_file )
536
+ if stat_result [6 ] == 0 :
537
+ raise SystemError ("empty source file %s" % (source_file ,))
538
+ except FileNotFoundError :
539
+ raise SystemError ("source file %s not available" % (source_file ,))
540
+
510
541
ccompile (None , name )
511
542
sys .path .insert (0 , __dir__ )
512
543
try :
0 commit comments