From d4334a2ee7e30f8a50f425393af188320a94c1d3 Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Sat, 18 Feb 2017 16:10:50 +0100 Subject: [PATCH] macros: automatically strip dev-dependencies All background written in upstream cargo GitHub issue[0]. In short, cargo build/install enforces us to have all dev-dependencies even they are not used for building/installed. [0] https://github.com/rust-lang/cargo/issues/3732 Signed-off-by: Igor Gnatenko --- data/macros.cargo | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/data/macros.cargo b/data/macros.cargo index 7126f2b..67372fa 100644 --- a/data/macros.cargo +++ b/data/macros.cargo @@ -7,8 +7,10 @@ %__cargo_is_lib() %{expand:%__cargo_inspector --target-kinds Cargo.toml | grep -q -F lib} %__cargo_is_bin() %{expand:%__cargo_inspector --target-kinds Cargo.toml | grep -q -F bin} -%cargo_prep %{expand:\ -%{__mkdir} -p .cargo && cat > .cargo/config << EOF \ +%cargo_prep (\ +set -eu \ +%{__mkdir} -p .cargo \ +cat > .cargo/config << EOF \ [build]\ rustc = "%{__rustc}"\ rustflags = %{__global_rustflags_toml}\ @@ -24,24 +26,32 @@ directory = "%{cargo_registry}"\ [source.crates-io]\ registry = "https://crates.io"\ replace-with = "local-registry"\ -EOF} +EOF\ +%if ! %{with check} \ +# https://github.com/rust-lang/cargo/issues/3732 \ +%{__awk} -i inplace -v INPLACE_SUFFIX=.orig '/^\\\[dev-dependencies\\\]$/{f=1;next} /^\\\[/{f=0}; !f' Cargo.toml \ +%endif \ +) %cargo_build %__cargo build %{__cargo_common_opts} %cargo_test %__cargo test %{__cargo_common_opts} -%cargo_install %{expand:(\ +%cargo_install (\ set -eu \ if %__cargo_is_lib; then \ CRATE_NAME=$(%__cargo_inspector --name Cargo.toml) \ CRATE_VERSION=$(%__cargo_inspector --version Cargo.toml) \ REG_DIR=%{buildroot}%{cargo_registry}/$CRATE_NAME-$CRATE_VERSION \ - mkdir -p $REG_DIR \ + %{__mkdir} -p $REG_DIR \ %__cargo package -l | xargs cp --parents -p -t $REG_DIR \ +%if ! %{with check} \ + %{__install} -p Cargo.toml.orig $REG_DIR/Cargo.toml \ +%endif \ echo '{"files":{},"package":""}' > $REG_DIR/.cargo-checksum.json \ fi \ if %__cargo_is_bin; then \ %__cargo install %{?_smp_mflags} --path . --root %{buildroot}%{_prefix} \ - rm %{buildroot}%{_prefix}/.crates.toml \ + %{__rm} %{buildroot}%{_prefix}/.crates.toml \ fi \ -)} +)