From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/tests/, eclass/
Date: Sun, 18 Jun 2023 14:57:51 +0000 (UTC) [thread overview]
Message-ID: <1687100264.59dbfb80f748a0fc5741a8f3028f7552af28eecf.mgorny@gentoo> (raw)
commit: 59dbfb80f748a0fc5741a8f3028f7552af28eecf
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Thu Jun 15 15:20:43 2023 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sun Jun 18 14:57:44 2023 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=59dbfb80
cargo.eclass: Add variable alternative to $(cargo_crate_uris)
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 <mgorny <AT> gentoo.org>
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: <crates>
# @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: [<crates>...]
+# @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
next reply other threads:[~2023-06-18 14:57 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-18 14:57 Michał Górny [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-03-03 19:27 [gentoo-commits] repo/gentoo:master commit in: eclass/tests/, eclass/ Sam James
2024-10-08 15:29 Ulrich Müller
2024-02-10 10:47 Michał Górny
2024-02-10 10:47 Michał Górny
2023-09-14 5:30 Michał Górny
2023-07-02 15:21 Michał Górny
2023-06-18 14:57 Michał Górny
2023-06-07 9:03 Ulrich Müller
2022-11-15 16:34 Michał Górny
2022-10-10 20:52 Michał Górny
2022-09-28 20:55 Michał Górny
2022-05-01 7:30 Michał Górny
2022-02-09 9:39 Michał Górny
2022-01-09 8:09 Michał Górny
2021-06-23 21:44 Michał Górny
2021-01-15 17:05 Michał Górny
2021-01-05 23:01 Sergei Trofimovich
2020-05-25 6:12 Michał Górny
2020-03-28 19:54 Sergei Trofimovich
2020-03-26 7:51 Sergei Trofimovich
2020-01-11 23:53 Sergei Trofimovich
2019-12-30 12:59 Michał Górny
2019-12-30 12:59 Michał Górny
2019-12-24 11:01 Sergei Trofimovich
2018-04-18 18:13 Mike Gilbert
2018-01-04 21:56 Michał Górny
2017-09-26 18:46 Ulrich Müller
2017-09-19 11:08 Michał Górny
2017-08-25 13:53 Michał Górny
2017-08-11 14:35 Michał Górny
2017-08-08 19:42 Michał Górny
2017-03-18 7:33 Michał Górny
2017-02-09 18:16 Mike Frysinger
2016-12-18 13:46 Michał Górny
2016-06-27 5:58 Michał Górny
2016-06-26 15:36 Michał Górny
2016-01-08 5:14 Michał Górny
2016-01-08 5:14 Michał Górny
2015-12-09 20:42 Michał Górny
2015-11-24 17:03 Mike Frysinger
2015-11-11 10:27 Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1687100264.59dbfb80f748a0fc5741a8f3028f7552af28eecf.mgorny@gentoo \
--to=mgorny@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox