Getting updated cargo.crates

Austin Ziegler halostatue at gmail.com
Thu Nov 30 17:46:54 UTC 2023


I was opening a new PR to update a Rust dependency today and could not
figure out how to update the `cargo.crates` section. Digging through the
cargo-fetch portgroup pointed me to
https://github.com/macports/macports-contrib/tree/master/cargo2port/cargo2port.tcl,
which fails to run because the Cargo.lock format appears not to be the same
as it was when written.

Using toml2json (from the Python remarshal package) and jq, I managed to
make a simple bash function that does the same thing, more or less. It
*always* prints using the max name / version lengths and it requires that
`Cargo.lock` be in the current directory, but these are small prices to
pay. This may also be simplified if you have
https://github.com/simonrupf/convert2json installed, where I believe you
could simply use `tq` (this is not currently available as a port; adding
one won't be hard, but feature selection will be tricky because it attempts
to install a `yq` binary by default, making it conflict with the yq port).

cargo2port() {
  toml2json Cargo.lock | jq -r $'
  def lpad($len; $fill): tostring | ($len - length) as $l | ($fill *
$l)[:$l] + .;
  def lpad($len): lpad($len; " ");
  def rpad($len; $fill): tostring | ($len - length) as $l | . + ($fill *
$l)[:$l];
  def rpad($len): rpad($len; " ");
  .package |
    map(select(.checksum != null)) |
    (. | max_by(.name | length) | .name | length) as $max_name |
    (. | max_by(.version | length) | .version | length) as $max_version |
    map("    \(.name | rpad($max_name))  \(.version | lpad($max_version))
 \(.checksum)") |
    join(" \\\\\n") as $body |
    "cargo.crates \\\\\n\($body)"
'
}

In any case, I hope this helps anyone else who wants to modify a Rust port.

-a
-- 
Austin Ziegler • halostatue at gmail.comaustin at halostatue.ca
http://www.halostatue.ca/http://twitter.com/halostatue
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macports.org/pipermail/macports-dev/attachments/20231130/c213f587/attachment.htm>


More information about the macports-dev mailing list