MCPcopy Create free account
hub / github.com/GNOME/gjs / init

Function init

modules/script/package.js:99–195  ·  view source on GitHub ↗

* Initialize directories and global variables. Must be called * before any of other API in Package is used. * `params` must be an object with at least the following keys: * - name: the package name ($(PACKAGE_NAME) in autotools, * eg. org.foo.Bar) * - version: the package version *

(params)

Source from the content-addressed store, hash-verified

97 * @param {object} params package parameters
98 */
99function init(params) {
100 globalThis.pkg = imports.package;
101 _pkgname = params.name;
102 name = _findEffectiveEntryPointName();
103 version = params.version;
104
105 // Must call it first, because it can only be called
106 // once, and other library calls might have it as a
107 // side effect
108 GLib.set_prgname(name);
109
110 prefix = params.prefix;
111 libdir = params.libdir;
112 datadir = GLib.build_filenamev([prefix, 'share']);
113 let libpath, girpath;
114
115 const loadResource = (path, baseName) => {
116 const resource = Gio.Resource.load(GLib.build_filenamev([path,
117 `${baseName}.src.gresource`]));
118 resource._register();
119
120 return `resource:///${baseName.replaceAll('.', '/')}/js`;
121 };
122
123 if (_runningFromMesonSource()) {
124 log('Running from Meson, using local files');
125 let bld = GLib.getenv('MESON_BUILD_ROOT');
126
127 pkglibdir = libpath = girpath = GLib.build_filenamev([bld, 'lib']);
128 pkgdatadir = GLib.build_filenamev([bld, 'data']);
129 localedir = GLib.build_filenamev([bld, 'po']);
130 _submoduledir = GLib.build_filenamev([bld, 'subprojects']);
131
132 GLib.setenv('GSETTINGS_SCHEMA_DIR', pkgdatadir, true);
133 const bldPath = GLib.build_filenamev([bld, 'src']);
134 try {
135 moduledir = loadResource(bldPath, name);
136 } catch {
137 try {
138 moduledir = loadResource(bldPath, _pkgname);
139 name = _pkgname;
140 } catch {
141 const src = GLib.getenv('MESON_SOURCE_ROOT');
142 moduledir = GLib.build_filenamev([src, 'src']);
143 }
144 }
145 } else if (_runningFromSource()) {
146 log('Running from source tree, using local files');
147 // Running from source directory
148 _base = GLib.get_current_dir();
149 _submoduledir = _base;
150 pkglibdir = GLib.build_filenamev([_base, 'lib']);
151 libpath = GLib.build_filenamev([pkglibdir, '.libs']);
152 girpath = pkglibdir;
153 pkgdatadir = GLib.build_filenamev([_base, 'data']);
154 localedir = GLib.build_filenamev([_base, 'po']);
155 moduledir = GLib.build_filenamev([_base, 'src']);
156

Callers 1

startFunction · 0.85

Calls 7

_runningFromMesonSourceFunction · 0.85
logFunction · 0.85
loadResourceFunction · 0.85
_runningFromSourceFunction · 0.85
prepend_search_pathMethod · 0.80
loadMethod · 0.80

Tested by

no test coverage detected