Files
snapd/update-pot
Maciej Borzecki a8db1bd739 update-pot: pass flags for invoking Go set by the build process
Some packaging frameworks (dh-golang in partcular) invokes go generate. The i18n
module invokes update-pot which in turn calls go install for xgettext-go. When
building with Go modules, the build script may need to pass -mod=vendor to go
install, which can be done by setting invoke flags.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-09-09 14:26:30 +02:00

93 lines
2.6 KiB
Bash
Executable File

#!/bin/sh
# -*- Mode: sh; indent-tabs-mode: t -*-
set -eu
# In LP#1758684 we got reports that the pot file generation
# is broken. To get to the bottom of this add checks here
# so that we error the build if this happens. Note that the
# strings may be update if those change but spread tests will
# tell us when it is needed.
check_canaries() {
c1="Alternative command to run"
c2="Name of the key to use, otherwise use the default key"
c3="too many arguments for command"
c4="%d days ago, at 15:04 MST"
for canary in "$c1" "$c2" "$c3" "$c4"; do
if ! grep -q "$canary" "$OUTPUT"; then
echo "canary '$canary' not found, pot extraction broken"
ls -lh "$OUTPUT"
exit 1
fi
done
}
HERE="$(readlink -f "$(dirname "$0")")"
OUTPUT="$HERE/po/snappy.pot"
if [ -n "${1:-}" ]; then
OUTPUT="$1"
fi
# ensure we have our xgettext-go
# shellcheck disable=SC2086
go install $GOINVOKEFLAGS github.com/snapcore/snapd/i18n/xgettext-go
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
# exclude vendor and _build subdir
find "$HERE" -type d \( -name "vendor" -o -name "_build" -o -name ".git" \) -prune -o -name "*.go" -type f -printf "%P\n" > "$tmpdir/go.files"
"${GOPATH%%:*}/bin/xgettext-go" \
-f "$tmpdir/go.files" \
-D "$HERE" \
-o "$OUTPUT" \
--add-comments-tag=TRANSLATORS: \
--sort-output \
--package-name=snappy\
--msgid-bugs-address=snappy-devel@lists.ubuntu.com \
--keyword=i18n.G \
--keyword-plural=i18n.NG
# check canary
check_canaries
sed -i 's/charset=CHARSET/charset=UTF-8/' "$OUTPUT"
find "$HERE" -path "$HERE/data/desktop/*.desktop.in" -type f -printf "%P\n" > "$tmpdir/desktop.files"
# we need the || true because Ubuntu 14.04's xgettext does not support
# extracting from desktop files.
xgettext \
-f "$tmpdir/desktop.files" \
-D "$HERE" \
-o "$OUTPUT" \
--language=Desktop \
--sort-output \
--package-name=snappy \
--msgid-bugs-address=snappy-devel@lists.ubuntu.com \
--join-existing || true
find "$HERE" -path "$HERE/data/polkit/*.policy" -type f -printf "%P\n" > "$tmpdir/polkit.files"
# we need the || true because of
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=891347
xgettext \
-f "$tmpdir/polkit.files" \
-D "$HERE" \
-o "$OUTPUT" \
--its="$HERE/po/its/polkit.its" \
--sort-output \
--package-name=snappy \
--msgid-bugs-address=snappy-devel@lists.ubuntu.com \
--join-existing || true
check_canaries
# language packs
for p in "${HERE}"/po/*.po; do
lang=$(basename "$p" .po)
mkdir -p "$HERE/share/locale/$lang/LC_MESSAGES"
msgfmt -v -o "$HERE/share/locale/$lang/LC_MESSAGES/snappy.mo" "$p"
done