[gnome-builder/wip/cosimoc/flatpak-greeter: 7/9] Apply the patches found for the module sources



commit d5641dc7a2f04ea4adabf65d33e27349471ff15c
Author: Simon Schampijer <simon schampijer endlessm com>
Date:   Tue Dec 13 22:24:07 2016 +0100

    Apply the patches found for the module sources

 plugins/flatpak/gbp-flatpak-clone-widget.c   |   13 +++++
 plugins/flatpak/gbp-flatpak-source-archive.c |   67 ++++++++++++++++++++++++++
 plugins/flatpak/gbp-flatpak-source-archive.h |    5 ++
 3 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/plugins/flatpak/gbp-flatpak-clone-widget.c b/plugins/flatpak/gbp-flatpak-clone-widget.c
index 233f576..1ea765f 100644
--- a/plugins/flatpak/gbp-flatpak-clone-widget.c
+++ b/plugins/flatpak/gbp-flatpak-clone-widget.c
@@ -303,6 +303,7 @@ gbp_flatpak_clone_widget_worker (GTask        *task,
   g_autoptr(GFile) dst = NULL;
   GError *error = NULL;
   GType git_callbacks_type;
+  guint i;
 
   g_assert (G_IS_TASK (task));
   g_assert (GBP_IS_FLATPAK_CLONE_WIDGET (self));
@@ -366,6 +367,18 @@ gbp_flatpak_clone_widget_worker (GTask        *task,
                                          &error);
     }
 
+  for (i = 0; req->src->patches[i]; i++)
+    {
+      if (!apply_patch (req->src->patches[i],
+                        req->project_file,
+                        self->strip_components,
+                        &error))
+        {
+          g_task_return_error (task, error);
+          return;
+        }
+    }
+
   /* copy manifest into the source directory */
   src = g_file_new_for_path (self->manifest);
   dst = g_file_get_child (req->project_file,
diff --git a/plugins/flatpak/gbp-flatpak-source-archive.c b/plugins/flatpak/gbp-flatpak-source-archive.c
index 53d3bb7..49ca417 100644
--- a/plugins/flatpak/gbp-flatpak-source-archive.c
+++ b/plugins/flatpak/gbp-flatpak-source-archive.c
@@ -303,6 +303,50 @@ unrpm (GFile   *dir,
 }
 
 static gboolean
+patch (GFile       *dir,
+       gboolean     use_git,
+       const char  *patch_path,
+       GError     **error,
+       ...)
+{
+  g_autoptr(GPtrArray) args = NULL;
+  const gchar *arg;
+  va_list ap;
+
+  va_start(ap, error);
+
+  args = g_ptr_array_new ();
+  if (use_git)
+    {
+      g_ptr_array_add (args, "git");
+      g_ptr_array_add (args, "apply");
+    }
+  else
+    {
+      g_ptr_array_add (args, "patch");
+    }
+
+  while ((arg = va_arg (ap, const gchar *)))
+    g_ptr_array_add (args, (gchar *) arg);
+
+  va_end (ap);
+
+  if (use_git)
+    {
+      g_ptr_array_add (args, (char *) patch_path);
+    }
+  else
+    {
+      g_ptr_array_add (args, "-i");
+      g_ptr_array_add (args, (char *) patch_path);
+    }
+
+  g_ptr_array_add (args, NULL);
+
+  return archive_spawnv (dir, NULL, error, (const char **) args->pdata);
+}
+
+static gboolean
 strip_components_into (GFile   *dest,
                        GFile   *src,
                        int      level,
@@ -549,3 +593,26 @@ fetch_archive (const gchar  *url,
 
   return g_steal_pointer (&source_dir);
 }
+
+gboolean
+apply_patch (const gchar  *path,
+             GFile        *source_dir,
+             guint         strip_components,
+             GError      **error)
+{
+  g_autoptr(GFile) patchfile = NULL;
+  g_autofree char *patch_path = NULL;
+  g_autofree char *strip_components_str = NULL;
+  gboolean use_git = FALSE;
+
+  patchfile = g_file_resolve_relative_path (source_dir, path);
+  if (patchfile == NULL)
+    return FALSE;
+
+  strip_components_str = g_strdup_printf ("-p%u", strip_components);
+  patch_path = g_file_get_path (patchfile);
+  if (!patch (source_dir, use_git, patch_path, error, strip_components_str, NULL))
+    return FALSE;
+
+  return TRUE;
+}
diff --git a/plugins/flatpak/gbp-flatpak-source-archive.h b/plugins/flatpak/gbp-flatpak-source-archive.h
index d662d94..707e5e6 100644
--- a/plugins/flatpak/gbp-flatpak-source-archive.h
+++ b/plugins/flatpak/gbp-flatpak-source-archive.h
@@ -26,4 +26,9 @@ GFile    *fetch_archive (const gchar  *url,
                          guint         strip_components,
                          GError      **error);
 
+gboolean  apply_patch (const gchar  *path,
+                       GFile        *source_dir,
+                       guint         strip_components,
+                       GError      **error);
+
 #endif /* GBP_FLATPAK_SOURCE_ARCHIVE_H */


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