[gnome-builder] flatpak/make: consider make arguments during build



commit a6ae7ef32538268880c5e4f1997577ec101c9d38
Author: Günther Wagner <info gunibert de>
Date:   Wed Jul 28 21:59:36 2021 +0200

    flatpak/make: consider make arguments during build
    
    It is now possible to define arguments for every phase in the pipeline.
    This enables us to use make-args and make-install-args in a flatpak
    manifest we currently don't consider.

 src/libide/foundry/ide-config.c            | 30 ++++++++++++++++++-
 src/libide/foundry/ide-config.h            |  9 ++++++
 src/libide/foundry/ide-pipeline-phase.h    | 47 ++++++++++++++++++++++++++++++
 src/libide/foundry/ide-pipeline.c          |  2 +-
 src/libide/foundry/ide-pipeline.h          | 20 +------------
 src/libide/foundry/meson.build             |  2 +-
 src/plugins/flatpak/gbp-flatpak-manifest.c | 12 ++++++++
 src/plugins/make/make_plugin.py            |  6 ++++
 8 files changed, 106 insertions(+), 22 deletions(-)
---
diff --git a/src/libide/foundry/ide-config.c b/src/libide/foundry/ide-config.c
index 7284bd498..1252fbbfa 100644
--- a/src/libide/foundry/ide-config.c
+++ b/src/libide/foundry/ide-config.c
@@ -48,6 +48,7 @@ typedef struct
   gchar          *toolchain_id;
   gchar          *prepend_path;
   gchar          *append_path;
+  GHashTable     *pipeline_args;
 
   GFile          *build_commands_dir;
 
@@ -316,6 +317,7 @@ ide_config_finalize (GObject *object)
 
   g_clear_pointer (&priv->build_commands, g_strfreev);
   g_clear_pointer (&priv->internal, g_hash_table_unref);
+  g_clear_pointer (&priv->pipeline_args, g_hash_table_unref);
   g_clear_pointer (&priv->config_opts, g_free);
   g_clear_pointer (&priv->display_name, g_free);
   g_clear_pointer (&priv->id, g_free);
@@ -714,6 +716,7 @@ ide_config_init (IdeConfig *self)
   priv->parallelism = -1;
   priv->locality = IDE_BUILD_LOCALITY_DEFAULT;
   priv->internal = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, _value_free);
+  priv->pipeline_args = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) 
g_strfreev);
 
   ide_config_set_environment (self, env);
   ide_config_set_runtime_environment (self, rt_env);
@@ -1834,7 +1837,7 @@ _ide_config_attach (IdeConfig *self)
   /*
    * We don't start monitoring changed events until we've gotten back
    * to the main loop (in case of threaded loaders) which happens from
-   * the point where the configuration is added ot the config manager.
+   * the point where the configuration is added to the config manager.
    */
 
   if (!(context = ide_object_get_context (IDE_OBJECT (self))))
@@ -1912,3 +1915,28 @@ ide_config_get_extensions (IdeConfig *self)
 
   return g_steal_pointer (&ret);
 }
+
+const gchar * const *
+ide_config_get_args_for_phase (IdeConfig        *self,
+                               IdePipelinePhase  phase)
+{
+  IdeConfigPrivate *priv = ide_config_get_instance_private (self);
+  const gchar * const *args;
+
+  g_return_val_if_fail (IDE_IS_CONFIG (self), NULL);
+
+  args = g_hash_table_lookup (priv->pipeline_args, GINT_TO_POINTER (phase));
+  return args;
+}
+
+void
+ide_config_set_args_for_phase (IdeConfig           *self,
+                               IdePipelinePhase     phase,
+                               const gchar * const *args)
+{
+  IdeConfigPrivate *priv = ide_config_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_CONFIG (self));
+
+  g_hash_table_insert (priv->pipeline_args, GINT_TO_POINTER (phase), g_strdupv ((gchar **)args));
+}
diff --git a/src/libide/foundry/ide-config.h b/src/libide/foundry/ide-config.h
index 66f2b175d..79dbd412f 100644
--- a/src/libide/foundry/ide-config.h
+++ b/src/libide/foundry/ide-config.h
@@ -28,6 +28,7 @@
 #include <libide-threading.h>
 
 #include "ide-foundry-types.h"
+#include "ide-pipeline-phase.h"
 
 G_BEGIN_DECLS
 
