Skip to content

Commit 416f3b9

Browse files
committed
Do stat with re-try on native test module binary.
1 parent 8caf99f commit 416f3b9

File tree

1 file changed

+35
-4
lines changed
  • graalpython/com.oracle.graal.python.test/src/tests/cpyext

1 file changed

+35
-4
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/__init__.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ def setUp(self):
7070
def ccompile(self, name):
7171
from distutils.core import setup, Extension
7272
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+
7381
module = Extension(name, sources=[source_file])
7482
args = ['--quiet', 'build', 'install_lib', '-f', '--install-dir=%s' % __dir__]
7583
setup(
@@ -81,12 +89,25 @@ def ccompile(self, name):
8189
ext_modules=[module]
8290
)
8391
# 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):
84104
try:
85-
stat_result = os.stat(source_file)
105+
stat_result = os.stat(path)
86106
if stat_result[6] == 0:
87-
raise SystemError("empty source file %s" % (source_file,))
107+
return False
88108
except FileNotFoundError:
89-
raise SystemError("source file %s not available" % (source_file,))
109+
return False
110+
return True
90111

91112

92113
c_template = """
@@ -502,11 +523,21 @@ def CPyExtType(name, code, **kwargs):
502523
kwargs.setdefault("ready_code", "")
503524
c_source = UnseenFormatter().format(template, **kwargs)
504525

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:
506528
if GRAALPYTHON:
507529
f.write(c_source)
508530
else:
509531
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+
510541
ccompile(None, name)
511542
sys.path.insert(0, __dir__)
512543
try:

0 commit comments

Comments
 (0)