Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
java jar ebuild - certain files in wrong folder [solved]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
g047
n00b
n00b


Joined: 22 Aug 2022
Posts: 23

PostPosted: Sun Jul 14, 2024 3:01 pm    Post subject: java jar ebuild - certain files in wrong folder [solved] Reply with quote

I'm trying to make a simple ebuild for a game named Unciv where I just retrieve the binary .jar.

The corresponding files get installed in the correct directories and everything launches fine, however files like save files or the game settings will be saved in my local repo at /var/db/repos/local/games-strategy/unciv-bin.

If possible via the ebuild, How do I make sure in-game created files are made so in a custom directory like /home/user/.local/share/unciv?

The ebuild in question can be seen here

Hopefully I've been clear, I'm still learning.

Thank you


Last edited by g047 on Wed Jul 17, 2024 8:17 am; edited 1 time in total
Back to top
View user's profile Send private message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 517

PostPosted: Sun Jul 14, 2024 4:32 pm    Post subject: Re: java jar ebuild - certain files in wrong folder Reply with quote

It seems to me that this program just saves in the current working directory. I don't think it will necessarily save in /var/db/repos... -- perhaps that's just where the program gets launched?

This seems like a fault in the program itself to me. If you can't fix it, perhaps you need to do something more than 'java -jar xxx.jar' to start it? I would use a wrapper script to create and change to a suitable directory, before launching the JVM.

BR, Lars.
Back to top
View user's profile Send private message
g047
n00b
n00b


Joined: 22 Aug 2022
Posts: 23

PostPosted: Sun Jul 14, 2024 7:00 pm    Post subject: Re: java jar ebuild - certain files in wrong folder Reply with quote

lars_the_bear wrote:
It seems to me that this program just saves in the current working directory. I don't think it will necessarily save in /var/db/repos... -- perhaps that's just where the program gets launched?


Oh darn you're right! :oops:
I can work with that and create a wrapper I guess, thanks.
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2401

PostPosted: Sun Jul 14, 2024 7:12 pm    Post subject: Reply with quote

You're both wrong. /var/db/repos is where the ebuild resides, not where the program is launched from. It must be launched at worst in the current user's home directory.


@g047 let me see your ebuild. In the mean time you can see this one: https://github.com/logrusx/gentoo/tree/master/app-misc/freeplane-bin

Best Regards,
Georgi
Back to top
View user's profile Send private message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 517

PostPosted: Mon Jul 15, 2024 7:04 am    Post subject: Reply with quote

logrusx wrote:
You're both wrong. /var/db/repos is where the ebuild resides, not where the program is launched from. It must be launched at worst in the current user's home directory.


This program, Unciv, writes in the CWD. I checked in the source. I presume that /var/db/repos just happened to be the CWD when testing the .ebuild.

BR, Lars.
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2401

PostPosted: Mon Jul 15, 2024 8:26 am    Post subject: Reply with quote

lars_the_bear wrote:
I presume that /var/db/repos just happened to be the CWD when testing the .ebuild.


The ebuild is a bash script which is executed in a special environment. Portage creates that environment. It doesn't run in /var/db/repos. The closest is PORTAGE_TEMPDIR, but then it's portage that runs inside it, not the program. That's just wrong assumption OP made.

The program cannot be run anywhere outside the user's home directory, unless run manually from the command line. Even then it may terminate because of lack of permissions. A user may have permissions to chdir into a directory but not create files inside it.

In the case when a program is run from a .desktop file, then there are certain variables that can be set, but it they aren't the CWD is user's home.

Here's the specification: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html

There's a key Path but I'm not sure which variables should be used to populate that key.

Best Regards,
Georgi
Back to top
View user's profile Send private message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 517

PostPosted: Mon Jul 15, 2024 10:04 am    Post subject: Reply with quote

logrusx wrote:
lars_the_bear wrote:
I presume that /var/db/repos just happened to be the CWD when testing the .ebuild.


The ebuild is a bash script which is executed in a special environment. Portage creates that environment. It doesn't run in /var/db/repos. The closest is PORTAGE_TEMPDIR, but then it's portage that runs inside it, not the program. That's just wrong assumption OP made.


I wouldn't presume to speak for the OP, but I'm guessing he/she ran 'emerge my_thing' in the same directory as the .ebuild file, and then ran 'java -jar /path/to/my_thing.jar' to test it. Presumably as root (?).

But I'm just guessing. I can't think of any other reason why the program would write into /var/db/repos...

Personally, I'm not keen on Java programs writing to the CWD. But this particular program seems (?) mostly to be targetting Android, where this is relatively common practice. On Android, the launcher framework (as I recall) sets the CWD to some app-specific writeable directory (used to be /data/data/my.package/files, but I've no idea what it is now).

On the desktop, Java applications ought to provide a way to configure where configuration/status/etc gets written. Maybe a JVM property or an environment variable. It's hard to do this in a platform-neutral way.

BR, Lars.
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2401

PostPosted: Mon Jul 15, 2024 10:09 am    Post subject: Reply with quote

lars_the_bear wrote:

I wouldn't presume to speak for the OP, but I'm guessing he/she ran 'emerge my_thing' in the same directory as the .ebuild file


As I said, ebuilds are run in a special environment, so it doesn't matter from which directory you run emerge.

lars_the_bear wrote:
, and then ran 'java -jar /path/to/my_thing.jar' to test it. Presumably as root (?).


That's not testing the ebuild, that's running the program itself.

