-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
executable file
·98 lines (73 loc) · 2.21 KB
/
run.py
File metadata and controls
executable file
·98 lines (73 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/python
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import time, sys, subprocess, io
should_run = True
class EventHandler(FileSystemEventHandler):
def __init__(self, paths: list[str]):
self.paths = paths
def on_modified(self, event):
global should_run
for path in self.paths:
if event.src_path.endswith(path):
should_run = True
return
args = sys.argv[1:]
watch = '--watch' in args
release = '--release' in args
generate = '--generate' in args
debug = '--debug' in args
if watch:
args.remove('--watch')
if release:
args.remove('--release')
if generate:
args.remove('--generate')
args += ['--file']
if debug:
args.remove('--debug')
if "--repeats" in args:
print("--repeats is used, suppressing errors", file=sys.stderr)
args += ['--errors', 'off']
files = [x for x in args if not x.startswith('--')]
observer = Observer()
observer.schedule(EventHandler(files), '.', recursive=True)
def run():
command = ["cargo", "build", "--quiet", "--bin", "gnag-cli"]
path = "target/debug/gnag-cli"
if release:
command += ['--release']
path = "target/release/gnag-cli"
# build cli
a = subprocess.run(command)
# run binary
if debug:
subprocess.run(["rust-gdb", "--quiet", "--args", path] + args)
os.exit(0)
else:
capture_output = generate
process = subprocess.run([path] + args, capture_output=capture_output)
if capture_output:
sys.stderr.buffer.write(process.stderr)
sys.stderr.flush()
if generate:
output_path = "crates/gnag-parser/src/lib.rs"
with open(output_path, "wb") as output:
output.write(process.stdout)
print(f"Generated file written to {output_path}", file=sys.stderr)
if watch:
observer.start()
# Keep the script running
try:
while True:
if should_run:
run()
should_run = False
if not watch:
break
time.sleep(0.1)
except KeyboardInterrupt:
pass
if watch:
observer.stop()
observer.join()