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

Fix: [CMake] Check nforenum and grfcodec return value #9085

Merged
merged 2 commits into from Apr 24, 2021

Conversation

glx22
Copy link
Contributor

@glx22 glx22 commented Apr 23, 2021

Motivation / Problem

When GRFCODEC_EXECUTABLE and NFORENUM_EXECUTABLE are manually specified, they are considered valid and GRFCODEC_FOUND is set, but the variables could contain errors and execution silently fail later.

Description

Always try to run GRFCODEC_EXECUTABLE and NFORENUM_EXECUTABLE and discard invalid values.
Check return value when running nforenum and grfcodec, and force the build to fail if needed.
I also fixed a dependency check error (modifying a .nfo would not trigger a grf rebuild)

Limitations

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 affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@TrueBrain
Copy link
Member

Honestly, I am not sure this is the correct solution. If you manually supply stuff, it should just try to execute that, and not evaluate if it is correct. For me it is such a slippery slope .. should we also check if it is really grfcodec, and not some other binary? :D Where does this end ;)
Also, I believe if you manually supply library locations, CMake also takes you on your word.

But aren't you running into a completely different problem, one I am having currently: if grfcodec runtime fails, CMake continues to build OpenTTD. Which is very .. euh .. annoying.

Example: change the sprite-count in openttdgui.nfo to one lower than you define. Now compile OpenTTD. It will succeed. But if you look closer, you see grfcodec failed, and the openttdgui.grf is an invalid file now.

Maybe if we solve that issue, the reason you created this issue is also resolved?

tldr, for me the keyword in your PR is and execution silently fail later, which to me is the real bug. This solution only fixes some parts of that real bug, still leaving a lot of room for things to go wrong another way :)

execute_process(COMMAND ${GRFCODEC_EXECUTABLE} -n -s -e -p1 ${GRF_SOURCE_FOLDER_NAME}.grf)
execute_process(COMMAND ${NFORENUM_EXECUTABLE} -s sprites/${GRF_SOURCE_FOLDER_NAME}.nfo RESULT_VARIABLE RESULT)
if(RESULT)
if(NOT RESULT MATCHES "^[0-9]*$")
Copy link
Member

Choose a reason for hiding this comment

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

what does this regex capture? Maybe a comment of some kind might help future-us, but mainly I am just curious :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RESULT can be "an integer return code from the last child or a string describing an error condition" as stated in CMake documentation. So if it's not an integer it didn't run at all and there's probably an issue with the executable itself.

Copy link
Member

Choose a reason for hiding this comment

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

Smart :D

@glx22 glx22 changed the title Fix: [CMake] Validate grfcodec and nforenum executables @glx22 Fix: [CMake] Check nforenum and grfcodec return value Apr 24, 2021
@glx22 glx22 changed the title @glx22 Fix: [CMake] Check nforenum and grfcodec return value Fix: [CMake] Check nforenum and grfcodec return value Apr 24, 2021
@glx22 glx22 merged commit aca2009 into OpenTTD:master Apr 24, 2021
@glx22 glx22 deleted the grfcodec branch April 24, 2021 19:16
@LordAro LordAro added the backport requested This PR should be backport to current release (RC / stable) label Apr 25, 2021
@LordAro LordAro added backported This PR is backported to a current release (RC / stable) and removed backport requested This PR should be backport to current release (RC / stable) labels May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported This PR is backported to a current release (RC / stable)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants