[gjs: 1/3] modules: Reorganize modules to support multiple globals. - Rename and move modules.gresource.xml ->
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 1/3] modules: Reorganize modules to support multiple globals. - Rename and move modules.gresource.xml ->
- Date: Sun, 2 Feb 2020 08:17:39 +0000 (UTC)
commit 22e3c526d38b407d3e3b79349cbb600d9cd53023
Author: Evan Welsh <noreply evanwelsh com>
Date: Wed Jan 8 17:45:36 2020 -0600
modules: Reorganize modules to support multiple globals.
- Rename and move modules.gresource.xml -> js.gresource.xml
This reflects that new environments may require JS
resources outside of modules/
- Move the "core" cairo, format, gettext, and signals logic
to modules/core/ to allow reuse across environments.
- Move the "legacy" (script-based) modules to modules/script/
- Move the script-based bootstrap files to modules/script/
- Move overrides to modules/core/ as they will be reused
across environments
- Update meson resource compilation.
- Update js.gresource.xml for new module paths.
- Update resource path references in C++.
.eslintignore | 2 +-
gjs/global.cpp | 7 ++---
gjs/importer.cpp | 5 +++-
js.gresource.xml | 36 ++++++++++++++++++++++++++
meson.build | 6 ++---
modules/{cairo.js => core/_cairo.js} | 3 ---
modules/{format.js => core/_format.js} | 22 +---------------
modules/{gettext.js => core/_gettext.js} | 0
modules/{signals.js => core/_signals.js} | 13 +---------
modules/{ => core}/overrides/.eslintrc.yml | 0
modules/{ => core}/overrides/GLib.js | 0
modules/{ => core}/overrides/GObject.js | 0
modules/{ => core}/overrides/Gio.js | 0
modules/{ => core}/overrides/Gtk.js | 0
modules/{ => core}/overrides/cairo.js | 0
modules/modules.gresource.xml | 29 ---------------------
modules/{ => script}/_bootstrap/coverage.js | 0
modules/{ => script}/_bootstrap/debugger.js | 0
modules/{ => script}/_bootstrap/default.js | 0
modules/{ => script}/_legacy.js | 0
modules/{ => script}/byteArray.js | 0
modules/script/cairo.js | 23 +++++++++++++++++
modules/script/format.js | 26 +++++++++++++++++++
modules/script/gettext.js | 37 ++++++++++++++++++++++++++
modules/{ => script}/jsUnit.js | 0
modules/{ => script}/lang.js | 0
modules/{ => script}/mainloop.js | 0
modules/{ => script}/package.js | 0
modules/script/signals.js | 40 +++++++++++++++++++++++++++++
modules/{ => script}/tweener/equations.js | 0
modules/{ => script}/tweener/tweenList.js | 0
modules/{ => script}/tweener/tweener.js | 0
32 files changed, 176 insertions(+), 73 deletions(-)
---
diff --git a/.eslintignore b/.eslintignore
index b9f94d7f..2abd6bb2 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -1,3 +1,3 @@
installed-tests/js/jasmine.js
installed-tests/js/modules/badOverrides/WarnLib.js
-modules/jsUnit.js
+modules/script/jsUnit.js
diff --git a/gjs/global.cpp b/gjs/global.cpp
index 8b4a80cd..68002a77 100644
--- a/gjs/global.cpp
+++ b/gjs/global.cpp
@@ -60,7 +60,8 @@ run_bootstrap(JSContext *cx,
JS::HandleObject global)
{
GjsAutoChar uri = g_strdup_printf(
- "resource:///org/gnome/gjs/modules/_bootstrap/%s.js", bootstrap_script);
+ "resource:///org/gnome/gjs/modules/script/_bootstrap/%s.js",
+ bootstrap_script);
JSAutoRealm ar(cx, global);
@@ -316,8 +317,8 @@ gjs_create_global_object(JSContext *cx)
* @global: a JS global object that has not yet been passed to this function
* @realm_name: (nullable): name of the realm, for debug output
* @bootstrap_script: (nullable): name of a bootstrap script (found at
- * resource://org/gnome/gjs/modules/_bootstrap/@bootstrap_script) or %NULL for
- * none
+ * resource://org/gnome/gjs/modules/script/_bootstrap/@bootstrap_script) or
+ * %NULL for none
*
* Defines properties on the global object such as 'window' and 'imports', and
* runs a bootstrap JS script on the global object to define any properties
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 802e22d3..c0f42bca 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -901,7 +901,10 @@ static const char* const* gjs_get_search_path(void) {
g_free(dirs);
}
- g_ptr_array_add(path, g_strdup("resource:///org/gnome/gjs/modules/"));
+ g_ptr_array_add(path,
+ g_strdup("resource:///org/gnome/gjs/modules/script/"));
+ g_ptr_array_add(path,
+ g_strdup("resource:///org/gnome/gjs/modules/core/"));
/* $XDG_DATA_DIRS /gjs-1.0 */
system_data_dirs = g_get_system_data_dirs();
diff --git a/js.gresource.xml b/js.gresource.xml
new file mode 100644
index 00000000..6e142169
--- /dev/null
+++ b/js.gresource.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/gjs">
+ <!-- Script-based Modules -->
+ <file>modules/script/_bootstrap/debugger.js</file>
+ <file>modules/script/_bootstrap/default.js</file>
+ <file>modules/script/_bootstrap/coverage.js</file>
+
+ <file>modules/script/tweener/equations.js</file>
+ <file>modules/script/tweener/tweener.js</file>
+ <file>modules/script/tweener/tweenList.js</file>
+
+ <file>modules/script/byteArray.js</file>
+ <file>modules/script/cairo.js</file>
+ <file>modules/script/gettext.js</file>
+ <file>modules/script/lang.js</file>
+ <file>modules/script/_legacy.js</file>
+ <file>modules/script/mainloop.js</file>
+ <file>modules/script/jsUnit.js</file>
+ <file>modules/script/signals.js</file>
+ <file>modules/script/format.js</file>
+ <file>modules/script/package.js</file>
+
+ <!-- Core Modules -->
+ <file>modules/core/overrides/cairo.js</file>
+ <file>modules/core/overrides/GLib.js</file>
+ <file>modules/core/overrides/Gio.js</file>
+ <file>modules/core/overrides/GObject.js</file>
+ <file>modules/core/overrides/Gtk.js</file>
+
+ <file>modules/core/_cairo.js</file>
+ <file>modules/core/_format.js</file>
+ <file>modules/core/_gettext.js</file>
+ <file>modules/core/_signals.js</file>
+ </gresource>
+</gresources>
diff --git a/meson.build b/meson.build
index b343a81d..d9a81721 100644
--- a/meson.build
+++ b/meson.build
@@ -430,9 +430,9 @@ module_cairo_srcs = [
'modules/cairo.cpp',
]
-module_resource_srcs = gnome.compile_resources('modules-resources',
- 'modules/modules.gresource.xml',
- c_name: 'modules_resources')
+module_resource_srcs = gnome.compile_resources('js-resources',
+ 'js.gresource.xml',
+ c_name: 'js_resources')
libgjs_dependencies = [glib, gobject, gthread, gio, gi, ffi, spidermonkey,
readline]
diff --git a/modules/cairo.js b/modules/core/_cairo.js
similarity index 97%
rename from modules/cairo.js
rename to modules/core/_cairo.js
index 7b0b184c..f02656d9 100644
--- a/modules/cairo.js
+++ b/modules/core/_cairo.js
@@ -143,6 +143,3 @@ var SurfaceType = {
QUARTZ_IMAGE: 13,
};
-// Merge stuff defined in native code
-Object.assign(this, imports.cairoNative);
-
diff --git a/modules/format.js b/modules/core/_format.js
similarity index 76%
rename from modules/format.js
rename to modules/core/_format.js
index 8f5a5c36..0df3b4ac 100644
--- a/modules/format.js
+++ b/modules/core/_format.js
@@ -1,6 +1,6 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
-/* exported format, printf, vprintf */
+/* exported vprintf */
const GjsPrivate = imports.gi.GjsPrivate;
@@ -65,23 +65,3 @@ function vprintf(string, args) {
return fillWidth(s, fillChar, width);
});
}
-
-function printf(...args) {
- let fmt = args.shift();
- print(vprintf(fmt, args));
-}
-
-/*
- * This function is intended to extend the String object and provide
- * an String.format API for string formatting.
- * It has to be set up using String.prototype.format = Format.format;
- * Usage:
- * "somestring %s %d".format('hello', 5);
- * It supports %s, %d, %x and %f, for %f it also support precisions like
- * "%.2f".format(1.526). All specifiers can be prefixed with a minimum
- * field width, e.g. "%5s".format("foo"). Unless the width is prefixed
- * with '0', the formatted string will be padded with spaces.
- */
-function format(...args) {
- return vprintf(this, args);
-}
diff --git a/modules/gettext.js b/modules/core/_gettext.js
similarity index 100%
rename from modules/gettext.js
rename to modules/core/_gettext.js
diff --git a/modules/signals.js b/modules/core/_signals.js
similarity index 95%
rename from modules/signals.js
rename to modules/core/_signals.js
index 10029477..bd133cf1 100644
--- a/modules/signals.js
+++ b/modules/core/_signals.js
@@ -20,7 +20,7 @@
* IN THE SOFTWARE.
*/
-/* exported addSignalMethods, WithSignals */
+/* exported addSignalMethods */
// A couple principals of this simple signal system:
// 1) should look just like our GObject signal binding
@@ -28,8 +28,6 @@
// 3) the expectation is that a given object will have a very small number of
// connections, but they may be to different signal names
-const Lang = imports.lang;
-
function _connect(name, callback) {
// be paranoid about callback arg since we'd start to throw from emit()
// if it was messed up
@@ -162,12 +160,3 @@ function addSignalMethods(proto) {
// this one is not in GObject, but useful
_addSignalMethod(proto, 'disconnectAll', _disconnectAll);
}
-
-var WithSignals = new Lang.Interface({
- Name: 'WithSignals',
- connect: _connect,
- disconnect: _disconnect,
- emit: _emit,
- signalHandlerIsConnected: _signalHandlerIsConnected,
- disconnectAll: _disconnectAll,
-});
diff --git a/modules/overrides/.eslintrc.yml b/modules/core/overrides/.eslintrc.yml
similarity index 100%
rename from modules/overrides/.eslintrc.yml
rename to modules/core/overrides/.eslintrc.yml
diff --git a/modules/overrides/GLib.js b/modules/core/overrides/GLib.js
similarity index 100%
rename from modules/overrides/GLib.js
rename to modules/core/overrides/GLib.js
diff --git a/modules/overrides/GObject.js b/modules/core/overrides/GObject.js
similarity index 100%
rename from modules/overrides/GObject.js
rename to modules/core/overrides/GObject.js
diff --git a/modules/overrides/Gio.js b/modules/core/overrides/Gio.js
similarity index 100%
rename from modules/overrides/Gio.js
rename to modules/core/overrides/Gio.js
diff --git a/modules/overrides/Gtk.js b/modules/core/overrides/Gtk.js
similarity index 100%
rename from modules/overrides/Gtk.js
rename to modules/core/overrides/Gtk.js
diff --git a/modules/overrides/cairo.js b/modules/core/overrides/cairo.js
similarity index 100%
rename from modules/overrides/cairo.js
rename to modules/core/overrides/cairo.js
diff --git a/modules/_bootstrap/coverage.js b/modules/script/_bootstrap/coverage.js
similarity index 100%
rename from modules/_bootstrap/coverage.js
rename to modules/script/_bootstrap/coverage.js
diff --git a/modules/_bootstrap/debugger.js b/modules/script/_bootstrap/debugger.js
similarity index 100%
rename from modules/_bootstrap/debugger.js
rename to modules/script/_bootstrap/debugger.js
diff --git a/modules/_bootstrap/default.js b/modules/script/_bootstrap/default.js
similarity index 100%
rename from modules/_bootstrap/default.js
rename to modules/script/_bootstrap/default.js
diff --git a/modules/_legacy.js b/modules/script/_legacy.js
similarity index 100%
rename from modules/_legacy.js
rename to modules/script/_legacy.js
diff --git a/modules/byteArray.js b/modules/script/byteArray.js
similarity index 100%
rename from modules/byteArray.js
rename to modules/script/byteArray.js
diff --git a/modules/script/cairo.js b/modules/script/cairo.js
new file mode 100644
index 00000000..1056a5c7
--- /dev/null
+++ b/modules/script/cairo.js
@@ -0,0 +1,23 @@
+// Copyright 2010 litl, LLC.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+
+// Merge stuff defined in the shared imports._cairo and then in native code
+Object.assign(this, imports._cairo, imports.cairoNative);
+
diff --git a/modules/script/format.js b/modules/script/format.js
new file mode 100644
index 00000000..a02fbe28
--- /dev/null
+++ b/modules/script/format.js
@@ -0,0 +1,26 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+/* exported format, printf, vprintf */
+
+var {vprintf} = imports._format;
+
+function printf(fmt, ...args) {
+ print(vprintf(fmt, args));
+}
+
+/*
+ * This function is intended to extend the String object and provide a
+ * String.format API for string formatting.
+ * It has to be set up using String.prototype.format = Format.format;
+ * Usage:
+ * "somestring %s %d".format('hello', 5);
+ * It supports %s, %d, %x and %f.
+ * For %f it also supports precisions like "%.2f".format(1.526).
+ * All specifiers can be prefixed with a minimum field width, e.g.
+ * "%5s".format("foo").
+ * Unless the width is prefixed with '0', the formatted string will be padded
+ * with spaces.
+ */
+function format(...args) {
+ return vprintf(this, args);
+}
diff --git a/modules/script/gettext.js b/modules/script/gettext.js
new file mode 100644
index 00000000..eefedcd5
--- /dev/null
+++ b/modules/script/gettext.js
@@ -0,0 +1,37 @@
+// Copyright 2019 Evan Welsh
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+
+/* exported LocaleCategory, bindtextdomain, dcgettext, dgettext, dngettext,
+ domain, dpgettext, gettext, ngettext, pgettext, setlocale, textdomain */
+
+var {
+ LocaleCategory,
+ bindtextdomain,
+ dcgettext,
+ dgettext,
+ dngettext,
+ domain,
+ dpgettext,
+ gettext,
+ ngettext,
+ pgettext,
+ setlocale,
+ textdomain,
+} = imports._gettext;
diff --git a/modules/jsUnit.js b/modules/script/jsUnit.js
similarity index 100%
rename from modules/jsUnit.js
rename to modules/script/jsUnit.js
diff --git a/modules/lang.js b/modules/script/lang.js
similarity index 100%
rename from modules/lang.js
rename to modules/script/lang.js
diff --git a/modules/mainloop.js b/modules/script/mainloop.js
similarity index 100%
rename from modules/mainloop.js
rename to modules/script/mainloop.js
diff --git a/modules/package.js b/modules/script/package.js
similarity index 100%
rename from modules/package.js
rename to modules/script/package.js
diff --git a/modules/script/signals.js b/modules/script/signals.js
new file mode 100644
index 00000000..47735738
--- /dev/null
+++ b/modules/script/signals.js
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2008 litl, LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/* exported addSignalMethods, WithSignals */
+
+const Lang = imports.lang;
+
+// Private API, remains exported for backwards compatibility reasons
+var {_connect, _disconnect, _emit, _signalHandlerIsConnected, _disconnectAll} = imports._signals;
+
+// Public API
+var {addSignalMethods} = imports._signals;
+
+var WithSignals = new Lang.Interface({
+ Name: 'WithSignals',
+ connect: _connect,
+ disconnect: _disconnect,
+ emit: _emit,
+ signalHandlerIsConnected: _signalHandlerIsConnected,
+ disconnectAll: _disconnectAll,
+});
diff --git a/modules/tweener/equations.js b/modules/script/tweener/equations.js
similarity index 100%
rename from modules/tweener/equations.js
rename to modules/script/tweener/equations.js
diff --git a/modules/tweener/tweenList.js b/modules/script/tweener/tweenList.js
similarity index 100%
rename from modules/tweener/tweenList.js
rename to modules/script/tweener/tweenList.js
diff --git a/modules/tweener/tweener.js b/modules/script/tweener/tweener.js
similarity index 100%
rename from modules/tweener/tweener.js
rename to modules/script/tweener/tweener.js
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]