@@ -228,5 +229,13 @@ void                  ide_config_set_internal_object       (IdeConfig
                                                             gpointer               instance);
 IDE_AVAILABLE_IN_3_34
 GPtrArray            *ide_config_get_extensions            (IdeConfig             *self);
+IDE_AVAILABLE_IN_41
+const gchar * const  *ide_config_get_args_for_phase        (IdeConfig             *self,
+                                                            IdePipelinePhase       phase);
+IDE_AVAILABLE_IN_41
+void                  ide_config_set_args_for_phase        (IdeConfig             *self,
+                                                            IdePipelinePhase       phase,
+                                                            const gchar *const    *args);
+
 
 G_END_DECLS
diff --git a/src/libide/foundry/ide-pipeline-phase.h b/src/libide/foundry/ide-pipeline-phase.h
new file mode 100644
index 000000000..452891c12
--- /dev/null
+++ b/src/libide/foundry/ide-pipeline-phase.h
@@ -0,0 +1,47 @@
+/* ide-pipeline-phase.h
+ *
+ * Copyright 2021 Günther Wagner <info gunibert de>
+ *
+ * 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 3 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum
+{
+  IDE_PIPELINE_PHASE_NONE         = 0,
+  IDE_PIPELINE_PHASE_PREPARE      = 1 << 0,
+  IDE_PIPELINE_PHASE_DOWNLOADS    = 1 << 1,
+  IDE_PIPELINE_PHASE_DEPENDENCIES = 1 << 2,
+  IDE_PIPELINE_PHASE_AUTOGEN      = 1 << 3,
+  IDE_PIPELINE_PHASE_CONFIGURE    = 1 << 4,
+  IDE_PIPELINE_PHASE_BUILD        = 1 << 6,
+  IDE_PIPELINE_PHASE_INSTALL      = 1 << 7,
+  IDE_PIPELINE_PHASE_COMMIT       = 1 << 8,
+  IDE_PIPELINE_PHASE_EXPORT       = 1 << 9,
+  IDE_PIPELINE_PHASE_FINAL        = 1 << 10,
+  IDE_PIPELINE_PHASE_BEFORE       = 1 << 28,
+  IDE_PIPELINE_PHASE_AFTER        = 1 << 29,
+  IDE_PIPELINE_PHASE_FINISHED     = 1 << 30,
+  IDE_PIPELINE_PHASE_FAILED       = 1 << 31,
+} IdePipelinePhase;
+
+G_END_DECLS
+
diff --git a/src/libide/foundry/ide-pipeline.c b/src/libide/foundry/ide-pipeline.c
index 1ac115855..dd5a0965e 100644
--- a/src/libide/foundry/ide-pipeline.c
+++ b/src/libide/foundry/ide-pipeline.c
@@ -292,7 +292,7 @@ struct _IdePipeline
 
   /*
    * Precalculation if we need to look for errors on stdout. We can't rely
-   * on @current_stage for this, becase log entries might come in
+   * on @current_stage for this, because log entries might come in
    * asynchronously and after the processes/stage has completed.
    */
   guint errors_on_stdout : 1;
diff --git a/src/libide/foundry/ide-pipeline.h b/src/libide/foundry/ide-pipeline.h
index 129d7d7bb..fa2b7ae33 100644
--- a/src/libide/foundry/ide-pipeline.h
+++ b/src/libide/foundry/ide-pipeline.h
@@ -34,6 +34,7 @@
 #include "ide-build-log.h"
 #include "ide-config.h"
 #include "ide-pipeline-stage.h"
+#include "ide-pipeline-phase.h"
 #include "ide-runtime.h"
 #include "ide-triplet.h"
 
@@ -44,25 +45,6 @@ G_BEGIN_DECLS
 #define IDE_PIPELINE_PHASE_WHENCE_MASK (IDE_PIPELINE_PHASE_BEFORE | IDE_PIPELINE_PHASE_AFTER)
 #define IDE_BUILD_ERROR                (ide_build_error_quark())
 
