SilverAndro / Machete

A gradle plugin to optimize built jars through individual file optimizations and increased compression
Mozilla Public License 2.0
21 stars 1 forks source link

Plugin assumes build directory exists when it might not #7

Closed lukebemish closed 1 year ago

lukebemish commented 1 year ago

The following line: https://github.com/SilverAndro/Machete/blob/422ab78c313b5e53c39c73f5711fa23f6d404b37/src/main/kotlin/io/github/p03w/machete/util/FileUtil.kt#L62 Will throw an error after ./gradlew clean is run if nothing has recreated the directory the file exists in yet.

SilverAndro commented 1 year ago

do you have some more info like your platform, example buildscript or anything I can use?

i have a patch that should fix any cases that would cause this, but as far as I can tell https://github.com/SilverAndro/Machete/blob/master/src/main/kotlin/io/github/p03w/machete/MachetePlugin.kt#L21-L23 guards against it?

I was only able to recreate this once by doing something with the native install detector that i cant recreate now.

lukebemish commented 1 year ago

Yeah, I ran into it here: https://github.com/GroovyMC/groovyduvet/blob/57ecd9c212deda2d45600a1b02da77b931adf99d/main/build.gradle#L216 Removing the line above that that creates the directory causes it to fail to build in a fresh environment due to the folder not existing. This is, obviously, a really complicated system to reproduce it - if you give me a day or two I'll try to reproduce it in a simpler environment. It could be that the subprojects have something to do with it?

SilverAndro commented 1 year ago

The sub projects might have something to do with it, although i havent had any issues so far (or heard of any from the QFAPI team) relating to the build directory getting pulled out from under the plugin.

I suppose i might be able to make oxipng unpacking (& related) lazy, but that might cause problems later when i work to parallelize machete so id rather not, unless maybe i create a task just to unpack it and have all optimization tasks depend on that

lukebemish commented 1 year ago

Alright, here you go, super minimal reproduction case: https://gist.github.com/lukebemish/d13d2c0e767f4b913ca5a730ba97cf93

This crashes unless the subproject/build folder exists, which it won't necessarily.

lukebemish commented 1 year ago

Sorry, I stand corrected - I think it crashes unless the root build folder exists. I'm not sure. If neither exist (like after running clean), it definitely crashes

SilverAndro commented 1 year ago

i still cant reproduce this locally, plugin application is always recreating the required directories. Are you able to pull+mavenLocal something i push to check if it fixes it?

lukebemish commented 1 year ago

Did you test specifically not applying in the root project but applying in a subproject as in my example? That's the only case I can reproduce it with. Yeah, I can definitely test something

lukebemish commented 1 year ago

Here is the project I tested this with. I cannot do any gradle operations on this project from the terminal, or import into IntellIJ, without it crashing. test.zip

SilverAndro commented 1 year ago

ahha, that did it, thanks much!

got it fixed locally, just need to fix a few minor things with the patch and itll be fixed in 2.0.1 :D

SilverAndro commented 1 year ago

alright, should be published, :shipit:

didnt encounter any issues locally, so should be good