From fb6d2b02177659c987b42014f5d457cdc76221ed Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Fri, 22 Jun 2018 21:57:54 +0200 Subject: [PATCH] Various improvements for %%cargo_* macros Signed-off-by: Igor Gnatenko --- 0001-macros-remove-Cargo.lock.patch | 4 +- 0002-macros-remove-spurious-whitespace.patch | 4 +- ...__cargo_common_opts-to-cargo_install.patch | 4 +- ...macros-make-cargo_-macros-parametric.patch | 96 +++++++++++++++++++ ...macros-remove-support-for-target-dir.patch | 71 ++++++++++++++ rust-packaging.spec | 7 +- 6 files changed, 179 insertions(+), 7 deletions(-) create mode 100644 0004-macros-make-cargo_-macros-parametric.patch create mode 100644 0005-macros-remove-support-for-target-dir.patch diff --git a/0001-macros-remove-Cargo.lock.patch b/0001-macros-remove-Cargo.lock.patch index eac95b4..57069a3 100644 --- a/0001-macros-remove-Cargo.lock.patch +++ b/0001-macros-remove-Cargo.lock.patch @@ -1,7 +1,7 @@ From 5313b352712486b4001827b04d906bdb91be2314 Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Mon, 8 Jan 2018 23:57:03 +0100 -Subject: [PATCH 1/3] macros: remove Cargo.lock +Subject: [PATCH 1/5] macros: remove Cargo.lock cargo-package automatically strips it out, but we package also some things directly from git. @@ -27,5 +27,5 @@ index ebf3edb..288554c 100644 # 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 \ -- -2.16.2 +2.18.0.rc2 diff --git a/0002-macros-remove-spurious-whitespace.patch b/0002-macros-remove-spurious-whitespace.patch index 2033124..9e11804 100644 --- a/0002-macros-remove-spurious-whitespace.patch +++ b/0002-macros-remove-spurious-whitespace.patch @@ -1,7 +1,7 @@ From cd6329635329fc7742a18f7ed0933298a0c56cf7 Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Tue, 9 Jan 2018 06:52:36 +0100 -Subject: [PATCH 2/3] macros: remove spurious whitespace +Subject: [PATCH 2/5] macros: remove spurious whitespace Fixes: https://pagure.io/fedora-rust/rust2rpm/issue/48 Reported-by: Josh Stone @@ -24,5 +24,5 @@ index 288554c..67b1950 100644 %if ! %{with check} \ # https://github.com/rust-lang/cargo/issues/3732 \ -- -2.16.2 +2.18.0.rc2 diff --git a/0003-macros-pass-__cargo_common_opts-to-cargo_install.patch b/0003-macros-pass-__cargo_common_opts-to-cargo_install.patch index f719a78..c5ff4b6 100644 --- a/0003-macros-pass-__cargo_common_opts-to-cargo_install.patch +++ b/0003-macros-pass-__cargo_common_opts-to-cargo_install.patch @@ -1,7 +1,7 @@ From c5bab762f56bf07cd0f4a2e2d58b7c295cddedd8 Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Tue, 20 Feb 2018 22:04:35 +0100 -Subject: [PATCH 3/3] macros: pass %__cargo_common_opts to %cargo_install +Subject: [PATCH 3/5] macros: pass %__cargo_common_opts to %cargo_install Reason this has not been done before is that cargo-install doesn't understand --release. Let's just add it to other commands and be done @@ -46,5 +46,5 @@ index 67b1950..22721e9 100644 fi \ ) -- -2.16.2 +2.18.0.rc2 diff --git a/0004-macros-make-cargo_-macros-parametric.patch b/0004-macros-make-cargo_-macros-parametric.patch new file mode 100644 index 0000000..8d8028a --- /dev/null +++ b/0004-macros-make-cargo_-macros-parametric.patch @@ -0,0 +1,96 @@ +From c9ce952e260ec0adb166bd6e1de652a0277d2437 Mon Sep 17 00:00:00 2001 +From: Igor Gnatenko +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 +--- + 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 + diff --git a/0005-macros-remove-support-for-target-dir.patch b/0005-macros-remove-support-for-target-dir.patch new file mode 100644 index 0000000..e8fbfcc --- /dev/null +++ b/0005-macros-remove-support-for-target-dir.patch @@ -0,0 +1,71 @@ +From 80237720ae3397fc66d8f06e13f868c4bd2723c1 Mon Sep 17 00:00:00 2001 +From: Igor Gnatenko +Date: Fri, 22 Jun 2018 21:53:09 +0200 +Subject: [PATCH 5/5] macros: remove support for target-dir + +Signed-off-by: Igor Gnatenko +--- + data/macros.cargo | 31 +++++++++++++++---------------- + 1 file changed, 15 insertions(+), 16 deletions(-) + +diff --git a/data/macros.cargo b/data/macros.cargo +index 96a2931..a0c456a 100644 +--- a/data/macros.cargo ++++ b/data/macros.cargo +@@ -35,30 +35,29 @@ EOF\ + %endif \ + ) + +-%__cargo_parse_opts(t:naf:) %{shrink:\ ++%__cargo_parse_opts(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_build(t:naf:) %{shrink:\ +-%{__cargo} build \ +- %{__cargo_common_opts} \ +- --release \ +- %{__cargo_parse_opts %{-t:-t%{-t*}} %{-n} %{-a} %{-f:-f%{-f*}}} \ +- %* \ ++%cargo_build(naf:) %{shrink:\ ++%{__cargo} build \ ++ %{__cargo_common_opts} \ ++ --release \ ++ %{__cargo_parse_opts %{-n} %{-a} %{-f:-f%{-f*}}} \ ++ %* \ + } + +-%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_test(naf:) %{shrink:\ ++%{__cargo} test \ ++ %{__cargo_common_opts} \ ++ --release \ ++ --no-fail-fast \ ++ %{__cargo_parse_opts %{-n} %{-a} %{-f:-f%{-f*}}} \ ++ %* \ + } + + %cargo_install(t:naf:) (\ +@@ -75,7 +74,7 @@ if %__cargo_is_lib; then \ + echo '{"files":{},"package":""}' > $REG_DIR/.cargo-checksum.json \ + fi \ + if %__cargo_is_bin; then \ +- %{shrink:%{-t:CARGO_TARGET_DIR=%{-t*}} %{__cargo} install \ ++ %{shrink:%{__cargo} install \ + %{__cargo_common_opts} \ + --path . \ + --root %{buildroot}%{_prefix} \ +-- +2.18.0.rc2 + diff --git a/rust-packaging.spec b/rust-packaging.spec index 9f6162f..dabffa1 100644 --- a/rust-packaging.spec +++ b/rust-packaging.spec @@ -2,7 +2,7 @@ Name: rust-packaging Version: 5 -Release: 7%{?dist} +Release: 8%{?dist} Summary: RPM macros for building Rust packages on various architectures License: MIT @@ -11,6 +11,8 @@ Source0: https://releases.pagure.org/fedora-rust/rust2rpm/rust2rpm-%{vers Patch0001: 0001-macros-remove-Cargo.lock.patch Patch0002: 0002-macros-remove-spurious-whitespace.patch Patch0003: 0003-macros-pass-__cargo_common_opts-to-cargo_install.patch +Patch0004: 0004-macros-make-cargo_-macros-parametric.patch +Patch0005: 0005-macros-remove-support-for-target-dir.patch BuildArch: noarch ExclusiveArch: %{rust_arches} noarch @@ -78,6 +80,9 @@ py.test-%{python3_version} -vv test.py %{python3_sitelib}/rust2rpm/ %changelog +* Fri Jun 22 2018 Igor Gnatenko - 5-8 +- Various improvements for %%cargo_* macros + * Tue Jun 19 2018 Miro Hrončok - 5-7 - Rebuilt for Python 3.7