GnuCash: refactor in support of enabling GSettings

GnuCash uses Gnome's GSettings to store user preferences. This was not
working before. wrapGAppsHook is introduced to solve this problem, but
it must be tweaked to not wrap GnuCash's cli utilities for fetching
financial quotes. Those are now deliberately wrapped with their Perl
library dependencies.

The existing code is refactored in an attempt to clarify which
dependencies are needed and why.
This commit is contained in:
StephenWithPH 2021-12-19 15:34:46 -08:00
parent 940d182e40
commit 7b74a76d9b
No known key found for this signature in database
GPG Key ID: 00D80E6A83C90F2C
4 changed files with 219 additions and 82 deletions

View File

@ -0,0 +1,18 @@
diff --git a/libgnucash/quotes/CMakeLists.txt b/libgnucash/quotes/CMakeLists.txt
index b33569d39..fdbfa10a9 100644
--- a/libgnucash/quotes/CMakeLists.txt
+++ b/libgnucash/quotes/CMakeLists.txt
@@ -1,6 +1,6 @@
set(_BIN_FILES "")
-foreach(file gnc-fq-check.in gnc-fq-helper.in gnc-fq-update.in gnc-fq-dump.in)
+foreach(file gnc-fq-check.in gnc-fq-helper.in gnc-fq-dump.in)
string(REPLACE ".in" "" _OUTPUT_FILE_NAME ${file})
set(_ABS_OUTPUT_FILE ${BINDIR_BUILD}/${_OUTPUT_FILE_NAME})
configure_file( ${file} ${_ABS_OUTPUT_FILE} @ONLY)
@@ -26,4 +26,4 @@ add_custom_target(quotes-bin ALL DEPENDS ${_BIN_FILES})
install(FILES ${_MAN_FILES} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
install(PROGRAMS ${_BIN_FILES} DESTINATION ${CMAKE_INSTALL_BINDIR})
-set_dist_list(quotes_DIST CMakeLists.txt gnc-fq-check.in gnc-fq-dump.in gnc-fq-helper.in gnc-fq-update.in Quote_example.pl README)
+set_dist_list(quotes_DIST CMakeLists.txt gnc-fq-check.in gnc-fq-dump.in gnc-fq-helper.in Quote_example.pl README)

View File

@ -0,0 +1,35 @@
diff --git a/gnucash/CMakeLists.txt b/gnucash/CMakeLists.txt
index 8e6e339d1..3936a8cb6 100644
--- a/gnucash/CMakeLists.txt
+++ b/gnucash/CMakeLists.txt
@@ -163,13 +163,6 @@ set(GNUCASH_BIN_INSTALL_NAME "gnucash")
set(VALGRIND_OUTDIR ${BINDIR_BUILD})
-configure_file(gnucash-valgrind.in ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/gnucash-valgrind @ONLY)
-
-file(COPY ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/gnucash-valgrind
- DESTINATION ${VALGRIND_OUTDIR}
- FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
-)
-
## Create the environment file
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/environment.in ENV_STRINGS_IN)
@@ -253,7 +246,6 @@ file(COPY ${ENV_FILE_OUT}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
-install(FILES ${SCRIPT_LIST} ${VALGRIND_OUTDIR}/gnucash-valgrind DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${ENVIRONMENT_FILE_DIR}/environment DESTINATION
${CMAKE_INSTALL_FULL_SYSCONFDIR}/gnucash)
@@ -274,7 +266,7 @@ gnc_add_scheme_targets(price-quotes
set_local_dist(gnucash_DIST_local CMakeLists.txt environment.in generate-gnc-script
gnucash.cpp gnucash-commands.cpp gnucash-cli.cpp gnucash-core-app.cpp
- gnucash-locale-macos.mm gnucash-locale-windows.c gnucash.rc.in gnucash-valgrind.in
+ gnucash-locale-macos.mm gnucash-locale-windows.c gnucash.rc.in
gnucash-gresources.xml ${gresource_files} price-quotes.scm
${gnucash_noinst_HEADERS} ${gnucash_EXTRA_DIST})

View File

@ -1,106 +1,190 @@
{ fetchurl, lib, stdenv, pkg-config, makeWrapper, cmake, gtest
, boost, icu, libxml2, libxslt, gettext, swig, isocodes, gtk3, glibcLocales
, webkitgtk, dconf, hicolor-icon-theme, libofx, aqbanking, gwenhywfar, libdbi
, libdbiDrivers, guile, perl, perlPackages
{ fetchurl
, lib
, stdenv
, aqbanking
, boost
, cmake
, glib
, glibcLocales
, gtest
, guile
, gwenhywfar
, icu
, libdbi
, libdbiDrivers
, libofx
, libxml2
, libxslt
, makeWrapper
, perl
, perlPackages
, pkg-config
, swig
, webkitgtk
, wrapGAppsHook
}:
let
# Enable gnc-fq-* to run in command line.
perlWrapper = stdenv.mkDerivation {
name = perl.name + "-wrapper-for-gnucash";
nativeBuildInputs = [ makeWrapper ];
buildInputs = [ perl ] ++ (with perlPackages; [ FinanceQuote DateManip ]);
dontUnpack = true;
installPhase = ''
mkdir -p $out/bin
for script in ${perl}/bin/*; do
makeWrapper $script $out''${script#${perl}} \
--prefix "PERL5LIB" ":" "$PERL5LIB"
done
'';
};
in
stdenv.mkDerivation rec {
pname = "gnucash";
version = "4.9";
src = fetchurl {
url = "mirror://sourceforge/gnucash/${pname}-${version}.tar.bz2";
sha256 = "sha256-mlUcMMG3EhmfwiJ6EJr7mE177xjhOBcLvHIlxsH6ty0=";
url = "https://github.com/Gnucash/gnucash/releases/download/${version}/gnucash-${version}.tar.bz2";
sha256 = "0bdpzb0wc9bjph5iff7133ppnkcqzfd10yi2qagij4mpq4q1qmcs";
};
nativeBuildInputs = [ pkg-config makeWrapper cmake gtest swig ];
nativeBuildInputs = [
cmake
makeWrapper
wrapGAppsHook
];
buildInputs = [
boost icu libxml2 libxslt gettext isocodes gtk3 glibcLocales
webkitgtk dconf libofx aqbanking gwenhywfar libdbi
libdbiDrivers guile
perlWrapper perl
aqbanking
boost
glib
glibcLocales
gtest
guile
gwenhywfar
icu
libdbi
libdbiDrivers
libofx
libxml2
libxslt
perl
pkg-config
swig
webkitgtk
] ++ (with perlPackages; [ FinanceQuote DateManip ]);
propagatedUserEnvPkgs = [ dconf ];
patches = [
# this patch disables test-gnc-timezone and test-gnc-datetime which fail due to nix datetime challenges
./0001-disable-date-and-time-tests.patch
# this patch prevents the building of gnc-fq-update, a utility which updates the GnuCash cli utils
./0002-disable-gnc-fq-update.patch
# this patch prevents the building of gnucash-valgrind
./0003-remove-valgrind.patch
];
# glib-2.62 deprecations
NIX_CFLAGS_COMPILE = "-DGLIB_DISABLE_DEPRECATION_WARNINGS";
# this patch disables test-gnc-timezone and test-gnc-datetime which fail due to nix datetime challenges
patches = [ ./0001-changes.patch ];
postPatch = ''
patchShebangs .
preConfigure = ''
export GUILE_AUTO_COMPILE=0 # this needs to be an env variable and not a cmake flag to suppress guile warning
'';
makeFlags = [ "GUILE_AUTO_COMPILE=0" ];
postInstall = ''
# Auto-updaters don't make sense in Nix.
rm $out/bin/gnc-fq-update
# Unnecessary in the release build.
rm $out/bin/gnucash-valgrind
wrapProgram "$out/bin/gnucash" \
--prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH:$out/share/gsettings-schemas/${pname}-${version}" \
--prefix XDG_DATA_DIRS : "${hicolor-icon-theme}/share" \
--prefix PERL5LIB ":" "$PERL5LIB" \
--set GNC_DBD_DIR ${libdbiDrivers}/lib/dbd \
--prefix GIO_EXTRA_MODULES : "${lib.getLib dconf}/lib/gio/modules"
'';
/*
GNUcash's `make check` target does not define its prerequisites but expects them to have already been built.
The list of targets below was built through trial and error based on failing tests.
*/
preCheck = ''
export LD_LIBRARY_PATH=$PWD/lib:$PWD/lib/gnucash:$PWD/lib/gnucash/test:$PWD/lib/gnucash/test/future''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
export NIX_CFLAGS_LINK="-lgtest -lgtest_main"
make test-scm-query test-split-register-copy-ops test-link-ofx test-import-backend test-import-account-matcher test-import-pending-matches test-qofquerycore test-import-map test-gnc-numeric test-gnc-rational test-gnc-int128 test-qofsession test-kvp-value test-gnc-guid test-numeric test-vendor test-job test-employee test-customer test-address test-business test-recurrence test-transaction-voiding test-transaction-reversal test-split-vs-account test-tokenizer test-aqb test-import-parse test-link-module-tax-us test-dynload test-agedver test-incompatdep test-modsysver test-load-c test-gnc-path-util test-xml2-is-file test-load-example-account test-query test-querynew test-lots test-group-vs-book test-account-object test-engine test-qof test-commodities test-object test-guid test-load-engine test-userdata-dir-invalid-home test-userdata-dir test-resolve-file-path test-gnc-glib-utils test-sqlbe test-column-types test-backend-dbi test-xml-transaction test-xml-pricedb test-xml-commodity test-xml-account test-string-converters test-load-backend test-kvp-frames test-dom-converters1 test-autoclear test-sx test-print-parse-amount gncmod-futuremodsys
'';
doCheck = true;
meta = {
description = "Personal and small-business financial-accounting application";
/*
GNUcash's `make check` target does not define its prerequisites but expects them to have already been built.
The list of targets below was built through trial and error based on failing tests.
*/
preCheck = ''
make \
test-account-object \
test-address \
test-agedver \
test-app-utils \
test-aqb \
test-autoclear \
test-backend-dbi \
test-business \
test-column-types \
test-commodities \
test-customer \
test-dom-converters1 \
test-dynload \
test-employee \
test-engine \
test-exp-parser \
test-gnc-glib-utils \
test-gnc-guid \
test-gnc-int128 \
test-gnc-numeric \
test-gnc-path-util \
test-gnc-rational \
test-group-vs-book \
test-guid \
test-import-account-matcher \
test-import-backend \
test-import-map \
test-import-parse \
test-import-pending-matches \
test-incompatdep \
test-job \
test-kvp-frames \
test-kvp-value \
test-link-module-tax-us \
test-link-ofx \
test-load-backend \
test-load-c \
test-load-engine \
test-load-example-account \
test-load-xml2 \
test-lots \
test-modsysver \
test-numeric \
test-object \
test-print-parse-amount \
test-qof \
test-qofquerycore \
test-qofsession \
test-query \
test-querynew \
test-recurrence \
test-resolve-file-path \
test-scm-query \
test-scm-query-string \
test-split-register-copy-ops \
test-split-vs-account \
test-sqlbe \
test-string-converters \
test-sx \
test-tokenizer \
test-transaction-reversal \
test-transaction-voiding \
test-userdata-dir \
test-userdata-dir-invalid-home \
test-vendor \
test-xml-account \
test-xml-commodity \
test-xml-pricedb \
test-xml-transaction \
test-xml2-is-file
export LD_LIBRARY_PATH="$PWD/lib:$PWD/lib/gnucash:$PWD/lib/gnucash/test:$PWD/lib/gnucash/test/future"
'';
preFixup = ''
gappsWrapperArgs+=(
--set GNC_DBD_DIR ${libdbiDrivers}/lib/dbd # specify where db drivers are
--set GSETTINGS_SCHEMA_DIR ${glib.makeSchemaPath "$out" "${pname}-${version}"} # specify where nix puts the gnome settings schemas
)
'';
# wrapGAppsHook would wrap all binaries including the cli utils which need Perl wrapping
dontWrapGApps = true;
# gnucash is wrapped using the args constructed for wrapGAppsHook.
# gnc-fq-* are cli utils written in Perl hence the extra wrapping
postFixup = ''
wrapProgram $out/bin/gnucash "''${gappsWrapperArgs[@]}"
for file in $out/bin/gnc-fq-check $out/bin/gnc-fq-dump $out/bin/gnc-fq-helper; do
wrapProgram $file \
--prefix PERL5LIB : "${with perlPackages; makeFullPerlPath [ DateManip FinanceQuote ]}"
done
'';
meta = with lib; {
description = "Personal and small business double entry accounting application.";
longDescription = ''
GnuCash is personal and small-business financial-accounting software,
freely licensed under the GNU GPL and available for GNU/Linux, BSD,
Solaris, macOS and Microsoft Windows.
Designed to be easy to use, yet powerful and flexible, GnuCash allows
you to track bank accounts, stocks, income and expenses. As quick and
intuitive to use as a checkbook register, it is based on professional
accounting principles to ensure balanced books and accurate reports.
Designed to be easy to use, yet powerful and flexible, GnuCash allows you to track bank accounts, stocks, income and expenses.
As quick and intuitive to use as a checkbook register, it is based on professional accounting principles to ensure balanced books and accurate reports.
'';
license = lib.licenses.gpl2Plus;
homepage = "http://www.gnucash.org/";
maintainers = [ lib.maintainers.domenkozar ];
platforms = lib.platforms.gnu ++ lib.platforms.linux;
homepage = "https://www.gnucash.org/";
license = licenses.gpl2Plus;
maintainers = [ maintainers.domenkozar ];
platforms = platforms.linux;
};
}