%cargo_install is now smart to handle libs and bins

So far we had %cargo_install (for binaries) and %cargo_install_crate
(for libraries) which is a bit awkward and requires us to put
additional arguments for latter one.

We can do all the magic behind the scene.

Closes: https://pagure.io/fedora-rust/rust2rpm/issue/7
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
This commit is contained in:
Igor Gnatenko 2017-02-10 22:10:12 +01:00
parent 5607956af4
commit c12df7d085

View file

@ -1,9 +1,13 @@
%__cargo %{_bindir}/cargo
%__cargo_common_opts --release %{?_smp_mflags}
%__cargo_inspector %{_rpmconfigdir}/cargodeps
%cargo_registry %{_usrsrc}/rust
%cargo_prep() %{expand:\
%__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 \
[build]\
rustc = "%{__rustc}"\
@ -26,12 +30,18 @@ EOF}
%cargo_test() %{expand:%__cargo test %{__cargo_common_opts} %{?1}}
%cargo_install() %{expand:%__cargo install %{?_smp_mflags} \\\
--path . \\\
--root %{buildroot}%{_prefix} \\\
%{?1} \\\
&& rm %{buildroot}%{_prefix}/.crates.toml}
%cargo_install_crate() %{expand: mkdir -p %{buildroot}%{cargo_registry}/%{1} && \\\
%__cargo package -l | xargs cp --parents -p -t %{buildroot}%{cargo_registry}/%{1} && \\\
echo '{"files":{},"package":""}' >%{buildroot}%{cargo_registry}/%{1}/.cargo-checksum.json}
%cargo_install %{expand:(\
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 -p -t $REG_DIR \
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 \
fi \
)}