mirror of
https://codeberg.org/guix/guix.git
synced 2026-04-28 06:34:05 +00:00
teams: rust: Improve audit-rust-crates script.
* etc/teams/rust/audit-rust-crates: Count the number of untested crates and print them at the end of running the script. [Begin]: Close open file descriptor. [crate-source]: Use variables. [package:rust, git-reference]: New matches. Change-Id: If3d9dec79175dfa521a4dfa54d2fedf69712d96e
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env -S gawk -f
|
#!/usr/bin/env -S gawk -f
|
||||||
# GNU Guix --- Functional package management for GNU
|
# GNU Guix --- Functional package management for GNU
|
||||||
# Copyright © 2025 Efraim Flashner <efraim@flashner.co.il>
|
# Copyright © 2025, 2026 Efraim Flashner <efraim@flashner.co.il>
|
||||||
#
|
#
|
||||||
# This file is part of GNU Guix.
|
# This file is part of GNU Guix.
|
||||||
#
|
#
|
||||||
@@ -21,20 +21,22 @@
|
|||||||
# ./etc/teams/rust/audit-rust-crates ./path/to/file.scm
|
# ./etc/teams/rust/audit-rust-crates ./path/to/file.scm
|
||||||
# Prints the output of cargo-audit to the shell.
|
# Prints the output of cargo-audit to the shell.
|
||||||
|
|
||||||
# Make sure we have cargo-audit in our PATH
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
if (system("which cargo-audit 1> /dev/null"))
|
"which cargo-audit" | getline cargoAudit
|
||||||
exit 1;
|
close("which cargo-audit")
|
||||||
|
cargoAudit = cargoAudit " audit --file -"
|
||||||
|
|
||||||
# Parse a record at a time.
|
# Parse a record at a time.
|
||||||
RS = "\n\n"
|
RS = "\n\n"
|
||||||
cargoAudit = "cargo-audit audit --file -"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check the crate-source origin-only inputs
|
# Check the crate-source origin-only inputs, like in rust-crates.scm
|
||||||
/crate-source/ {
|
/crate-source/ {
|
||||||
for(i=3; i <= NF-2; i++) {
|
for(i=3; i <= NF-2; i++) {
|
||||||
if($i == "(crate-source") {
|
if($i == "(crate-source") {
|
||||||
cargoLock = cargoLock "[[package]]\nname = " $(i+1) "\nversion = " $(i+2) "\n"
|
crateName = $(i+1)
|
||||||
|
crateVersion = $(i+2)
|
||||||
|
cargoLock = cargoLock "[[package]]\nname = " crateName "\nversion = " crateVersion "\n"
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,21 +52,58 @@ BEGIN {
|
|||||||
}
|
}
|
||||||
gsub(/)/, "", crateVersion)
|
gsub(/)/, "", crateVersion)
|
||||||
cargoLock = cargoLock "[[package]]\nname = " crateName "\nversion = " crateVersion "\n"
|
cargoLock = cargoLock "[[package]]\nname = " crateName "\nversion = " crateVersion "\n"
|
||||||
|
next
|
||||||
}
|
}
|
||||||
|
|
||||||
# The xxxx-cargo-input variables have a set style
|
# Parse the crates created from packages using 'cargo package'
|
||||||
# TODO: Replace the last dash between the name and the version with a space!
|
/package:rust/ {
|
||||||
# This doesn't take into account swapping between "-" and "_" so we skip it.
|
pkg = $2
|
||||||
#( $2 ~ /-cargo-inputs/ ) {
|
split(pkg, name_version, "-")
|
||||||
# sub(/-cargo-inputs/, "", $2)
|
crateVersion = name_version[length(name_version)]
|
||||||
# gsub(/)/, "", $0)
|
crateName = substr(pkg, 6, (length(pkg) - length(crateVersion) - 6))
|
||||||
# gsub(/rust-/, "", $0)
|
split(crateVersion, versionDots, ".")
|
||||||
# #gensub(/([[:alpha:]])-([[:digit:]]+)/, "\\1 \\2", "g", $i)
|
if(crateVersion && (crateVersion != "(git-version") && (length(versionDots) == 3) && crateName) {
|
||||||
# print "[[package]]\nname = \"" $2 "\"\nversion = \"1.0.0\"\ndependencies = ["
|
cargoLock = cargoLock "[[package]]\nname = \"" crateName "\"\nversion = \"" crateVersion "\"\n"
|
||||||
# for (i = 4; i <= NF; i++) {
|
} else {
|
||||||
# print "\"" $i "\","
|
untested++
|
||||||
# }
|
#print("Unable to test " $0)
|
||||||
# print "]"
|
}
|
||||||
#}
|
next
|
||||||
|
}
|
||||||
|
|
||||||
END { print cargoLock | cargoAudit }
|
# We make an attempt to create the crate name from the package name otherwise
|
||||||
|
/git-reference/ {
|
||||||
|
for(i=3; i <= NF; i++) {
|
||||||
|
if($i == "(version")
|
||||||
|
crateVersion = $(i+1)
|
||||||
|
if($i == "(name")
|
||||||
|
crateName = $(i+1)
|
||||||
|
if($i == "(git-file-name") {
|
||||||
|
crateName = $(i+1)
|
||||||
|
crateVersion = $(i+2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gsub(/)/, "", crateVersion)
|
||||||
|
gsub(/)/, "", crateName)
|
||||||
|
sub(/rust-/, "", crateName)
|
||||||
|
# The crate version MUST be major.minor.patch
|
||||||
|
split(crateVersion, versionParts, ".")
|
||||||
|
if(crateVersion && (crateVersion != "(git-version") && (length(versionParts) == 3) && crateName) {
|
||||||
|
cargoLock = cargoLock "[[package]]\nname = " crateName "\nversion = " crateVersion "\n"
|
||||||
|
} else {
|
||||||
|
untested++
|
||||||
|
#print("Unable to test " $0)
|
||||||
|
}
|
||||||
|
next
|
||||||
|
}
|
||||||
|
|
||||||
|
# Note those which we were unable to parse
|
||||||
|
/define rust/ {
|
||||||
|
if($3 == "#f)")
|
||||||
|
next
|
||||||
|
print("Unable to parse " $0)
|
||||||
|
}
|
||||||
|
|
||||||
|
{ untested++ }
|
||||||
|
|
||||||
|
END { print("Number of crates untested: " untested); print cargoLock | cargoAudit }
|
||||||
|
|||||||
Reference in New Issue
Block a user