[gnome-builder/wip/tintou/sysroot: 28/28] sysroot: try to guess the pkgconfig paths and always show them



commit 532c7dbd98491a9d2a880ea15e02f485ebe636d6
Author: Corentin Noël <corentin noel collabora co uk>
Date:   Wed Mar 14 17:06:19 2018 +0000

    sysroot: try to guess the pkgconfig paths and always show them
    
    Architecture support is also added with 4 suggestions representing the most common targets

 doc/help/howto/sysroot.rst                         |   4 +-
 src/plugins/sysroot/gbp-sysroot-manager.c          | 169 ++++++++++++++++++++-
 src/plugins/sysroot/gbp-sysroot-manager.h          |   5 +
 src/plugins/sysroot/gbp-sysroot-preferences-row.c  |  74 ++++++++-
 src/plugins/sysroot/gbp-sysroot-preferences-row.ui |  59 ++++++-
 src/plugins/sysroot/gbp-sysroot-runtime.c          |  51 +++++--
 6 files changed, 332 insertions(+), 30 deletions(-)
---
diff --git a/doc/help/howto/sysroot.rst b/doc/help/howto/sysroot.rst
index 60b27b973..bec71f9c4 100644
--- a/doc/help/howto/sysroot.rst
+++ b/doc/help/howto/sysroot.rst
@@ -4,9 +4,10 @@ Use a Custom Sysroot
 
 If you need to use a custom sysroot. You can configure a new target in `Preferences->SDKs`.
 
-There are three fields to fill:
+There are four fields to fill:
 
 - Name: The name of your choice describing this sysroot.
+- Arch: The architecture targeted by the sysroot.
 - Sysroot path: The absolute path on your filesystem leading to the sysroot.
 - Additional pkg-config path: (optional) A colon separated list of absolute path leading to pkg-config 
folders of the sysroot.
 
@@ -18,5 +19,6 @@ The configuration will be stored in ~/.config/gnome-builder/sysroot/general.conf
 
     [Sysroot 0]
     Name=My Sysroot 😎
+    Arch=x86_64
     Path=/path/to/my_sysroot
     PkgConfigPath=/path/to/my_sysroot/usr/lib/x86_64-linux-gnu/pkgconfig
diff --git a/src/plugins/sysroot/gbp-sysroot-manager.c b/src/plugins/sysroot/gbp-sysroot-manager.c
index 19e428828..dbc0d7bf0 100644
--- a/src/plugins/sysroot/gbp-sysroot-manager.c
+++ b/src/plugins/sysroot/gbp-sysroot-manager.c
@@ -17,6 +17,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#define G_LOG_DOMAIN "gbp-sysroot-manager"
+#define BASIC_LIBDIRS "/usr/lib/pkgconfig:/usr/share/pkgconfig"
+
 #include "gbp-sysroot-manager.h"
 
 struct _GbpSysrootManager
@@ -30,6 +33,7 @@ G_DEFINE_TYPE (GbpSysrootManager, gbp_sysroot_manager, G_TYPE_OBJECT)
 enum {
   TARGET_MODIFIED,
   TARGET_NAME_CHANGED,
+  TARGET_ARCH_CHANGED,
   N_SIGNALS
 };
 
