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

internal: build gamemode instead of downloading prebuilt #1732

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions skymp5-functions-lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
project(skymp5-functions-lib)

set(GAMEMODE_REPO Pospelove/skymp5-gamemode)
set(GAMEMODE_REVISION master)
set(GAMEMODE_REPO_OWNER Pospelove)
set(GAMEMODE_REPO_NAME skymp5-gamemode)
set(GAMEMODE_REPO ${GAMEMODE_REPO_OWNER}/${GAMEMODE_REPO_NAME})
set(GAMEMODE_BRANCH master)

if(BUILD_GAMEMODE)
if(NOT GITHUB_TOKEN)
message(FATAL_ERROR "GITHUB_TOKEN is not set. Please set it to your GitHub personal access token.")
endif()
# The URL to the raw gamemode.js file.
set(GAMEMODE_JS_URL "https://raw.githubusercontent.com/${GAMEMODE_REPO}/${GAMEMODE_REVISION}/build/gamemode.js")

# The destination where the file will be saved.
set(GAMEMODE_JS_DEST "${CMAKE_BINARY_DIR}/dist/server/gamemode.js")

set(GAMEMODE_ZIP_URL "https://github.com/${GAMEMODE_REPO}/archive/refs/heads/${GAMEMODE_BRANCH}.zip")
set(GAMEMODE_ZIP_DEST "${CMAKE_BINARY_DIR}/gamemode.zip")
set(GAMEMODE_ZIP_EXTRACT_DIR "${CMAKE_BINARY_DIR}/gamemode-zip")
set(GAMEMODE_JS_DEST_DIR "${CMAKE_BINARY_DIR}/dist/server")

# Pass variables to the download script.
set(SCRIPT_PATH "${CMAKE_CURRENT_LIST_DIR}/download.cmake")
configure_file(${SCRIPT_PATH} ${CMAKE_BINARY_DIR}/download.cmake)
set(SCRIPT_PATH "${CMAKE_CURRENT_LIST_DIR}/download-and-build.cmake")
configure_file(${SCRIPT_PATH} ${CMAKE_BINARY_DIR}/download-and-build.cmake)

add_custom_target(skymp5-functions-lib ALL
SOURCES ${sources}
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/dist/server
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/${GAMEMODE_REPO_NAME}-${GAMEMODE_BRANCH}
COMMAND ${CMAKE_COMMAND} -E env DOWNLOAD_NO_PROGRESS=1
${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/download.cmake
COMMENT "Downloading gamemode.js file..."
${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/download-and-build.cmake
COMMENT "Downloading & building gamemode repo..."
)
else()
add_custom_target(skymp5-functions-lib ALL
Expand Down
56 changes: 56 additions & 0 deletions skymp5-functions-lib/download-and-build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
include(${CMAKE_SOURCE_DIR}/cmake/yarn.cmake)

message(STATUS "Downloading gamemode sources")

file(DOWNLOAD ${GAMEMODE_ZIP_URL} ${GAMEMODE_ZIP_DEST}
STATUS status
LOG log
TLS_VERIFY ON
HTTPHEADER "Authorization: token ${GITHUB_TOKEN}"
)
list(GET status 0 status_code)
list(GET status 1 status_string)
if(NOT status_code EQUAL 0)
message(FATAL_ERROR "error: downloading gamemode sources failed: ${status_string}")
endif()

message(STATUS "Downloaded gamemode sources")

message(STATUS "Extracting gamemode sources")

# Execute the CMake command to extract the zip file
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xvf ${GAMEMODE_ZIP_DEST}
RESULT_VARIABLE TAR_RESULT
OUTPUT_QUIET # stop telling gamemode filenames in console
)

if(NOT TAR_RESULT EQUAL "0")
message(FATAL_ERROR "Failed to extract gamemode zip file")
endif()

message(STATUS "Extracted gamemode sources")

message(STATUS "Installing yarn dependencies for gamemode")

yarn_execute_command(
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/skymp5-functions-lib/${GAMEMODE_REPO_NAME}-${GAMEMODE_BRANCH}
COMMAND install
)

message(STATUS "Installed yarn dependencies for gamemode")

message(STATUS "Building gamemode.js")

yarn_execute_command(
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/skymp5-functions-lib/${GAMEMODE_REPO_NAME}-${GAMEMODE_BRANCH}
COMMAND build
)

message(STATUS "Built gamemode.js")

message(STATUS "Installing gamemode.js")

file(COPY ${CMAKE_BINARY_DIR}/skymp5-functions-lib/${GAMEMODE_REPO_NAME}-${GAMEMODE_BRANCH}/build/gamemode.js DESTINATION "${GAMEMODE_JS_DEST_DIR}")

message(STATUS "Installed gamemode.js")
13 changes: 0 additions & 13 deletions skymp5-functions-lib/download.cmake

This file was deleted.

Loading