added script for creating crates tarball
authorJan Palus <atler@pld-linux.org>
Fri, 5 Feb 2021 16:52:53 +0000 (17:52 +0100)
committerJan Palus <atler@pld-linux.org>
Fri, 5 Feb 2021 18:13:13 +0000 (19:13 +0100)
create-crates.sh [new file with mode: 0755]
delta.spec

diff --git a/create-crates.sh b/create-crates.sh
new file mode 100755 (executable)
index 0000000..414c80c
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+for cmd in bsdtar rpm-specdump cargo; do
+  if ! command -v $cmd > /dev/null 2> /dev/null; then
+    not_installed="$not_installed$cmd "
+  fi
+done
+
+if [ -n "$not_installed" ]; then
+  echo "ERROR: required commands not found: $not_installed" >&2
+  exit 1
+fi
+
+pkg_dir=$(readlink -f $(dirname "$0"))
+pkg_name=$(basename "$pkg_dir")
+
+if [ ! -f "$pkg_dir/$pkg_name.spec" ]; then
+  echo "ERROR: unable to determine package name" >&2
+  exit 1
+fi
+
+spec_dump=$(rpm-specdump "$pkg_dir/$pkg_name.spec")
+pkg_version=$(echo "$spec_dump" | grep PACKAGE_VERSION | cut -f3 -d' ')
+pkg_src=$(basename $(echo "$spec_dump" | grep SOURCEURL0 | cut -f3- -d' '))
+crates_file="$pkg_name-crates-$pkg_version.tar.xz"
+
+if [ -e "$pkg_dir/$crates_file" ]; then
+  echo "ERROR: crates file $crates_file already exists" >&2
+  exit 1
+fi
+
+if [ ! -f "$pkg_dir/$pkg_src" ]; then
+  echo "ERROR: source file $pkg_src not found" >&2
+  exit 1
+fi
+
+tmpdir=$(mktemp -d)
+
+rm_tmpdir() {
+  if [ -n "$tmpdir" -a -d "$tmpdir" ]; then
+    rm -rf "$tmpdir"
+  fi
+}
+
+trap rm_tmpdir EXIT INT HUP
+
+cd "$tmpdir"
+bsdtar xf "$pkg_dir/$pkg_src"
+src_dir=$(ls)
+if [ $(echo "$src_dir" | wc -l) -ne 1 ]; then
+  echo "ERROR: unexpected source structure:\n$src_dir" >&2
+  exit 1
+fi
+
+cd "$src_dir"
+cargo vendor
+if [ $? -ne 0 ]; then
+  echo "ERROR: cargo vendor failed" >&2
+  exit 1
+fi
+
+cd ..
+tar cJf "$pkg_dir/$crates_file" "$src_dir"/{Cargo.lock,vendor}
+
+# vim: expandtab shiftwidth=2 tabstop=2
index f3cff42baaaefcbcbd3c52627fd6a72c8ceb06ae..bb6abebc895523274f744e6e79c1279cd394d66d 100644 (file)
@@ -6,10 +6,7 @@ License:       MIT
 Group:         Applications
 Source0:       https://github.com/dandavison/delta/archive/%{version}/%{name}-%{version}.tar.gz
 # Source0-md5: d75f73bc71407b86489eff88f837274d
-# cd delta-%{version}
-# cargo vendor
-# cd ..
-# tar cJf delta-crates-%{version}.tar.xz delta-%{version}/{vendor,Cargo.lock}
+# ./create-crates.sh
 Source1:       %{name}-crates-%{version}.tar.xz
 # Source1-md5: 55f896f9511f16f17d8d209d903904f1
 URL:           https://github.com/dandavison/delta
This page took 0.086073 seconds and 4 git commands to generate.