-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathCompiler.js
More file actions
92 lines (76 loc) · 2.12 KB
/
Compiler.js
File metadata and controls
92 lines (76 loc) · 2.12 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
import Gio from "gi://Gio";
import dbus_previewer from "../../Previewer/DBusPreviewer.js";
import { createTmpDir, copy } from "../../util.js";
import { setupValaProject } from "./vala.js";
let ready_to_build = false;
const session_build_dir = await createTmpDir("vala");
export default function ValaCompiler({ session }) {
const { file } = session;
const meson_builddir = "builddir";
const module_file = session_build_dir
.get_child(meson_builddir)
.get_child("libworkbenchcode.so");
async function compile() {
if (!ready_to_build) {
try {
await setupValaProject(session_build_dir);
ready_to_build = true;
} catch (err) {
console.error(err);
return false;
}
}
await copy(
"main.vala",
file,
session_build_dir,
Gio.FileCopyFlags.OVERWRITE | Gio.FileCopyFlags.ALL_METADATA,
);
// TODO: Do not run setup if the build directory is already
// configured
const meson_launcher = new Gio.SubprocessLauncher();
meson_launcher.set_cwd(session_build_dir.get_path());
const meson_setup = meson_launcher.spawnv([
"meson",
"setup",
meson_builddir,
]);
await meson_setup.wait_async(null);
const setup_result = meson_setup.get_successful();
if (!setup_result) {
return false;
}
const meson_clean = meson_launcher.spawnv([
"meson",
"compile",
"--clean",
"-C",
meson_builddir,
]);
await meson_clean.wait_async(null);
if (!meson_clean.get_successful()) {
return false;
}
const meson_compile = meson_launcher.spawnv([
"meson",
"compile",
"-C",
meson_builddir,
]);
await meson_compile.wait_async(null);
const compile_result = meson_compile.get_successful();
meson_launcher.close();
return compile_result;
}
async function run() {
try {
const proxy = await dbus_previewer.getProxy("vala");
await proxy.RunAsync(module_file.get_path(), session.file.get_uri());
} catch (err) {
console.error(err);
return false;
}
return true;
}
return { compile, run };
}