Skip to content

Commit

Permalink
bindings/guile - remove gnc-module wrapper
Browse files Browse the repository at this point in the history
Emit appropriate deprecation warnings in case code tries to invoke the removed functions.
Only for gnc:module-load a more elaborate compat function has
been written which should allow code using this obsolete function
to continue to function. The emitted deprecation warning will
guide the user to update his/her code for future compatibility.
  • Loading branch information
gjanssens committed Dec 6, 2019
1 parent e8451ae commit 88706e5
Show file tree
Hide file tree
Showing 36 changed files with 81 additions and 881 deletions.
3 changes: 1 addition & 2 deletions bindings/CMakeLists.txt
Expand Up @@ -6,6 +6,5 @@ set_local_dist(bindings_DIST_local
business-core.i
core-utils.i
engine.i
engine-common.i
gnc-module.i)
engine-common.i)
set(bindings_DIST ${bindings_DIST_local} ${guile_DIST} ${python_bindings_DIST} PARENT_SCOPE)
39 changes: 0 additions & 39 deletions bindings/gnc-module.i

This file was deleted.

14 changes: 1 addition & 13 deletions bindings/guile/CMakeLists.txt
Expand Up @@ -20,15 +20,6 @@ gnc_add_swig_guile_command (swig-engine-c
${CMAKE_SOURCE_DIR}/bindings/engine-common.i
)

# Command to generate the swig-gnc-module.c wrapper file
gnc_swig_extract_header_files (gnc-module GNC_MODULE_HEADERS)
gnc_add_swig_guile_command (swig-gnc-module-c
SWIG_GNC_MODULE_C swig-gnc-module.c
${CMAKE_SOURCE_DIR}/bindings/gnc-module.i
"${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_SOURCE_DIR}/libgnucash/gnc-module"
${GNC_MODULE_HEADERS}
)

set(guile_HEADERS
glib-guile.h
gnc-engine-guile.h
Expand All @@ -46,8 +37,7 @@ add_library(gnucash-guile SHARED
${guile_SOURCES}
${guile_HEADERS}
${SWIG_CORE_UTILS_GUILE_C}
${SWIG_ENGINE_C}
${SWIG_GNC_MODULE_C})
${SWIG_ENGINE_C})

add_dependencies(gnucash-guile
swig-runtime-h)
Expand All @@ -67,7 +57,6 @@ target_link_libraries(gnucash-guile
PRIVATE
gnc-core-utils
gnc-engine
gnc-module
${GLIB2_LDFLAGS})

