From: Ian Jackson Date: Sun, 18 Apr 2021 20:33:41 +0000 (+0100) Subject: update-cargo-metadata: New maintenance script X-Git-Tag: otter-0.5.0~15 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=356b03fc7fffe049508e0ed262c7ebdef1612dcb;p=otter.git update-cargo-metadata: New maintenance script Signed-off-by: Ian Jackson --- diff --git a/update-cargo-metadata b/update-cargo-metadata new file mode 100755 index 00000000..f86ce6b9 --- /dev/null +++ b/update-cargo-metadata @@ -0,0 +1,42 @@ +#!/bin/bash +# usage: +# ./update-cargo-metadata +# copies from toplevel Cargo.toml to others +# the part copied is the paragraph which starts with version= + +set -e + +fail () { echo >&2 "${0##*/}: error: $*"; exit 12; } + +[ $# = 0 ] || fail "bad usage" + +files=$(git ls-files :\*/Cargo.toml :Cargo.toml) + +for f in $files; do + perl -i~ -pe ' + BEGIN { + $/ = "\n\n"; + open I, "Cargo.toml" or die $!; + our $re = qr{^version\s*\=}; + our $std; + while () { + next unless m{$re}; + $std = $_; + last; + } + die "not found in ./Cargo.toml" unless defined $std; +# $std =~ s{\s*$}{}; + } + + next unless m{$re}; + next if $y++; +# s{\s*$}{};; +# $_ = $std.$&; + $_ = $std; + END { + $y or die "not found in '$f'"; + } + ' $f +done + +echo "working tree file(s) maybe updated, check with git."