summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
authorDoug Goldstein <cardoe@gentoo.org>2016-11-25 09:46:24 -0600
committerDoug Goldstein <cardoe@gentoo.org>2016-11-30 11:17:51 -0600
commit29ee4443ea44db1227b22e0b68b1351686a22c5a (patch)
treee74c9f42eece995648339ef87eb26c2e3b80428d /eclass
parentdev-util/cargo: preserve older build method (diff)
downloadgentoo-29ee4443ea44db1227b22e0b68b1351686a22c5a.tar.gz
gentoo-29ee4443ea44db1227b22e0b68b1351686a22c5a.tar.bz2
gentoo-29ee4443ea44db1227b22e0b68b1351686a22c5a.zip
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@gentoo.org>
Diffstat (limited to 'eclass')
-rw-r--r--eclass/cargo.eclass57
1 files changed, 38 insertions, 19 deletions
diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index 19c66c8d4aa8..f2b2b12149d1 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