Mk/Uses/cargo.mk: Add support for CARGO_USE_GITLAB/GL_TUPLE to cargo-crates

This commit is contained in:
Tobias Kortkamp 2019-08-06 08:12:39 +00:00
parent 06a20ec4a0
commit 076bb3ef0b
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=508234
2 changed files with 38 additions and 7 deletions

View file

@ -3,8 +3,14 @@
BEGIN {
gh_tuple_len = 0
gl_tuple_len = 0
crates_len = 0
package_name = "<unknown>"
gitlab_sites["https://gitlab.com"] = 1
gitlab_sites["https://gitlab.freedesktop.org"] = 1
gitlab_sites["https://gitlab.gnome.org"] = 1
gitlab_sites["https://gitlab.redox-os.org"] = 1
}
/^"checksum .* .* \(registry\+.*\)" = ".*"/ {
@ -50,23 +56,41 @@ function split_url(s) {
url["port"] = url_host[2]
}
!gh_tuple_seen[$0] && /^source = "git\+(https|http|git):\/\/github.com\/.*#.*"/ {
!gh_tuple_seen[$0] && /^source = "git\+(https|http|git):\/\/.*\/.*#.*"/ {
gh_tuple_seen[$0] = 1
split_url(substr($3, 1, length($3) - 1))
split_url(substr($3, 1 + length("\"git+"), length($3) - 1 - length("\"git+")))
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)
if (url["host"] == "github.com") {
gh_tuple[gh_tuple_len++] = sprintf(\
"%s:%s:%s:%s", account, project, tag, package_name)
} else {
repo_site = sprintf("%s://%s", url["scheme"], url["host"])
for (site in gitlab_sites) {
if (repo_site != site) {
continue
}
if (ENVIRON["GL_SITE"] == site) {
gl_tuple[gl_tuple_len++] = sprintf(\
"%s:%s:%s:%s", account, project, tag, package_name)
} else {
gl_tuple[gl_tuple_len++] = sprintf(\
"%s:%s:%s:%s:%s", site, account, project, tag, package_name)
}
break
}
}
}
function print_array(start, arr, arrlen) {
@ -85,8 +109,15 @@ END {
printf "USE_GITHUB=\tnodefault\n"
}
print_array("GH_TUPLE=", gh_tuple, gh_tuple_len)
if (gl_tuple_len > 0 && ENVIRON["USE_GITLAB"] == "") {
printf "USE_GITLAB=\tnodefault\n"
}
print_array("GL_TUPLE=", gl_tuple, gl_tuple_len)
print_array("CARGO_CRATES=", crates, crates_len)
if (gh_tuple_len > 0) {
printf "CARGO_USE_GITHUB=\tyes\n"
}
if (gl_tuple_len > 0) {
printf "CARGO_USE_GITLAB=\tyes\n"
}
}

View file

@ -289,7 +289,7 @@ cargo-crates: extract
--manifest-path ${CARGO_CARGOTOML} \
--verbose; \
fi
@${SETENV} USE_GITHUB=${USE_GITHUB} \
@${SETENV} USE_GITHUB=${USE_GITHUB} USE_GITLAB=${USE_GITLAB} GL_SITE=${GL_SITE} \
${AWK} -f ${SCRIPTSDIR}/cargo-crates.awk ${CARGO_CARGOLOCK}
# cargo-crates-licenses will try to grab license information from