[vlc-devel] [PATCH 5/8] contrib: add cargo-vendor-archive.sh script

Romain Vimont rom1v at videolabs.io
Tue Aug 25 22:13:56 CEST 2020


On Tue, Aug 25, 2020 at 04:45:06PM +0200, Thomas Guillem wrote:
> This script can be used to package a cargo vendor archive containing all
> dependencies of a Rust project. If this archive is uploaded to the VideoLAN
> FTP, the contrib's cargo will try to use it instead of using crates.io.
> 
> This will also allow us to keep all Rust dependencies.
> ---
>  contrib/cargo-vendor-archive.sh | 53 +++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
>  create mode 100755 contrib/cargo-vendor-archive.sh
> 
> diff --git a/contrib/cargo-vendor-archive.sh b/contrib/cargo-vendor-archive.sh
> new file mode 100755
> index 00000000000..dc7aeef0004
> --- /dev/null
> +++ b/contrib/cargo-vendor-archive.sh
> @@ -0,0 +1,53 @@
> +#!/bin/sh
> +
> +set -e
> +
> +usage()
> +{
> +cat << EOF
> +usage: $0 <archive>
> +
> +Fetch and archive all dependencies from a Rust archive using 'cargo vendor'.
> +EOF
> +}
> +
> +if [ "x$1" = "x" ]; then
> +    usage
> +    exit 1
> +fi
> +
> +# Setup cargo path
> +CARGO=
> +if [ -d "$(dirname $0)/bin/.cargo" ];then
> +    CARGO_HOME=$(realpath $(dirname $0)/bin/.cargo)
> +    CARGO="CARGO_HOME=\"${CARGO_HOME}\" ${CARGO_HOME}/bin/cargo"

You should probably escape-quote ${CARGO_HOME} too, in case it contains
a space:

    $ CARGO_HOME='abc def'
    $ CARGO="CARGO_HOME=\"${CARGO_HOME}\" ${CARGO_HOME}/bin/cargo"
    $ eval printf '%s\\n' ${CARGO} vendor --locked
    CARGO_HOME=abc def
    abc
    def/bin/cargo
    vendor
    --locked

vs:

    $ CARGO_HOME='abc def'
    $ CARGO="CARGO_HOME=\"${CARGO_HOME}\" \"${CARGO_HOME}\"/bin/cargo"
    $ eval printf '%s\\n' ${CARGO} vendor --locked
    CARGO_HOME=abc def
    abc def/bin/cargo
    vendor
    --locked

(But maybe not using "eval" at all would be a better solution.)

> +else
> +    CARGO=cargo
> +fi
> +
> +# Extract archive into a tmp dir
> +TMP_DIR=.tmp-$(basename $1)
> +rm -rf ${TMP_DIR}
> +mkdir ${TMP_DIR}
> +
> +tar xf $1 -C ${TMP_DIR}

"$1"

> +cd ${TMP_DIR}/*
> +
> +# Fetch all dependencies
> +eval ${CARGO} vendor --locked
> +
> +# Archive all dependencies
> +name=$(basename `pwd`)-vendor
> +tar -jcf ${name}.tar.bz2 vendor --transform "s,vendor,${name},"
> +
> +mv ${name}.tar.bz2 ../..

"$name"

> +cd ../..
> +
> +rm -rf ${TMP_DIR}
> +
> +echo ""
> +echo "Please upload this package'${name}.tar.bz2' to our VideoLAN FTP,"

(missing space)

> +echo ""
> +echo "and write the following checksum into the contrib/src/<project>/cargo-vendor-SHA512SUMS:"
> +echo ""
> +sha512sum ${name}.tar.bz2
> -- 
> 2.28.0
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list