Closed flukejones closed 4 years ago
Thanks for the feedback @Luke-Nukem, maybe we can join efforts here. :)
I don't do much with Python, but I'll certainly have a go at it. I was considering the use of this service combined with another service named cargo_deny
, which would use this amazing tool to check licenses etc.
I would strongly prefer if we used a much simpler script here. I currently use this:
#!/bin/bash
#defaults
SOURCE=""
BASE_DIR="$(pwd)"
SRC_DIR="$(pwd)"
EXT_DIR="$(pwd)"
while test $# -gt 0; do
case $1 in
*-source)
if test -n "$SOURCE"; then
echo Source is defined twiced.
exit 1
fi
SOURCE="$2"
shift
;;
*-outdir)
# just dummy ...
MYOUTDIR="$2"
shift
;;
*)
echo Unknown parameter $1.
echo 'Usage: crate-do-vendor --source $SOURCE'
exit 1
;;
esac
shift
done
if [ -z "$SOURCE" ]; then
SOURCE="*.tar.gz"
fi
# If the archive is a blob of files with no root dir create a tmp dir
# otherwise we find the root dir name, or default to a directory input.
# The later case is valuable for working with SCM sources
if [ ! -d $SOURCE ] && [ $(tar --exclude="*/*" -tf $SOURCE |wc -l) -gt 1 ]; then
mkdir tmp
SRC_DIR="tmp"
EXT_DIR=$SRC_DIR
elif [ ! -d $SOURCE ] && [ $(tar --exclude="*/*" -tf $SOURCE |wc -l) = 1 ]; then
SRC_DIR="$(tar --exclude="*/*" -tf $SOURCE)"
elif [ -d $SOURCE ]; then
SRC_DIR="$SOURCE"
fi;
if [ "${SOURCE%.tar.gz}" != "$SOURCE" ]; then
tar xfz $SOURCE -C "$EXT_DIR" || exit 1
elif [ "${SOURCE%.tar.bz2}" != "$SOURCE" ]; then
tar xfj $SOURCE -C "$EXT_DIR" || exit 1
elif [ "${SOURCE%.tar.xz}" != "$SOURCE" ]; then
tar xfJ $SOURCE -C "$EXT_DIR" || exit 1
elif [ "${SOURCE%.tar}" != "$SOURCE" ]; then
tar xf $SOURCE -C "$EXT_DIR" || exit 1
elif [ -d "$SOURCE" ]; then
echo "$SOURCE is a directory" || exit 1
else
echo "ERROR: unknown archive format $SOURCE"
exit 1
fi
cd $BASE_DIR/$SRC_DIR
cargo vendor | head -n -1 > $BASE_DIR/cargo_config
echo 'directory = "vendor"' >> $BASE_DIR/cargo_config
tar pcfJ vendor.tar.xz vendor
mv vendor.tar.xz $BASE_DIR
echo "
The following should be added to your spec file:
%global rustflags '-Clink-arg=-Wl,-z,relro,-z,now'
Source1: vendor.tar.xz
Source2: cargo_config
%prep
%setup -qa1
mkdir .cargo
cp %{SOURCE2} .cargo/config
%build
RUSTFLAGS=%{rustflags} cargo build --release
%install
RUSTFLAGS=%{rustflags} cargo install --root=%{buildroot}%{_prefix} --path .
"
# Cleanup
echo "Removing $SOURCE/vendor"
rm -rf vendor
if [ ! -d "$SOURCE" ]; then
echo "$SOURCE was an archive, removing unpacked directory" || exit 1
rm -rf $BASE_DIR/$SRC_DIR
fi
The benefits it provides are that it is smaller and easier to work with, and if the vendored sources change then the initial cargo config file is updated without requiring the package maintainer to update the spec file manually. The service file looks like:
<services>
<service name="rust_vendor" mode="disabled">
<param name="source">mdcat-*.tar.gz</param>
</service>
</services>
Ignore the above. I'm working on the main python script now to fix a few things and add ability to use a directory - this does work much better due to the helper funcs to find the Cargo.toml.
A PR will be incoming soon.
Awesome to read, thank you! :)
I started on a similar service a little while ago here. The main difference being that it can allow specifying a plain directory to run vendor in, which allows the use of it just after a git repo pull with
obs_scm
.Seeing as this repo is in the main openSUSE lot, it would be great to see this.