@@ -39,7 +43,7 @@ static gchar *
 sysroot_manager_get_path (void)
 {
   g_autofree gchar *directory_path = NULL;
-  gchar *conf_file = NULL;
+  g_autofree gchar *conf_file = NULL;
 
   directory_path = g_build_filename (g_get_user_config_dir (),
                                      ide_get_program_name (),
@@ -51,6 +55,69 @@ sysroot_manager_get_path (void)
   return g_steal_pointer (&conf_file);
 }
 
+/**
+ * sysroot_manager_find_additional_pkgconfig_paths:
+ *
+ * Returns a colon-separated list of additional pkgconfig paths
+ *
+ * Returns: (transfer full) (nullable): additional guessed paths
+ */
+static gchar *
+sysroot_manager_find_additional_pkgconfig_paths (GbpSysrootManager *self,
+                                                 const gchar       *target)
+{
+  g_autofree gchar *path = NULL;
+  g_autofree gchar *lib64_path = NULL;
+  g_autofree gchar *libmultiarch_path = NULL;
+  g_autofree gchar *returned_paths = NULL;
+
+  g_assert (GBP_IS_SYSROOT_MANAGER (self));
+  g_assert (self->key_file != NULL);
+  g_assert (target != NULL);
+
+  path = gbp_sysroot_manager_get_target_path (self, target);
+  lib64_path = g_build_path (G_DIR_SEPARATOR_S, path, "usr", "lib64", "pkgconfig", NULL);
+  libmultiarch_path = g_build_path (G_DIR_SEPARATOR_S, path, "usr", "lib", "pkg-config.multiarch", NULL);
+
+  if (g_file_test (lib64_path, G_FILE_TEST_EXISTS))
+    {
+      returned_paths = lib64_path;
+    }
+
+  if (g_file_test (libmultiarch_path, G_FILE_TEST_EXISTS))
+    {
+      g_autoptr(GFileInputStream) file_stream = NULL;
+      g_autoptr(GFile) multiarch_file = g_file_new_for_path (libmultiarch_path);
+      g_autoptr(GError) file_error = NULL;
+
+      file_stream = g_file_read (multiarch_file, NULL, &file_error);
+      if (file_error == NULL)
+        {
+          g_autoptr(GDataInputStream) data_stream = NULL;
+          g_autofree gchar *line = NULL;
+
+          data_stream = g_data_input_stream_new (G_INPUT_STREAM (file_stream));
+          while ((line = (gchar *)g_data_input_stream_read_line_utf8 (data_stream, NULL, NULL, &file_error)) 
!= NULL)
+            {
+              g_autofree gchar *multiarch_path = NULL;
+
+              if (file_error != NULL)
+                {
+                  g_critical ("Error while reading \"%s\": %s", libmultiarch_path, file_error->message);
+                  break;
+                }
+
+              multiarch_path = g_build_path (G_DIR_SEPARATOR_S, path, "usr", "lib", line, "pkgconfig", NULL);
+              returned_paths = g_strjoin (":", multiarch_path, returned_paths, NULL);
+            }
+        }
+      else
+        g_critical ("Unable to read \"%s\": %s", libmultiarch_path, file_error->message);
+    }
+
+  return g_strdup (returned_paths);
+}
+
 static void
 sysroot_manager_save (GbpSysrootManager *self)
 {
@@ -101,7 +168,7 @@ gbp_sysroot_manager_create_target (GbpSysrootManager *self)
 
   for (guint i = 0; i < UINT_MAX; i++)
     {
-      gchar * result;
+      gchar *result;
       g_autoptr(GString) sysroot_name = g_string_new (NULL);
 
       g_string_printf (sysroot_name, "Sysroot %u", i);
@@ -180,6 +247,49 @@ gbp_sysroot_manager_get_target_name (GbpSysrootManager *self,
   return g_key_file_get_string (self->key_file, target, "Name", NULL);
 }
 
+/**
+ * gbp_sysroot_manager_set_target_arch:
+ * @self: a #GbpSysrootManager
+ * @target: the unique identifier of the target
+ * @name: the architecture of the target
+ *
+ * Sets the architecture of the target.
+ */
+void
+gbp_sysroot_manager_set_target_arch (GbpSysrootManager *self,
+                                     const gchar       *target,
+                                     const gchar       *arch)
+{
+  g_return_if_fail (GBP_IS_SYSROOT_MANAGER (self));
+  g_return_if_fail (self->key_file != NULL);
+  g_return_if_fail (target != NULL);
+
+  g_key_file_set_string (self->key_file, target, "Arch", arch);
+  g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, GBP_SYSROOT_MANAGER_TARGET_CHANGED);
+  g_signal_emit (self, signals[TARGET_ARCH_CHANGED], 0, target, arch);
+  sysroot_manager_save (self);
+}
+
+/**
+ * gbp_sysroot_manager_get_target_arch:
+ * @self: a #GbpSysrootManager
+ * @target: the unique identifier of the target
+ *
+ * Gets the architecture of the target.
+ *
+ * Returns: (transfer full): the architecture of the target.
+ */
+gchar *
+gbp_sysroot_manager_get_target_arch (GbpSysrootManager *self,
+                                     const gchar       *target)
+{
+  g_return_val_if_fail (GBP_IS_SYSROOT_MANAGER (self), NULL);
+  g_return_val_if_fail (self->key_file != NULL, NULL);
+  g_return_val_if_fail (target != NULL, NULL);
+
+  return g_key_file_get_string (self->key_file, target, "Arch", NULL);
+}
+
 /**
  * gbp_sysroot_manager_set_target_path:
  * @self: a #GbpSysrootManager
@@ -193,14 +303,59 @@ gbp_sysroot_manager_set_target_path (GbpSysrootManager *self,
                                      const gchar       *target,
                                      const gchar       *path)
 {
+  g_autofree gchar *current_path = NULL;
+  g_autofree gchar *current_pkgconfigs = NULL;
+
   g_return_if_fail (GBP_IS_SYSROOT_MANAGER (self));
   g_return_if_fail (self->key_file != NULL);
   g_return_if_fail (target != NULL);
   g_return_if_fail (path != NULL);
 
+  current_path = gbp_sysroot_manager_get_target_path (self, target);
   g_key_file_set_string (self->key_file, target, "Path", path);
   g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, GBP_SYSROOT_MANAGER_TARGET_CHANGED);
   sysroot_manager_save (self);
+
+  current_pkgconfigs = gbp_sysroot_manager_get_target_pkg_config_path (self, target);
+  if (current_pkgconfigs == NULL || g_strcmp0 (current_pkgconfigs, "") == 0)
+    {
+      g_auto(GStrv) path_parts = NULL;
+      g_autofree gchar *additional_paths = NULL;
+
+      // Prepend the sysroot path to the BASIC_LIBDIRS values
+      path_parts = g_strsplit (BASIC_LIBDIRS, ":", 0);
+      for (gint i = g_strv_length (path_parts) - 1; i >= 0; i--)
+        {
+          g_autofree gchar *path_i = NULL;
+
+          path_i = g_build_path (G_DIR_SEPARATOR_S, path, path_parts[i], NULL);
+          current_pkgconfigs = g_strjoin (":", path_i, current_pkgconfigs, NULL);
+        }
+
+      additional_paths = sysroot_manager_find_additional_pkgconfig_paths (self, target);
+      current_pkgconfigs = g_strjoin (":", current_pkgconfigs, additional_paths, NULL);
+
+      gbp_sysroot_manager_set_target_pkg_config_path (self, target, current_pkgconfigs);
+    }
+  else
+    {
+      g_autoptr(GError) regex_error = NULL;
+      g_autoptr(GRegex) regex = NULL;
+      g_autofree gchar *current_path_escaped = NULL;
+
+      current_path_escaped = g_regex_escape_string (current_path, -1);
+      regex = g_regex_new (current_path_escaped, 0, 0, &regex_error);
+      if (regex_error == NULL)
+        {
+          current_pkgconfigs = g_regex_replace_literal (regex, current_pkgconfigs, (gssize) -1, 0, path, 0, 
&regex_error);
+          if (regex_error == NULL)
+            gbp_sysroot_manager_set_target_pkg_config_path (self, target, current_pkgconfigs);
+          else
+            g_critical ("Regex error: %s", regex_error->message);
+        }
+      else
+        g_critical ("Regex error: %s", regex_error->message);
+    }
 }
 
 /**
@@ -321,6 +476,16 @@ gbp_sysroot_manager_class_init (GbpSysrootManagerClass *klass)
                                 2,
                                 G_TYPE_STRING,
                                 G_TYPE_STRING);
+
+  signals [TARGET_ARCH_CHANGED] =
+    g_signal_new_class_handler ("target-arch-changed",
+                                G_TYPE_FROM_CLASS (klass),
+                                G_SIGNAL_RUN_FIRST,
+                                NULL, NULL, NULL, NULL,
+                                G_TYPE_NONE,
+                                2,
+                                G_TYPE_STRING,
+                                G_TYPE_STRING);
 }
 
 static void
diff --git a/src/plugins/sysroot/gbp-sysroot-manager.h b/src/plugins/sysroot/gbp-sysroot-manager.h
index b1edeffaf..5da6e30db 100644
--- a/src/plugins/sysroot/gbp-sysroot-manager.h
+++ b/src/plugins/sysroot/gbp-sysroot-manager.h
@@ -42,6 +42,11 @@ void                      gbp_sysroot_manager_set_target_name             (GbpSy
                                                                            const gchar       *path);
 gchar                    *gbp_sysroot_manager_get_target_name             (GbpSysrootManager *self,
                                                                            const gchar       *target);
+void                      gbp_sysroot_manager_set_target_arch             (GbpSysrootManager *self,
+                                                                           const gchar       *target,
+                                                                           const gchar       *arch);
+gchar                    *gbp_sysroot_manager_get_target_arch             (GbpSysrootManager *self,
+                                                                           const gchar       *target);
 void                      gbp_sysroot_manager_set_target_path             (GbpSysrootManager *self,
                                                                            const gchar       *target,
                                                                            const gchar       *path);
diff --git a/src/plugins/sysroot/gbp-sysroot-preferences-row.c 
b/src/plugins/sysroot/gbp-sysroot-preferences-row.c
index 5c5b8579a..e0320cd69 100644
--- a/src/plugins/sysroot/gbp-sysroot-preferences-row.c
+++ b/src/plugins/sysroot/gbp-sysroot-preferences-row.c
@@ -28,8 +28,9 @@ struct _GbpSysrootPreferencesRow
   gchar *sysroot_id;
   GtkLabel *display_name;
   GtkEntry *name_entry;
-  GtkEntry *sysroot_entry;
+  DzlFileChooserEntry *sysroot_entry;
   GtkEntry *pkg_config_entry;
+  GtkComboBox *arch_combobox;
   GtkButton *delete_button;
   GtkWidget *popover;
 };
@@ -61,17 +62,37 @@ sysroot_preferences_row_name_changed (GbpSysrootPreferencesRow *self,
 
 static void
 sysroot_preferences_row_sysroot_changed (GbpSysrootPreferencesRow *self,
+                                         GParamSpec               *pspec,
                                          gpointer                  user_data)
 {
   GbpSysrootManager *sysroot_manager = NULL;
+  g_autofree gchar *sysroot_path = NULL;
+  GFile *file;
 
   g_assert (GBP_IS_SYSROOT_PREFERENCES_ROW (self));
-  g_assert (GTK_IS_ENTRY (user_data));
+  g_assert (DZL_IS_FILE_CHOOSER_ENTRY (user_data));
 
   sysroot_manager = gbp_sysroot_manager_get_default ();
+  file = dzl_file_chooser_entry_get_file (DZL_FILE_CHOOSER_ENTRY (user_data));
+  sysroot_path = g_file_get_path (file);
   gbp_sysroot_manager_set_target_path (sysroot_manager,
                                        self->sysroot_id,
-                                       gtk_entry_get_text (GTK_ENTRY (user_data)));
+                                       sysroot_path);
+}
+
+static void
+sysroot_preferences_row_arch_changed (GbpSysrootPreferencesRow *self,
+                                      gpointer                  user_data)
+{
+  GbpSysrootManager *sysroot_manager = NULL;
+
+  g_assert (GBP_IS_SYSROOT_PREFERENCES_ROW (self));
+  g_assert (GTK_IS_COMBO_BOX (user_data));
+
+  sysroot_manager = gbp_sysroot_manager_get_default ();
+  gbp_sysroot_manager_set_target_arch (sysroot_manager,
+                                       self->sysroot_id,
+                                       gtk_combo_box_get_active_id (GTK_COMBO_BOX (user_data)));
 }
 
 static void
@@ -89,6 +110,31 @@ sysroot_preferences_row_pkg_config_changed (GbpSysrootPreferencesRow *self,
                                                   gtk_entry_get_text (GTK_ENTRY (user_data)));
 }
 
+static void
+sysroot_preferences_row_target_changed (GbpSysrootPreferencesRow                *self,
+                                        const gchar                             *target,
+                                        GbpSysrootManagerTargetModificationType  mod_type,
+                                        gpointer                                 user_data)
+{
+  GbpSysrootManager *sysroot_manager = NULL;
+  g_autofree gchar *value = NULL;
+
+  g_assert (GBP_IS_SYSROOT_PREFERENCES_ROW (self));
+  g_assert (GBP_IS_SYSROOT_MANAGER (user_data));
+
+  if (mod_type != GBP_SYSROOT_MANAGER_TARGET_CHANGED)
+    return;
+
+  if (g_strcmp0 (target, self->sysroot_id) != 0)
+    return;
+
+  sysroot_manager = GBP_SYSROOT_MANAGER (user_data);
+  value = gbp_sysroot_manager_get_target_pkg_config_path (sysroot_manager,
+                                                          self->sysroot_id);
+  if (value != NULL)
+    gtk_entry_set_text (self->pkg_config_entry, value);
+}
+
 static void
 sysroot_preferences_row_clicked (GbpSysrootPreferencesRow *self,
                                  gpointer                  user_data)
@@ -181,14 +227,15 @@ static void
 gbp_sysroot_preferences_row_constructed (GObject *object)
 {
   GbpSysrootManager *sysroot_manager = NULL;
-  gchar *value;
+  g_autofree gchar *value = NULL;
   GbpSysrootPreferencesRow *self = (GbpSysrootPreferencesRow *) object;
 
   sysroot_manager = gbp_sysroot_manager_get_default ();
   gtk_entry_set_text (self->name_entry,
                       gbp_sysroot_manager_get_target_name (sysroot_manager, self->sysroot_id));
-  gtk_entry_set_text (self->sysroot_entry,
-                      gbp_sysroot_manager_get_target_path (sysroot_manager, self->sysroot_id));
+  gtk_combo_box_set_active_id (self->arch_combobox, gbp_sysroot_manager_get_target_arch (sysroot_manager, 
self->sysroot_id));
+  dzl_file_chooser_entry_set_file (self->sysroot_entry,
+                      g_file_new_for_path (gbp_sysroot_manager_get_target_path (sysroot_manager, 
self->sysroot_id)));
   value = gbp_sysroot_manager_get_target_pkg_config_path (sysroot_manager, self->sysroot_id);
   if (value != NULL)
     gtk_entry_set_text (self->pkg_config_entry, value);
@@ -199,8 +246,14 @@ gbp_sysroot_preferences_row_constructed (GObject *object)
                            self,
                            G_CONNECT_SWAPPED);
 
-  g_signal_connect_object (self->sysroot_entry,
+  g_signal_connect_object (self->arch_combobox,
                            "changed",
+                           G_CALLBACK (sysroot_preferences_row_arch_changed),
+                           self,
+                           G_CONNECT_SWAPPED);
+
+  g_signal_connect_object (self->sysroot_entry,
+                           "notify::file",
                            G_CALLBACK (sysroot_preferences_row_sysroot_changed),
                            self,
                            G_CONNECT_SWAPPED);
@@ -210,6 +263,12 @@ gbp_sysroot_preferences_row_constructed (GObject *object)
                            G_CALLBACK (sysroot_preferences_row_pkg_config_changed),
                            self,
                            G_CONNECT_SWAPPED);
+
+  g_signal_connect_object (sysroot_manager,
+                           "target-changed",
+                           G_CALLBACK (sysroot_preferences_row_target_changed),
+                           self,
+                           G_CONNECT_SWAPPED);
 }
 
 static void
@@ -236,6 +295,7 @@ gbp_sysroot_preferences_row_class_init (GbpSysrootPreferencesRowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GbpSysrootPreferencesRow, display_name);
   gtk_widget_class_bind_template_child (widget_class, GbpSysrootPreferencesRow, popover);
   gtk_widget_class_bind_template_child (widget_class, GbpSysrootPreferencesRow, name_entry);
+  gtk_widget_class_bind_template_child (widget_class, GbpSysrootPreferencesRow, arch_combobox);
   gtk_widget_class_bind_template_child (widget_class, GbpSysrootPreferencesRow, sysroot_entry);
   gtk_widget_class_bind_template_child (widget_class, GbpSysrootPreferencesRow, pkg_config_entry);
   gtk_widget_class_bind_template_child (widget_class, GbpSysrootPreferencesRow, delete_button);
diff --git a/src/plugins/sysroot/gbp-sysroot-preferences-row.ui 
b/src/plugins/sysroot/gbp-sysroot-preferences-row.ui
index 853ed6a8e..a97588c34 100644
--- a/src/plugins/sysroot/gbp-sysroot-preferences-row.ui
+++ b/src/plugins/sysroot/gbp-sysroot-preferences-row.ui
@@ -23,6 +23,25 @@
       </object>
     </child>
   </template>
+  <object class="GtkListStore" id="arch_liststore">
+    <columns>
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0">i386</col>
+      </row>
+      <row>
+        <col id="0">x86_64</col>
+      </row>
+      <row>
+        <col id="0">arm</col>
+      </row>
+      <row>
+        <col id="0">aarch64</col>
+      </row>
+    </data>
+  </object>
   <object class="GtkPopover" id="popover">
     <property name="relative-to">image</property>
     <property name="position">bottom</property>
@@ -60,7 +79,7 @@
           <object class="GtkLabel">
             <property name="visible">true</property>
             <property name="xalign">1.0</property>
-            <property name="label" translatable="yes">Sysroot path</property>
+            <property name="label" translatable="yes">Architecture</property>
           </object>
           <packing>
             <property name="left_attach">0</property>
@@ -68,10 +87,14 @@
           </packing>
         </child>
         <child>
-          <object class="GtkEntry" id="sysroot_entry">
+          <object class="GtkComboBox" id="arch_combobox">
             <property name="visible">true</property>
             <property name="hexpand">true</property>
-            <property name="can-focus">true</property>
+            <property name="has-entry">true</property>
+            <property name="model">arch_liststore</property>
+            <property name="id-column">0</property>
+            <property name="entry-text-column">0</property>
+            <property name="active">0</property>
           </object>
           <packing>
             <property name="left_attach">1</property>
@@ -82,7 +105,7 @@
           <object class="GtkLabel">
             <property name="visible">true</property>
             <property name="xalign">1.0</property>
-            <property name="label" translatable="yes">Additional Pkg-config path</property>
+            <property name="label" translatable="yes">Sysroot path</property>
           </object>
           <packing>
             <property name="left_attach">0</property>
@@ -90,16 +113,40 @@
           </packing>
         </child>
         <child>
-          <object class="GtkEntry" id="pkg_config_entry">
+          <object class="DzlFileChooserEntry" id="sysroot_entry">
             <property name="visible">true</property>
             <property name="hexpand">true</property>
             <property name="can-focus">true</property>
+            <property name="local-only">true</property>
+            <property name="action">GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER</property>
           </object>
           <packing>
             <property name="left_attach">1</property>
             <property name="top_attach">2</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">true</property>
+            <property name="xalign">1.0</property>
+            <property name="label" translatable="yes">Pkg-config paths</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">3</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkEntry" id="pkg_config_entry">
+            <property name="visible">true</property>
+            <property name="hexpand">true</property>
+            <property name="can-focus">true</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">3</property>
+          </packing>
+        </child>
         <child>
           <object class="GtkButton" id="delete_button">
             <style>
@@ -113,7 +160,7 @@
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">3</property>
+            <property name="top_attach">4</property>
             <property name="width">2</property>
           </packing>
         </child>
diff --git a/src/plugins/sysroot/gbp-sysroot-runtime.c b/src/plugins/sysroot/gbp-sysroot-runtime.c
index cadadcc29..dc9d7fb1e 100644
--- a/src/plugins/sysroot/gbp-sysroot-runtime.c
+++ b/src/plugins/sysroot/gbp-sysroot-runtime.c
@@ -26,7 +26,6 @@
 #include "gbp-sysroot-subprocess-launcher.h"
 
 // This is a list of common libdirs to use
-#define BASIC_LIBDIRS "/usr/lib/pkgconfig:/usr/share/pkgconfig"
 #define RUNTIME_PREFIX "sysroot:"
 
 struct _GbpSysrootRuntime
@@ -76,7 +75,7 @@ gbp_sysroot_runtime_get_sysroot_id (GbpSysrootRuntime *self)
 
 static IdeSubprocessLauncher *
 gbp_sysroot_runtime_create_launcher (IdeRuntime  *runtime,
-                                     GError      **error)
+                                     GError     **error)
 {
   IdeSubprocessLauncher *ret;
   GbpSysrootRuntime *self = GBP_SYSROOT_RUNTIME(runtime);
@@ -115,18 +114,6 @@ gbp_sysroot_runtime_create_launcher (IdeRuntime  *runtime,
 
       ide_subprocess_launcher_setenv (ret, "PKG_CONFIG_SYSROOT_DIR", g_strdup (sysroot_path), TRUE);
 
-      // Prepend the sysroot path to the BASIC_LIBDIRS values
-      path_parts = g_strsplit (BASIC_LIBDIRS, ":", 0);
-      for (gint i = g_strv_length (path_parts) - 1; i >= 0; i--)
-        {
-          g_autofree gchar *path_i = NULL;
-          g_autofree gchar *libdir_tmp = NULL;
-
-          path_i = g_build_path (G_DIR_SEPARATOR_S, sysroot_path, path_parts[i], NULL);
-          libdir_tmp = g_strjoin (":", path_i, sysroot_libdirs, NULL);
-          sysroot_libdirs = g_steal_pointer (&libdir_tmp);
-        }
-
       pkgconfig_dirs = gbp_sysroot_manager_get_target_pkg_config_path (sysroot_manager, sysroot_id);
       if (pkgconfig_dirs != NULL && g_strcmp0 (pkgconfig_dirs, "") != 0)
         {
@@ -149,6 +136,40 @@ gbp_sysroot_runtime_create_launcher (IdeRuntime  *runtime,
   IDE_RETURN (ret);
 }
 
+static gchar **
+gbp_sysroot_runtime_get_system_include_dirs (IdeRuntime *runtime)
+{
+  GbpSysrootRuntime *self = GBP_SYSROOT_RUNTIME(runtime);
+  GbpSysrootManager *sysroot_manager = NULL;
+  const gchar *sysroot_id = NULL;
+  const gchar *result_paths[2] = { NULL, NULL };
+  g_autofree gchar *sysroot_path = NULL;
+  g_autofree gchar *full_path = NULL;
+
+  g_return_val_if_fail (GBP_IS_SYSROOT_RUNTIME (self), NULL);
+
+  sysroot_manager = gbp_sysroot_manager_get_default ();
+  sysroot_id = gbp_sysroot_runtime_get_sysroot_id (self);
+  sysroot_path = gbp_sysroot_manager_get_target_path (sysroot_manager, sysroot_id);
+  full_path = g_build_path (G_DIR_SEPARATOR_S, sysroot_path, "/usr/include", NULL);
+  result_paths[0] = full_path;
+
+  return g_strdupv ((char**) result_paths);
+}
+
+static gchar *
+gbp_sysroot_runtime_get_arch (IdeRuntime *runtime)
+{
+  GbpSysrootRuntime *self = GBP_SYSROOT_RUNTIME(runtime);
+  GbpSysrootManager *sysroot_manager = NULL;
+  const gchar *sysroot_id = NULL;
+
+  g_return_val_if_fail (GBP_IS_SYSROOT_RUNTIME (self), NULL);
+
+  sysroot_manager = gbp_sysroot_manager_get_default ();
+  sysroot_id = gbp_sysroot_runtime_get_sysroot_id (self);
+  return gbp_sysroot_manager_get_target_arch (sysroot_manager, sysroot_id);
+}
 
 static void
 sysroot_runtime_target_name_changed (GbpSysrootRuntime *self,
@@ -186,6 +207,8 @@ gbp_sysroot_runtime_class_init (GbpSysrootRuntimeClass *klass)
   object_class->constructed = gbp_sysroot_runtime_constructed;
 
   runtime_class->create_launcher = gbp_sysroot_runtime_create_launcher;
+  runtime_class->get_system_include_dirs = gbp_sysroot_runtime_get_system_include_dirs;
+  runtime_class->get_arch = gbp_sysroot_runtime_get_arch;
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]