Skip to content

Commit

Permalink
Scripts/cargo-crates.awk: Move split_url() to separate file
Browse files Browse the repository at this point in the history
Also stop leaking local variables
  • Loading branch information
Tobias Kortkamp authored and Tobias Kortkamp committed Sep 7, 2021
1 parent 0ef8700 commit d8fbaa5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
30 changes: 0 additions & 30 deletions Mk/Scripts/cargo-crates.awk
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,6 @@ function add_crate() {
crate_source = "<unknown>"
}

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]
}

!gh_tuple_seen[$0] && /^source = "git\+(https|http|git):\/\/.*\/.*#.*"/ {
gh_tuple_seen[$0] = 1
split_url(substr($3, 1 + length("\"git+"), length($3) - 1 - length("\"git+")))
Expand Down
29 changes: 29 additions & 0 deletions Mk/Scripts/split-url.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function split_url(s, url_scheme, url_fragment, url_query, url_authority, url_auth, url_user, url_host) {
# 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]
}
2 changes: 1 addition & 1 deletion Mk/Uses/cargo.mk
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ cargo-crates: extract
--verbose; \
fi
@${SETENV} USE_GITHUB=${USE_GITHUB} USE_GITLAB=${USE_GITLAB} GL_SITE=${GL_SITE} \
${AWK} -f ${SCRIPTSDIR}/cargo-crates.awk ${CARGO_CARGOLOCK}
${AWK} -f ${SCRIPTSDIR}/split-url.awk -f ${SCRIPTSDIR}/cargo-crates.awk ${CARGO_CARGOLOCK}

# cargo-crates-licenses will try to grab license information from
# all downloaded crates.
Expand Down

0 comments on commit d8fbaa5

Please sign in to comment.