Need help to package Referencer as snap

Hello,
Referencer is a software to manage bibliography and create bib files needed by latex. It is no more present in the ubuntu 18.04 archives. It has been orphaned from Debian archive. It also depends on gconfmm2.6 that is also unmaintained. More over referencer developpement doesn’s seems to be very active as the last release dates back to 2014.
However only few software exist to manage bibliography with latex (jabref, zotero and kbitex). Because of its simplicity and its good integration with Gnome, Referencer has a great interest. Thus I tried to package as Snap.

I download the source here :
https://launchpad.net/referencer/1./1.2.2/+download/referencer-1.2.2.tar.gz
Fix the following bug https://bugs.launchpad.net/referencer/+bug/1645639 and successfully build it on Ubuntu 18.04.

The I create the following Yaml file (I am not sure about the needed build-packages) :

name: referencer # you probably want to 'snapcraft register <name>'
version: '1.2.2' # just for humans, typically '1.2+git' or '1.3.2'
summary: manage your bibliograpy # 79 char long summary
description: |
  manage your bibliograpy

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

apps:
  referencer:
    command: bin/referencer

parts:
  referencer:
    # See 'snapcraft plugins'
    plugin: autotools
    source: ./referencer-1.2.2/
    build-packages:
        - build-essential
        - gnome-doc-utils
        - gtkmm-documentation
        - libboost1.65-dev
        - intltool
        - python2.7-dev
        - libpython2.7-dev
        - libpython-dev
        - python-dev
    stage-packages:
        - libatk1.0-0
        - libatkmm-1.6-1v5
        - libblkid1
        - libboost-regex1.65.1
        - libcairo2
        - libcairomm-1.0-1v5
        - libdatrie1
        - libdbus-glib-1-2
        - libfontconfig1
        - libgconf-2-4
        - libgconfmm-2.6-1v5
        - libgdk-pixbuf2.0-0
        - libglibmm-2.4-1v5
        - libgpg-error0
        - libgraphite2-3
        - libgtk2.0-0
        - libgtkmm-2.4-1v5
        - libharfbuzz0b
        - libicu60
        - libjbig0
        - libjpeg-turbo8
        - liblcms2-2
        - libnspr4
        - libnss3
        - libpango-1.0-0
        - libpangocairo-1.0-0
        - libpangoft2-1.0-0
        - libpangomm-1.4-1v5
        - libpixman-1-0
        - libpng16-16
        - libpoppler73
        - libpoppler-glib8
        - libpython2.7
        - libsigc++-2.0-0v5
        - libthai0
        - libtiff5
        - libx11-6
        - libxau6
        - libxcb1
        - libxcb-render0
        - libxcb-shm0
        - libxcomposite1
        - libxcursor1
        - libxdamage1
        - libxdmcp6
        - libxext6
        - libxfixes3
        - libxi6
        - libxinerama1
        - libxml2
        - libxrandr2
        - libxrender1
        - zlib1g
        - libc6

I am facing first the following error/warning :

The GLIBC version of the targeted core is 2.23. A newer libc will be required for the following files:
- /home/maxime/Apps/snap_referencer_2/prime/lib/x86_64-linux-gnu/libblkid.so.1.1.0 (requires GLIBC 2.25)
- /home/maxime/Apps/snap_referencer_2/prime/lib/x86_64-linux-gnu/libexpat.so.1.6.7 (requires GLIBC 2.25)
- /home/maxime/Apps/snap_referencer_2/prime/usr/lib/x86_64-linux-gnu/libgnutls.so.30.14.10 (requires GLIBC 2.25)
- /home/maxime/Apps/snap_referencer_2/prime/lib/x86_64-linux-gnu/libbsd.so.0.8.7 (requires GLIBC 2.25)
- /home/maxime/Apps/snap_referencer_2/prime/lib/x86_64-linux-gnu/libcrypt-2.27.so (requires GLIBC 2.25)
- /home/maxime/Apps/snap_referencer_2/prime/usr/lib/x86_64-linux-gnu/libexpatw.so.1.6.7 (requires GLIBC 2.25)
- /home/maxime/Apps/snap_referencer_2/prime/usr/lib/x86_64-linux-gnu/libp11-kit.so.0.3.0 (requires GLIBC 2.26)