install(TARGETS gnucash-guile
Expand Down Expand Up @@ -139,7 +128,6 @@ gnc_add_scheme_targets(scm-engine-2
add_custom_target(scm-engine ALL DEPENDS scm-engine-2 scm-engine-1 scm-engine-0)

set(scm_gnc_module_DEPENDS
gnc-module
gnucash-guile)

gnc_add_scheme_targets(scm-gnc-module
Expand Down
2 changes: 0 additions & 2 deletions bindings/guile/gnc-guile-bindings.c
Expand Up @@ -34,7 +34,6 @@ static int is_initialized = 0;

extern SCM scm_init_sw_core_utils_module (void);
extern SCM scm_init_sw_engine_module (void);
extern SCM scm_init_sw_gnc_module_module (void);

void
gnc_guile_bindings_init(void)
Expand All @@ -44,7 +43,6 @@ gnc_guile_bindings_init(void)
/* Do what's necessary to initialize the bindings */
scm_init_sw_core_utils_module();
scm_init_sw_engine_module();
scm_init_sw_gnc_module_module();

is_initialized = 1;
}
Expand Down
65 changes: 46 additions & 19 deletions bindings/guile/gnc-module.scm
Expand Up @@ -27,23 +27,50 @@

(define-module (gnucash gnc-module))

;; Guile 2 needs to find the symbols from the extension at compile time already
(eval-when
(compile load eval expand)
(load-extension "libgnucash-guile" "gnc_guile_bindings_init"))
(use-modules (sw_gnc_module))
(define (no-op-deprecation-warning)
(issue-deprecation-warning "* WARNING * Guile wrappers for the gnc module system have been deprecated.")
(issue-deprecation-warning "This particular function call is now a no-op. Please use equivalent (use-modules ...) calls instead."))

; Export the swig-wrapped symbols in the public interface of this module
(let ((i (module-public-interface (current-module))))
(module-use! i (resolve-interface '(sw_gnc_module))))

(define-public gnc:module-system-init gnc-module-system-init)
(define-public gnc:module-system-refresh gnc-module-system-refresh)
(define-public gnc:module-load gnc-module-load)
(define-public gnc:module-load-optional gnc-module-load-optional)
(define-public gnc:module-unload gnc-module-unload)

;; Guile 2 needs to load external modules at compile time
(define-syntax-rule (gnc:module-begin-syntax form ...)
(eval-when (load compile eval expand) (begin form ...)))
(export gnc:module-begin-syntax)
(define-public (gnc:module-system-init)
(no-op-deprecation-warning))
(define-public (gnc:module-system-refresh)
(no-op-deprecation-warning))
(define-public (gnc:module-load-optional)
(no-op-deprecation-warning))
(define-public (gnc:module-unload)
(no-op-deprecation-warning))
(define-public (gnc:module-load gnc-mod-name mod-sys-version)
(let* ((mod-name-split (string-split gnc-mod-name #\/))
(mod-name-str (string-join mod-name-split " "))
(scm-mod-name (map string->symbol mod-name-split)))
(cond
((string=? gnc-mod-name "gnucash/app-utils")
(issue-deprecation-warning "* WARNING * 'gnc:module-load (\"gnucash/app-utils\" 0)' has been deprecated and will be removed in gnucash 5.0.")
(issue-deprecation-warning "Use '(use-modules (gnucash engine)(gnucash app-utils))' instead.")
(issue-deprecation-warning "Use of the '(gnucash engine)' guile module is optional and depends on whether or not you use functions from this module in your code or not.")
(use-modules (gnucash engine)(gnucash app-utils)))
((or
(string=? gnc-mod-name "gnucash/tax/de_DE")
(string=? gnc-mod-name "gnucash/tax/us"))
(set! scm-mod-name (list 'gnucash 'locale (list-ref scm-mod-name 2) 'tax))
(set! mod-name-str (string-join (map symbol->string scm-mod-name) " "))
(issue-deprecation-warning (string-concatenate (list "* WARNING * '(gnc:module-load \"" gnc-mod-name "\" 0)' has been deprecated.")))
(issue-deprecation-warning (string-concatenate (list "Use '(use-modules (" mod-name-str "))' instead.")))
(module-use! (current-module) (resolve-interface scm-mod-name)))
((or
(string=? gnc-mod-name "gnucash/gnome-utils")
(string=? gnc-mod-name "gnucash/html")
(string=? gnc-mod-name "gnucash/report/report-system"))
(when (string=? gnc-mod-name"gnucash/report/report-system")
(set! mod-name-str "gnucash report"))
(set! scm-mod-name (list 'gnucash 'report))
(issue-deprecation-warning (string-concatenate (list "* WARNING * '(gnc:module-load \"" gnc-mod-name "\" 0)' has been deprecated.")))
(issue-deprecation-warning (string-concatenate (list "Use '(use-modules (gnucash engine)(gnucash app-utils)(" mod-name-str "))' instead.")))
(issue-deprecation-warning "Use of the '(gnucash engine)' or '(gnucash app-utils)' guile modules is optional and depends on whether or not you use functions from this module in your code or not.")
(use-modules (gnucash engine)(gnucash app-utils))
(module-use! (current-module) (resolve-interface scm-mod-name)))
(else
(issue-deprecation-warning (string-concatenate (list "* WARNING * '(gnc:module-load \"" gnc-mod-name "\" 0)' has been deprecated.")))
(issue-deprecation-warning (string-concatenate ( list "Use '(use-modules (" mod-name-str "))' instead.")))
(issue-deprecation-warning "Additional guile modules may have to be loaded depending on your specific code.")
(module-use! (current-module) (resolve-interface scm-mod-name))))))
45 changes: 0 additions & 45 deletions bindings/guile/test/CMakeLists.txt
@@ -1,9 +1,5 @@
# C(++) tests requiring a proper guile environment set up

add_subdirectory(mod-foo)
add_subdirectory(mod-bar)
add_subdirectory(mod-baz)

set(ENGINE_TEST_INCLUDE_DIRS
${CMAKE_SOURCE_DIR}/libgnucash/backend/xml
${CMAKE_SOURCE_DIR}/libgnucash/engine
Expand Down Expand Up @@ -115,43 +111,6 @@ if (HAVE_SRFI64)

endif (HAVE_SRFI64)


set (test_gnc_module_SCHEME
test-gnc-module-scm-init.scm
test-gnc-module-load-scm.scm
test-gnc-module-swigged-c.scm
test-gnc-module-load-deps.scm
test-gnc-module-scm-dynload.scm
test-gnc-module-scm-module.scm
test-gnc-module-scm-multi.scm
)

set (test_gnc_module_DEPENDS
scm-gnc-module
scm-test-core
scm-mod-foo
gncmod-bar
scm-mod-baz
)

gnc_add_scheme_test_targets (test-gnc-modules-scm
"${test_gnc_module_SCHEME}"
"tests"
"${test_gnc_module_DEPENDS}"
TRUE
)
gnc_add_scheme_tests ("${test_gnc_module_SCHEME}")
if(NOT WIN32)
# This little dance is needed because gnc_module_init will assert if
# it finds libgncmod-futuremod.so outside of a test that expects it.
get_guile_env()
set(_GNC_MODULE_PATH "${LIBDIR_BUILD}:${LIBDIR_BUILD}/gnucash:${LIBDIR_BUILD}/gnucash/test")
foreach(test_file ${test_gnc_module_SCHEME})
get_filename_component(basename ${test_file} NAME_WE)
set_tests_properties(${basename} PROPERTIES ENVIRONMENT "${GUILE_ENV};GNC_MODULE_PATH=${_GNC_MODULE_PATH}")
endforeach()
endif()

set(test_engine_SCHEME_DIST
srfi64-extras.scm
${bindings_test_SCHEME}
Expand All @@ -164,14 +123,10 @@ set_local_dist(test_guile_DIST_local
CMakeLists.txt
test-scm-query.cpp
${test_engine_SCHEME_DIST}
${test_gnc_module_SCHEME}
${test_scm_SCHEME}
)
set(test_guile_DIST
${test_guile_DIST_local}
${mod_bar_DIST}
${mod_baz_DIST}
${mod_foo_DIST}
PARENT_SCOPE
)

Expand Down
35 changes: 0 additions & 35 deletions bindings/guile/test/mod-bar/CMakeLists.txt

This file was deleted.

33 changes: 0 additions & 33 deletions bindings/guile/test/mod-bar/bar.c

This file was deleted.

28 changes: 0 additions & 28 deletions bindings/guile/test/mod-bar/bar.h

This file was deleted.

33 changes: 0 additions & 33 deletions bindings/guile/test/mod-bar/bar.i

This file was deleted.

0 comments on commit 88706e5

Please sign in to comment.