Skip to content

Commit

Permalink
Open Cargo.toml as stdin to get the package metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
ayosec committed Aug 30, 2021
1 parent 9a96f04 commit 1448ba0
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions pkg/common/metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
#
# For every field, exports a `PACKAGE_<NAME>` variable.

set -Ce

METADATA_TABLE=''

cat "$(git rev-parse --show-toplevel)/Cargo.toml" |
while read -r LINE
do
if [[ $LINE =~ ^\[(.*)\] ]]
then
METADATA_TABLE="${BASH_REMATCH[1]}"
elif [ "$METADATA_TABLE" = package ] &&
[[ $LINE =~ ^([^[:space:]]*)[[:space:]]*=[[:space:]]*\"(.*)\" ]]
then
METADATA_VARNAME="PACKAGE_${BASH_REMATCH[1]^^}"
printf 'export %s=%q\n' "$METADATA_VARNAME" "${BASH_REMATCH[2]}"
fi
done
exec 0< "$(git rev-parse --show-toplevel)/Cargo.toml"

while read -r LINE
do
if [[ $LINE =~ ^\[(.*)\] ]]
then
METADATA_TABLE="${BASH_REMATCH[1]}"
elif [ "$METADATA_TABLE" = package ] &&
[[ $LINE =~ ^([^[:space:]]*)[[:space:]]*=[[:space:]]*\"(.*)\" ]]
then
METADATA_VARNAME="PACKAGE_${BASH_REMATCH[1]^^}"
printf 'export %s=%q\n' "$METADATA_VARNAME" "${BASH_REMATCH[2]}"
fi
done

0 comments on commit 1448ba0

Please sign in to comment.