mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-07-11 02:16:39 +02:00
[cmake] Fix CPMUtil on Windows by avoiding a temp dir (#4195)
Signed-off-by: crueter <crueter@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4195 Reviewed-by: MaranBr <maranbr@eden-emu.dev> Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
This commit is contained in:
+35
-89
@@ -95,7 +95,7 @@ macro(echo)
|
|||||||
execute_process(COMMAND ${CMAKE_COMMAND} -E echo
|
execute_process(COMMAND ${CMAKE_COMMAND} -E echo
|
||||||
"${message}")
|
"${message}")
|
||||||
else()
|
else()
|
||||||
message(STATUS "${message}")
|
message(DEBUG "${message}")
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
@@ -120,47 +120,6 @@ macro(sleep time)
|
|||||||
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${time})
|
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${time})
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
# Analogous to GNU mktemp, with fallbacks
|
|
||||||
function(mktempdir out)
|
|
||||||
# shell out to system mktemp if available
|
|
||||||
find_program(MKTEMP_EXECUTABLE mktemp)
|
|
||||||
if (MKTEMP_EXECUTABLE)
|
|
||||||
execute_process(COMMAND mktemp -d
|
|
||||||
OUTPUT_VARIABLE dir
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
RESULT_VARIABLE ret)
|
|
||||||
|
|
||||||
if (ret EQUAL 0)
|
|
||||||
set(${out} "${dir}" PARENT_SCOPE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
string(RANDOM LENGTH 10 rand_str)
|
|
||||||
set(tmp_str "tmp.${rand_str}")
|
|
||||||
|
|
||||||
# create something in /tmp if it exists
|
|
||||||
if(EXISTS "/tmp" AND IS_DIRECTORY "/tmp")
|
|
||||||
set(dir "/tmp/${tmp_str}")
|
|
||||||
file(MAKE_DIRECTORY "${dir}" RESULT res)
|
|
||||||
if (res EQUAL 0)
|
|
||||||
set(${out} "${dir}" PARENT_SCOPE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# tmpdir does not exist, extremely legacy mode
|
|
||||||
set(dir "${CMAKE_CURRENT_LIST_DIR}/.tmp/${tmp_str}")
|
|
||||||
file(MAKE_DIRECTORY "${dir}" RESULT res)
|
|
||||||
if (res EQUAL 0)
|
|
||||||
set(${out} "${dir}" PARENT_SCOPE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
fatal("Fatal: Could not create temporary directory. "
|
|
||||||
"Check write permissions to the current directory")
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
# Get a package's effective URL.
|
# Get a package's effective URL.
|
||||||
function(get_package_url)
|
function(get_package_url)
|
||||||
set(oneValueArgs
|
set(oneValueArgs
|
||||||
@@ -218,6 +177,7 @@ endfunction()
|
|||||||
# Download a URL to file, with a sha512 hash
|
# Download a URL to file, with a sha512 hash
|
||||||
# And retry 5 times
|
# And retry 5 times
|
||||||
function(cpm_download url file)
|
function(cpm_download url file)
|
||||||
|
echo("Downloading ${url} to ${file}")
|
||||||
list(LENGTH ARGN argn_len)
|
list(LENGTH ARGN argn_len)
|
||||||
if(argn_len GREATER 0)
|
if(argn_len GREATER 0)
|
||||||
list(GET ARGN 0 hash)
|
list(GET ARGN 0 hash)
|
||||||
@@ -229,8 +189,7 @@ function(cpm_download url file)
|
|||||||
foreach(i RANGE 5)
|
foreach(i RANGE 5)
|
||||||
file(DOWNLOAD ${url} ${file}
|
file(DOWNLOAD ${url} ${file}
|
||||||
${args}
|
${args}
|
||||||
STATUS ret
|
STATUS ret)
|
||||||
LOG log)
|
|
||||||
|
|
||||||
list(GET ret 0 code)
|
list(GET ret 0 code)
|
||||||
if (code EQUAL 0)
|
if (code EQUAL 0)
|
||||||
@@ -339,60 +298,47 @@ function(fetch_package)
|
|||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Temporary directory.
|
|
||||||
mktempdir(TMP)
|
|
||||||
|
|
||||||
# Get filename from URL
|
|
||||||
get_filename_component(base_filename ${ARG_URL} NAME)
|
|
||||||
|
|
||||||
# Download
|
|
||||||
set(file ${TMP}/${base_filename})
|
|
||||||
cpm_download(${ARG_URL} ${file} ${ARG_HASH})
|
|
||||||
message(DEBUG "Downloaded ${base_filename}")
|
|
||||||
|
|
||||||
# Extract the downloaded archive
|
|
||||||
# TODO: Moar error handling
|
|
||||||
set(dir ${TMP}/${base_filename}-extracted)
|
|
||||||
file(MAKE_DIRECTORY ${dir})
|
|
||||||
|
|
||||||
file(ARCHIVE_EXTRACT
|
|
||||||
INPUT ${file}
|
|
||||||
DESTINATION ${dir})
|
|
||||||
|
|
||||||
# This is copied near-verbatim from ExternalProject/extractfile.cmake.in
|
|
||||||
|
|
||||||
# If there's just one subdirectory and nothing else, move it
|
|
||||||
file(GLOB contents "${dir}/*")
|
|
||||||
list(REMOVE_ITEM contents "${dir}/.DS_Store")
|
|
||||||
list(LENGTH contents n)
|
|
||||||
|
|
||||||
# If n == 1 and contents points to a directory, this is a GitHub-style pack
|
|
||||||
# In this case contents points to the subdir which will get renamed
|
|
||||||
# If not, contents will point to the parent dir which will get renamed
|
|
||||||
if (NOT n EQUAL 1 OR NOT IS_DIRECTORY "${contents}")
|
|
||||||
set(contents "${dir}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
file(REAL_PATH "${contents}" contents_abs)
|
|
||||||
|
|
||||||
# paths
|
# paths
|
||||||
cmake_path(ABSOLUTE_PATH ARG_PATH
|
cmake_path(ABSOLUTE_PATH ARG_PATH
|
||||||
NORMALIZE
|
NORMALIZE
|
||||||
OUTPUT_VARIABLE abs_path)
|
OUTPUT_VARIABLE abs_path)
|
||||||
|
|
||||||
cmake_path(GET abs_path PARENT_PATH path_parent)
|
cmake_path(GET abs_path PARENT_PATH path_parent)
|
||||||
cmake_path(GET abs_path FILENAME path_name)
|
file(MAKE_DIRECTORY ${path_parent})
|
||||||
|
|
||||||
# rename tmp dir
|
# Get filename from URL
|
||||||
set(tmp_renamed "${TMP}/${path_name}")
|
get_filename_component(base_filename ${ARG_URL} NAME)
|
||||||
file(RENAME "${contents_abs}" "${tmp_renamed}")
|
|
||||||
|
|
||||||
# now copy
|
# Download
|
||||||
# TODO: Error handling beyond what cmake does????
|
set(file ${path_parent}/${base_filename})
|
||||||
file(COPY ${tmp_renamed} DESTINATION ${path_parent})
|
cpm_download(${ARG_URL} ${file} ${ARG_HASH})
|
||||||
|
echo("Downloaded ${base_filename}")
|
||||||
|
|
||||||
|
# Extract
|
||||||
|
echo("Extracting ${file}...")
|
||||||
|
file(ARCHIVE_EXTRACT
|
||||||
|
INPUT ${file}
|
||||||
|
DESTINATION ${abs_path})
|
||||||
|
|
||||||
|
# This is copied near-verbatim from ExternalProject/extractfile.cmake.in
|
||||||
|
|
||||||
|
# If there's just one subdirectory and nothing else, move it
|
||||||
|
file(GLOB contents "${abs_path}/*")
|
||||||
|
list(REMOVE_ITEM contents "${abs_path}/.DS_Store")
|
||||||
|
list(LENGTH contents n)
|
||||||
|
|
||||||
|
# If n == 1 and contents points to a directory, this is a GitHub-style pack
|
||||||
|
# In this case contents points to the subdir which will get renamed
|
||||||
|
# If not, contents will point to the parent dir which will get renamed
|
||||||
|
if (n EQUAL 1 AND IS_DIRECTORY "${contents}")
|
||||||
|
set(temp_path "${abs_path}_tmp")
|
||||||
|
file(RENAME "${contents}" "${temp_path}")
|
||||||
|
file(REMOVE_RECURSE "${abs_path}")
|
||||||
|
file(RENAME "${temp_path}" "${abs_path}")
|
||||||
|
endif()
|
||||||
|
|
||||||
# TODO: only echo this in script mode
|
# TODO: only echo this in script mode
|
||||||
message(DEBUG "Extracted to ${abs_path}")
|
echo("Extracted to ${abs_path}")
|
||||||
|
|
||||||
# Apply patches
|
# Apply patches
|
||||||
apply_patches("${ARG_PATCHES}" "${abs_path}")
|
apply_patches("${ARG_PATCHES}" "${abs_path}")
|
||||||
@@ -401,7 +347,7 @@ function(fetch_package)
|
|||||||
file(WRITE "${abs_path}/.cpm_patch_key" ${ARG_PATCH_KEY})
|
file(WRITE "${abs_path}/.cpm_patch_key" ${ARG_PATCH_KEY})
|
||||||
|
|
||||||
# done! :)
|
# done! :)
|
||||||
file(REMOVE_RECURSE ${TMP})
|
file(REMOVE_RECURSE ${file})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
# compute a hash of all patch file contents
|
# compute a hash of all patch file contents
|
||||||
|
|||||||
@@ -19,6 +19,48 @@ macro(parse_key key)
|
|||||||
parse_object(${object})
|
parse_object(${object})
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
|
||||||
|
# Analogous to GNU mktemp, with fallbacks
|
||||||
|
function(mktempdir out)
|
||||||
|
# shell out to system mktemp if available
|
||||||
|
cpm_find_program(MKTEMP_EXECUTABLE mktemp)
|
||||||
|
if (MKTEMP_EXECUTABLE)
|
||||||
|
execute_process(COMMAND mktemp -d
|
||||||
|
OUTPUT_VARIABLE dir
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
RESULT_VARIABLE ret)
|
||||||
|
|
||||||
|
if (ret EQUAL 0)
|
||||||
|
set(${out} "${dir}" PARENT_SCOPE)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
string(RANDOM LENGTH 10 rand_str)
|
||||||
|
set(tmp_str "tmp.${rand_str}")
|
||||||
|
|
||||||
|
# create something in /tmp if it exists
|
||||||
|
if(EXISTS "/tmp" AND IS_DIRECTORY "/tmp")
|
||||||
|
set(dir "/tmp/${tmp_str}")
|
||||||
|
file(MAKE_DIRECTORY "${dir}" RESULT res)
|
||||||
|
if (res EQUAL 0)
|
||||||
|
set(${out} "${dir}" PARENT_SCOPE)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# tmpdir does not exist, extremely legacy mode
|
||||||
|
set(dir "${CMAKE_CURRENT_LIST_DIR}/.tmp/${tmp_str}")
|
||||||
|
file(MAKE_DIRECTORY "${dir}" RESULT res)
|
||||||
|
if (res EQUAL 0)
|
||||||
|
set(${out} "${dir}" PARENT_SCOPE)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
fatal("Fatal: Could not create temporary directory. "
|
||||||
|
"Check write permissions to the current directory")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Get a package's effective URL, for an already parsed object
|
# Get a package's effective URL, for an already parsed object
|
||||||
function(get_package_url_object out)
|
function(get_package_url_object out)
|
||||||
if (${url})
|
if (${url})
|
||||||
|
|||||||
Reference in New Issue
Block a user