Skip to content

Commit

Permalink
Mk/Uses/cargo.mk: Support new Cargo.lock format
Browse files Browse the repository at this point in the history
The new format [1,2] dropped the [metadata] table.  As a consequence
our cargo-crates.awk script no longer outputs CARGO_CRATES.  We can
get the crate list from the various [[package]] tables instead.
This should work with the new as well as the old format.

[1] rust-lang/cargo#7070
[2] rust-lang/cargo#7579

PR:		242416
Reported by:	jbeich
  • Loading branch information
tobik authored and tobik committed Dec 5, 2019
1 parent 3e3c773 commit f3304ef
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions Mk/Scripts/cargo-crates.awk
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,47 @@ BEGIN {
gl_tuple_len = 0
crates_len = 0
package_name = "<unknown>"
crate_name = "<unknown>"
crate_version = "<unknown>"
crate_source = "<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\+.*\)" = ".*"/ {
# $2: crate
# $3: version
# $4: url
# $6: checksum
crates[crates_len++] = sprintf("%s-%s", $2, $3)
}

/^name = ".*"/ {
crate_name = $3
gsub(/"/, "", crate_name)

package_name = $3
gsub("[^a-zA-Z_]", "", package_name)
}

/^version = ".*"/ {
crate_version = $3
gsub(/"/, "", crate_version)
}

/^source = ".*"/ {
crate_source = $3
gsub(/"/, "", crate_source)
}

/^\[\[package\]\]$/ {
add_crate()
}

function add_crate() {
if (crate_source == "registry+https://github.com/rust-lang/crates.io-index") {
crates[crates_len++] = sprintf("%s-%s", crate_name, crate_version)
}
crate_name = "<unknown>"
crate_version = "<unknown>"
crate_source = "<unknown>"
}

function split_url(s) {
# scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment]
split(s, url_scheme, "://")
Expand Down Expand Up @@ -112,6 +133,8 @@ function print_array(start, arr, arrlen) {
}

END {
add_crate()

if (gh_tuple_len > 0 && ENVIRON["USE_GITHUB"] == "") {
printf "USE_GITHUB=\tnodefault\n"
}
Expand Down

0 comments on commit f3304ef

Please sign in to comment.