summaryrefslogtreecommitdiff
path: root/etc
diff options
context:
space:
mode:
authorEfraim Flashner <efraim@flashner.co.il>2026-04-21 12:33:54 +0300
committerEfraim Flashner <efraim@flashner.co.il>2026-04-21 17:05:52 +0300
commit6a2c7213665a34ff09b0a0fa95d52f1f8708d63f (patch)
tree712981cd079def6fe516ac89d86e5f24941b9aa1 /etc
parent7a3739951208b91fa144c4835ee9006198ff0fe4 (diff)
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
Diffstat (limited to 'etc')
-rwxr-xr-xetc/teams/rust/audit-rust-crates87
1 files changed, 63 insertions, 24 deletions
diff --git a/etc/teams/rust/audit-rust-crates b/etc/teams/rust/audit-rust-crates
index d5546fd1e1..bf0479a7c4 100755
--- a/etc/teams/rust/audit-rust-crates
+++ b/etc/teams/rust/audit-rust-crates
@@ -1,6 +1,6 @@
#!/usr/bin/env -S gawk -f
# 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.
#
@@ -21,20 +21,22 @@
# ./etc/teams/rust/audit-rust-crates ./path/to/file.scm
# Prints the output of cargo-audit to the shell.
-# Make sure we have cargo-audit in our PATH
BEGIN {
- if (system("which cargo-audit 1> /dev/null"))
- exit 1;
+ "which cargo-audit" | getline cargoAudit
+ close("which cargo-audit")
+ cargoAudit = cargoAudit " audit --file -"
+
# Parse a record at a time.
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/ {
for(i=3; i <= NF-2; i++) {
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
}
}
@@ -44,27 +46,64 @@ BEGIN {
/crate-uri/ {
for(i=3; i <= NF; i++) {
if($i == "(version")
- crateVersion = $(i+1)
+ crateVersion = $(i+1)
if($i == "(crate-uri")
- crateName = $(i+1)
+ crateName = $(i+1)
}
gsub(/)/, "", crateVersion)
cargoLock = cargoLock "[[package]]\nname = " crateName "\nversion = " crateVersion "\n"
+ next
+}
+
+# Parse the crates created from packages using 'cargo package'
+/package:rust/ {
+ pkg = $2
+ split(pkg, name_version, "-")
+ crateVersion = name_version[length(name_version)]
+ crateName = substr(pkg, 6, (length(pkg) - length(crateVersion) - 6))
+ split(crateVersion, versionDots, ".")
+ if(crateVersion && (crateVersion != "(git-version") && (length(versionDots) == 3) && crateName) {
+ cargoLock = cargoLock "[[package]]\nname = \"" crateName "\"\nversion = \"" crateVersion "\"\n"
+ } else {
+ untested++
+ #print("Unable to test " $0)
+ }
+ next
+}
+
+# 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
}
-# The xxxx-cargo-input variables have a set style
-# TODO: Replace the last dash between the name and the version with a space!
-# This doesn't take into account swapping between "-" and "_" so we skip it.
-#( $2 ~ /-cargo-inputs/ ) {
-# sub(/-cargo-inputs/, "", $2)
-# gsub(/)/, "", $0)
-# gsub(/rust-/, "", $0)
-# #gensub(/([[:alpha:]])-([[:digit:]]+)/, "\\1 \\2", "g", $i)
-# print "[[package]]\nname = \"" $2 "\"\nversion = \"1.0.0\"\ndependencies = ["
-# for (i = 4; i <= NF; i++) {
-# print "\"" $i "\","
-# }
-# print "]"
-#}
+# Note those which we were unable to parse
+/define rust/ {
+ if($3 == "#f)")
+ next
+ print("Unable to parse " $0)
+ }
+
+{ untested++ }
-END { print cargoLock | cargoAudit }
+END { print("Number of crates untested: " untested); print cargoLock | cargoAudit }