Skip to content

Commit 8065152

Browse files
committed
bindings/zig/generate.py: rearrange for better clarity.
1 parent 67fc54b commit 8065152

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

bindings/zig/generate.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,24 @@
393393
os.chdir(here[0])
394394

395395

396+
def xchg_1vs2(matchobj):
397+
if matchobj.group(2) == '1':
398+
return matchobj.group(1) + '2'
399+
else:
400+
return matchobj.group(1) + '1'
401+
402+
403+
print("generating blst.zig...") or sys.stdout.flush()
404+
with open("blst.zig", "w") as fd:
405+
print("//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", file=fd)
406+
print("// DO NOT EDIT THIS FILE!!!", file=fd)
407+
print("// The file is auto-generated by " + here[-1], file=fd)
408+
print("//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", file=fd)
409+
print(top_zig, file=fd)
410+
print(p1_zig, file=fd)
411+
print(re.sub(r'((?<!f)[pgPG\*])([12])', xchg_1vs2, p1_zig), file=fd)
412+
413+
396414
def newer(*files):
397415
assert len(files) > 1
398416
rh = files[-1]
@@ -426,31 +444,17 @@ def newer(*files):
426444
print("pub const {} = {};".format(key, val), file=fd)
427445
del pubs
428446

429-
430-
def xchg_1vs2(matchobj):
431-
if matchobj.group(2) == '1':
432-
return matchobj.group(1) + '2'
433-
else:
434-
return matchobj.group(1) + '1'
435-
436-
437-
print("generating blst.zig...") or sys.stdout.flush()
438-
with open("blst.zig", "w") as fd:
439-
print("//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", file=fd)
440-
print("// DO NOT EDIT THIS FILE!!!", file=fd)
441-
print("// The file is auto-generated by " + here[-1], file=fd)
442-
print("//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", file=fd)
443-
print(top_zig, file=fd)
444-
print(p1_zig, file=fd)
445-
print(re.sub(r'((?<!f)[pgPG\*])([12])', xchg_1vs2, p1_zig), file=fd)
446-
447447
version = "0.3.16"
448448

449449
os.chdir("../..")
450-
with open("build.zig.zon", "r") as fd:
451-
m = re.search(r'\.version = "([^"]+)"', fd.read())
452-
if m.group(1) == version:
453-
sys.exit(0)
450+
try:
451+
with open("build.zig.zon", "r") as fd:
452+
m = re.search(r'\.version = "([^"]+)"', fd.read())
453+
if m and m.group(1) == version:
454+
sys.exit(0)
455+
except OSError as e:
456+
if e.errno != 2: # not "no such file or directory"
457+
raise e
454458

455459
print("generating build.zig.zon...") or sys.stdout.flush()
456460
zon = """.{

0 commit comments

Comments
 (0)