I ignored it and I ran :

snap install referencer_1.2.2_amd64.snap --devmode

and I tried to run referencer but I have the following issue :

/snap/bin/referencer 
(process:13586): Gtk-WARNING **: 10:32:32.600: Locale not supported by C library.
	Using the fallback 'C' locale.
Gtk-Message: 10:32:32.662: Failed to load module "gail"
Gtk-Message: 10:32:32.662: Failed to load module "atk-bridge"
Gtk-Message: 10:32:32.686: Failed to load module "canberra-gtk-module"
terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid
Abandon (core dumped)

Any idea to fix these issues ? Am I on the good way to make such snap ?

Thank

i would drop all the stage-packages: and instead use the gtk2 desktop helper by adding it to the referencer: part like:

    after:
      - desktop-gtk2

(if there are any dependencies missing after build, add them one by one so you end up with just a small stage-packages: entry)

You seem to not be building on a 16.04 host, which causes a libc discrepancy, try to use snapcraft cleanbuild in a container (lxd or multipass) or build on https://build.snapcraft.io or launchpad to get around this.

there are some good examples in the snapcrafters github repo… i.e. take a look at:

Thank you for your answer,
I correct my snapcraft.yaml and run snapcraft through lxd with the command snapcraft buildclean.

Here my new snapcraft.yaml :

name: referencer # you probably want to 'snapcraft register <name>'
version: '1.2.2' # just for humans, typically '1.2+git' or '1.3.2'
summary: manage your bibliograpy # 79 char long summary
description: |
  manage your bibliograpy

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

apps:
  referencer:
    command: bin/referencer
    desktop: share/applications/referencer.desktop

parts:
  referencer:
    # See 'snapcraft plugins'
    plugin: autotools
    source: ./referencer-1.2.2/
    after:
        - desktop-gtk2
    build-packages:
        - build-essential
        - gnome-doc-utils
        - intltool
        - python2.7-dev
        - libxml2-dev
        - libpoppler-glib-dev
        - libgconfmm-2.6-dev
        - libgtkmm-2.4-dev
        - libboost-regex-dev
        - rarian-compat
        
    stage-packages:
        - libc6
        - libatkmm-1.6-1v5
        - libcairomm-1.0-1v5
        - libdbus-glib-1-2
        - libgconf-2-4
        - libdb5.3
        - libgconfmm-2.6-1v5
        - libpangomm-1.4-1v5
        - libglibmm-2.4-1v5
        - libpoppler-glib8
        - libpoppler58
        - python2.7
        - libpython2.7
        - libgtkmm-2.4-1v5
        - libboost-regex1.58.0
        - libsigc++-2.0-0v5

I have no more warnings about glibc. That is a good step forward.
However, the executable installed in /snap/bin/referencer still crash with this log :

/snap/bin/referencer 

(process:6758): Gtk-WARNING **: Locale not supported by C library.
	Using the fallback 'C' locale.
Gtk-Message: Failed to load module "gail"
Gtk-Message: Failed to load module "atk-bridge"
Gtk-Message: Failed to load module "canberra-gtk-module"
terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid
Abandon (core dumped)

It looks like the same issue than this https://bugs.launchpad.net/snapcraft/+bug/1577557 and seems to be related at this following discussion https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1576411

Update : 
calling referencer with this command :
env LC_ALL=C.UTF-8 /snap/bin/referencer

seems to go further... but crash with this log : 

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
ImportError: No module named site

Any idea ?
Thanks

Best regards

When using the desktop-* parts you should prepend desktop-launch to your command to set up the library paths and required desktop-environment runtime caches:

apps:
  referencer:
    command: desktop-launch $SNAP/bin/referencer

