You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rust-packaging/0004-macros-make-cargo_-mac...

97 lines
4.6 KiB

From c9ce952e260ec0adb166bd6e1de652a0277d2437 Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
Date: Fri, 22 Jun 2018 21:04:59 +0200
Subject: [PATCH 4/5] macros: make %cargo_* macros parametric
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Unfortunately cargo-install doesn't accept --target-dir, so have to pass
setting through envvar.
Also %{shrink:…} them so it looks nicer in build log.
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
---
data/macros.cargo | 62 ++++++++++++++++++++++++++++++++++-------------
1 file changed, 45 insertions(+), 17 deletions(-)
diff --git a/data/macros.cargo b/data/macros.cargo
index 22721e9..96a2931 100644
--- a/data/macros.cargo
+++ b/data/macros.cargo
@@ -35,25 +35,53 @@ EOF\
%endif \
)
-%cargo_build %__cargo build --release %{__cargo_common_opts}
+%__cargo_parse_opts(t:naf:) %{shrink:\
+%{-f:%{-a:%{error:Can't specify both -f(%{-f*}) and -a}}} \
+ %{-t:--target-dir %{-t*}} \
+ %{-n:--no-default-features} \
+ %{-a:--all-features} \
+ %{-f:--features %{-f*}} \
+ %{nil}
+}
-%cargo_test %__cargo test --release %{__cargo_common_opts} --no-fail-fast
+%cargo_build(t:naf:) %{shrink:\
+%{__cargo} build \
+ %{__cargo_common_opts} \
+ --release \
+ %{__cargo_parse_opts %{-t:-t%{-t*}} %{-n} %{-a} %{-f:-f%{-f*}}} \
+ %* \
+}
-%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 \
- %__cargo package -l | xargs %{__cp} --parents -a -t $REG_DIR \
-%if ! %{with check} \
- %{__cp} -a Cargo.toml.orig $REG_DIR/Cargo.toml \
-%endif \
- echo '{"files":{},"package":""}' > $REG_DIR/.cargo-checksum.json \
+%cargo_test(t:naf:) %{shrink:\
+%{__cargo} test \
+ %{__cargo_common_opts} \
+ --release \
+ --no-fail-fast \
+ %{__cargo_parse_opts %{-t:-t%{-t*}} %{-n} %{-a} %{-f:-f%{-f*}}} \
+ %* \
+}
+
+%cargo_install(t:naf:) (\
+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 \
+ %{__cargo} package -l | xargs %{__cp} --parents -a -t $REG_DIR \
+%if ! %{with check} \
+ %{__cp} -a Cargo.toml.orig $REG_DIR/Cargo.toml \
+%endif \
+ echo '{"files":{},"package":""}' > $REG_DIR/.cargo-checksum.json \
fi \
-if %__cargo_is_bin; then \
- %__cargo install %{__cargo_common_opts} --path . --root %{buildroot}%{_prefix} \
- %{__rm} %{buildroot}%{_prefix}/.crates.toml \
+if %__cargo_is_bin; then \
+ %{shrink:%{-t:CARGO_TARGET_DIR=%{-t*}} %{__cargo} install \
+ %{__cargo_common_opts} \
+ --path . \
+ --root %{buildroot}%{_prefix} \
+ %{__cargo_parse_opts %{-n} %{-a} %{-f:-f%{-f*}}} \
+ %* \
+ }\
+ %{__rm} %{buildroot}%{_prefix}/.crates.toml \
fi \
)
--
2.18.0.rc2