MinecraftForge / Srg2Source

Applies source level refactors to java source code.
GNU Lesser General Public License v2.1
60 stars 32 forks source link

ApplyRangeMap is stripping the last newline. #38

Closed Gamebuster19901 closed 4 years ago

Gamebuster19901 commented 4 years ago

I've been having an issue with forgegradle where ./gradlew genPatches will add +\ No newline at end of file in the middle of every .patch file. (Specifically, the last diff hunk of every patch file).

image

After running ./gradlew genPatches, the files in /forge/build/applyRangeMapBase/output.zip are all missing new lines at the end of the file, when the originals in /clean/build/applyPatches/output.zip all have newline characters at the end. image

ForgeGradle uses diff4j to generate patch files. When diff4j encounters no newline at the last diff hunk it encounters, it will add +\ No newline at end of file, and then print the bottom context lines. If the last hunk isn't at the end of the file, it will cause the no newline comment to appear in the middle of the patch file.

https://github.com/cloudbees/diff4j/blob/87d621ea70bc8d014d8da11f78b4293142fa8099/src/main/java/com/cloudbees/diff/UnifiedDiff.java#L142-L166

I'd normally submit a PR to fix the issue, but I am unable to build Srg2Source, so I'm unable to debug the issue any further.

My operating system is Ubuntu 18.04.5 LTS

Possibly relates to #34?

Gamebuster19901 commented 4 years ago

Some new information - parts of every hunk in a patch file are offset:

image

LexManos commented 4 years ago

Honestly, I think this has more to do with your particular setup then it does on FG/S2S. It's been working for years on all different kinds of setups for everyone else in dev. And obviously I can't reproduce it on my end, so you'll need to try and figure out what on your setup causes it. Try different JVMs/Args/whatever you can think of.

Gamebuster19901 commented 4 years ago

I haven't been able to figure out the exact cause yet, however I have created a reproducible test case:

Steps:

  1. Install Ubuntu 18.04.5 LTS (https://releases.ubuntu.com/18.04.5/ubuntu-18.04.5-desktop-amd64.iso)
  2. Create and enter new folder
  3. Right click -> [Open in Terminal]
  4. In the terminal enter the following commands:
  5. sudo add-apt-repository universe
  6. sudo apt-get update
  7. sudo apt-get install git
  8. sudo apt-get install openjdk-8-jdk
  9. git init
  10. git remote add official https://github.com/MinecraftForge/MinecraftForge.git
  11. git pull official/1.15.x
  12. ./gradlew setup
  13. ./gradlew genPatches
  14. git diff
  15. Scroll down using the down arrow key.
Gamebuster19901 commented 4 years ago

This is very strange. I just upgraded my cpu, motherboard, and RAM and now I'm no longer able to reproduce this...

I'm just going to go ahead and close this issue instead of figuring out why.