commit: 29ee4443ea44db1227b22e0b68b1351686a22c5a
Author: Doug Goldstein <cardoe <AT> gentoo <DOT> org>
AuthorDate: Fri Nov 25 15:46:24 2016 +0000
Commit: Doug Goldstein <cardoe <AT> gentoo <DOT> org>
CommitDate: Wed Nov 30 17:17:51 2016 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=29ee4443
eclass/cargo: support cargo dependency vendoring
Add support for newer dependency vendoring which allows us to download
the dependencies with the package manager and just have cargo use that
to compile the package.
Signed-off-by: Doug Goldstein <cardoe <AT> gentoo.org>
eclass/cargo.eclass | 57 +++++++++++++++++++++++++++++++++++------------------
1 file changed, 38 insertions(+), 19 deletions(-)
diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index 19c66c8..f2b2b12 100644
--- a/eclass/cargo.eclass
+++ b/eclass/cargo.eclass
@@ -22,11 +22,7 @@ EXPORT_FUNCTIONS src_unpack src_compile src_install
IUSE="${IUSE} debug"
ECARGO_HOME="${WORKDIR}/cargo_home"
-#ECARGO_REPO="github.com-88ac128001ac3a9a"
-ECARGO_REPO="github.com-1ecc6299db9ec823"
-ECARGO_INDEX="${ECARGO_HOME}/registry/index/${ECARGO_REPO}"
-ECARGO_SRC="${ECARGO_HOME}/registry/src/${ECARGO_REPO}"
-ECARGO_CACHE="${ECARGO_HOME}/registry/cache/${ECARGO_REPO}"
+ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
# @FUNCTION: cargo_crate_uris
# @DESCRIPTION:
@@ -47,18 +43,29 @@ cargo_crate_uris() {
cargo_src_unpack() {
debug-print-function ${FUNCNAME} "$@"
- mkdir -p "${ECARGO_INDEX}" || die
- mkdir -p "${ECARGO_CACHE}" || die
- mkdir -p "${ECARGO_SRC}" || die
+ mkdir -p "${ECARGO_VENDOR}" || die
mkdir -p "${S}" || die
local archive
for archive in ${A}; do
case "${archive}" in
*.crate)
- ebegin "Unpacking ${archive}"
- cp "${DISTDIR}"/${archive} "${ECARGO_CACHE}/"
|| die
- tar -xf "${DISTDIR}"/${archive} -C
"${ECARGO_SRC}/" || die
+ ebegin "Loading ${archive} into Cargo registry"
+ tar -xf "${DISTDIR}"/${archive} -C
"${ECARGO_VENDOR}/" || die
+ # generate sha256sum of the crate itself as
cargo needs this
+ shasum=$(sha256sum "${DISTDIR}"/${archive} |
cut -d ' ' -f 1)
+ pkg=$(basename ${archive} .crate)
+ cat <<- EOF >
${ECARGO_VENDOR}/${pkg}/.cargo-checksum.json
+ {
+ "package": "${shasum}",
+ "files": {}
+ }
+ EOF
+ # if this is our target package we need it in
${WORKDIR} too
+ # to make ${S} (and handle any revisions too)
+ if [[ ${P} == ${pkg}* ]]; then
+ tar -xf "${DISTDIR}"/${archive} -C
"${WORKDIR}" || die
+ fi
eend $?
;;
cargo-snapshot*)
@@ -70,18 +77,29 @@ cargo_src_unpack() {
touch "${S}"/target/snapshot/bin/cargo || die
eend $?
;;
- cargo-registry*)
- ebegin "Unpacking ${archive}"
- tar -xzf "${DISTDIR}"/${archive} -C
"${ECARGO_INDEX}" --strip-components 1 || die
- # prevent cargo from attempting to download
this again
- touch "${ECARGO_INDEX}"/.cargo-index-lock || die
- eend $?
- ;;
*)
unpack ${archive}
;;
esac
done
+
+ cargo_gen_config
+}
+
+# @FUNCTION: cargo_gen_config
+# @DESCRIPTION:
+# Generate the $CARGO_HOME/config necessary to use our local registry
+cargo_gen_config() {
+ debug-print-function ${FUNCNAME} "$@"
+
+ cat <<- EOF > ${ECARGO_HOME}/config
+ [source.gentoo]
+ directory = "${ECARGO_VENDOR}"
+
+ [source.crates-io]
+ replace-with = "gentoo"
+ local-registry = "/nonexistant"
+ EOF
}
# @FUNCTION: cargo_src_compile
@@ -92,7 +110,8 @@ cargo_src_compile() {
export CARGO_HOME="${ECARGO_HOME}"
- cargo build -v $(usex debug "" --release)
+ cargo build -v $(usex debug "" --release) \
+ || die "cargo build failed"
}
# @FUNCTION: cargo_src_install