-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch.fu
121 lines (98 loc) · 3.46 KB
/
watch.fu
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// This builds and tests several generations of the compiler,
// immediately and on every compiler source change,
// always starting from a base bootstrap of
// a known-to-work historical compiler version.
//
// Effectively, this limits the dialect of the language
// that is usable in the compiler itself
// to whatever is supported by the committed-in-repo
// known-to-work C++ sources.
//
// These sources are periodically updated,
// akin to an internal release, making newer syntax
// and language features available for compiler development.
//
//
fn main()
{
mut run_no = 0;
:REBUILD_LOOP for (;;)
{
let start = now::utc();
mut run_pid: spawn::PID;
mut dirty: bool;
ev::Loop(
loop_start: ||
{
// Track changes ///////////////
mut files: string[];
fn collect(dir: string)
{
fs::readdir(dir): |path, type, recurse|
{
if (path.ends(with: ".fu"))
files ~= path;
else if (type == fs::DT_DIR || type == fs::DT_UNKNOWN)
recurse();
}
}
collect("./src");
collect("./lib");
if !(files)
{
println(" WATCH Found no source files to watch.");
}
else
{
// println(" WATCH files:\n\t" ~ files.join(",\n\t"));
ev::Loop::watch_files(files,
else: |err|
println(" WATCH err(" err ") files:\n\t" files.join(",\n\t")));
}
// Launch rebuild //////////////
mut recycle = !run_no++;
if (recycle && env::get("QUICK"))
{
println("\n QUICK Skipping recycle.")
recycle = false;
}
let argv = [ recycle ? "./recycle" : "./cycle" ];
// println("REBUILD Spawning argv(" argv.join(" ") ").");
run_pid = ev::Loop::spawn(:argv,
stdout: "Parent",
stderr: "Parent",
else: |err|
println("SPWN ER argv(" argv.join(" ") ") err(" err ")"));
},
watch_event: |lax watch_id|
{
// println(" WATCH A watch has triggered watch_id(" ~ watch_id ~ ").");
let now = now::utc();
if (abs(now - start) > 0.125/*s*/)
{
if (run_pid)
{
// println(" WATCH Still running, setting dirty = true.");
dirty = true;
}
else
{
continue :REBUILD_LOOP;
}
}
},
child_closed: |lax pid, lax signo, lax code|
{
// println(" CHILD EXIT pid(" pid ") signo(" signo ") code(" code ")");
assert(pid == run_pid);
run_pid = 0;
if (dirty)
{
// println(" CHILD Re-running because dirty == true.");
continue :REBUILD_LOOP;
}
},
);
return 0;
}
}