[gjs] package: Add requireSymbol() method
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] package: Add requireSymbol() method
- Date: Thu, 11 May 2017 06:23:20 +0000 (UTC)
commit ca34972ee1e853bd1034584441fd258e6c390ac6
Author: Florian Müllner <fmuellner gnome org>
Date: Fri Mar 3 21:01:21 2017 +0100
package: Add requireSymbol() method
While the existing require() method provides a convenient way
to check for hard dependencies, it only tests whether a particular
typelib can be imported. The newly added checkSymbol() method on
the other hand allows for finer-grained tests, but leaves it to
the caller to check the return value. Fill that gap by providing
a requireSymbol() method that wraps checkSymbol() to error out
when the dependency is not satisfied.
https://bugzilla.gnome.org/show_bug.cgi?id=779593
modules/package.js | 27 ++++++++++++++++-----------
1 files changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/modules/package.js b/modules/package.js
index 03fceaa..5a5cd22 100644
--- a/modules/package.js
+++ b/modules/package.js
@@ -232,18 +232,23 @@ function run(module) {
* indicates any version.
*/
function require(libs) {
- for (let l in libs) {
- let version = libs[l];
-
- if (version != '')
- imports.gi.versions[l] = version;
+ for (let l in libs)
+ requireSymbol(l, libs[l]);
+}
- try {
- imports.gi[l];
- } catch(e) {
- printerr('Unsatisfied dependency: ' + e.message);
- System.exit(1);
- }
+/**
+ * requireSymbol:
+ *
+ * As checkSymbol(), but exit with an error if the
+ * dependency cannot be satisfied.
+ */
+function requireSymbol(lib, version, symbol) {
+ if (!checkSymbol(lib, version, symbol)) {
+ if (symbol)
+ printerr(`Unsatisfied dependency: No ${symbol} in ${lib}`);
+ else
+ printerr(`Unsatisfied dependency: ${lib}`);
+ System.exit(1);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]