Opt-in for an easy-way CMake target to create soh.otr file (#3057)

* use a convenient cmake target for gen soh otr

* Update generate-builds.yml

* Apply for all conditions

* grandma change
This commit is contained in:
AltoXorg 2023-08-16 08:26:23 +08:00 committed by GitHub
parent 74d6678543
commit 6923c2d3c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 9 deletions

View File

@ -47,10 +47,7 @@ jobs:
run: | run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
cmake --no-warn-unused-cli -H. -Bbuild-cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=Release cmake --no-warn-unused-cli -H. -Bbuild-cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=Release
cmake --build build-cmake --config Release --target ZAPD cmake --build build-cmake --config Release --target GenerateSohOtr
mkdir Extract
cp -r OTRExporter/assets/ ./Extract/assets
./build-cmake/ZAPD/ZAPD.out botr -se OTR --norom
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v3
with: with:
name: soh.otr name: soh.otr

View File

@ -132,6 +132,18 @@ add_custom_target(
DEPENDS ZAPD DEPENDS ZAPD
) )
# Target to generate only soh.otr
add_custom_target(
GenerateSohOtr
# CMake versions prior to 3.17 do not have the rm command, use remove instead for older versions
COMMAND ${CMAKE_COMMAND} -E $<IF:$<VERSION_LESS:${CMAKE_VERSION},3.17>,remove,rm> -f soh.otr
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter/extract_assets.py -z "$<TARGET_FILE:ZAPD>" --norom
COMMAND ${CMAKE_COMMAND} -DSYSTEM_NAME=${CMAKE_SYSTEM_NAME} -DTARGET_DIR="$<TARGET_FILE_DIR:ZAPD>" -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DBINARY_DIR=${CMAKE_BINARY_DIR} -DONLYSOHOTR=On -P ${CMAKE_CURRENT_SOURCE_DIR}/copy-existing-otrs.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter
COMMENT "Generating soh.otr..."
DEPENDS ZAPD
)
if(CMAKE_SYSTEM_NAME MATCHES "Linux") if(CMAKE_SYSTEM_NAME MATCHES "Linux")
find_package(ImageMagick COMPONENTS convert) find_package(ImageMagick COMPONENTS convert)
if (ImageMagick_FOUND) if (ImageMagick_FOUND)

View File

@ -33,6 +33,22 @@ def BuildOTR(xmlPath, rom, zapd_exe=None, genHeaders=None):
print("Aborting...", file=os.sys.stderr) print("Aborting...", file=os.sys.stderr)
print("\n") print("\n")
def BuildSohOtr(zapd_exe=None):
shutil.copytree("assets", "Extract/assets")
if not zapd_exe:
zapd_exe = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPDTR/ZAPD.out"
exec_cmd = [zapd_exe, "botr", "-se", "OTR", "--norom"]
print(exec_cmd)
exitValue = subprocess.call(exec_cmd)
if exitValue != 0:
print("\n")
print("Error when building soh.otr file...", file=os.sys.stderr)
print("Aborting...", file=os.sys.stderr)
print("\n")
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-z", "--zapd", help="Path to ZAPD executable", dest="zapd_exe", type=str) parser.add_argument("-z", "--zapd", help="Path to ZAPD executable", dest="zapd_exe", type=str)
@ -40,9 +56,17 @@ def main():
parser.add_argument("--non-interactive", help="Runs the script non-interactively for use in build scripts.", dest="non_interactive", action="store_true") parser.add_argument("--non-interactive", help="Runs the script non-interactively for use in build scripts.", dest="non_interactive", action="store_true")
parser.add_argument("-v", "--verbose", help="Display rom's header checksums and their corresponding xml folder", dest="verbose", action="store_true") parser.add_argument("-v", "--verbose", help="Display rom's header checksums and their corresponding xml folder", dest="verbose", action="store_true")
parser.add_argument("--gen-headers", help="Generate source headers to be checked in", dest="gen_headers", action="store_true") parser.add_argument("--gen-headers", help="Generate source headers to be checked in", dest="gen_headers", action="store_true")
parser.add_argument("--norom", help="Generate only soh.otr to be bundled to the game", dest="norom", action="store_true")
args = parser.parse_args() args = parser.parse_args()
if args.norom:
if (os.path.exists("Extract")):
shutil.rmtree("Extract")
BuildSohOtr(args.zapd_exe)
return
roms = [ Z64Rom(args.rom) ] if args.rom else rom_chooser.chooseROM(args.verbose, args.non_interactive) roms = [ Z64Rom(args.rom) ] if args.rom else rom_chooser.chooseROM(args.verbose, args.non_interactive)
for rom in roms: for rom in roms:
if (os.path.exists("Extract")): if (os.path.exists("Extract")):

