[gnome-builder/gnome-builder-3-32] foundry: locate build flags from environment when possible
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/gnome-builder-3-32] foundry: locate build flags from environment when possible
- Date: Thu, 18 Apr 2019 20:34:34 +0000 (UTC)
commit bcc1b01d364342381df21a151786ec3b1fe8634a
Author: Giovanni Campagna <gcampagn cs stanford edu>
Date: Thu Apr 18 09:27:27 2019 -0700
foundry: locate build flags from environment when possible
If the build system is limited and cannot mine build flags, use the
CFLAGS/CXXFLAGS environment variables set in the build configuration.
This allows users to use custom build systems and still have proper
diagnostics and code completion, if they fill in their .buildconfig
correctly.
src/libide/foundry/ide-build-system.c | 77 +++++++++++++++++++++++++++++++----
1 file changed, 70 insertions(+), 7 deletions(-)
---
diff --git a/src/libide/foundry/ide-build-system.c b/src/libide/foundry/ide-build-system.c
index b3440d0da..8baa6506c 100644
--- a/src/libide/foundry/ide-build-system.c
+++ b/src/libide/foundry/ide-build-system.c
@@ -86,13 +86,76 @@ ide_build_system_real_get_build_flags_async (IdeBuildSystem *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
- ide_task_report_new_error (self,
- callback,
- user_data,
- ide_build_system_real_get_build_flags_async,
- G_IO_ERROR,
- G_IO_ERROR_NOT_SUPPORTED,
- "Fetching build flags is not supported");
+ g_autoptr(IdeContext) context = NULL;
+ g_autoptr(IdeTask) task = NULL;
+ g_autoptr(GError) error = NULL;
+ g_auto(GStrv) parsed_flags = NULL;
+ IdeBuildManager *build_manager;
+ IdeEnvironment *env;
+ const gchar *flags = NULL;
+ const gchar *path;
+ IdePipeline *pipeline;
+ IdeConfig *config;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (IDE_IS_BUILD_SYSTEM (self));
+ g_assert (G_IS_FILE (file));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, ide_build_system_real_get_build_flags_async);
+
+ /* Avoid work immediately if we can */
+ if (ide_task_return_error_if_cancelled (task))
+ return;
+
+ if (!g_file_is_native (file) || !(path = g_file_peek_path (file)))
+ {
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ "Cannot get build flags for non-native file");
+ return;
+ }
+
+ if (!(context = ide_object_ref_context (IDE_OBJECT (self))) ||
+ !(build_manager = ide_build_manager_from_context (context)) ||
+ !(pipeline = ide_build_manager_get_pipeline (build_manager)) ||
+ !(config = ide_pipeline_get_config (pipeline)) ||
+ !(env = ide_config_get_environment (config)))
+ {
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_INITIALIZED,
+ "Cannot access build flags without build config");
+ return;
+ }
+
+ if (ide_path_is_cpp_like (path))
+ {
+ flags = ide_environment_getenv (env, "CXXFLAGS");
+ }
+ else if (ide_path_is_c_like (path))
+ {
+ if (!(flags = ide_environment_getenv (env, "CFLAGS")))
+ flags = ide_environment_getenv (env, "CXXFLAGS");
+ }
+ else
+ {
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ "Cannot extract build flags for unknown file type: \"%s\"",
+ path);
+ }
+
+ if (flags == NULL)
+ flags = "";
+
+ if (!g_shell_parse_argv (flags, NULL, &parsed_flags, &error))
+ ide_task_return_error (task, g_steal_pointer (&error));
+ else
+ ide_task_return_pointer (task, g_steal_pointer (&parsed_flags), g_strfreev);
}
static gchar **
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]