[gnc-module] clean up deprecation warnings

* use reasonable max-width
* compact code
* use (ice-9 match)
This commit is contained in:
Christopher Lam 2020-02-09 11:34:43 +08:00
parent f5c0ddd786
commit 907bff34c3

View File

@ -27,50 +27,55 @@
(define-module (gnucash 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."))
(use-modules (ice-9 match))
(define (deprecate . lst)
(issue-deprecation-warning (string-concatenate lst)))
(define (no-op-deprecation-warning)
(deprecate "* WARNING * Guile wrappers for the gnc module system have been \
deprecated. This particular function call is now a no-op. Please use \
equivalent (use-modules ...) calls instead."))
(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-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))))))
(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)))
(match gnc-mod-name
("gnucash/app-utils"
(deprecate "* WARNING * 'gnc:module-load (\"gnucash/app-utils\" 0)' has \
been deprecated and will be removed in gnucash 5.0. Use '(use-modules (gnucash \
engine) (gnucash app-utils))' instead. 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 "gnucash/tax/de_DE" "gnucash/tax/us")
(set! scm-mod-name `(gnucash locale ,(list-ref scm-mod-name 2) tax))
(set! mod-name-str (string-join (map symbol->string scm-mod-name) " "))
(deprecate "* WARNING * '(gnc:module-load \"" gnc-mod-name "\" 0)' has \
been deprecated. Use '(use-modules (" mod-name-str "))' instead.")
(module-use! (current-module) (resolve-interface scm-mod-name)))
((or "gnucash/gnome-utils" "gnucash/html" "gnucash/report/report-system")
(when (string=? gnc-mod-name "gnucash/report/report-system")
(set! mod-name-str "gnucash report"))
(set! scm-mod-name '(gnucash report))
(deprecate "* WARNING * '(gnc:module-load \"" gnc-mod-name "\" 0)' has \
been deprecated. Use '(use-modules (gnucash engine) (gnucash app-utils) \
(" mod-name-str "))' instead. 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)))
(_ (deprecate "* WARNING * '(gnc:module-load \"" gnc-mod-name "\" 0)' \
has been deprecated. Use '(use-modules (" mod-name-str "))' instead. \
Additional guile modules may have to be loaded depending on your specific code.")
(module-use! (current-module) (resolve-interface scm-mod-name))))))