11import Gio from "gi://Gio" ;
22import dbus_previewer from "../../Previewer/DBusPreviewer.js" ;
3- import { decode } from "../../util.js" ;
43
54export default function ValaCompiler ( { session } ) {
65 const { file } = session ;
76
8- const module_file = file . get_child ( "libworkbenchcode.so" ) ;
9- const file_vala = file . get_child ( "main.vala" ) ;
7+ const meson_builddir = "builddir" ;
8+ const module_file = file
9+ . get_child ( meson_builddir )
10+ . get_child ( "libworkbenchcode.so" ) ;
1011
1112 async function compile ( ) {
12- let args ;
13+ // TODO: Do not run setup if the build directory is already
14+ // configured
15+ const meson_launcher = new Gio . SubprocessLauncher ( ) ;
16+ meson_launcher . set_cwd ( file . get_path ( ) ) ;
17+ const meson_setup = meson_launcher . spawnv ( [
18+ "meson" ,
19+ "setup" ,
20+ meson_builddir ,
21+ ] ) ;
1322
14- try {
15- const [ contents ] = await file_vala . load_contents_async ( null ) ;
16- const code = decode ( contents ) ;
17- args = getValaCompilerArguments ( code ) ;
18- } catch ( error ) {
19- console . debug ( error ) ;
20- return ;
23+ await meson_setup . wait_async ( null ) ;
24+ const setup_result = meson_setup . get_successful ( ) ;
25+ if ( ! setup_result ) {
26+ return false ;
2127 }
2228
23- const valac_launcher = new Gio . SubprocessLauncher ( ) ;
24- valac_launcher . set_cwd ( file . get_path ( ) ) ;
25- const valac = valac_launcher . spawnv ( [
26- "valac" ,
27- file_vala . get_path ( ) ,
28- "--hide-internal" ,
29- "-X" ,
30- "-shared" ,
31- "-X" ,
32- "-fpic" ,
33- "--library" ,
34- "workbench" ,
35- "-o" ,
36- module_file . get_path ( ) ,
37- "--vapi" ,
38- "/dev/null" ,
39- ...args ,
29+ const meson_compile = meson_launcher . spawnv ( [
30+ "meson" ,
31+ "compile" ,
32+ "-C" ,
33+ meson_builddir ,
4034 ] ) ;
4135
42- await valac . wait_async ( null ) ;
36+ await meson_compile . wait_async ( null ) ;
37+ const compile_result = meson_compile . get_successful ( ) ;
4338
44- const result = valac . get_successful ( ) ;
45- valac_launcher . close ( ) ;
46- return result ;
39+ meson_launcher . close ( ) ;
40+
41+ return compile_result ;
4742 }
4843
4944 async function run ( ) {
@@ -60,11 +55,3 @@ export default function ValaCompiler({ session }) {
6055
6156 return { compile, run } ;
6257}
63-
64- // Takes a string starting with the line
65- // #!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1
66- // and return ["--pkg", "gtk4", "--pkg", "libadwaita-1"]
67- // FIXME: consider using https://docs.gtk.org/glib/struct.OptionContext.html instead
68- function getValaCompilerArguments ( text ) {
69- return text . split ( "\n" ) [ 0 ] ?. split ( "-S vala " ) [ 1 ] ?. split ( " " ) || [ ] ;
70- }
0 commit comments