]> git.pld-linux.org Git - packages/rpm-build-tools.git/commitdiff
rust-crates: add support for non-top level (located in subdir) rust packages
authorJan Palus <atler@pld-linux.org>
Sat, 3 Sep 2022 10:56:54 +0000 (12:56 +0200)
committerJan Palus <atler@pld-linux.org>
Sat, 3 Sep 2022 10:56:54 +0000 (12:56 +0200)
rust-crates.sh

index 8e245bcc82f9271bc43354e19bbe6551e0f04e36..24cebe189386435f5f6a272492032fdcca5d3706 100755 (executable)
@@ -5,6 +5,7 @@ usage() {
   echo
   echo "\t-p <package_name>\tforce cargo <package_name> for version override instead of automatic detection"
   echo "\t-o <crates_file>\tforce output file name instead of automatically determined name"
+  echo "\t-d <src subdirectory>\tsubdirectory within source directory where rust sources are located"
   echo "\t-f\t\t\toverwrite creates file if it already exists"
   echo "\t-v\t\t\tset cargo package version to @@VERSION@@ for easier crates tarball reuse"
   echo "\t-h\t\t\tprint this help"
@@ -23,7 +24,7 @@ if [ -n "$not_installed" ]; then
   exit 1
 fi
 
-while getopts :p:o:fvh OPTNAME; do
+while getopts :p:o:d:fvh OPTNAME; do
   case $OPTNAME in
     p)
       force_cargo_package="$OPTARG"
@@ -34,6 +35,9 @@ while getopts :p:o:fvh OPTNAME; do
     o)
       crates_file="$OPTARG"
       ;;
+    d)
+      subdir="$OPTARG"
+      ;;
     v)
       version_override=1
       ;;
@@ -105,7 +109,7 @@ if [ $(echo "$src_dir" | wc -l) -ne 1 ]; then
   exit 1
 fi
 
-cd "$src_dir"
+cd "$src_dir${subdir:+/$subdir}"
 cargo vendor
 if [ $? -ne 0 ]; then
   echo "ERROR: cargo vendor failed" >&2
@@ -128,8 +132,8 @@ if [ -n "$version_override" ]; then
   perl -pi -e 'BEGIN { undef $/;} s/(\[\[package\]\]\nname\s*=\s*"'"$cargo_package"'"\nversion\s*=\s*")[^"]+/$1\@\@VERSION\@\@/m' Cargo.lock
 fi
 
-cd ..
-tar cJf "$pkg_dir/$crates_file" "$src_dir"/{Cargo.lock,vendor}
+cd "$tmpdir"
+tar cJf "$pkg_dir/$crates_file" "$src_dir${subdir:+/$subdir}"/{Cargo.lock,vendor}
 echo "Created $pkg_dir/$crates_file"
 
 # vim: expandtab shiftwidth=2 tabstop=2
This page took 0.124091 seconds and 4 git commands to generate.