dev-cpp/pangomm: stable 2.42.1 for hppa, bug #717144
[gentoo.git] / eclass / cargo.eclass
index fb759f95903f2144c454d2ad6dbccf61afe68ffa..6f7ffdb626b4143730f56d4f0ea9005f4b6887d8 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1999-2019 Gentoo Authors
+# Copyright 1999-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: cargo.eclass
 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
 
@@ -43,16 +39,13 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
 # @DESCRIPTION:
 # Generates the URIs to put in SRC_URI to help fetch dependencies.
 cargo_crate_uris() {
+       local -r regex='^([a-zA-Z0-9_\-]+)-([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
@@ -129,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} "$@"
 
@@ -140,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
@@ -151,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"
 }
 
@@ -161,10 +172,11 @@ cargo_src_compile() {
 cargo_src_install() {
        debug-print-function ${FUNCNAME} "$@"
 
-       cargo install -vv -j $(makeopts_jobs) --path ${CARGO_INSTALL_PATH} \
+       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
 }
@@ -175,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"
 }