twinkle icon indicating copy to clipboard operation
twinkle copied to clipboard

Make relocatable in the filesystem

Open probonopd opened this issue 3 years ago • 7 comments

It would be nice if the application could run from paths other the one defined at compile time. This would allow one to put Twinkle into Mac-style .app bundles, ROX-style .AppDir directories, and .AppImage files.

Currently we get

image

when we try to run Twinkle from a location other than the one that was defined at compile time:

make DESTDIR=appdir install ; find appdir/
(...)
appdir/usr/local/bin/twinkle
(...)
appdir/usr/local/share/twinkle
(...)
./appdir/usr/local/bin/twinkle

This is because an absolute path to DATADIR https://github.com/LubosD/twinkle/search?q=DATADIR gets compiled in.

It would be nicer if instead of compiling in DATADIR this would be figured out at runtime

probonopd avatar Oct 22 '22 15:10 probonopd

In the meantime, super crude workaround (only used duing my own development):

FreeBSD% sudo ln -s $(readlink -f appdir/usr/local/share/twinkle) /usr/local/share
FreeBSD% ./appdir/usr/local/bin/twinkle

probonopd avatar Oct 22 '22 15:10 probonopd

make DESTDIR=appdir install ; find appdir/

You need to use CMAKE_INSTALL_PREFIX instead:

cmake .. -DCMAKE_INSTALL_PREFIX=appdir [...]
make install

Setting DESTDIR after the build will merely install the already-built files elsewhere, which is not what you want here. (It is useful for other purposes, just not for this one.)

The Twinkle core is also used to build a non-GUI client, so it cannot depend on Qt, but I guess we could always check XDG_DATA_DIRS ourselves. But given how we still don't observe XDG_CONFIG_HOME yet, I wouldn't hold my breath over this one. :smirk:

fbriere avatar Oct 22 '22 17:10 fbriere

@fbiere, what I want to achieve is that it still works after renaming or moving appdir. I can find some crude ways involving binary patching, but a clean solution would be so much nicer. Not super urgent though.


Workaround:

sed -i'' -e 's|/usr/local|././/local|g' appdir/usr/local/bin/twinkle
echo > ./appdir/Twinkle <<\EOF
#!/bin/sh
HERE="$(dirname "$(readlink -f "${0}")")"
cd "${HERE}/usr" # https://github.com/LubosD/twinkle/issues/311
exec local/bin/twinkle "$@"
EOF
chmod +x ./appdir/Twinkle
./appdir/Twinkle

probonopd avatar Oct 22 '22 18:10 probonopd

While working on something completely unrelated, I just coincidentally discovered that the GUI client has a --share option that appears to do exactly what you want.

fbriere avatar Oct 31 '22 17:10 fbriere

Thanks, will try it out.

coincidentally discovered

Since we both didn't immediately discover it, this makes me wonder why it isn't the default...

probonopd avatar Oct 31 '22 18:10 probonopd

Since we both didn't immediately discover it, this makes me wonder why it isn't the default...

Because it needs an actual value, such as --share appdir/usr/local/share/twinkle in your case.

fbriere avatar Oct 31 '22 18:10 fbriere

I see. I can make that work for my use case, even though it's a bit less elegant than "automagic" would be. Thanks! Issue can be closed unless the project wants to keep it open.

probonopd avatar Oct 31 '22 19:10 probonopd