Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 630428 - cargo.eclass should properly parse semantic versions
Summary: cargo.eclass should properly parse semantic versions
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Rust Project
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-08 21:42 UTC by Stephen Demos
Modified: 2017-09-09 13:30 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephen Demos 2017-09-08 21:42:29 UTC
The cargo.eclass cargo_crate_uris function fails when the crate has prerelease information in the version number. An example of a widely used crate which recently had this problem is error_chain (https://crates.io/crates/error-chain/0.11.0-rc.2). It attempts to get the package from https://crates.io/api/v1/crates/error-chain-0.11.0/rc.2/download instead of from https://crates.io/api/v1/crates/error-chain/0.11.0-rc.2/download, because the variable expansion breaks the crate name at the last hyphen. Crates on crates.io follow the semantic version spec (http://semver.org/) which allows for dashes in the version number when specifying a pre-release version.
Comment 1 Dirkjan Ochtman (RETIRED) gentoo-dev 2017-09-09 13:30:30 UTC
I've fixed this (somewhat crudely) in 22e6f49add5eb11715f230a50790c0eecf4f5f1f:

--- a/eclass/cargo.eclass
+++ b/eclass/cargo.eclass
@@ -31,9 +31,14 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
 cargo_crate_uris() {
 	local crate
 	for crate in "$@"; do
-		local name version url
+		local name version url pretag
 		name="${crate%-*}"
 		version="${crate##*-}"
+		pretag="[a-zA-Z]+"
+		if [[ $version =~ $pretag ]]; then
+			version="${name##*-}-${version}"
+			name="${name%-*}"
+		fi
 		url="https://crates.io/api/v1/crates/${name}/${version}/download -> ${crate}.crate"
 		echo "${url}"
 	done

This at least let me bump cargo to 0.21.0, which indeed suffers from the error-chain rc dependency mentioned.