From 2ea05872d087c7d1b8aed3bf0816cc0141aaafbd Mon Sep 17 00:00:00 2001 From: nor Date: Thu, 1 Feb 2024 02:06:30 +0800 Subject: [PATCH 1/4] add meson args and env support --- src/projects/mesonproject.vala | 50 ++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/src/projects/mesonproject.vala b/src/projects/mesonproject.vala index 908f6e86..b2c69e3d 100644 --- a/src/projects/mesonproject.vala +++ b/src/projects/mesonproject.vala @@ -27,6 +27,9 @@ class Vls.MesonProject : Project { private string build_dir; private bool configured_once; private bool requires_general_build; + private string[] special_args = {}; + private string[] special_comp = {}; + private string[] special_envp = {}; /** * Substitute special arguments like `@INPUT@` and `@OUTPUT@` as they @@ -292,10 +295,14 @@ class Vls.MesonProject : Project { debug ("%sconfiguring build dir %s ...", configured_once ? "re" : "", build_dir); if (configured_once) spawn_args += "--reconfigure"; + foreach(var item in special_comp) { + warning("meson setup arg %s", item); + spawn_args += item; + } Process.spawn_sync ( build_dir, spawn_args, - null, + special_envp, SpawnFlags.SEARCH_PATH, null, out proc_stdout, @@ -761,10 +768,15 @@ class Vls.MesonProject : Project { if (requires_general_build) { int proc_status; string proc_stdout, proc_stderr; + string[] spwan_args = {"meson", "compile"}; + foreach(var item in special_comp) { + warning("meson compile arg %s", item); + spwan_args += item; + } Process.spawn_sync (build_dir, - {"meson", "compile"}, - null, + spwan_args, + special_envp, SpawnFlags.SEARCH_PATH, null, out proc_stdout, @@ -783,6 +795,38 @@ class Vls.MesonProject : Project { public MesonProject (string root_path, FileCache file_cache, Cancellable? cancellable = null) throws Error { base (root_path, file_cache); + // read system envionment; + string[] system_env_key = Environment.list_variables(); + if (system_env_key != null) { + foreach(var item in system_env_key) { + var sys_env = item+"="+Environment.get_variable(item); + debug("system env is %s", sys_env); + special_envp += sys_env; + } + } + // get config from settings.json + var check_path = root_path + "/.vscode/settings.json"; + warning("meson check option at %s", check_path); + var settings_json = File.new_for_path(check_path); + if (settings_json.query_exists()) { + var dis = new DataInputStream(settings_json.read()); + var settings_json_parser = new Json.Parser(); + settings_json_parser.load_from_stream(dis); + var root_node = settings_json_parser.get_root(); + var root_object = root_node.get_object(); + var ret_options = root_object.get_array_member("mesonbuild.configureOptions"); + foreach(var option in ret_options.get_elements()) { + var opt = option.get_string(); + special_args += opt; + } + var compile_options = root_object.get_array_member("mesonbuild.compileOptions"); + foreach(var option in compile_options.get_elements()) { + var opt = option.get_string(); + special_comp += opt; + } + // maybe can reuse mesonbuild buildDir + // this.build_dir = root_object.get_string_member_with_default("mesonbuild.buildFolder", root_path +"/builddir"); + } this.build_dir = DirUtils.make_tmp (@"vls-meson-$(str_hash (root_path))-XXXXXX"); reconfigure_if_stale (cancellable); } From 76ca165ded6d307083be42b5d6de413e5ae0fc1b Mon Sep 17 00:00:00 2001 From: nor Date: Thu, 1 Feb 2024 23:48:45 +0800 Subject: [PATCH 2/4] update code --- src/projects/mesonproject.vala | 39 +++++++++++++--------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/projects/mesonproject.vala b/src/projects/mesonproject.vala index b2c69e3d..6bdf294e 100644 --- a/src/projects/mesonproject.vala +++ b/src/projects/mesonproject.vala @@ -27,9 +27,8 @@ class Vls.MesonProject : Project { private string build_dir; private bool configured_once; private bool requires_general_build; - private string[] special_args = {}; - private string[] special_comp = {}; - private string[] special_envp = {}; + private string[] meson_setup_args = {}; + private string[] meson_compile_args = {}; /** * Substitute special arguments like `@INPUT@` and `@OUTPUT@` as they @@ -295,14 +294,14 @@ class Vls.MesonProject : Project { debug ("%sconfiguring build dir %s ...", configured_once ? "re" : "", build_dir); if (configured_once) spawn_args += "--reconfigure"; - foreach(var item in special_comp) { + foreach(var item in meson_setup_args) { warning("meson setup arg %s", item); spawn_args += item; } Process.spawn_sync ( build_dir, spawn_args, - special_envp, + null, SpawnFlags.SEARCH_PATH, null, out proc_stdout, @@ -768,15 +767,15 @@ class Vls.MesonProject : Project { if (requires_general_build) { int proc_status; string proc_stdout, proc_stderr; - string[] spwan_args = {"meson", "compile"}; - foreach(var item in special_comp) { + string[] spawn_args = {"meson", "compile"}; + foreach(var item in meson_compile_args) { warning("meson compile arg %s", item); - spwan_args += item; + spawn_args += item; } Process.spawn_sync (build_dir, - spwan_args, - special_envp, + spawn_args, + null, SpawnFlags.SEARCH_PATH, null, out proc_stdout, @@ -795,17 +794,8 @@ class Vls.MesonProject : Project { public MesonProject (string root_path, FileCache file_cache, Cancellable? cancellable = null) throws Error { base (root_path, file_cache); - // read system envionment; - string[] system_env_key = Environment.list_variables(); - if (system_env_key != null) { - foreach(var item in system_env_key) { - var sys_env = item+"="+Environment.get_variable(item); - debug("system env is %s", sys_env); - special_envp += sys_env; - } - } // get config from settings.json - var check_path = root_path + "/.vscode/settings.json"; + var check_path = Path.build_filename(root_path, "/.vscode/settings.json"); warning("meson check option at %s", check_path); var settings_json = File.new_for_path(check_path); if (settings_json.query_exists()) { @@ -817,17 +807,18 @@ class Vls.MesonProject : Project { var ret_options = root_object.get_array_member("mesonbuild.configureOptions"); foreach(var option in ret_options.get_elements()) { var opt = option.get_string(); - special_args += opt; + meson_setup_args += opt; } var compile_options = root_object.get_array_member("mesonbuild.compileOptions"); foreach(var option in compile_options.get_elements()) { var opt = option.get_string(); - special_comp += opt; + meson_compile_args += opt; } // maybe can reuse mesonbuild buildDir - // this.build_dir = root_object.get_string_member_with_default("mesonbuild.buildFolder", root_path +"/builddir"); + this.build_dir = root_object.get_string_member_with_default("mesonbuild.buildFolder", root_path +"/builddir"); + }else{ + this.build_dir = DirUtils.make_tmp (@"vls-meson-$(str_hash (root_path))-XXXXXX"); } - this.build_dir = DirUtils.make_tmp (@"vls-meson-$(str_hash (root_path))-XXXXXX"); reconfigure_if_stale (cancellable); } From 75ee1eb31c65dae6a4b780e71ec493192c457d8b Mon Sep 17 00:00:00 2001 From: nor Date: Sat, 30 Mar 2024 11:26:23 +0800 Subject: [PATCH 3/4] option vscode setting file exception process --- src/projects/mesonproject.vala | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/projects/mesonproject.vala b/src/projects/mesonproject.vala index 6bdf294e..467f55d6 100644 --- a/src/projects/mesonproject.vala +++ b/src/projects/mesonproject.vala @@ -769,7 +769,7 @@ class Vls.MesonProject : Project { string proc_stdout, proc_stderr; string[] spawn_args = {"meson", "compile"}; foreach(var item in meson_compile_args) { - warning("meson compile arg %s", item); + debug("meson compile arg %s", item); spawn_args += item; } @@ -795,13 +795,21 @@ class Vls.MesonProject : Project { public MesonProject (string root_path, FileCache file_cache, Cancellable? cancellable = null) throws Error { base (root_path, file_cache); // get config from settings.json - var check_path = Path.build_filename(root_path, "/.vscode/settings.json"); - warning("meson check option at %s", check_path); - var settings_json = File.new_for_path(check_path); - if (settings_json.query_exists()) { - var dis = new DataInputStream(settings_json.read()); - var settings_json_parser = new Json.Parser(); - settings_json_parser.load_from_stream(dis); + var vscode_settings_json_path = Path.build_filename(root_path, "/.vscode/settings.json"); + debug("meson check option at %s", vscode_settings_json_path); + var vscode_settings_json = File.new_for_path(vscode_settings_json_path); + var settings_json_parser = new Json.Parser(); + var load_vscode_settings = false; + if (vscode_settings_json.query_exists()) { + try { + var dis = new DataInputStream(vscode_settings_json.read()); + settings_json_parser.load_from_stream(dis); + load_vscode_settings = true; + } catch (Error e) { + warning ("%s", e.message); + } + } + if (load_vscode_settings) { var root_node = settings_json_parser.get_root(); var root_object = root_node.get_object(); var ret_options = root_object.get_array_member("mesonbuild.configureOptions"); From 6e513f6c76cf6022b9942e83ebd1c7e0e89ae2a4 Mon Sep 17 00:00:00 2001 From: nor Date: Sat, 30 Mar 2024 11:28:18 +0800 Subject: [PATCH 4/4] fix log --- src/projects/mesonproject.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/projects/mesonproject.vala b/src/projects/mesonproject.vala index 467f55d6..c2bdb2a2 100644 --- a/src/projects/mesonproject.vala +++ b/src/projects/mesonproject.vala @@ -295,7 +295,7 @@ class Vls.MesonProject : Project { if (configured_once) spawn_args += "--reconfigure"; foreach(var item in meson_setup_args) { - warning("meson setup arg %s", item); + debug("meson setup arg %s", item); spawn_args += item; } Process.spawn_sync (