[anjuta] libanjuta, am-project: move pkg-config code to libanjuta
- From: Johannes Schmid <jhs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] libanjuta, am-project: move pkg-config code to libanjuta
- Date: Mon, 13 Dec 2010 23:16:37 +0000 (UTC)
commit 0ba154a04a34a2633629f7730af372d030dd351d
Author: Johannes Schmid <jhs gnome org>
Date: Tue Dec 14 00:07:24 2010 +0100
libanjuta, am-project: move pkg-config code to libanjuta
libanjuta/Makefile.am | 3 +
libanjuta/anjuta-pkg-config.c | 172 +++++++++++++++++++++++++++++++++++++++
libanjuta/anjuta-pkg-config.h | 27 ++++++
plugins/am-project/am-project.c | 135 +++++--------------------------
4 files changed, 222 insertions(+), 115 deletions(-)
---
diff --git a/libanjuta/Makefile.am b/libanjuta/Makefile.am
index df2108c..2c313b3 100644
--- a/libanjuta/Makefile.am
+++ b/libanjuta/Makefile.am
@@ -115,6 +115,8 @@ libanjuta_3_la_SOURCES= \
anjuta-file-list.h \
anjuta-pkg-config-chooser.h \
anjuta-pkg-config-chooser.c \
+ anjuta-pkg-config.h \
+ anjuta-pkg-config.c \
anjuta-column-text-view.h \
anjuta-column-text-view.c \
anjuta-file-drop-entry.h \
@@ -185,6 +187,7 @@ libanjuta_include = \
anjuta-dock-pane.h \
anjuta-file-list.h \
anjuta-pkg-config-chooser.h \
+ anjuta-pkg-config.h \
anjuta-column-text-view.h \
anjuta-file-drop-entry.h \
anjuta-entry.h
diff --git a/libanjuta/anjuta-pkg-config.c b/libanjuta/anjuta-pkg-config.c
new file mode 100644
index 0000000..6a663df
--- /dev/null
+++ b/libanjuta/anjuta-pkg-config.c
@@ -0,0 +1,172 @@
+/*
+ * anjuta-pkg-config.c
+ *
+ * Copyright (C) 2010 - Johannes Schmid
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+#include <string.h>
+
+#include <libanjuta/anjuta-pkg-config.h>
+#include <libanjuta/anjuta-utils.h>
+
+/* Blacklist for packages that shouldn't be parsed. Those packages
+ * usually contain the same include paths as their top-level package
+ * Checked with g_str_has_prefix() so partial names are ok!
+ */
+const gchar* ignore_packages[] =
+{
+ "gdk-x11-",
+ NULL
+};
+
+static GList*
+remove_includes (GList* includes, GList* dependencies)
+{
+ GList* dir;
+ for (dir = dependencies; dir != NULL; dir = g_list_next (dir))
+ {
+ GList* find = g_list_find_custom (includes, dir->data, (GCompareFunc)strcmp);
+ if (find)
+ {
+ g_free (find->data);
+ includes = g_list_delete_link (includes, find);
+ }
+ }
+ return includes;
+}
+
+/*
+ * anjuta_pkg_config_list_dependencies:
+ * @pkg_name: Name of the package to get the include directories for
+ * @error: Error handling
+ *
+ * This does (potentially) blocking, call from a thread if necessary
+ *
+ * Returns: a list of packages @pkg depends on
+ */
+GList*
+anjuta_pkg_config_list_dependencies (const gchar* package, GError** error)
+{
+ GList* deps = NULL;
+ gchar* cmd;
+ gchar *err;
+ gchar *out;
+ gint status;
+
+ cmd = g_strdup_printf ("pkg-config --print-requires --print-requires-private %s",
+ package);
+ if (g_spawn_command_line_sync (cmd, &out, &err, &status, error))
+ {
+ gchar** depends = g_strsplit (out, "\n", -1);
+ if (depends != NULL)
+ {
+ gchar** depend;
+ for (depend = depends; *depend != NULL; depend++)
+ {
+ if (strlen (*depend) && !anjuta_pkg_config_ignore_package (*depend))
+ {
+ deps = g_list_append (deps, g_strdup (*depend));
+ }
+ }
+ g_strfreev (depends);
+ }
+ g_free (out);
+ }
+ g_free (cmd);
+
+ return deps;
+}
+
+/*
+ * anjuta_pkg_config_get_directories:
+ * @pkg_name: Name of the package to get the include directories for
+ * @no_deps: Don't include directories of the dependencies
+ * @error: Error handling
+ *
+ * This does (potentially) blocking, call from a thread if necessary
+ *
+ * Returns: a list of include directories of the package
+ */
+GList*
+anjuta_pkg_config_get_directories (const gchar* pkg_name, gboolean no_deps, GError** error)
+{
+ gchar *cmd;
+ gchar *err;
+ gchar *out;
+ gint status;
+ GList *dirs = NULL;
+
+ cmd = g_strdup_printf ("pkg-config --cflags-only-I %s", pkg_name);
+
+ if (g_spawn_command_line_sync (cmd, &out, &err, &status, error))
+ {
+ gchar **flags;
+
+ flags = g_strsplit (out, " ", -1);
+
+ if (flags != NULL)
+ {
+ gchar **flag;
+
+ for (flag = flags; *flag != NULL; flag++)
+ {
+ if (g_regex_match_simple ("\\.*/include/\\w+", *flag, 0, 0) == TRUE)
+ {
+ dirs = g_list_prepend (dirs, g_strdup (*flag + 2));
+ }
+ }
+ g_strfreev (flags);
+ }
+ g_free (out);
+ }
+ g_free (cmd);
+
+ if (dirs && no_deps)
+ {
+ GList* pkgs = anjuta_pkg_config_list_dependencies (pkg_name, error);
+ GList* pkg;
+ for (pkg = pkgs; pkg != NULL; pkg = g_list_next (pkg))
+ {
+ GList* dep_dirs = anjuta_pkg_config_get_directories (pkg->data, FALSE, NULL);
+ dirs = remove_includes (dirs, dep_dirs);
+ anjuta_util_glist_strings_free (dep_dirs);
+ }
+ anjuta_util_glist_strings_free (pkgs);
+ }
+
+ return dirs;
+}
+
+/*
+ * anjuta_pkg_config_ignore_package
+ * @name: Name of the package to ignore
+ *
+ * Returns: TRUE if the package does not contain
+ * valid information for the build system and should be
+ * ignored.
+ */
+gboolean
+anjuta_pkg_config_ignore_package (const gchar* name)
+{
+ const gchar** pkg;
+ for (pkg = ignore_packages; *pkg != NULL; pkg++)
+ {
+ if (g_str_has_prefix (name, *pkg))
+ return TRUE;
+ }
+ return FALSE;
+}
\ No newline at end of file
diff --git a/libanjuta/anjuta-pkg-config.h b/libanjuta/anjuta-pkg-config.h
new file mode 100644
index 0000000..693c484
--- /dev/null
+++ b/libanjuta/anjuta-pkg-config.h
@@ -0,0 +1,27 @@
+/*
+ * anjuta-pkg-config.h
+ *
+ * Copyright (C) 2010 - Johannes Schmid
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+ #include <glib.h>
+
+GList* anjuta_pkg_config_list_dependencies (const gchar* package,
+ GError** error);
+GList* anjuta_pkg_config_get_directories (const gchar* pkg_name,
+ gboolean no_deps,
+ GError** error);
+gboolean anjuta_pkg_config_ignore_package (const gchar* name);
\ No newline at end of file
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index bcc4a21..1dc3e89 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -33,6 +33,7 @@
#include <libanjuta/interfaces/ianjuta-project.h>
#include <libanjuta/anjuta-debug.h>
#include <libanjuta/anjuta-utils.h>
+#include <libanjuta/anjuta-pkg-config.h>
#include <string.h>
#include <memory.h>
@@ -212,17 +213,6 @@ static AmpNodeInfo AmpNodeInformations[] = {
*---------------------------------------------------------------------------*/
-/* Blacklist for packages that shouldn't be parsed. Those packages
- * usually contain the same include paths as their top-level package
- * Checked with g_str_has_prefix() so partial names are ok!
- */
-const gchar* ignore_packages[] =
-{
- "gdk-x11-",
- NULL
-};
-
-
/* ----- Standard GObject types and variables ----- */
enum {
@@ -1956,121 +1946,37 @@ list_all_children (GList **children, GFile *dir)
}
}
-static GList*
-amp_project_get_includes (const gchar* pkg_name)
-{
- gchar *cmd;
- gchar *err;
- gchar *out;
- GError *error;
- gint status;
- GList *dirs = NULL;
-
- cmd = g_strdup_printf ("pkg-config --cflags-only-I %s", pkg_name);
-
- if (g_spawn_command_line_sync (cmd, &out, &err, &status, &error))
- {
- gchar **flags;
-
- flags = g_strsplit (out, " ", -1);
-
- if (flags != NULL)
- {
- gchar **flag;
-
- for (flag = flags; *flag != NULL; flag++)
- {
- if (g_regex_match_simple ("\\.*/include/\\w+", *flag, 0, 0) == TRUE)
- {
- dirs = g_list_prepend (dirs, g_strdup (*flag + 2));
- }
- }
- g_strfreev (flags);
- }
- }
- else
- {
- if (error)
- {
- g_warning ("Could not query dependencies: %s",
- error->message);
- g_error_free (error);
- }
- }
- g_free (cmd);
- return dirs;
-}
-
-static GList*
-amp_project_remove_includes (GList* includes, GList* dependencies)
-{
- GList* dir;
- for (dir = dependencies; dir != NULL; dir = g_list_next (dir))
- {
- GList* find = g_list_find_custom (includes, dir->data, (GCompareFunc)strcmp);
- if (find)
- {
- g_free (find->data);
- includes = g_list_delete_link (includes, find);
- }
- }
- return includes;
-}
-
-static gboolean
-amp_project_ignore_package (const gchar* name)
-{
- const gchar** pkg;
- for (pkg = ignore_packages; *pkg != NULL; pkg++)
- {
- if (g_str_has_prefix (name, *pkg))
- return TRUE;
- }
- return FALSE;
-}
-
static AnjutaProjectNode *
amp_project_load_package (AmpProject *project, AnjutaProjectNode *node, GError **error)
{
- gchar *cmd;
- gchar *err;
- gchar *out;
- gint status;
- GList* dependency_dirs = NULL;
+ GList* deps;
+ GList* dep;
GList* include_dirs = NULL;
- /* list package depencies */
- cmd = g_strdup_printf ("pkg-config --print-requires --print-requires-private %s",
- anjuta_project_node_get_name (node));
- if (g_spawn_command_line_sync (cmd, &out, &err, &status, NULL))
+ deps = anjuta_pkg_config_list_dependencies (anjuta_project_node_get_name (node),
+ error);
+ for (dep = deps; dep != NULL; dep = g_list_next (dep))
{
- gchar** depends = g_strsplit (out, "\n", -1);
- if (depends != NULL)
- {
- gchar** depend;
- for (depend = depends; *depend != NULL; depend++)
- {
- if (strlen (*depend) && !amp_project_ignore_package (*depend))
- {
- AnjutaProjectNode *pkg;
- dependency_dirs = g_list_concat (dependency_dirs,
- amp_project_get_includes (*depend));
- /* Create a package node for the depedencies */
+ /* Create a package node for the depedencies */
+ AnjutaProjectNode *pkg;
- pkg = project_node_new (project, ANJUTA_PROJECT_PACKAGE, NULL, *depend, NULL);
- anjuta_project_node_append (node, pkg);
- }
- }
- g_strfreev (depends);
- }
+ pkg = project_node_new (project, ANJUTA_PROJECT_PACKAGE, NULL, dep->data, NULL);
+ anjuta_project_node_append (node, pkg);
}
+ anjuta_util_glist_strings_free (deps);
- if ((include_dirs = amp_project_get_includes (anjuta_project_node_get_name (node))))
+ if (*error != NULL)
+ {
+ g_warning ("Error getting dependencies: %s", (*error)->message);
+ g_error_free (*error);
+ *error = NULL;
+ }
+
+ if ((include_dirs = anjuta_pkg_config_get_directories (anjuta_project_node_get_name (node),
+ TRUE, error)))
{
GList* include_dir;
- include_dirs = amp_project_remove_includes (include_dirs, dependency_dirs);
-
for (include_dir = include_dirs; include_dir != NULL; include_dir = g_list_next (include_dir))
{
GList* children = NULL;
@@ -2092,7 +1998,6 @@ amp_project_load_package (AmpProject *project, AnjutaProjectNode *node, GError *
}
}
anjuta_util_glist_strings_free (include_dirs);
- anjuta_util_glist_strings_free (dependency_dirs);
return node;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]