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

Enforce Package Download URL Specified Without Protocol #163

Merged
merged 2 commits into from
Oct 10, 2024
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
22 changes: 4 additions & 18 deletions cmake/CDeps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,15 @@ function(cdeps_get_package_dir NAME OUTPUT_DIR)
endif()
endfunction()

# Resolves the given package URL to a valid URL.
#
# cdeps_resolve_package_url(<url> <output_url>)
#
# This function resolves the given `<url>` to a valid URL and outputs it to the
# `<output_url>` variable.
function(cdeps_resolve_package_url URL OUTPUT_URL)
if(URL MATCHES ".*://")
set("${OUTPUT_URL}" "${URL}" PARENT_SCOPE)
else()
set("${OUTPUT_URL}" https://${URL} PARENT_SCOPE)
endif()
endfunction()

# Downloads the source files of an external package.
#
# cdeps_download_package(<name> <url> <ref> [RECURSE_SUBMODULES])
#
# This function downloads the source files of an external package named `<name>`
# using Git. It downloads the source files from the specified `<url>` with a
# particular `<ref>`. The `<ref>` can be a branch, tag, or commit hash.
# particular `<ref>`. The `<url>` must be specified without a protocol (e.g.,
# `github.com/user/repo`), while the `<ref>` can be a branch, tag, or commit
# hash.
#
# If the `RECURSE_SUBMODULES` option is specified, the external package will be
# downloaded along with its submodules recursively.
Expand Down Expand Up @@ -98,16 +86,14 @@ function(cdeps_download_package NAME URL REF)
endif()
endif()

cdeps_resolve_package_url("${URL}" GIT_URL)

set(CLONE_OPTS -b "${REF}" --depth 1)
if(ARG_RECURSE_SUBMODULES)
list(APPEND CLONE_OPTS --recurse-submodules)
endif()

message(STATUS "CDeps: Downloading ${NAME} from ${GIT_URL} at ${REF}")
execute_process(
COMMAND "${GIT_EXECUTABLE}" clone ${CLONE_OPTS} "${GIT_URL}"
COMMAND "${GIT_EXECUTABLE}" clone ${CLONE_OPTS} https://${URL}.git
${PACKAGE_DIR}/src
ERROR_VARIABLE ERR
RESULT_VARIABLE RES
Expand Down
17 changes: 0 additions & 17 deletions test/test_utilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,3 @@ section("retrieve the path of package directories")
assert(OUTPUT STREQUAL some-root/CppStarter)
endsection()
endsection()

section("resolve package URLs")
section("it should resolve a package URL that contains an HTTP protocol")
cdeps_resolve_package_url(http://github.com/threeal/cpp-starter OUTPUT)
assert(OUTPUT STREQUAL http://github.com/threeal/cpp-starter)
endsection()

section("it should resolve a package URL that contains an HTTPS protocol")
cdeps_resolve_package_url(https://github.com/threeal/cpp-starter OUTPUT)
assert(OUTPUT STREQUAL https://github.com/threeal/cpp-starter)
endsection()

section("it should resolve a package URL that contains no protocol")
cdeps_resolve_package_url(github.com/threeal/cpp-starter OUTPUT)
assert(OUTPUT STREQUAL https://github.com/threeal/cpp-starter)
endsection()
endsection()