# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=cargo-geiger
pkgver=0.11.3
pkgrel=1
pkgdesc='Detects usage of unsafe Rust in a Rust crate and its dependencies'
arch=('x86_64')
url='https://github.com/rust-secure-code/cargo-geiger'
license=('Apache' 'MIT')
depends=('curl')
makedepends=('git' 'rust')
options=('!lto')
_commit='ce60c0b49131c1d937353f4c221ca43f22d52ced'
source=("$pkgname::git+$url.git#commit=$_commit")
md5sums=('SKIP')

pkgver() {
  cd "$pkgname"
  git describe --tags | sed "s/(cargo-geiger-serde\|cargo-geiger\|geiger)//;s/-//"
}

prepare() {
  cd "$pkgname"

  # download dependencies
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd "$pkgname"
  cargo build --release --frozen
}

check() {
  cd "$pkgname"
  cargo test --frozen
}

package() {
  cd "$pkgname"

  # binary
  install -vDm755 -t "$pkgdir/usr/bin" "target/release/$pkgname"

  # licenses
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" cargo-geiger/LICENSE*

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" *.md
}