As for using python, you probably want to add a PYTHONPATH environment variable:

apps:
  referencer:
    command: desktop-launch $SNAP/bin/referencer
    desktop: share/applications/referencer.desktop
    environment:
      PYTHONPATH: $SNAP/lib:$SNAP/usr/lib:$PYTHONPATH

Hello,
Thank you for your answer.
It seems that the snap referencer is working little bit better with python.

However I still have some big issues to launch referencer using the following command
snap run referencer

Here the output :

/snap/referencer/x1/usr/bin/update-mime-database: 22: exec: update-mime-database.real: not found
/snap/referencer/x1/bin/desktop-launch: line 332: /snap/referencer/x1/usr/lib/x86_64-linux-gnu/glib-2.0/gio-querymodules: No such file or directory
/snap/referencer/x1/bin/desktop-launch: line 360: /snap/referencer/x1/usr/lib/x86_64-linux-gnu/glib-2.0/glib-compile-schemas: No such file or directory
/snap/referencer/x1/bin/desktop-launch: line 389: /snap/referencer/x1/usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders: No such file or directory
/snap/referencer/x1/usr/sbin/update-icon-caches: 16: /snap/referencer/x1/usr/sbin/update-icon-caches: gtk-update-icon-cache: not found
WARNING: icon cache generation failed for /home/maxime/snap/referencer/x1/.local/share/icons/Adwaita
/snap/referencer/x1/usr/sbin/update-icon-caches: 16: /snap/referencer/x1/usr/sbin/update-icon-caches: gtk-update-icon-cache: not found
WARNING: icon cache generation failed for /home/maxime/snap/referencer/x1/.local/share/icons/DMZ-Black
/snap/referencer/x1/usr/sbin/update-icon-caches: 16: /snap/referencer/x1/usr/sbin/update-icon-caches: gtk-update-icon-cache: not found
WARNING: icon cache generation failed for /home/maxime/snap/referencer/x1/.local/share/icons/DMZ-White
/snap/referencer/x1/usr/sbin/update-icon-caches: 16: /snap/referencer/x1/usr/sbin/update-icon-caches: gtk-update-icon-cache: not found
WARNING: icon cache generation failed for /home/maxime/snap/referencer/x1/.local/share/icons/Humanity
/snap/referencer/x1/usr/sbin/update-icon-caches: 16: /snap/referencer/x1/usr/sbin/update-icon-caches: gtk-update-icon-cache: not found
WARNING: icon cache generation failed for /home/maxime/snap/referencer/x1/.local/share/icons/Humanity-Dark
/snap/referencer/x1/usr/sbin/update-icon-caches: 16: /snap/referencer/x1/usr/sbin/update-icon-caches: gtk-update-icon-cache: not found
WARNING: icon cache generation failed for /home/maxime/snap/referencer/x1/.local/share/icons/LoginIcons
/snap/referencer/x1/usr/sbin/update-icon-caches: 16: /snap/referencer/x1/usr/sbin/update-icon-caches: gtk-update-icon-cache: not found
WARNING: icon cache generation failed for /home/maxime/snap/referencer/x1/.local/share/icons/hicolor
/snap/referencer/x1/usr/sbin/update-icon-caches: 16: /snap/referencer/x1/usr/sbin/update-icon-caches: gtk-update-icon-cache: not found
WARNING: icon cache generation failed for /home/maxime/snap/referencer/x1/.local/share/icons/ubuntu-mono-dark
/snap/referencer/x1/usr/sbin/update-icon-caches: 16: /snap/referencer/x1/usr/sbin/update-icon-caches: gtk-update-icon-cache: not found
WARNING: icon cache generation failed for /home/maxime/snap/referencer/x1/.local/share/icons/ubuntu-mono-light
/snap/referencer/x1/bin/desktop-launch: line 458: /snap/referencer/x1/usr/lib/x86_64-linux-gnu/libgtk2.0-0/gtk-query-immodules-2.0: No such file or directory
/snap/referencer/x1/bin/desktop-launch: line 468: /snap/referencer/x1/bin/referencer: No such file or directory

