[polari] Split out JS config



commit 4e86d80c93c4ccf1fea5a5ed922da5e57ca09cdf
Author: Florian Müllner <fmuellner gnome org>
Date:   Sun Feb 7 15:58:48 2021 +0100

    Split out JS config
    
    We currently set up all build-time variables in config.h, and
    pass the ones that are relevant to JS to package.start().
    
    That won't work when we switch to ES modules, as we'll handle
    over control to JS by evaluating a (module) file instead of an
    embedded script.
    
    Prepare for that by setting up a config.js file with the variables
    that are relevant for JS.
    
    https://gitlab.gnome.org/GNOME/polari/-/merge_requests/176

 meson.build                                  | 12 ++----------
 src/config.js.in                             |  4 ++++
 src/meson.build                              | 16 ++++++++++++++++
 src/org.gnome.Polari.src.gresource.xml.meson |  1 +
 src/polari.c                                 |  9 +++++----
 5 files changed, 28 insertions(+), 14 deletions(-)
---
diff --git a/meson.build b/meson.build
index a7d345e3..02993fcc 100644
--- a/meson.build
+++ b/meson.build
@@ -40,10 +40,6 @@ gjs = dependency('gjs-1.0', version: '>= 1.57.3')
 
 conf = configuration_data()
 
-conf.set_quoted('PACKAGE_NAME', meson.project_name())
-conf.set_quoted('PACKAGE_VERSION', '@VCS_TAG@')
-conf.set_quoted('PREFIX', prefix)
-conf.set_quoted('LIBDIR', libdir)
 conf.set_quoted('PKGLIBDIR', pkglibdir)
 
 cc = meson.get_compiler('c')
@@ -51,12 +47,8 @@ conf.set('HAVE_STRCASESTR', cc.has_function('strcasestr'))
 conf.set('SNAPSHOT', get_option('snapshot'))
 
 config_h = declare_dependency(
-  sources: vcs_tag(
-    command: ['git', 'describe'],
-    input: configure_file(
-      configuration: conf,
-      output: 'config.h.in'
-    ),
+  sources: configure_file(
+    configuration: conf,
     output: 'config.h'
   ),
   include_directories: include_directories('.')
diff --git a/src/config.js.in b/src/config.js.in
new file mode 100644
index 00000000..c2fea8f1
--- /dev/null
+++ b/src/config.js.in
@@ -0,0 +1,4 @@
+var PACKAGE_NAME = '@PACKAGE_NAME@';
+var PACKAGE_VERSION = '@PACKAGE_VERSION@';
+var PREFIX = '@PREFIX@';
+var LIBDIR = '@LIBDIR@';
diff --git a/src/meson.build b/src/meson.build
index 9d08af17..efc01f96 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -53,9 +53,25 @@ src_resources_xml = configure_file(
   configuration: resource_data
 )
 
+config_js = vcs_tag(
+  command: ['git', 'describe'],
+  input: configure_file(
+    configuration: {
+      'PACKAGE_NAME': meson.project_name(),
+      'PACKAGE_VERSION': '@VCS_TAG@',
+      'PREFIX': prefix,
+      'LIBDIR': libdir,
+    },
+    input: 'config.js.in',
+    output: 'config.js.in'
+  ),
+  output: 'config.js'
+)
+
 src_resources = gnome.compile_resources(
   'src-resources',
   src_resources_xml,
+  dependencies: config_js,
   c_name: 'src_resources'
 )
 
diff --git a/src/org.gnome.Polari.src.gresource.xml.meson b/src/org.gnome.Polari.src.gresource.xml.meson
index 292e9663..d21402ee 100644
--- a/src/org.gnome.Polari.src.gresource.xml.meson
+++ b/src/org.gnome.Polari.src.gresource.xml.meson
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource prefix="/org/gnome/Polari/js">
+    <file>config.js</file>
 @JS_SOURCE_FILES@
   </gresource>
 </gresources>
diff --git a/src/polari.c b/src/polari.c
index 48c24608..f6e5d0dd 100644
--- a/src/polari.c
+++ b/src/polari.c
@@ -6,10 +6,11 @@
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GjsContext, g_object_unref)
 
 const char *src =
-  "imports.package.start({ name: '" PACKAGE_NAME "',"
-  "                        version: '" PACKAGE_VERSION "',"
-  "                        prefix: '" PREFIX "',"
-  "                        libdir: '" LIBDIR "' });";
+  "const Config = imports.config;"
+  "imports.package.start({ name: Config.PACKAGE_NAME,"
+  "                        version: Config.PACKAGE_VERSION,"
+  "                        prefix: Config.PREFIX,"
+  "                        libdir: Config.LIBDIR });";
 
 static char **
 get_js_argv (int argc, const char * const *argv)


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