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

Add Gradle generator #276

Merged
merged 1 commit into from
May 23, 2024
Merged

Add Gradle generator #276

merged 1 commit into from
May 23, 2024

Conversation

hadess
Copy link
Contributor

@hadess hadess commented May 10, 2022

I don't know what I'm doing, but I can parse the logs of a Gradle build and generate a json file to build Ghidra.

Copy link

@mpi3d mpi3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll try to improve this.

gradle/flatpak-gradle-generator.py Outdated Show resolved Hide resolved
gradle/README.md Show resolved Hide resolved
@mpi3d
Copy link

mpi3d commented May 11, 2022

The script doesn't work out of the box. I had to make some changes:
flatpak-gradle-generator.zip
Also it supports .exe deps

@hadess
Copy link
Contributor Author

hadess commented May 11, 2022

The script doesn't work out of the box. I had to make some changes:

Could you please post a new version of this without changing all the quotes by double-quotes? It adds a lot of changes that aren't necessary to implement what you need.

I also don't understand why you removed the regexp. Maybe the easiest would be if you attached the full gradle log for us to test, then we can try it out.

@mpi3d
Copy link

mpi3d commented May 12, 2022

Here it is:
files.zip

@hadess
Copy link
Contributor Author

hadess commented May 12, 2022

I kept the code to create arch-specific urls, but I also:

  • changed the arguments parsing to match the help (it wasn't possible to request multiple arches without changing the order or arguments in a way that didn't match the help output)
  • used flatpak arches instead of the "gradle" ones in the arguments
  • modified regex to not catch local filenames (instead of expecting "Downloading" etc.)
  • add only-arches info to urls that need it

I'm pretty happy with this now, so if anyone else wants to experiment.

@mpi3d
Copy link

mpi3d commented May 12, 2022

Good. Any idea when this will be merged?

@hadess
Copy link
Contributor Author

hadess commented May 12, 2022

Good. Any idea when this will be merged?

No, but porting the jadx or Bisq Flatpaks to use it would certainly show whether it's fit for purpose. In the meanwhile, it's not disappearing, and we can use it for Ghidra.

@mpi3d
Copy link

mpi3d commented May 12, 2022

Ok

@Mailaender
Copy link
Contributor

Mailaender commented May 15, 2022

I couldn't get the script to work, but I don't understand the approach. For @Terasology I can ./gradlew dependencies which gives me:

Root project 'Terasology'
------------------------------------------------------------

api (n)
No dependencies

apiElements (n)
No dependencies

archives - Configuration for archive artifacts. (n)
No dependencies

classpath
No dependencies

codeMetrics
\--- org.terasology.config:codemetrics:1.6.3

default - Configuration for default artifacts. (n)
No dependencies

enforcedApiElements (n)
No dependencies

enforcedRuntimeElements (n)
No dependencies

natives
+--- org.lwjgl:lwjgl-bom:3.2.3
|    +--- org.lwjgl:lwjgl:3.2.3 (c)
|    +--- org.lwjgl:lwjgl-assimp:3.2.3 (c)
|    +--- org.lwjgl:lwjgl-glfw:3.2.3 (c)
|    +--- org.lwjgl:lwjgl-openal:3.2.3 (c)
|    +--- org.lwjgl:lwjgl-opengl:3.2.3 (c)
|    \--- org.lwjgl:lwjgl-stb:3.2.3 (c)
+--- org.lwjgl:lwjgl -> 3.2.3
+--- org.lwjgl:lwjgl-assimp -> 3.2.3
|    \--- org.lwjgl:lwjgl:3.2.3
+--- org.lwjgl:lwjgl-glfw -> 3.2.3
|    \--- org.lwjgl:lwjgl:3.2.3
+--- org.lwjgl:lwjgl-openal -> 3.2.3
|    \--- org.lwjgl:lwjgl:3.2.3
+--- org.lwjgl:lwjgl-opengl -> 3.2.3
|    \--- org.lwjgl:lwjgl:3.2.3
+--- org.lwjgl:lwjgl-stb -> 3.2.3
|    \--- org.lwjgl:lwjgl:3.2.3
+--- org.terasology.jnlua:jnlua_natives:0.1.0-SNAPSHOT
\--- org.terasology.jnbullet:JNBullet:1.0.2

Can this be parsed instead?

@mpi3d
Copy link

mpi3d commented May 16, 2022

I tried on Ghidra. But it doesn't list all the dependencies.

@hadess
Copy link
Contributor Author

hadess commented May 23, 2022

I couldn't get the script to work, but I don't understand the approach.

What failed exactly? Can you provide the gradle log?

@Mailaender
Copy link
Contributor

I am missing Python dependencies on @openSUSE.

@mpi3d
Copy link

mpi3d commented May 24, 2022

Which ones? aiohttp? Just do a pip install aiohttp

@Mailaender
Copy link
Contributor

Seems like updating pip with pip itself solved the installation problems. Yet the script does not run:

Traceback (most recent call last):
  File "./flatpak-gradle-generator.py", line 109, in <module>
    main()
  File "./flatpak-gradle-generator.py", line 101, in main
    sources = asyncio.run(parse_urls(urls, urls_arch, args.destdir))
AttributeError: module 'asyncio' has no attribute 'run'

@gasinvein
Copy link
Member

Seems like updating pip with pip itself solved the installation problems. Yet the script does not run:

Traceback (most recent call last):
  File "./flatpak-gradle-generator.py", line 109, in <module>
    main()
  File "./flatpak-gradle-generator.py", line 101, in main
    sources = asyncio.run(parse_urls(urls, urls_arch, args.destdir))
AttributeError: module 'asyncio' has no attribute 'run'

This means your Python version is way too old. IIRC asyncio.run was added in 3.7.

