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: add BUILD_PATCHES option #1730

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ jobs:
&& ./build.sh --configure \
-DBUILD_UNIT_TESTS=OFF \
-DBUILD_GAMEMODE=ON \
-DBUILD_PATCHES=ON \
-DOFFLINE_MODE=OFF \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-DGITHUB_TOKEN=${{env.GAMEMODE_GITHUB_TOKEN}}
Expand Down
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ option(PREPARE_NEXUS_ARCHIVES "Prepare SP and other archives during build or not
option(BUILD_UNIT_TESTS "Build unit tests (excluded from build when off - workaround for #1182)" ON)
option(INSTALL_CLIENT_DIST "Install the client into SKYRIM_DIR after build" OFF)
option(BUILD_GAMEMODE "Build gamemode" OFF)
option(BUILD_PATCHES "Build patches" OFF)
option(OFFLINE_MODE "Enable offline mode in generated server settings and client settings" ON)

message(STATUS JS_ENGINE_TRACING_ENABLED=${JS_ENGINE_TRACING_ENABLED})
Expand Down Expand Up @@ -120,6 +121,18 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)

if(BUILD_PATCHES)
if(GITHUB_TOKEN)
include(cmake/download_and_apply_git_patch.cmake)
set(PATCH_URL "https://raw.githubusercontent.com/Pospelove/skymp5-patches/master/patch.patch?token=${GITHUB_TOKEN}")
set(EXPECTED_SHA512 "0")
set(PATCH_FILE "${CMAKE_BINARY_DIR}/patch.patch")
download_and_apply_git_patch(${PATCH_URL} ${PATCH_FILE} ${EXPECTED_SHA512})
else()
message(FATAL_ERROR "GITHUB_TOKEN is not set. Please set it to your GitHub personal access token.")
endif()
endif()

add_subdirectory(viet)
add_subdirectory(savefile)
add_subdirectory(papyrus-vm)
Expand Down
40 changes: 40 additions & 0 deletions cmake/download_and_apply_git_patch.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function(download_and_apply_git_patch patch_url patch_file expected_sha512)
# Download the patch file
message(STATUS "Downloading patch file: ${patch_url}")
file(DOWNLOAD ${patch_url} ${patch_file}
TIMEOUT 60 # Adjust the timeout as necessary
EXPECTED_HASH SHA512=${expected_sha512}
STATUS download_status
SHOW_PROGRESS)

# Check if download was successful
list(GET download_status 0 status_code)
list(GET download_status 1 status_string)
if(NOT status_code EQUAL 0)
message(FATAL_ERROR "Error downloading patch: ${status_string}")
endif()

# Check if the patch has already been applied
execute_process(
COMMAND git apply --check ${patch_file}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE PATCH_APPLIED
OUTPUT_QUIET
ERROR_QUIET
)

# Apply the git patch if it has not been applied yet
if(NOT PATCH_APPLIED EQUAL 0)
message(STATUS "Applying git patch ${patch_file}")
execute_process(
COMMAND git apply ${patch_file}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE PATCH_RESULT
)
if(NOT PATCH_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to apply git patch: ${patch_file}")
endif()
else()
message(STATUS "Patch ${patch_file} already applied")
endif()
endfunction()
Loading