-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Simplify build-system and support editable install
* Switch to using "FetchContent_Populate" instead of custom logic for checking archive integrity * Disambiguate executable location installing it into `s5cmd/bin` * Add support for editable install using `importlib.metadata` to lookup location of executable.
- Loading branch information
Showing
2 changed files
with
24 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,31 @@ | ||
cmake_minimum_required(VERSION 3.15...3.26) | ||
project(${SKBUILD_PROJECT_NAME} LANGUAGES NONE) | ||
|
||
function(_check_archive dest_file expected_sha256 output_var) | ||
get_filename_component(filename ${dest_file} NAME) | ||
message(STATUS "Checking ${filename}") | ||
|
||
if(NOT EXISTS ${dest_file}) | ||
message(STATUS "Checking ${filename} - nonexistent") | ||
set(${output_var} "nonexistent" PARENT_SCOPE) | ||
return() | ||
endif() | ||
|
||
file(SHA256 ${dest_file} current_hash) | ||
if(NOT ${current_hash} STREQUAL ${expected_sha256}) | ||
message(STATUS "Checking ${filename} - expired") | ||
set(${output_var} "expired" PARENT_SCOPE) | ||
return() | ||
endif() | ||
|
||
message(STATUS "Checking ${filename} - up-to-date") | ||
set(${output_var} "ok" PARENT_SCOPE) | ||
endfunction() | ||
|
||
# Set in the current scope the following variables: | ||
# - s5cmd_archive_url | ||
# - s5cmd_archive_sha256 | ||
include(${CMAKE_CURRENT_SOURCE_DIR}/s5cmdUrls.cmake) | ||
|
||
# | ||
# Download archive | ||
# Download & extract archive | ||
# | ||
cmake_path(GET s5cmd_archive_url FILENAME archive_filename) | ||
set(destination_file "${CMAKE_CURRENT_BINARY_DIR}/${archive_filename}") | ||
|
||
_check_archive(${destination_file} ${s5cmd_archive_sha256} result) | ||
|
||
if(result MATCHES "^(nonexistent|expired)$") | ||
message(STATUS "Downloading ${s5cmd_archive_url}") | ||
file( | ||
DOWNLOAD | ||
${s5cmd_archive_url} | ||
${destination_file} | ||
EXPECTED_HASH SHA256=${s5cmd_archive_sha256} | ||
) | ||
elseif(result STREQUAL "ok") | ||
# ok | ||
else() | ||
message(FATAL_ERROR "Unknown result value: ${result}") | ||
endif() | ||
set(download_dir "${PROJECT_BINARY_DIR}") | ||
set(extract_dir "${PROJECT_BINARY_DIR}/s5cmd-binary-distribution") | ||
include(FetchContent) | ||
FetchContent_Populate(s5cmd | ||
URL ${s5cmd_archive_url} | ||
URL_HASH SHA256=${s5cmd_archive_sha256} | ||
DOWNLOAD_DIR ${download_dir} | ||
SOURCE_DIR "${extract_dir}" | ||
) | ||
|
||
# | ||
# Extract archive | ||
# Install executable | ||
# | ||
set(executable_name "s5cmd${CMAKE_EXECUTABLE_SUFFIX}") | ||
|
||
string(MAKE_C_IDENTIFIER ${archive_filename} extract_subdir) | ||
set(extract_dir "${CMAKE_CURRENT_BINARY_DIR}/${extract_subdir}") | ||
message(STATUS "Extracting ${archive_filename} into ${extract_dir}") | ||
file(ARCHIVE_EXTRACT | ||
INPUT ${destination_file} | ||
DESTINATION ${extract_dir} | ||
PATTERNS "${executable_name}" | ||
VERBOSE | ||
) | ||
|
||
set(_permissions PERMISSIONS | ||
OWNER_READ OWNER_WRITE OWNER_EXECUTE | ||
GROUP_READ GROUP_EXECUTE | ||
WORLD_READ WORLD_EXECUTE | ||
) | ||
|
||
install(PROGRAMS ${extract_dir}/${executable_name} DESTINATION "s5cmd" ${_permissions}) | ||
set(executable_name "s5cmd${CMAKE_EXECUTABLE_SUFFIX}") | ||
install(PROGRAMS ${extract_dir}/${executable_name} DESTINATION "s5cmd/bin" ${_permissions}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters