Getting updated cargo.crates

Herby G herby.gillot at gmail.com
Thu Nov 30 22:37:16 UTC 2023


You can check out `cargo2port` ( https://ports.macports.org/port/cargo2port/
), and I have a similar utility here:
https://github.com/herbygillot/cargo2ports

On Thu, Nov 30, 2023 at 2:07 PM Austin Ziegler <halostatue at gmail.com> wrote:

> 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/52c1b9e1/attachment.htm>


More information about the macports-dev mailing list