This repository was archived by the owner on Jul 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcc.js
executable file
·58 lines (50 loc) · 1.46 KB
/
cc.js
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
#!/usr/bin/env -S deno run --allow-env --allow-net --allow-read --allow-run
const server = Deno.env.get("CC_WRAPPERS_SERVER");
const whoami = path.basename(import.meta.url);
const cc_unwrapped = Deno.env.get(
{ "cc.js": "CC_UNWRAPPED", "cxx.js": "CXX_UNWRAPPED" }[whoami]
);
async function realArgs(args) {
const rsp = args.find((arg) => arg.startsWith("@"));
if (!rsp) return args;
const rsp_content = await Deno.readTextFile(rsp.slice(1));
return rsp_content
.split("\n")
.filter((arg) => arg)
.map((l) => (l.startsWith('"') ? JSON.parse(l) : l));
}
function parseArgs(args) {
if (!args.includes("-c")) return null;
const file = args.find((arg) => arg.endsWith(".c") || arg.endsWith(".cpp"));
if (!file) return null;
if (
args.includes("-DPROFILING") ||
args.includes("-DDEBUG") ||
args.includes("-DTHREADED_RTS") ||
args.includes("-fPIC")
)
return null;
return {
directory: Deno.cwd(),
arguments: [cc_unwrapped, ...args],
file,
};
}
async function onParsedArgs(args, parsed_args) {
try {
if (parsed_args) {
await (
await fetch(server, {
body: JSON.stringify(parsed_args),
method: "POST",
})
).json();
}
} finally {
}
const p = Deno.run({ cmd: [cc_unwrapped, ...args] });
const ec = await p.status();
Deno.exit(ec.code);
}
onParsedArgs(Deno.args, parseArgs(await realArgs(Deno.args)));