summaryrefslogtreecommitdiff
path: root/eclass/cargo.eclass
diff options
context:
space:
mode:
authorV3n3RiX <venerix@redcorelinux.org>2020-01-15 15:51:32 +0000
committerV3n3RiX <venerix@redcorelinux.org>2020-01-15 15:51:32 +0000
commit21435953e16cda318a82334ddbadb3b5c36d9ea7 (patch)
treee1810a4b135afce04b34862ef0fab2bfaeb8aeca /eclass/cargo.eclass
parent7bc9c63c9da678a7e6fceb095d56c634afd22c56 (diff)
gentoo resync : 15.01.2020
Diffstat (limited to 'eclass/cargo.eclass')
-rw-r--r--eclass/cargo.eclass58
1 files changed, 38 insertions, 20 deletions
diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index 13dd5c355fb3..79d8863017d1 100644
--- a/eclass/cargo.eclass
+++ b/eclass/cargo.eclass
@@ -12,16 +12,12 @@
if [[ -z ${_CARGO_ECLASS} ]]; then
_CARGO_ECLASS=1
-if [[ ${PV} == *9999* ]]; then
- # we need at least this for cargo vendor subommand
- CARGO_DEPEND=">=virtual/cargo-1.37.0"
-else
- CARGO_DEPEND="virtual/cargo"
-fi
+# we need this for 'cargo vendor' subcommand and net.offline config knob
+RUST_DEPEND=">=virtual/rust-1.37.0"
case ${EAPI} in
- 6) DEPEND="${CARGO_DEPEND}";;
- 7) BDEPEND="${CARGO_DEPEND}";;
+ 6) DEPEND="${RUST_DEPEND}";;
+ 7) BDEPEND="${RUST_DEPEND}";;
*) die "EAPI=${EAPI:-0} is not supported" ;;
esac
@@ -34,20 +30,22 @@ IUSE="${IUSE} debug"
ECARGO_HOME="${WORKDIR}/cargo_home"
ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
+# @ECLASS-VARIABLE: CARGO_INSTALL_PATH
+# @DESCRIPTION:
+# Allows overriding the default cwd to run cargo install from
+: ${CARGO_INSTALL_PATH:=.}
+
# @FUNCTION: cargo_crate_uris
# @DESCRIPTION:
# Generates the URIs to put in SRC_URI to help fetch dependencies.
cargo_crate_uris() {
+ local -r regex='^(.*)-([0-9]+\.[0-9]+\.[0-9]+.*)$'
local crate
for crate in "$@"; do
- local name version url pretag
- name="${crate%-*}"
- version="${crate##*-}"
- pretag="^[a-zA-Z]+"
- if [[ $version =~ $pretag ]]; then
- version="${name##*-}-${version}"
- name="${name%-*}"
- fi
+ 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}"
done
@@ -124,7 +122,14 @@ cargo_live_src_unpack() {
# @FUNCTION: cargo_gen_config
# @DESCRIPTION:
-# Generate the $CARGO_HOME/config necessary to use our local registry
+# Generate the $CARGO_HOME/config necessary to use our local registry and settings.
+# Cargo can also be configured through environment variables in addition to the TOML syntax below.
+# For each configuration key below of the form foo.bar the environment variable CARGO_FOO_BAR
+# can also be used to define the value.
+# Environment variables will take precedent over TOML configuration,
+# and currently only integer, boolean, and string keys are supported.
+# For example the build.jobs key can also be defined by CARGO_BUILD_JOBS.
+# Or setting CARGO_TERM_VERBOSE=false in make.conf will make build quieter.
cargo_gen_config() {
debug-print-function ${FUNCNAME} "$@"
@@ -135,7 +140,18 @@ cargo_gen_config() {
[source.crates-io]
replace-with = "gentoo"
local-registry = "/nonexistant"
+
+ [net]
+ offline = true
+
+ [build]
+ jobs = $(makeopts_jobs)
+
+ [term]
+ verbose = true
EOF
+ # honor NOCOLOR setting
+ [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo "color = 'never'" >> "${ECARGO_HOME}/config"
}
# @FUNCTION: cargo_src_compile
@@ -146,7 +162,7 @@ cargo_src_compile() {
export CARGO_HOME="${ECARGO_HOME}"
- cargo build -vv -j $(makeopts_jobs) $(usex debug "" --release) "$@" \
+ cargo build $(usex debug "" --release) "$@" \
|| die "cargo build failed"
}
@@ -156,9 +172,11 @@ cargo_src_compile() {
cargo_src_install() {
debug-print-function ${FUNCNAME} "$@"
- cargo install -vv -j $(makeopts_jobs) --root="${ED}/usr" $(usex debug --debug "") "$@" \
+ cargo install --path ${CARGO_INSTALL_PATH} \
+ --root="${ED}/usr" $(usex debug --debug "") "$@" \
|| die "cargo install failed"
rm -f "${ED}/usr/.crates.toml"
+ rm -f "${ED}/usr/.crates2.json"
[ -d "${S}/man" ] && doman "${S}/man" || return 0
}
@@ -169,7 +187,7 @@ cargo_src_install() {
cargo_src_test() {
debug-print-function ${FUNCNAME} "$@"
- cargo test -vv -j $(makeopts_jobs) $(usex debug "" --release) "$@" \
+ cargo test $(usex debug "" --release) "$@" \
|| die "cargo test failed"
}