View File

@ -1,11 +1,11 @@
message(STATUS "Copying otr files...") message(STATUS "Copying otr files...")
if(EXISTS ${SOURCE_DIR}/OTRExporter/oot.otr) if(NOT ONLYSOHOTR AND EXISTS ${SOURCE_DIR}/OTRExporter/oot.otr)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy oot.otr ${SOURCE_DIR}) execute_process(COMMAND ${CMAKE_COMMAND} -E copy oot.otr ${SOURCE_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy oot.otr ${BINARY_DIR}/soh/) execute_process(COMMAND ${CMAKE_COMMAND} -E copy oot.otr ${BINARY_DIR}/soh/)
message(STATUS "Copied oot.otr") message(STATUS "Copied oot.otr")
endif() endif()
if(EXISTS ${SOURCE_DIR}/OTRExporter/oot-mq.otr) if(NOT ONLYSOHOTR AND EXISTS ${SOURCE_DIR}/OTRExporter/oot-mq.otr)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy oot-mq.otr ${SOURCE_DIR}) execute_process(COMMAND ${CMAKE_COMMAND} -E copy oot-mq.otr ${SOURCE_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy oot-mq.otr ${BINARY_DIR}/soh/) execute_process(COMMAND ${CMAKE_COMMAND} -E copy oot-mq.otr ${BINARY_DIR}/soh/)
message(STATUS "Copied oot-mq.otr") message(STATUS "Copied oot-mq.otr")
@ -18,10 +18,10 @@ endif()
# Additionally for Windows, copy the otrs to the target dir, side by side with soh.exe # Additionally for Windows, copy the otrs to the target dir, side by side with soh.exe
if(SYSTEM_NAME MATCHES "Windows") if(SYSTEM_NAME MATCHES "Windows")
if(EXISTS ${SOURCE_DIR}/OTRExporter/oot.otr) if(NOT ONLYSOHOTR AND EXISTS ${SOURCE_DIR}/OTRExporter/oot.otr)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy oot.otr ${TARGET_DIR}) execute_process(COMMAND ${CMAKE_COMMAND} -E copy oot.otr ${TARGET_DIR})
endif() endif()
if(EXISTS ${SOURCE_DIR}/OTRExporter/oot-mq.otr) if(NOT ONLYSOHOTR AND EXISTS ${SOURCE_DIR}/OTRExporter/oot-mq.otr)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy oot-mq.otr ${TARGET_DIR}) execute_process(COMMAND ${CMAKE_COMMAND} -E copy oot-mq.otr ${TARGET_DIR})
endif() endif()
if(EXISTS ${SOURCE_DIR}/OTRExporter/soh.otr) if(EXISTS ${SOURCE_DIR}/OTRExporter/soh.otr)
@ -29,7 +29,7 @@ if(SYSTEM_NAME MATCHES "Windows")
endif() endif()
endif() endif()
if(NOT EXISTS ${SOURCE_DIR}/oot.otr AND NOT EXISTS ${SOURCE_DIR}/oot-mq.otr) if(NOT ONLYSOHOTR AND (NOT EXISTS ${SOURCE_DIR}/oot.otr AND NOT EXISTS ${SOURCE_DIR}/oot-mq.otr))
message(FATAL_ERROR "Failed to copy. No OTR files found.") message(FATAL_ERROR "Failed to copy. No OTR files found.")
endif() endif()
if(NOT EXISTS ${SOURCE_DIR}/soh.otr) if(NOT EXISTS ${SOURCE_DIR}/soh.otr)