-typedef enum
-{
-  IDE_PIPELINE_PHASE_NONE         = 0,
-  IDE_PIPELINE_PHASE_PREPARE      = 1 << 0,
-  IDE_PIPELINE_PHASE_DOWNLOADS    = 1 << 1,
-  IDE_PIPELINE_PHASE_DEPENDENCIES = 1 << 2,
-  IDE_PIPELINE_PHASE_AUTOGEN      = 1 << 3,
-  IDE_PIPELINE_PHASE_CONFIGURE    = 1 << 4,
-  IDE_PIPELINE_PHASE_BUILD        = 1 << 6,
-  IDE_PIPELINE_PHASE_INSTALL      = 1 << 7,
-  IDE_PIPELINE_PHASE_COMMIT       = 1 << 8,
-  IDE_PIPELINE_PHASE_EXPORT       = 1 << 9,
-  IDE_PIPELINE_PHASE_FINAL        = 1 << 10,
-  IDE_PIPELINE_PHASE_BEFORE       = 1 << 28,
-  IDE_PIPELINE_PHASE_AFTER        = 1 << 29,
-  IDE_PIPELINE_PHASE_FINISHED     = 1 << 30,
-  IDE_PIPELINE_PHASE_FAILED       = 1 << 31,
-} IdePipelinePhase;
-
 typedef enum
 {
   IDE_BUILD_ERROR_UNKNOWN = 0,
diff --git a/src/libide/foundry/meson.build b/src/libide/foundry/meson.build
index dc8899d54..4da8d1fcf 100644
--- a/src/libide/foundry/meson.build
+++ b/src/libide/foundry/meson.build
@@ -73,7 +73,7 @@ libide_foundry_enum_headers = [
   'ide-config.h',
   'ide-device.h',
   'ide-device-info.h',
-  'ide-pipeline.h',
+  'ide-pipeline-phase.h',
   'ide-runtime.h',
   'ide-test.h',
 ]
diff --git a/src/plugins/flatpak/gbp-flatpak-manifest.c b/src/plugins/flatpak/gbp-flatpak-manifest.c
index ba0750eb6..a7e5ebc77 100644
--- a/src/plugins/flatpak/gbp-flatpak-manifest.c
+++ b/src/plugins/flatpak/gbp-flatpak-manifest.c
@@ -344,6 +344,8 @@ gbp_flatpak_manifest_initable_init (GInitable     *initable,
   g_autofree gchar *run_args = NULL;
   g_autoptr(JsonParser) parser = NULL;
   g_auto(GStrv) build_commands = NULL;
+  g_auto(GStrv) make_args = NULL;
+  g_auto(GStrv) make_install_args = NULL;
   g_auto(GStrv) post_install = NULL;
   const gchar *app_id_field = "app-id";
   g_autoptr(IdeContext) context = NULL;
@@ -455,6 +457,16 @@ gbp_flatpak_manifest_initable_init (GInitable     *initable,
   else
     ide_config_set_locality (IDE_CONFIG (self), IDE_BUILD_LOCALITY_IN_TREE);
 
+  if (discover_strv_field (primary, "make-args", &make_args))
+    ide_config_set_args_for_phase (IDE_CONFIG (self),
+                                   IDE_PIPELINE_PHASE_BUILD,
+                                   (const gchar * const *)make_args);
+
+  if (discover_strv_field (primary, "make-install-args", &make_install_args))
+    ide_config_set_args_for_phase (IDE_CONFIG (self),
+                                   IDE_PIPELINE_PHASE_INSTALL,
+                                   (const gchar * const *)make_install_args);
+
   discover_environ (self, root_obj);
 
   self->root = json_node_ref (root);
diff --git a/src/plugins/make/make_plugin.py b/src/plugins/make/make_plugin.py
index 2b26586a3..54f3e9912 100644
--- a/src/plugins/make/make_plugin.py
+++ b/src/plugins/make/make_plugin.py
@@ -89,6 +89,9 @@ class MakePipelineAddin(Ide.Object, Ide.PipelineAddin):
         build_launcher = pipeline.create_launcher()
         build_launcher.set_cwd(build_system.get_make_dir().get_path())
         build_launcher.push_argv(make)
+        build_args = config.get_args_for_phase(Ide.PipelinePhase.BUILD)
+        if build_args:
+            build_launcher.push_args(build_args)
         if config.props.parallelism > 0:
             build_launcher.push_argv('-j{}'.format(config.props.parallelism))
 
@@ -110,6 +113,9 @@ class MakePipelineAddin(Ide.Object, Ide.PipelineAddin):
         install_launcher.set_cwd(build_system.get_make_dir().get_path())
         install_launcher.push_argv(make)
         install_launcher.push_argv('install')
+        install_args = config.get_args_for_phase(Ide.PipelinePhase.INSTALL)
+        if install_args:
+            install_launcher.push_args(install_args)
 
         install_stage = Ide.PipelineStageLauncher.new(context, install_launcher)
         install_stage.set_name(_("Install project"))


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