public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH v2] Add 'host' variable to GIT_CRATES to support other host like self-host gitlab or gitea
@ 2024-12-03 16:28 MYT
  0 siblings, 0 replies; only message in thread
From: MYT @ 2024-12-03 16:28 UTC (permalink / raw
  To: gentoo-dev; +Cc: MYT

This change indroduces possibility to fetch git crates from hosts other
than github/main gitlab instance, like the gnome's gitlab which wasn't
possible before. This is done by adding new key in the crate value
`;gitlab` for example.

Signed-off-by: MYT <mytdragon@protonmail.com>
---
 eclass/cargo.eclass | 41 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)

diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index 02b048732f7f..b1285e13a5b2 100644
--- a/eclass/cargo.eclass
+++ b/eclass/cargo.eclass
@@ -138,6 +138,10 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
 # - optionally: the path to look for Cargo.toml in.
 #   - This will also replace the string "%commit%" with the commit's checksum.
 #   - Defaults to: "${crate}-%commit%"
+# - optionally: the git host so it would generate tarball download link.
+#   - E.g. gitlab
+#   - It fallbacks to detecting from URL if it's gitlab.com or github.com
+#     if no host provided.
 #
 # Example of a simple definition with no path to Cargo.toml:
 # @CODE
@@ -153,6 +157,13 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
 # 	[rustpython-parser]="https://github.com/RustPython/RustPython;4f38cb68e4a97aeea9eb19673803a0bd5f655383;RustPython-%commit%/compiler/parser"
 # )
 # @CODE
+#
+# Example with host defined:
+# @CODE
+# declare -A GIT_CRATES=(
+#	[clapper]="https://gitlab.gnome.org/JanGernert/clapper-rs;530b6fd53a60563d8038f7a1d9d735d6dc496adb;clapper-rs-%commit%/libclapper-rs;gitlab"
+# )
+# @CODE
 
 # @ECLASS_VARIABLE: CARGO_BOOTSTRAP
 # @DEFAULT_UNSET
@@ -269,22 +280,38 @@ _cargo_set_crate_uris() {
 
 	if declare -p GIT_CRATES &>/dev/null; then
 		if [[ $(declare -p GIT_CRATES) == "declare -A"* ]]; then
-			local crate commit crate_uri crate_dir repo_ext feat_expr
+			local crate commit crate_uri crate_dir host repo_ext feat_expr
 
 			for crate in "${!GIT_CRATES[@]}"; do
-				IFS=';' read -r crate_uri commit crate_dir <<< "${GIT_CRATES[${crate}]}"
+				IFS=';' read -r crate_uri commit crate_dir host <<< "${GIT_CRATES[${crate}]}"
+
+				if [[ -z ${host} ]]; then
+					case "${crate_uri}" in
+						https://github.com/*)
+							host="github"
+						;;
+						https://gitlab.com/*)
+							host="gitlab"
+						;;
+					esac
+				fi
 
-				case "${crate_uri}" in
-					https://github.com/*)
+				case "${host}" in
+					github)
 						repo_ext=".gh"
 						repo_name="${crate_uri##*/}"
 						crate_uri="${crate_uri%/}/archive/%commit%.tar.gz"
 					;;
-					https://gitlab.com/*)
+					gitlab)
 						repo_ext=".gl"
 						repo_name="${crate_uri##*/}"
 						crate_uri="${crate_uri%/}/-/archive/%commit%/${repo_name}-%commit%.tar.gz"
 					;;
+					gitea)
+						repo_ext=".gt"
+						repo_name="${crate_uri##*/}"
+						crate_uri="${crate_uri%/}/archive/%commit%.tar.gz"
+					;;
 					*)
 						repo_ext=
 						repo_name="${crate}"
@@ -395,11 +422,11 @@ _cargo_gen_git_config() {
 	git_crates_type="$(declare -p GIT_CRATES 2>&-)"
 
 	if [[ ${git_crates_type} == "declare -A "* ]]; then
-		local crate commit crate_uri crate_dir
+		local crate commit crate_uri crate_dir host
 		local -A crate_patches
 
 		for crate in "${!GIT_CRATES[@]}"; do
-			IFS=';' read -r crate_uri commit crate_dir <<< "${GIT_CRATES[${crate}]}"
+			IFS=';' read -r crate_uri commit crate_dir host <<< "${GIT_CRATES[${crate}]}"
 			: "${crate_dir:=${crate}-%commit%}"
 			crate_patches["${crate_uri}"]+="${crate} = { path = \"${WORKDIR}/${crate_dir//%commit%/${commit}}\" };;"
 		done
-- 
2.45.2




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-12-03 16:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-03 16:28 [gentoo-dev] [PATCH v2] Add 'host' variable to GIT_CRATES to support other host like self-host gitlab or gitea MYT

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox