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

Change: When building NewGRFs, use grfid (from grfcodec) to calculate NewGRF MD5 hash. #11492

Merged
merged 1 commit into from Nov 26, 2023

Conversation

PeterN
Copy link
Member

@PeterN PeterN commented Nov 25, 2023

Motivation / Problem

#11491 adds 32bpp sprites to the extra data NewGRF, which requires it to be built as container v2, but our build scripts do not correctly calculate the MD5 hash for container v2 NewGRFs.

Baseset.cmake uses CMake's built in MD5 function to calculate the hash of orig_extra.grf. However hash calculation only works for v1 container grfs.

The tool grfid from grfcodec can be used to calculate both v1 and v2 hashes, however grfcodec isn't currently a build dependency.

Description

Vendor grfid (with some changes due to our updated Md5 implementation and use of fmt, and use it in the build process.

Switch to NewGRF container v2. A side effect of this is that the files are a about 10% larger.

Update the build system to use grfid from grfcodec to calculate the hash of the custom NewGRFs. This requires a bit more effect than before as MD5 was a nice cmake built-in. The hash is written to a file which is stored in the source tree to enable OpenTTD to be compiled if grfcodec is not present.

Limitations

I removed the copyright message on grfid -- it's my name but I never put that there, so...

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

src/grfid/grfid.cpp Fixed Show fixed Hide fixed
src/grfid/grfid.cpp Fixed Show fixed Hide fixed
src/grfid/grfid.cpp Fixed Show fixed Hide fixed
src/grfid/grfid.cpp Fixed Show fixed Hide fixed
src/grfid/grfid.cpp Outdated Show resolved Hide resolved
media/baseset/CMakeLists.txt Outdated Show resolved Hide resolved
media/baseset/CMakeLists.txt Outdated Show resolved Hide resolved
src/grfid/grfid.cpp Fixed Show fixed Hide fixed
src/grfid/grfid.cpp Fixed Show fixed Hide fixed
@glx22
Copy link
Contributor

glx22 commented Nov 26, 2023

Might be simpler to generate md5 file only if cmake has found grfcodec (using grfid that comes with it) and store the md5 file in repo for when grfcodec is not found (like we do for the grf themselves).

@TrueBrain
Copy link
Member

TrueBrain commented Nov 26, 2023

What is a bit missing in the motivation, is why you want to do this.

I kinda deduce that you want to upgrade from v1 to v2? Maybe for the history add a few words in the description why that is something we would like.

Not disgreeing, to be clear, I was just missing the reason why :)

Edit: ah, seems #11491 is related to this PR :) Guess that caused it ;)

@PeterN
Copy link
Member Author

PeterN commented Nov 26, 2023

Now updated to just use grfid from grfcodec only when building the NewGRFs as well. Still a bit of wrangling going on but at least there's no code being duplicated.

@PeterN PeterN changed the title Add: 'Vendor' grfid tool from grfcodec to calculate orig_extra.grf hash Change: When building NewGRFs, use grfid (from grfcodec) to calculate NewGRF MD5 hash. Nov 26, 2023
cmake/CreateGrfCommand.cmake Outdated Show resolved Hide resolved
… NewGRF MD5 hash.

This allows for v2 container NewGRFs to be created. Hashes are needed for building the baseset metadata, so the .hash files are stored the source tree so they can be built if grfcodec and grfid are not present.

The hash of openttd.grf is not actually needed, but it is simpler to leave it in than handle only orig_extra.grf.
@PeterN PeterN enabled auto-merge (squash) November 26, 2023 15:41
@PeterN PeterN merged commit 872fdcb into OpenTTD:master Nov 26, 2023
20 checks passed
@PeterN PeterN deleted the grfid branch November 26, 2023 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants