#!/bin/bash

# compileSdkVersion
read -d '' p << 'EOF' || true
if (m/^\\s*compileSdkVersion:\\s([^"]*),/) {
  print $1;
  exit;
}
EOF
needed=$(cat build.gradle | perl -ne "$p")
current=34
check_update_needed compileSdkVersion "$needed" "$current"


# minSdkVersion
read -d '' p << 'EOF' || true
if (m/^\\s*minSdkVersion:\\s([^"]*),/) {
  print $1;
  exit;
}
EOF
needed=$(cat build.gradle | perl -ne "$p")
current=21
check_update_needed minSdkVersion "$needed" "$current"


# gradle
read -d '' p << 'EOF' || true
if (m|distributionUrl=https\\\\://services.gradle.org/distributions/gradle-(.*)-.*.zip|) {
  print $1;
  exit;
}
EOF
needed=$(cat gradle/wrapper/gradle-wrapper.properties | perl -ne "$p")
current='[% c("var/gradle_version") %]'
check_update_needed gradle "$needed" "$current"


# nss-nspr
read -d '' p << 'EOF' || true
if (m/NSS_ARCHIVE="nss-(.*-with-nspr-.*)\\.tar\\.gz"/) {
  print $1;
  exit;
}
EOF
needed=$(cat libs/build-all.sh | perl -ne "$p")
current='[% c("var/nss_version") %]-with-nspr-[% c("var/nspr_version") %]'
check_update_needed nss-nspr "$needed" "$current"

# uniffi
read -d '' p << 'EOF' || true
if (m/^\\s*uniffi\\s*=\\s*"([^"]*)"/) {
  print $1;
  exit;
}
EOF
needed=$(cat Cargo.toml | perl -ne "$p")
current='[% pc("uniffi-rs", "version") %]'
check_update_needed uniffi "$needed" "$current"
