Skip to content

Commit 4696398

Browse files
committed
vala: Compile inside a temporary directory
This allows to compile projects without granting access to the filesystem. Additionally, all sessions opened that compile Vala code will use the same build directory, allowing us to reuse the same meson configuration.
1 parent 7826298 commit 4696398

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/langs/vala/Compiler.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
11
import Gio from "gi://Gio";
22
import dbus_previewer from "../../Previewer/DBusPreviewer.js";
3+
import { createTmpDir, copy } from "../../util.js";
4+
import { setupValaProject } from "./vala.js";
5+
6+
let ready_to_build = false;
7+
const session_build_dir = await createTmpDir("vala");
38

49
export default function ValaCompiler({ session }) {
510
const { file } = session;
611

712
const meson_builddir = "builddir";
8-
const module_file = file
13+
const module_file = session_build_dir
914
.get_child(meson_builddir)
1015
.get_child("libworkbenchcode.so");
1116

1217
async function compile() {
18+
if (!ready_to_build) {
19+
try {
20+
await setupValaProject(session_build_dir);
21+
ready_to_build = true;
22+
} catch (err) {
23+
console.error(err);
24+
return false;
25+
}
26+
}
27+
28+
await copy(
29+
"main.vala",
30+
file,
31+
session_build_dir,
32+
Gio.FileCopyFlags.OVERWRITE | Gio.FileCopyFlags.ALL_METADATA,
33+
);
34+
1335
// TODO: Do not run setup if the build directory is already
1436
// configured
1537
const meson_launcher = new Gio.SubprocessLauncher();
16-
meson_launcher.set_cwd(file.get_path());
38+
meson_launcher.set_cwd(session_build_dir.get_path());
1739
const meson_setup = meson_launcher.spawnv([
1840
"meson",
1941
"setup",
@@ -26,6 +48,19 @@ export default function ValaCompiler({ session }) {
2648
return false;
2749
}
2850

51+
const meson_clean = meson_launcher.spawnv([
52+
"meson",
53+
"compile",
54+
"--clean",
55+
"-C",
56+
meson_builddir,
57+
]);
58+
59+
await meson_clean.wait_async(null);
60+
if (!meson_clean.get_successful()) {
61+
return false;
62+
}
63+
2964
const meson_compile = meson_launcher.spawnv([
3065
"meson",
3166
"compile",

0 commit comments

Comments
 (0)