It look like nothing exist although everything is here !

If I run referencer inside /snap/referencer/x1/bin/ with this command

env LC_ALL=C.UTF-8 ./desktop-launch referencer

referencer begins to start, but failed, I thing, due to wrong read and write permission.

Below is my last yaml file. Have you any suggestion ?
Thanks

Best Regards

    name: referencer # you probably want to 'snapcraft register <name>'
    version: '1.2.2' # just for humans, typically '1.2+git' or '1.3.2'
    summary: manage your bibliograpy # 79 char long summary
    description: |
    manage your bibliograpy

    grade: devel # must be 'stable' to release into candidate/stable channels
    confinement: devmode # use 'strict' once you have the right plugs and slots
    icon: ./referencer-1.2.2/data/referencer.svg

    apps:
      referencer:
        command: env LC_ALL=C.UTF-8 $SNAP/bin/desktop-launch referencer
        desktop: usr/local/share/applications/referencer.desktop
        environment:
          PYTHONPATH: $SNAP/lib/x86_64-linux-gnu/:$SNAP/usr/lib/python2.7/:/$SNAP/usr/lib/python2.7/plat-x86_64-linux-gnu/:/$SNAP/lib/referencer/:$PYTHONPATH
          PYTHONHOME: $SNAP/lib/x86_64-linux-gnu/:$SNAP/usr/lib/python2.7/:/$SNAP/usr/lib/python2.7/plat-x86_64-linux-gnu/:/$SNAP/lib/referencer/:$PYTHONHOME

    parts:
      referencer:
        # See 'snapcraft plugins'
        plugin: autotools
        source: ./referencer-1.2.2/
        after:
            - desktop-gtk2
        organize:
          share/: usr/local/share/
          lib/: usr/local/lib/
        build-packages:
            - build-essential
            - gnome-doc-utils
            - intltool
            - python2.7-dev
            - libxml2-dev
            - libpoppler-glib-dev
            - libgconfmm-2.6-dev
            - libgtkmm-2.4-dev
            - libboost-regex-dev
            - rarian-compat
            
        stage-packages:
            - libc6
            - libatkmm-1.6-1v5
            - libcairomm-1.0-1v5
            - libdbus-glib-1-2
            - libgconf-2-4
            - libdb5.3
            - libgconfmm-2.6-1v5
            - libpangomm-1.4-1v5
            - libglibmm-2.4-1v5
            - libpoppler-glib8
            - libpoppler58
            - python2.7
            - libpython2.7
            - libgtkmm-2.4-1v5
            - libboost-regex1.58.0
            - libsigc++-2.0-0v5

Hello,
My snap application runs if I launch it from a terminal in the $snap directory :
cd /snap/referencer/x1/
snap run referencer
If I run it from any other place, referencer failed to launch because it fail to find important data :
Glib::ustring Utility::findDataFile(const Glib::ustring&):
Glib::build_filename: what is Datadir ‘/share/referencer’
Utility::findDataFile: couldn’t find file ‘/home/maxime/app/data/crossref.ui’
terminate called after throwing an instance of ‘Glib::FileError’
Abandon (core dumped)

The function findDataFile try to find the file crossref.ui and build its path with the glib get_current_dir() function. This function should return the environnement variable $PWD, which is set to ‘/home/maxime/app/data/’ if I try to launch referencer from my home directory…

The function findDataFile also search in DATADIR directory which seams to set to /share/referencer… (return value of Glib::build_filename (DATADIR, filename); ).

What does the variable DATADIR refer to ? The datadir environnement variable ?
Can we reset the $PWD or $DATADIR environnement variables before launching this snap ?

I already tried that in the snapcraft.yaml
environment:
datadir: $SNAP/share/referencer/
datarootdir: $SNAP/share/referencer/
prefixe: $SNAP/

Thank you