|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | | -import os |
4 | | -import sys |
5 | | -import subprocess |
6 | | -import re |
| 3 | +import os, re, sys, subprocess |
7 | 4 |
|
8 | | -here = re.split(r'/(?=[^/]*$)', sys.argv[0]) |
9 | | -if len(here) > 1: |
10 | | - os.chdir(here[0]) |
11 | | - |
12 | | - |
13 | | -def newer(*files): |
14 | | - assert len(files) > 1 |
15 | | - rh = files[-1] |
16 | | - if not os.path.exists(rh): |
17 | | - return True |
18 | | - for lh in files[:-1]: |
19 | | - if os.stat(lh).st_mtime > os.stat(rh).st_mtime: |
20 | | - return True |
21 | | - return False |
22 | | - |
23 | | - |
24 | | -if newer("../blst.h", "c.zig"): |
25 | | - print("generating c.zig...") or sys.stdout.flush() |
26 | | - ret = subprocess.run(["zig", "translate-c", "../blst.h", "-D__BLST_ZIG__"], |
27 | | - capture_output=True, text=True) |
28 | | - with open("c.zig", "w") as fd: |
29 | | - print("// automatically generated with 'zig translate-c'", file=fd) |
30 | | - for line in ret.stdout.splitlines(): |
31 | | - if "no file" in line: |
32 | | - break |
33 | | - elif not line.startswith("pub const _"): |
34 | | - print(line, file=fd) |
35 | | - |
36 | | -print("generating root.zig...") or sys.stdout.flush() |
37 | 5 | root_zig = """ |
| 6 | +// Copyright Supranational LLC |
| 7 | +// SPDX-License-Identifier: Apache-2.0 |
| 8 | +
|
38 | 9 | const std = @import("std"); |
39 | 10 |
|
40 | 11 | pub const c = @import("c.zig"); |
@@ -393,6 +364,35 @@ def newer(*files): |
393 | 364 | } |
394 | 365 | }; |
395 | 366 | """ |
| 367 | +here = re.split(r'/(?=[^/]*$)', sys.argv[0]) |
| 368 | +if len(here) > 1: |
| 369 | + os.chdir(here[0]) |
| 370 | + |
| 371 | + |
| 372 | +def newer(*files): |
| 373 | + assert len(files) > 1 |
| 374 | + rh = files[-1] |
| 375 | + if not os.path.exists(rh): |
| 376 | + return True |
| 377 | + for lh in files[:-1]: |
| 378 | + if os.stat(lh).st_mtime > os.stat(rh).st_mtime: |
| 379 | + return True |
| 380 | + return False |
| 381 | + |
| 382 | + |
| 383 | +if newer("../blst.h", "c.zig"): |
| 384 | + print("generating c.zig...") or sys.stdout.flush() |
| 385 | + ret = subprocess.run(["zig", "translate-c", "../blst.h", "-D__BLST_ZIG__"], |
| 386 | + capture_output=True, text=True) |
| 387 | + with open("c.zig", "w") as fd: |
| 388 | + print("// automatically generated with 'zig translate-c'", file=fd) |
| 389 | + for line in ret.stdout.splitlines(): |
| 390 | + if "no file" in line: |
| 391 | + break |
| 392 | + elif not line.startswith("pub const _"): |
| 393 | + print(line, file=fd) |
| 394 | + |
| 395 | +print("generating root.zig...") or sys.stdout.flush() |
396 | 396 |
|
397 | 397 |
|
398 | 398 | def xchg_1vs2(matchobj): |
|
0 commit comments