johanmattssonm / birdfont

A font editor for creating fonts in TTF, EOT, SVG and BIRDFONT format.
https://birdfont.org
462 stars 32 forks source link

Search for resources relative to the main binary on Linux #97

Closed probonopd closed 4 years ago

probonopd commented 4 years ago

BirdFont contains code to look for resources in various places:

https://github.com/johanmattssonm/birdfont/blob/ad86764211ab337c96fcb73a8310d3dcd51a6615/libbirdfont/SearchPaths.vala#L32-L98

On a Linux system, this resolves to (tested with strace):

/Contents/Resources/birdfont_resources/icons.birdfont
/home/icons.birdfont
/home/me/.\\\\icons.birdfont
/home/me/\\\\icons.birdfont
/home/me/\\icons.birdfont
/home/me/\\icons.birdfont\\
/home/me/icons.birdfont
/home/me/resources/icons.birdfont
/home/me/resources/linux/icons.birdfont
//icons.birdfont
/icons.birdfont
/usr/local/share/birdfont/icons.birdfont
/usr/share/birdfont/icons.birdfont

Unfortunately it does not look in <location of the main birdfont binary>/../share/birdfont, which means that BirdFont is currently not relocatable on Linux.

According to https://mail.gnome.org/archives/vala-list/2009-August/msg00124.html,

GLib.FileUtils.read_link on "/proc/self/exe"

will give you the name of your executable with full path and all links resolved (because kernel actually reverse-calculates it from the open file).

Could this be added please?

johanmattssonm commented 4 years ago

Sure. I have committed code for this. Please let me know if I managed to screw it up somehow. Cheers

probonopd commented 4 years ago

Thank you very much. :+1:

This should remove the need for this workaround then:

https://github.com/probonopd/birdfont/blob/6a4c19e2b1a4c985d3f9fcc14b706d1a4f1c6a79/.travis.yml#L94-L106

On a related note, do you know how to do this more elegantly?

https://github.com/probonopd/birdfont/blob/6a4c19e2b1a4c985d3f9fcc14b706d1a4f1c6a79/.travis.yml#L16-L17

johanmattssonm commented 4 years ago

I found a few bugs in the install script but upgrading to the latest commit and running "./install.py -d appdir" might do the trick.

probonopd commented 4 years ago

Thank you, working on it.

probonopd commented 4 years ago

Works. Thank you very much.