[gnome-builder] meson-templates: add command-line templates for C and Vala



commit c9f11c1a0b2a41c079828f6c50c436a75dd0110f
Author: Yotam Nachum <yotamnachum1 gmail com>
Date:   Thu Sep 20 19:11:21 2018 +0300

    meson-templates: add command-line templates for C and Vala

 .../meson-templates/meson-templates.gresource.xml  |  3 ++
 src/plugins/meson-templates/meson_templates.py     | 20 +++++++++
 .../meson-templates/resources/src/main-cli.c       | 48 ++++++++++++++++++++++
 .../meson-templates/resources/src/main-cli.vala    |  7 ++++
 .../meson-templates/resources/src/meson-cli.build  | 20 +++++++++
 5 files changed, 98 insertions(+)
---
diff --git a/src/plugins/meson-templates/meson-templates.gresource.xml 
b/src/plugins/meson-templates/meson-templates.gresource.xml
index 1ee3e0789..198b3b545 100644
--- a/src/plugins/meson-templates/meson-templates.gresource.xml
+++ b/src/plugins/meson-templates/meson-templates.gresource.xml
@@ -17,6 +17,7 @@
     <file compressed="true">resources/src/gi_composites.py</file>
     <file compressed="true">resources/src/main.js.tmpl</file>
     <file compressed="true">resources/src/main.c</file>
+    <file compressed="true">resources/src/main-cli.c</file>
     <file compressed="true">resources/src/main.cpp</file>
     <file compressed="true">resources/src/hello.src.gresource.xml</file>
     <file compressed="true">resources/src/window.c</file>
@@ -25,6 +26,7 @@
     <file compressed="true">resources/src/window.py</file>
     <file compressed="true">resources/src/window.vala</file>
     <file compressed="true">resources/src/main.vala</file>
+    <file compressed="true">resources/src/main-cli.vala</file>
     <file compressed="true">resources/src/hello.py.in</file>
     <file compressed="true">resources/src/main.py</file>
     <file compressed="true">resources/src/application.in</file>
@@ -32,6 +34,7 @@
     <file compressed="true">resources/src/meson-cs.build</file>
     <file compressed="true">resources/build-aux/meson/postinstall.py</file>
     <file compressed="true">resources/meson.build</file>
+    <file compressed="true">resources/src/meson-cli.build</file>
     <file compressed="true">resources/flatpak.json</file>
     <file compressed="true">resources/flatpak-gtksharp.json.tmpl</file>
     <file compressed="true">resources/data/meson.build</file>
diff --git a/src/plugins/meson-templates/meson_templates.py b/src/plugins/meson-templates/meson_templates.py
index 19c3468e7..90f192943 100644
--- a/src/plugins/meson-templates/meson_templates.py
+++ b/src/plugins/meson-templates/meson_templates.py
@@ -38,6 +38,7 @@ class LibraryTemplateProvider(GObject.Object, Ide.TemplateProvider):
     def do_get_project_templates(self):
         return [GnomeProjectTemplate(),
                 LibraryProjectTemplate(),
+                CLIProjectTemplate(),
                 EmptyProjectTemplate()]
 
 
@@ -344,3 +345,22 @@ class EmptyProjectTemplate(MesonTemplate):
     def prepare_files(self, files):
         files['resources/src/meson-empty.build'] = 'src/meson.build'
 
+
+class CLIProjectTemplate(MesonTemplate):
+    def __init__(self):
+        super().__init__(
+            'cli',
+            _('Command Line Tool'),
+            'pattern-cli',
+            _('Create a new command line project'),
+            ['C', 'Vala'],
+            200
+         )
+
+    def prepare_files(self, files):
+        files['resources/src/meson-cli.build'] = 'src/meson.build'
+
+        if self.language == 'c':
+            files['resources/src/main-cli.c'] = 'src/main.c'
+        elif self.language == 'vala':
+            files['resources/src/main-cli.vala'] = 'src/main.vala'
diff --git a/src/plugins/meson-templates/resources/src/main-cli.c 
b/src/plugins/meson-templates/resources/src/main-cli.c
new file mode 100644
index 000000000..fe5e9bab8
--- /dev/null
+++ b/src/plugins/meson-templates/resources/src/main-cli.c
@@ -0,0 +1,48 @@
+{{include "license.c"}}
+
+#include "{{prefix}}-config.h"
+
+#include <glib.h>
+{{if enable_i18n}}
+#include <glib/gi18n.h>
+{{end}}
+#include <stdlib.h>
+
+gint
+main (gint   argc,
+      gchar *argv[])
+{
+  g_autoptr(GOptionContext) context = NULL;
+  g_autoptr(GError) error = NULL;
+  gboolean version = FALSE;
+  GOptionEntry main_entries[] = {
+{{if enable_i18n}}
+    { "version", 0, 0, G_OPTION_ARG_NONE, &version, N_("Show program version") },
+{{else}}
+    { "version", 0, 0, G_OPTION_ARG_NONE, &version, "Show program version" },
+{{end}}
+    { NULL }
+  };
+
+{{if enable_i18n}}
+  context = g_option_context_new (_("- my command line tool"));
+  g_option_context_add_main_entries (context, main_entries, GETTEXT_PACKAGE);
+{{else}}
+  context = g_option_context_new ("- my command line tool");
+  g_option_context_add_main_entries (context, main_entries, NULL);
+{{end}}
+
+  if (!g_option_context_parse (context, &argc, &argv, &error))
+    {
+      g_printerr ("%s\n", error->message);
+      return EXIT_FAILURE;
+    }
+
+  if (version)
+    {
+      g_printerr ("%s\n", PACKAGE_VERSION);
+      return EXIT_SUCCESS;
+    }
+
+  return EXIT_SUCCESS;
+}
diff --git a/src/plugins/meson-templates/resources/src/main-cli.vala 
b/src/plugins/meson-templates/resources/src/main-cli.vala
new file mode 100644
index 000000000..6c26fee79
--- /dev/null
+++ b/src/plugins/meson-templates/resources/src/main-cli.vala
@@ -0,0 +1,7 @@
+{{include "license.vala"}}
+
+int main (string[] args)
+{
+       stdout.printf ("Hello World\n");
+       return 0;
+}
diff --git a/src/plugins/meson-templates/resources/src/meson-cli.build 
b/src/plugins/meson-templates/resources/src/meson-cli.build
new file mode 100644
index 000000000..a62ee9efb
--- /dev/null
+++ b/src/plugins/meson-templates/resources/src/meson-cli.build
@@ -0,0 +1,20 @@
+{{name_}}_sources = [
+{{if language == "c"}}
+  'main.c',
+{{else if language == "vala"}}
+  'main.vala',
+{{end}}
+]
+
+{{name_}}_deps = [
+  dependency('glib-2.0'),
+{{if language == "vala"}}
+  dependency('gobject-2.0'),
+{{end}}
+]
+
+executable('{{name}}', {{name_}}_sources,
+{{if language == "vala"}}  vala_args: '--target-glib=2.58',{{end}}
+  dependencies: {{name_}}_deps,
+  install: true,
+)
\ No newline at end of file


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