From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 8DD4A158008 for ; Fri, 16 Jun 2023 19:21:39 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 00BCBE091D; Fri, 16 Jun 2023 19:20:58 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 94A30E0917 for ; Fri, 16 Jun 2023 19:20:57 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH v2 2/5] cargo.eclass: Add variable alternative to $(cargo_crate_uris) Date: Fri, 16 Jun 2023 21:19:55 +0200 Message-ID: <20230616192050.9828-3-mgorny@gentoo.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616192050.9828-1-mgorny@gentoo.org> References: <20230616192050.9828-1-mgorny@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: df8423b9-093a-43f0-8d85-6adbd0343efb X-Archives-Hash: 440777ff13d4f91b7a68651e8384f568 Add a helper function that sets ${CARGO_CRATE_URIS} variable to make it possible to set SRC_URI without subshells. This gives a slight speedup (~20%): ``` real 300 it/s user 324 it/s ``` Signed-off-by: Michał Górny --- eclass/cargo.eclass | 48 +++++++++++++++++++++++++------------ eclass/tests/cargo-bench.sh | 4 +++- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass index 991e808d453f..4e0cd1e4de70 100644 --- a/eclass/cargo.eclass +++ b/eclass/cargo.eclass @@ -68,7 +68,7 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo" # " # inherit cargo # ... -# SRC_URI="$(cargo_crate_uris)" +# SRC_URI="${CARGO_CRATE_URIS}" # @CODE # @ECLASS_VARIABLE: GIT_CRATES @@ -162,31 +162,31 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo" # group, and then switch over to building with FEATURES=userpriv. # Or vice-versa. -# @FUNCTION: cargo_crate_uris +# @ECLASS_VARIABLE: CARGO_CRATE_URIS +# @OUTPUT_VARIABLE +# @DESCRIPTION: +# List of URIs to put in SRC_URI created from CRATES variable. + +# @FUNCTION: _cargo_set_crate_uris +# @USAGE: # @DESCRIPTION: # Generates the URIs to put in SRC_URI to help fetch dependencies. # Constructs a list of crates from its arguments. # If no arguments are provided, it uses the CRATES variable. -cargo_crate_uris() { +# The value is set as CARGO_CRATE_URIS. +_cargo_set_crate_uris() { local -r regex='^([a-zA-Z0-9_\-]+)-([0-9]+\.[0-9]+\.[0-9]+.*)$' - local crate crates - - if [[ -n ${@} ]]; then - crates="$@" - elif [[ -n ${CRATES} ]]; then - crates="${CRATES}" - else - eerror "CRATES variable is not defined and nothing passed as argument" - die "Can't generate SRC_URI from empty input" - fi + local crates=${1} + local crate + CARGO_CRATE_URIS= for crate in ${crates}; do local name version url [[ $crate =~ $regex ]] || die "Could not parse name and version from crate: $crate" name="${BASH_REMATCH[1]}" version="${BASH_REMATCH[2]}" url="https://crates.io/api/v1/crates/${name}/${version}/download -> ${crate}.crate" - echo "${url}" + CARGO_CRATE_URIS+="${url} " done local git_crates_type @@ -214,12 +214,30 @@ cargo_crate_uris() { ;; esac - printf -- '%s -> %s\n' "${crate_uri//%commit%/${commit}}" "${repo_name}-${commit}${repo_ext}.tar.gz" + CARGO_CRATE_URIS+="${crate_uri//%commit%/${commit}} -> ${repo_name}-${commit}${repo_ext}.tar.gz " done elif [[ -n ${git_crates_type} ]]; then die "GIT_CRATE must be declared as an associative array" fi } +_cargo_set_crate_uris "${CRATES}" + +# @FUNCTION: cargo_crate_uris +# @USAGE: [...] +# @DESCRIPTION: +# Generates the URIs to put in SRC_URI to help fetch dependencies. +# Constructs a list of crates from its arguments. +# If no arguments are provided, it uses the CRATES variable. +cargo_crate_uris() { + local crates=${*-${CRATES}} + if [[ -z ${crates} ]]; then + eerror "CRATES variable is not defined and nothing passed as argument" + die "Can't generate SRC_URI from empty input" + fi + + _cargo_set_crate_uris "${crates}" + echo "${CARGO_CRATE_URIS}" +} # @FUNCTION: cargo_gen_config # @DESCRIPTION: diff --git a/eclass/tests/cargo-bench.sh b/eclass/tests/cargo-bench.sh index cdc5e4431c14..11b740f8dfcd 100755 --- a/eclass/tests/cargo-bench.sh +++ b/eclass/tests/cargo-bench.sh @@ -12,8 +12,9 @@ RUNS=3 doit() { for (( i = 0; i < ITERATIONS; i++ )); do + _cargo_set_crate_uris "${CRATES}" SRC_URI=" - $(cargo_crate_uris) + ${CARGO_CRATE_URIS} " done } @@ -102,6 +103,7 @@ CRATES=" " inherit cargo + timeit texit -- 2.41.0