# HG changeset patch # User Peter Nelson # Date 2023-11-26 15:59:41 # Node ID c6b977d63ddb5653d9d0ede55093457b01148d2f # Parent d924f9b088454cdf93f0705ee211b627fbe6d379 Change: When building NewGRFs, use grfid (from grfcodec) to calculate NewGRF MD5 hash. (#11492) 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. diff --git a/cmake/CreateGrfCommand.cmake b/cmake/CreateGrfCommand.cmake --- a/cmake/CreateGrfCommand.cmake +++ b/cmake/CreateGrfCommand.cmake @@ -28,12 +28,13 @@ function(create_grf_command) list(APPEND GRF_PNG_BINARY_FILES ${GRF_PNG_BINARY_FILE}) endforeach() - add_custom_command(OUTPUT ${GRF_BINARY_FILE} + add_custom_command(OUTPUT ${GRF_BINARY_FILE} ${GRF_BINARY_FILE}.hash COMMAND ${CMAKE_COMMAND} -DGRF_SOURCE_FOLDER=${CMAKE_CURRENT_SOURCE_DIR} -DGRF_BINARY_FILE=${GRF_BINARY_FILE} -DNFORENUM_EXECUTABLE=${NFORENUM_EXECUTABLE} -DGRFCODEC_EXECUTABLE=${GRFCODEC_EXECUTABLE} + -DGRFID_EXECUTABLE=${GRFID_EXECUTABLE} -P ${CMAKE_SOURCE_DIR}/cmake/scripts/CreateGRF.cmake MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/cmake/scripts/CreateGRF.cmake DEPENDS ${GRF_PNG_BINARY_FILES} diff --git a/cmake/FindGrfcodec.cmake b/cmake/FindGrfcodec.cmake --- a/cmake/FindGrfcodec.cmake +++ b/cmake/FindGrfcodec.cmake @@ -2,6 +2,7 @@ # find_program(GRFCODEC_EXECUTABLE grfcodec) +find_program(GRFID_EXECUTABLE grfid) find_program(NFORENUM_EXECUTABLE nforenum) include(FindPackageHandleStandardArgs) @@ -9,5 +10,6 @@ find_package_handle_standard_args(Grfcod FOUND_VAR GRFCODEC_FOUND REQUIRED_VARS GRFCODEC_EXECUTABLE + GRFID_EXECUTABLE NFORENUM_EXECUTABLE ) diff --git a/cmake/scripts/Baseset.cmake b/cmake/scripts/Baseset.cmake --- a/cmake/scripts/Baseset.cmake +++ b/cmake/scripts/Baseset.cmake @@ -58,6 +58,7 @@ list(SORT ${PLACE_HOLDER}) string(REPLACE ";" "\n" ${PLACE_HOLDER} "${${PLACE_HOLDER}}") # Get the grf md5 -file(MD5 ${BASESET_EXTRAGRF_FILE} ORIG_EXTRA_GRF_MD5) +file(READ ${BASESET_EXTRAGRF_FILE}.hash ORIG_EXTRA_GRF_MD5) +string(STRIP ${ORIG_EXTRA_GRF_MD5} ORIG_EXTRA_GRF_MD5) configure_file(${BASESET_SOURCE_FILE} ${BASESET_BINARY_FILE}) diff --git a/cmake/scripts/CreateGRF.cmake b/cmake/scripts/CreateGRF.cmake --- a/cmake/scripts/CreateGRF.cmake +++ b/cmake/scripts/CreateGRF.cmake @@ -11,6 +11,9 @@ endif() if(NOT GRFCODEC_EXECUTABLE) message(FATAL_ERROR "Script needs GRFCODEC_EXECUTABLE defined") endif() +if(NOT GRFID_EXECUTABLE) + message(FATAL_ERROR "Script needs GRFID_EXECUTABLE defined") +endif() if(NOT GRF_SOURCE_FOLDER) message(FATAL_ERROR "Script needs GRF_SOURCE_FOLDER defined") endif() @@ -55,4 +58,15 @@ if(RESULT) message(FATAL_ERROR "GRFCodec failed") endif() +execute_process(COMMAND ${GRFID_EXECUTABLE} -m ${GRF_SOURCE_FOLDER_NAME}.grf OUTPUT_VARIABLE GRFID_HASH RESULT_VARIABLE RESULT) +if(RESULT) + if(NOT RESULT MATCHES "^[0-9]*$") + message(FATAL_ERROR "Failed to run GRFID (${RESULT}), please check GRFID_EXECUTABLE variable") + endif() + message(FATAL_ERROR "GRFID failed") +endif() + +file(WRITE ${GRF_BINARY_FILE}.hash ${GRFID_HASH}) + +# Copy build files back to the source directory. execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${GRF_SOURCE_FOLDER_NAME}.grf ${GRF_BINARY_FILE}) diff --git a/media/baseset/CMakeLists.txt b/media/baseset/CMakeLists.txt --- a/media/baseset/CMakeLists.txt +++ b/media/baseset/CMakeLists.txt @@ -49,6 +49,7 @@ foreach(BASESET_SOURCE_FILE IN LISTS BAS MAIN_DEPENDENCY ${BASESET_SOURCE_FILE} DEPENDS ${LANG_SOURCE_FILES} ${BASESET_EXTRAGRF_FILE} + ${BASESET_EXTRAGRF_FILE}.hash ${CMAKE_SOURCE_DIR}/cmake/scripts/Baseset.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating ${BASESET_SOURCE_FILE_NAME} baseset metadata file" diff --git a/media/baseset/openttd.grf.hash b/media/baseset/openttd.grf.hash new file mode 100644 --- /dev/null +++ b/media/baseset/openttd.grf.hash @@ -0,0 +1,1 @@ +237f3152daa7706aa30784ba72fb727a diff --git a/media/baseset/orig_extra.grf.hash b/media/baseset/orig_extra.grf.hash new file mode 100644 --- /dev/null +++ b/media/baseset/orig_extra.grf.hash @@ -0,0 +1,1 @@ +1fb8473f51d1c57c3bba4ae6cfca1cb2