And again, running emerge has nothing to do with running the program. You can emerge a package and never run it.

Best Regards,
Georgi
Back to top
View user's profile Send private message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 517

PostPosted: Mon Jul 15, 2024 10:22 am    Post subject: Reply with quote

logrusx wrote:

That's not testing the ebuild, that's running the program itself.


It's testing that the ebuild resulted in an installation in which the program can be run. But that's just a matter of semantics, isn't it?

BR, Lars.
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2401

PostPosted: Mon Jul 15, 2024 11:35 am    Post subject: Reply with quote

lars_the_bear wrote:
logrusx wrote:

That's not testing the ebuild, that's running the program itself.


It's testing that the ebuild resulted in an installation in which the program can be run. But that's just a matter of semantics, isn't it?

BR, Lars.


I think I got what you meant, I should have misunderstood it in the beginning. OP is probably testing the program while still in /var/db/repos as root, is that what you meant? I was just caught up in portage terminology and stuff.

Best Regards,
Georgi
Back to top
View user's profile Send private message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 517

PostPosted: Mon Jul 15, 2024 11:42 am    Post subject: Reply with quote

logrusx wrote:
OP is probably testing the program while still in /var/db/repos as root, is that what you meant? I was just caught up in portage terminology and stuff.


That was my guess, yes. But my guesses have been known to be wrong ;)

Local file storage is a pain in Java. The Java bytecode is notionally platform-agnostic, but it doesn't abstract the filesystem. The problem in this case is not with Gentoo/Portage, I think, but in the way the app's developers assume they'll always be able to write to the CWD (and that it will be appropriate to do so). Android is the only platform I know where that's the case.

BR, Lars.
Back to top
View user's profile Send private message
g047
n00b
n00b


Joined: 22 Aug 2022
Posts: 23

PostPosted: Wed Jul 17, 2024 8:16 am    Post subject: Reply with quote

So yeah, the corresponding save files were indeed stored in whatever location I launched the program from, I used pkg_postinst() to make sure the program will be launched from the directory I want, and now it works as intended, even if it feels a bit hacky :roll:

Anyway, thanks for the help
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2401

PostPosted: Wed Jul 17, 2024 9:09 am    Post subject: Reply with quote

g047 wrote:
I used pkg_postinst() to make sure the program will be launched from the directory I want


You should not launch the program in the ebuild. Please show us your ebuild, there might be better ways to do what you've done.

Best Regards,
Georgi
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22618

PostPosted: Wed Jul 17, 2024 2:27 pm    Post subject: Reply with quote

From the information so far, I would solve this by using src_install to write to $D a wrapper program. The wrapper could look like this (untested):
Code:
#!/bin/sh

set -eu

mkdir -m700 -p ~/.local ~/.local/share ~/.local/share/unciv
cd ~/.local/share/unciv
exec java -jar /path/to/unciv.jar
Use of -p tells mkdir that it is not an error for the directory to exist. Each layer is enumerated, since -m applies only to the directories created explicitly. Customize that java invocation as needed.
Back to top
View user's profile Send private message
g047
n00b
n00b


Joined: 22 Aug 2022
Posts: 23

PostPosted: Thu Jul 18, 2024 12:59 pm    Post subject: Reply with quote

logrusx wrote:

You should not launch the program in the ebuild. Please show us your ebuild, there might be better ways to do what you've done.

Best Regards,
Georgi


Sure, take a look https://bpa.st/W6RQ
But I'm not launching the program from the ebuild itself afaik

For reference, the original unciv launcher in /usr/bin/unciv is
Code:

#!/bin/bash
gjl_package=unciv-bin
gjl_jar="unciv-bin.jar"
source /usr/share/java-config-2/launcher/launcher.ba


@Hu
This does seem as a more correct approach as i created the corresponding folders manually.
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2401

PostPosted: Thu Jul 18, 2024 2:08 pm    Post subject: Reply with quote

Have you noticed there's a linuxFilesForJar.zip in the relase files with a ready made .desktop file as well as bash script that does exactly what you want to do?

Otherwise you're doing some thing that are not clear to me and I would argue they are not necessary, but to do that I have to roll up my sleeves and test it, which I don't feel like doing right now.

Best Regards,
Georgi
Back to top
View user's profile Send private message
g047
n00b
n00b


Joined: 22 Aug 2022
Posts: 23

PostPosted: Thu Jul 18, 2024 4:31 pm    Post subject: Reply with quote

logrusx wrote:
Have you noticed there's a linuxFilesForJar.zip in the relase files with a ready made .desktop file as well as bash script that does exactly what you want to do?
Georgi


I did not notice that, I'll update my ebuild this weekend so it will use the bash script, thanks.
Back to top
View user's profile Send private message
charles17
Advocate
Advocate


Joined: 02 Mar 2008
Posts: 3684

PostPosted: Fri Jul 19, 2024 6:54 am    Post subject: Reply with quote

g047 wrote:
Sure, take a look https://bpa.st/W6RQ
But I'm not launching the program from the ebuild itself afaik

For reference, the original unciv launcher in /usr/bin/unciv is
Code:

#!/bin/bash
gjl_package=unciv-bin
gjl_jar="unciv-bin.jar"
source /usr/share/java-config-2/launcher/launcher.ba

For a launcher look for java-pkg_dolauncher on https://devmanual.gentoo.org/eclass-reference/java-utils-2.eclass/
Find examples runnning qgrep java-pkg_dolauncher
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum