Blob Blame History Raw
#!/bin/bash -euf

dnf -y --best install rust-packaging "$pkg-devel"

provides=$(rpm -qP "$pkg-devel")

while read -r prv; do
  if [[ "$prv" =~ ^crate\(([^/]+)\)\ \=\ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then
    crate="${BASH_REMATCH[1]}"
    version="${BASH_REMATCH[2]}"
  fi
done <<< "$provides"

echo "$crate ($version)"

cargo_registry=$(rpm --eval "%{cargo_registry}")
crate_dir="$cargo_registry/$crate-$version"
crate_toml="$crate_dir/Cargo.toml"

# XXX: ideally we should just install -tests subpackage
# which would require all necessary deps
$(rpm --eval "%{__cargo_inspector}") --test-requires "$crate_toml" | \
  sed -r -e "s/(.*)/'\1'/" | xargs -r sudo dnf -y install

# XXX: sed is needed due to https://github.com/rpm-software-management/rpm/issues/472
rpm -D "_with_check 1" --eval "%cargo_prep" | \
  sed -r -e "s/%if (.+)/if [ \1 ]; then/;s/%endif/fi/" -e "s/<< EOF/<< 'EOF'/" > prep.sh
# XXX: We can't run eval directly, so source it
source prep.sh

exec $(rpm --eval "%cargo_test") --manifest-path "$crate_toml" "$@"