1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-12-20 04:02:27 +00:00
freebsd-ports/Mk/Scripts/cargo-crates.awk
Tobias Kortkamp 05b30a8d06 When specifying Git dependencies in Cargo.toml developers can set 3
additional keys: rev, branch, tag [1].  These are reflected in a
projects' Cargo.lock file as e.g.

git+https://github.com/servo/angle?branch=servo#a1371e8a160128677af863d1d73f150862ba42b2
git+https://github.com/rust-lang/libc?tag=0.2.26#288942e6858a4b2f8ee56338da5386263b9c4b82

Currently cargo-crates.awk generates the wrong output in these cases:

GH_TUPLE=	servo:angle?branch=servo:a1371e8a160128677af863d1d73f150862ba42b2:angle \
		rust-lang:libc?tag=0.2.26:288942e6858a4b2f8ee56338da5386263b9c4b82:libc

Fix cargo-crates.awk to ignore the query string (except in the tag
case) and generate

GH_TUPLE=	servo:angle:a1371e8a160128677af863d1d73f150862ba42b2:angle \
		rust-lang:libc:0.2.26:libc

instead.

[1] https://github.com/rust-lang/cargo/blob/master/src/doc/specifying-dependencies.md#specifying-dependencies-from-git-repositories

PR:		220548
Reported by:	jbeich
Reviewed by:	jbeich, mat
Differential Revision:	https://reviews.freebsd.org/D11571
2017-07-19 14:00:16 +00:00

92 lines
1.9 KiB
Awk

# MAINTAINER: ports@FreeBSD.org
# $FreeBSD$
BEGIN {
gh_tuple_len = 0
crates_len = 0
package_name = "<unknown>"
}
/^"checksum .* .* \(registry\+.*\)" = ".*"/ {
# $2: crate
# $3: version
# $4: url
# $6: checksum
crates[crates_len++] = sprintf("%s-%s", $2, $3)
}
/^name = ".*"/ {
package_name = $3
gsub("[^a-zA-Z_]", "", package_name)
}
function split_url(s) {
# scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment]
split(s, url_scheme, "://")
url["scheme"] = url_scheme[1]
split(url_scheme[2], url_fragment, "#")
url["fragment"] = url_fragment[2]
split(url_fragment[1], url_query, "?")
url["query"] = url_query[2]
split(url_query[1], url_authority, "/")
url["path"] = substr(url_query[1], length(url_authority[1]) + 1)
split(url_authority[1], url_auth, "@")
if (length(url_auth) == 2) {
split(url_auth[1], url_user, ":")
url["user"] = url_user[1]
url["password"] = url_user[2]
split(url_auth[2], url_host, ":")
} else {
url["user"] = ""
url["password"] = ""
split(url_auth[1], url_host, ":")
}
url["host"] = url_host[1]
url["port"] = url_host[2]
}
/^source = "git\+(https|http|git):\/\/github.com\/.*#.*"/ {
split_url(substr($3, 1, length($3) - 1))
split(url["path"], path, "/")
account = path[2]
project = path[3]
gsub("\.git$", "", project)
if (match(url["query"], "^tag=")) {
split(url["query"], tag_, "=")
tag = tag_[2]
} else {
tag = url["fragment"]
}
gh_tuple[gh_tuple_len++] = sprintf(\
"%s:%s:%s:%s", account, project, tag, package_name)
}
function print_array(start, arr, arrlen) {
end = " \\\n"
for (i = 0; i < arrlen; i++) {
if (i == arrlen - 1) {
end = "\n"
}
printf "%s\t%s%s", start, arr[i], end
start = "\t"
}
}
END {
if (gh_tuple_len > 0 && ENVIRON["USE_GITHUB"] == "") {
printf "USE_GITHUB=\tnodefault\n"
}
print_array("GH_TUPLE=", gh_tuple, gh_tuple_len)
print_array("CARGO_CRATES=", crates, crates_len)
if (gh_tuple_len > 0) {
printf "CARGO_USE_GITHUB=\tyes\n"
}
}