Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make relocatable in the filesystem #311

Open
probonopd opened this issue Oct 22, 2022 · 7 comments
Open

Make relocatable in the filesystem #311

probonopd opened this issue Oct 22, 2022 · 7 comments

Comments

@probonopd
Copy link

probonopd commented Oct 22, 2022

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
Copy link
Author

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

@fbriere
Copy link
Collaborator

fbriere commented Oct 22, 2022

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. 😏

@probonopd
Copy link
Author

probonopd commented Oct 22, 2022

@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

@fbriere
Copy link
Collaborator

fbriere commented Oct 31, 2022

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.

@probonopd
Copy link
Author

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...

@fbriere
Copy link
Collaborator

fbriere commented Oct 31, 2022

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.

@probonopd
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants