Changeset - r28179:c6b977d63ddb
[Not reviewed]
master
0 5 2
Peter Nelson - 5 months ago 2023-11-26 15:59:41
peter1138@openttd.org
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.
7 files changed with 23 insertions and 2 deletions:
0 comments (0 inline, 0 general)
cmake/CreateGrfCommand.cmake
Show inline comments
 
@@ -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}
cmake/FindGrfcodec.cmake
Show inline comments
 
@@ -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
 
)
cmake/scripts/Baseset.cmake
Show inline comments
 
@@ -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})
cmake/scripts/CreateGRF.cmake
Show inline comments
 
@@ -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})
media/baseset/CMakeLists.txt
Show inline comments
 
@@ -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"
media/baseset/openttd.grf.hash
Show inline comments
 
new file 100644
 
237f3152daa7706aa30784ba72fb727a
media/baseset/orig_extra.grf.hash
Show inline comments
 
new file 100644
 
1fb8473f51d1c57c3bba4ae6cfca1cb2
0 comments (0 inline, 0 general)