@hadess
Copy link
Contributor Author

hadess commented May 24, 2022

AttributeError: module 'asyncio' has no attribute 'run'

From https://docs.python.org/3/library/asyncio-task.html#asyncio.run

asyncio.run(coro, *, debug=False)
New in version 3.7.

Python 3.7 was released in 2018, close to 4 years ago. Time to update.

@muelli muelli mentioned this pull request Jul 12, 2022
@TobTobXX
Copy link

Just for some external input: I've also worked on this and have a semi-working script here: https://github.com/TobTobXX/flatpak-builder-tools/blob/master/gradle/flatpak-gradle-generator.sh.

Parsing build logs or ./gradlew dependencies both have the issue that they don't include dependencies that are pure POMs (ie. parent POMs that are used for inheritance and referenced external POMs).

Instead, my script runs a ./gradle build --dry-run, but sets a custom cache directory. This ensures all assets that are needed for an offline build are downloaded. (One issue my script has to deal with now is that some POMs differ depending on the mirror you use.)

I've not submitted a PR yet, since I'm still testing my script on various projects, but if you want to use it, go ahead.

@hadess
Copy link
Contributor Author

hadess commented Aug 27, 2022

Parsing build logs or ./gradlew dependencies both have the issue that they don't include dependencies that are pure POMs (ie. parent POMs that are used for inheritance and referenced external POMs).

I think this might be a problem with using gradlew instead of gradle, or a problem with the build scripts because the build tools should already log all the downloaded assets.

But not knowing what software you're trying to package, or the exact steps, it's difficult to say. Note that the build script we use for Ghidra uses a sandboxed dependency download section, to avoid any sort of cache from being used inadvertently.

I've not submitted a PR yet, since I'm still testing my script on various projects, but if you want to use it, go ahead.

I doubt that a bash script would be accepted. In any case, that would be something to discuss on your own PR, not this one.

@Mailaender
Copy link
Contributor

Can you maybe post an example usage? I managed to download all dependencies for JSkat, but it seems they are not discovered by Gradle:

Plugin [id: 'org.openjfx.javafxplugin', version: '0.0.13'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.openjfx.javafxplugin:org.openjfx.javafxplugin.gradle.plugin:0.0.13')
  Searched in the following repositories:
    Gradle Central Plugin Repository

@hadess
Copy link
Contributor Author

hadess commented Sep 12, 2022

There's already an explanation in the README added in the patch. But I tested the generator with https://github.com/b0n541/jskat-multimodule (next time, please make sure to attach the full output of what you did, here I had to even search what jskat was).

$ flatpak install -y --user org.freedesktop.Sdk.Extension.openjdk17//21.08
[...]
$ flatpak run --command=bash --share=network --filesystem=`pwd` -d org.freedesktop.Sdk//21.08
[📦 org.freedesktop.Sdk jskat-multimodule]$ source /usr/lib/sdk/openjdk17/enable.sh
[📦 org.freedesktop.Sdk jskat-multimodule]$ ./gradlew -g gradle-cache/ --info --console plain clean installDist > gradle-log.txt

Running the script on the log threw an error, but I edited the script to remove the URL that caused the error, and re-ran it, and it generated a json file. It didn't seem like the file was needed, as it built without it.

@Mailaender
Copy link
Contributor

Running the generator is not a problem, but I don't know how to apply this in the Flatpak manifest.

@hadess
Copy link
Contributor Author

hadess commented Sep 12, 2022

Running the generator is not a problem, but I don't know how to apply this in the Flatpak manifest.

It's a json file, you include it. See the Ghidra manifest for example:
https://github.com/flathub/org.ghidra_sre.Ghidra/blob/master/org.ghidra_sre.Ghidra.json#L142

@Mailaender
Copy link
Contributor

The shell script moves files by default into maven-local where Gradle can't find it.

@MessiasLima
Copy link

Does it need to be merged in order to use it?

@hadess
Copy link
Contributor Author

hadess commented Apr 26, 2023

The shell script moves files by default into maven-local where Gradle can't find it.

I'm not sure where you get that, there's no mentions of maven-local in the script.

Does it need to be merged in order to use it?

Absolutely not, a second user might make it easier to get this patch merged, hopefully.

@MessiasLima
Copy link

I tried to run in my application and I'm using detekt for static code analysis. However, when I run it cannot get the .jar file from detekt because there is no .jar file in the repo. As you can see here.

The script fails because of that but detekt is not even used in production code.

Do you have any hint about what to do in this case?

@mpi3d
Copy link

mpi3d commented Apr 30, 2023

You might implement an option in the script to use a custom url for specific packages. Or even ignore the url.

Or you can currently remove the url manually.

@MessiasLima
Copy link

You might implement an option in the script to use a custom url for specific packages. Or even ignore the url.

Or you can currently remove the url manually.

I ignored the Url and it worked, thank you!

@hfiguiere hfiguiere added the java label Apr 5, 2024
@hadess hadess force-pushed the wip/hadess/add-gradle branch 2 times, most recently from 7e36abc to df0f1c2 Compare May 20, 2024 17:48
@hfiguiere
Copy link
Collaborator

I'd be fine merging this. It works for you then it can be fixed later for other use cases that fail. Otherwise it never will.

@TingPing
Copy link
Member

TingPing commented May 21, 2024

Please have somebody in CODEOWNERS, otherwise 👍

@hadess
Copy link
Contributor Author

hadess commented May 22, 2024

Please have somebody in CODEOWNERS, otherwise 👍

Done.

@hfiguiere hfiguiere merged commit 8f12caf into master May 23, 2024
@hfiguiere hfiguiere deleted the wip/hadess/add-gradle branch May 23, 2024 03:28
hadess added a commit to flathub/org.ghidra_sre.Ghidra that referenced this pull request Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants