Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions examples/editor.scm
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

(push-duplicate-handler! 'merge-generics)
(use-typelibs
;; load GObject first to prevent warnings, even if we don't directly need it
(("GObject" "2.0") #:select ())
(("Gio" "2.0") #:renamer (protect* '(application:new receive)))
("Gtk" "3.0")
("Gdk" "3.0"))
Expand Down
31 changes: 27 additions & 4 deletions module/gi/repository.scm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
(eval-when (expand load eval)
(load-extension "libguile-gi" "gig_init_repository"))

(define %gig-duplicate-handlers
(append
(lookup-duplicates-handlers
'(merge-generics replace warn-override-core))
(list %gig-duplicate-warn)
(lookup-duplicates-handlers
'(last))))

(define-method (load (info <GIBaseInfo>))
(%load-info info LOAD_EVERYTHING))

Expand All @@ -45,10 +53,14 @@

(define* (typelib->module module lib #:optional version)
(require lib version)
(set! module (cond
((module? module) module)
((list? module) (resolve-module module))
(else (error "not a module: ~A" module))))
(set! module
(cond
((module? module) module)
((list? module)
(let ((m (resolve-module module)))
(set-module-duplicates-handlers! m %gig-duplicate-handlers)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight oversight, we should first check whether m is a fresh module.

m))
(else (error "not a module: ~A" module))))

(unless (module-public-interface module)
(let ((interface (make-module)))
Expand All @@ -57,6 +69,17 @@
(set-module-kind! interface 'interface)
(set-module-public-interface! module interface)))

(for-each
(lambda (dep)
(module-use!
module
(let ((module (list 'gi (string->symbol dep)))
(lib+version (string-split dep #\-)))
(or (false-if-exception (resolve-interface module))
(module-public-interface
(apply typelib->module module lib+version))))))
(immediate-dependencies lib))

(save-module-excursion
(lambda ()
(set-current-module module)
Expand Down
68 changes: 68 additions & 0 deletions src/gig_repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,47 @@
#include "gig_flag.h"
#include "gig_repository.h"

static SCM module_name_proc = SCM_UNDEFINED;

static SCM
scm_module_name(SCM module)
{
if (SCM_UNBNDP(module_name_proc))
module_name_proc = scm_c_public_ref("guile", "module-name");
return scm_call_1(module_name_proc, module);
}

static SCM
gig_duplicate_warn(SCM module, SCM name, SCM int1, SCM val1, SCM int2, SCM val2, SCM var, SCM val)
{

SCM _module_s, _name_s, _int1_s, _int2_s, _val1_s, _val2_s;
gchar *module_s, *name_s, *int1_s, *int2_s, *val1_s, *val2_s;
scm_dynwind_begin(0);

_int1_s = scm_object_to_string(scm_module_name(int1), SCM_UNDEFINED);
_int2_s = scm_object_to_string(scm_module_name(int2), SCM_UNDEFINED);
_val1_s = scm_object_to_string(val1, SCM_UNDEFINED);
_val2_s = scm_object_to_string(val2, SCM_UNDEFINED);
_module_s = scm_object_to_string(scm_module_name(module), SCM_UNDEFINED);
_name_s = scm_object_to_string(name, SCM_UNDEFINED);

module_s = scm_dynwind_or_bust("%gig-duplicate-warn", scm_to_utf8_string(_module_s));
name_s = scm_dynwind_or_bust("%gig-duplicate-warn", scm_to_utf8_string(_name_s));
int1_s = scm_dynwind_or_bust("%gig-duplicate-warn", scm_to_utf8_string(_int1_s));
int2_s = scm_dynwind_or_bust("%gig-duplicate-warn", scm_to_utf8_string(_int2_s));
val1_s = scm_dynwind_or_bust("%gig-duplicate-warn", scm_to_utf8_string(_val1_s));
val2_s = scm_dynwind_or_bust("%gig-duplicate-warn", scm_to_utf8_string(_val2_s));

gig_warning_load("%s: `%s' imported from both %s and %s", module_s, name_s, int1_s, int2_s);
gig_debug_load("binding from %s: %s", int1_s, val1_s);
gig_debug_load("binding from %s: %s", int2_s, val2_s);

scm_dynwind_end();

return SCM_BOOL_F;
}

static SCM
require(SCM lib, SCM version)
{
Expand All @@ -48,6 +89,31 @@ require(SCM lib, SCM version)
return SCM_UNSPECIFIED;
}

static SCM
immediate_dependencies(SCM lib)
{
gchar *_lib, **deps;
guint n_deps;
SCM ret, iter;

scm_dynwind_begin(0);
_lib = scm_dynwind_or_bust("immediate-dependencies", scm_to_utf8_string(lib));
deps = g_irepository_get_immediate_dependencies(NULL, _lib);
scm_dynwind_end();

if (deps == NULL)
scm_misc_error("immediate-dependencies", "could not find dependencies for ~A", scm_list_1(lib));
n_deps = g_strv_length(deps);

ret = scm_make_list(scm_from_uint(n_deps), SCM_UNDEFINED);
iter = ret;
for (guint i = 0; i < n_deps; i++, iter = scm_cdr(iter))
scm_set_car_x(iter, scm_from_utf8_string(deps[i]));
g_strfreev(deps);

return ret;
}

static SCM
infos(SCM lib)
{
Expand Down Expand Up @@ -349,7 +415,9 @@ prepend_search_path(SCM s_dir)
void
gig_init_repository()
{
scm_c_define_gsubr("%gig-duplicate-warn", 8, 0, 0, gig_duplicate_warn);
scm_c_define_gsubr("require", 1, 1, 0, require);
scm_c_define_gsubr("immediate-dependencies", 1, 0, 0, immediate_dependencies);
scm_c_define_gsubr("infos", 1, 0, 0, infos);
scm_c_define_gsubr("info", 2, 0, 0, info);
scm_c_define_gsubr("%load-info", 1, 1, 0, load);
Expand Down