Bug 1887099 - Update Flatpak and Snap to build desktop files with strings_all artifact. r=rjl

Differential Revision: https://phabricator.services.mozilla.com/D219937

--HG--
extra : amend_source : ff99e6b0adeb1fb9b7e6f7378e388a6f014ae489
This commit is contained in:
Rob Lemley 2024-10-17 10:25:50 +03:00
Родитель f21f8ae9e5
Коммит 716c85df2a
10 изменённых файлов: 105 добавлений и 65 удалений

Просмотреть файл

@ -0,0 +1,35 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
Set up variables for Deb, Flatpak, and Snap packages
"""
import json
from taskgraph.transforms.base import TransformSequence
from taskgraph.transforms.run import set_label, use_fetches
from comm_taskgraph.util.l10n import read_locales_file
transforms = TransformSequence()
transforms.add(set_label)
transforms.add(use_fetches)
@transforms.add
def set_environment_vars(config, tasks):
for task in tasks:
env = task["worker"]["env"]
pkg_locales_file = task.pop("package-locales-file", None)
if pkg_locales_file:
pkg_locales = read_locales_file(pkg_locales_file)
env["PKG_LOCALES"] = json.dumps(pkg_locales)
desktop_locales_file = task.pop("desktop-locales-file", None)
if desktop_locales_file:
desktop_locales = read_locales_file(desktop_locales_file)
env["DESKTOP_LOCALES"] = json.dumps(desktop_locales)
yield task

Просмотреть файл

@ -0,0 +1,11 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
def read_locales_file(locales_file):
"""Parse the passed locales file for a list of locales, exclude ja-JP-mac."""
with open(locales_file, mode="r") as fp:
locales = [l for l in fp.read().split() if not l.startswith("ja-JP-mac")]
return locales

Просмотреть файл

@ -17,9 +17,6 @@ python3 /scripts/build_desktop_file.py -o "$WORKSPACE/org.mozilla.Thunderbird.de
import argparse
import json
import os
import urllib.request
import zipfile
from pathlib import Path
from typing import List, Union
@ -73,32 +70,23 @@ def build_template(
output: Path,
template: Path,
l10n_base: Path,
locales_file: Path,
fluent_files: List[str],
locales: List[str],
fluent_resources: List[str],
is_beta: bool,
is_esr: bool,
):
with open(locales_file) as fp:
locale_data = json.load(fp)
locales = [l for l in locale_data.keys() if l != "ja-JP-mac"]
# Bug 1912126 - hard code this until this script is updated for Github proper
comm_l10n_rev = "4d226985e366c377cf397e4e42aa95e9e2ed3336"
get_strings(l10n_base, comm_l10n_rev, fluent_files)
wmclass = "thunderbird"
if is_beta:
wmclass = wmclass + "-beta"
elif is_esr:
wmclass = wmclass + "-esr"
locales_plus = locales + ["en-US"]
l10n_strings = FluentTranslator(l10n_base.resolve(), locales_plus, fluent_files)
l10n_strings = FluentTranslator(l10n_base.resolve(), locales_plus, fluent_resources)
with open(template) as fp:
jinja_template = jinja2.Template(fp.read())
translate_multi = get_multi_translate(l10n_strings)
result = jinja_template.render(
strings=l10n_strings, translate=translate_multi, wmclass=wmclass
)
@ -107,28 +95,6 @@ def build_template(
fp.write(result)
def get_extract_members(
zip_file: zipfile.ZipFile, file_pats: List[str], prefix: str
) -> List[zipfile.ZipInfo]:
for m in zip_file.infolist():
for pat in file_pats:
if m.filename.endswith(pat):
m.filename = os.path.relpath(m.filename, prefix)
print(f"Found {m.filename} in strings repo.")
yield m
def get_strings(l10n_base, rev, fluent_files):
url = COMM_L10N_ZIP.format(rev=rev)
temp_file, headers = urllib.request.urlretrieve(url)
with zipfile.ZipFile(temp_file, "r") as strings_zip:
to_extract = get_extract_members(
strings_zip, fluent_files, COMM_L10N_ZIP_PREFIX.format(rev=rev)
)
strings_zip.extractall(path=l10n_base, members=to_extract)
def main():
parser = argparse.ArgumentParser()
@ -140,7 +106,11 @@ def main():
"-l", dest="l10n_base", type=Path, required=True, help="l10n-central root path"
)
parser.add_argument(
"-L", dest="locales_file", type=Path, required=True, help="List of supported locales"
"-L",
dest="locales",
type=str,
required=True,
help="JSON encoded list of supported locales",
)
parser.add_argument(
"-f", dest="fluent_files", type=str, required=True, action="extend", nargs="+"
@ -162,11 +132,13 @@ def main():
args = parser.parse_args()
locales = json.loads(args.locales)
build_template(
args.output,
args.template,
args.l10n_base,
args.locales_file,
locales,
args.fluent_files,
args.is_beta,
args.is_esr,

Просмотреть файл

@ -1,2 +1,3 @@
fluent.runtime==0.4.0
jinja2==3.1.2
zstandard==0.23.0

Просмотреть файл

@ -15,6 +15,9 @@ COPY topsrcdir/comm/taskcluster/docker/recipes/fluent_requirements.txt /scripts/
COPY topsrcdir/comm/taskcluster/docker/recipes/build_desktop_file.py /scripts/build_desktop_file.py
COPY topsrcdir/comm/taskcluster/docker/recipes/org.mozilla.thunderbird.desktop.jinja2 /scripts/org.mozilla.thunderbird.desktop.jinja2
# %include third_party/python/taskcluster_taskgraph/taskgraph/run-task/fetch-content
ADD topsrcdir/third_party/python/taskcluster_taskgraph/taskgraph/run-task/fetch-content /scripts/fetch-content
# Set up Python virtual environment
ENV VENV_DIR="/scripts"
RUN /scripts/make_venv.sh /scripts/fluent_requirements.txt

Просмотреть файл

@ -8,10 +8,10 @@ set -xe
test "$VERSION"
test "$BUILD_NUMBER"
test "$CANDIDATES_DIR"
test "$L10N_CHANGESETS"
test "$FLATPAK_BRANCH"
test "$RELEASE_NOTES_URL"
test "$RAW_FILE_URL"
test "$PKG_LOCALES"
test "$DESKTOP_LOCALES"
# Optional environment variables
: WORKSPACE "${WORKSPACE:=/home/worker/workspace}"
@ -50,31 +50,30 @@ rm -rf ~/.local/share/flatpak/
$CURL -o "${WORKSPACE}/thunderbird.tar.bz2" \
"${CANDIDATES_DIR}/${VERSION}-candidates/build${BUILD_NUMBER}/linux-x86_64/en-US/thunderbird-${VERSION}.tar.bz2"
# Download locale information and extract locales to be included in snap
$CURL -o "${WORKSPACE}/onchange-locales" "${RAW_FILE_URL}/mail/locales/onchange-locales"
$CURL -o "${WORKSPACE}/l10n-changesets.json" "${RAW_FILE_URL}/mail/locales/l10n-changesets.json"
locales=$(< "${WORKSPACE}/onchange-locales" sed "s/ja-JP-mac//")
# Fetch langpack extension for each locale
mkdir -p "$DISTRIBUTION_DIR"
mkdir -p "$DISTRIBUTION_DIR/extensions"
for locale in $locales; do
readarray -t locales < <(echo "$PKG_LOCALES" | jq -r '.[]')
for locale in "${locales[@]}"; do
$CURL -o "$DISTRIBUTION_DIR/extensions/langpack-${locale}@thunderbird.mozilla.org.xpi" \
"$CANDIDATES_DIR/${VERSION}-candidates/build${BUILD_NUMBER}/linux-x86_64/xpi/${locale}.xpi"
done
# Download artifacts from dependencies and build the .desktop file.
(
[[ "$FLATPAK_BRANCH" = "stable" ]] && VERSION_FLAG="--esr" || VERSION_FLAG="--beta"
source "${SCRIPT_DIR}/venv/bin/activate"
python3 /scripts/fetch-content task-artifacts --dest "${WORKSPACE}"
[[ "$FLATPAK_BRANCH" = "stable" ]] && VERSION_FLAG="--esr" || VERSION_FLAG="--beta"
python3 "${SCRIPT_DIR}/build_desktop_file.py" \
-o "${WORKSPACE}/org.mozilla.Thunderbird.desktop" \
-t "${SCRIPT_DIR}/org.mozilla.thunderbird.desktop.jinja2" \
-l "${WORKSPACE}/l10n-central" \
-L "${WORKSPACE}/l10n-changesets.json" \
-L "$DESKTOP_LOCALES" \
-f "mail/branding/thunderbird/brand.ftl" \
-f "mail/messenger/flatpak.ftl" \
"$VERSION_FLAG"
"${VERSION_FLAG}"
)
# Generate AppData XML from template, add various
@ -144,7 +143,7 @@ appstream-util mirror-screenshots "${appdir}"/share/app-info/xmls/org.mozilla.Th
# of locales configured on the user's system are downloaded, instead of
# all locales.
mkdir -p "${appdir}/lib/thunderbird/distribution/extensions"
for locale in $locales; do
for locale in "${locales[@]}"; do
install -D -m644 -t "${appdir}/share/runtime/langpack/${locale%%-*}/" "${DISTRIBUTION_DIR}/extensions/langpack-${locale}@thunderbird.mozilla.org.xpi"
ln -sf "/app/share/runtime/langpack/${locale%%-*}/langpack-${locale}@thunderbird.mozilla.org.xpi" "${appdir}/lib/thunderbird/distribution/extensions/langpack-${locale}@thunderbird.mozilla.org.xpi"
done

Просмотреть файл

@ -51,6 +51,9 @@ COPY topsrcdir/comm/taskcluster/docker/recipes/fluent_requirements.txt /scripts/
COPY topsrcdir/comm/taskcluster/docker/recipes/build_desktop_file.py /scripts/build_desktop_file.py
COPY topsrcdir/comm/taskcluster/docker/recipes/org.mozilla.thunderbird.desktop.jinja2 /scripts/org.mozilla.thunderbird.desktop.jinja2
# %include third_party/python/taskcluster_taskgraph/taskgraph/run-task/fetch-content
ADD topsrcdir/third_party/python/taskcluster_taskgraph/taskgraph/run-task/fetch-content /scripts/fetch-content
# Set up Python virtual environment
RUN /scripts/make_venv.sh /scripts/fluent_requirements.txt

Просмотреть файл

@ -9,7 +9,8 @@ set -xe
test "$VERSION"
test "$BUILD_NUMBER"
test "$CANDIDATES_DIR"
test "$RAW_FILE_URL"
test "$PKG_LOCALES"
test "$DESKTOP_LOCALES"
# Optional environment variables
: WORKSPACE "${WORKSPACE:=/home/worker/workspace}"
@ -35,13 +36,9 @@ $CURL -o "${WORKSPACE}/${PRODUCT}.tar.bz2" \
"${CANDIDATES_DIR}/${VERSION}-candidates/build${BUILD_NUMBER}/linux-x86_64/en-US/${PRODUCT}-${VERSION}.tar.bz2"
tar -C "$SOURCE_DEST" -xf "${WORKSPACE}/${PRODUCT}.tar.bz2" --strip-components=1
# Download locale information and extract locales to be included in snap
$CURL -o "${WORKSPACE}/onchange-locales" "${RAW_FILE_URL}/mail/locales/onchange-locales"
$CURL -o "${WORKSPACE}/l10n-changesets.json" "${RAW_FILE_URL}/mail/locales/l10n-changesets.json"
locales=$(< "${WORKSPACE}/onchange-locales" sed "s/ja-JP-mac//")
# Download L10N XPIs (excluding ja-JP-mac)
for locale in $locales; do
readarray -t locales < <(echo "$PKG_LOCALES" | jq -r '.[]')
for locale in "${locales[@]}"; do
$CURL -o "$SOURCE_DEST/distribution/extensions/langpack-${locale}@${PRODUCT}.mozilla.org.xpi" \
"$CANDIDATES_DIR/${VERSION}-candidates/build${BUILD_NUMBER}/linux-x86_64/xpi/${locale}.xpi"
done
@ -49,11 +46,15 @@ done
# Download artifacts from dependencies and build the .desktop file.
(
source "${SCRIPT_DIR}/venv/bin/activate"
python3 "${SCRIPT_DIR}/build_desktop_file.py" -o "${WORKSPACE}/org.mozilla.thunderbird.desktop" \
python3 /scripts/fetch-content task-artifacts --dest "${WORKSPACE}"
python3 "${SCRIPT_DIR}/build_desktop_file.py" \
-o "${WORKSPACE}/org.mozilla.thunderbird.desktop" \
-t "${SCRIPT_DIR}/org.mozilla.thunderbird.desktop.jinja2" \
-l "${WORKSPACE}/l10n-central" \
-L "${WORKSPACE}/l10n-changesets.json" \
-f "mail/branding/thunderbird/brand.ftl" \
-l "${WORKSPACE}/l10n-central" \
-L "$DESKTOP_LOCALES" \
-f "mail/branding/thunderbird/brand.ftl" \
-f "mail/messenger/flatpak.ftl"
)
cp -v "$WORKSPACE/org.mozilla.thunderbird.desktop" "$DISTRIBUTION_DIR"

Просмотреть файл

@ -8,10 +8,12 @@ transforms:
- gecko_taskgraph.transforms.release:run_on_releases
- gecko_taskgraph.transforms.release_deps:transforms
- gecko_taskgraph.transforms.release_flatpak_repackage:transforms
- comm_taskgraph.transforms.packaging_l10n:transforms
- gecko_taskgraph.transforms.task:transforms
kind-dependencies:
- post-beetmover-dummy
- shippable-l10n-pre
task-defaults:
description: Generates flatpak by repackaging the existing .tar.bz2
@ -19,6 +21,13 @@ task-defaults:
run-on-releases: [beta, esr128]
shipping-phase: promote
scopes: []
package-locales-file: comm/mail/locales/onchange-locales
desktop-locales-file: comm/mail/locales/shipped-locales
dependencies:
shippable-l10n-pre: shippable-l10n-pre-shippable-l10n-pre/opt
fetches:
shippable-l10n-pre:
- strings_all.tar.zst
treeherder:
platform: linux64-shippable/opt
kind: build
@ -48,7 +57,6 @@ task-defaults:
https://archive.mozilla.org/pub/{task[shipping-product]}/candidates
LC_ALL: C.UTF-8
LANG: C.UTF-8
L10N_CHANGESETS: "{config_params[comm_head_repository]}/raw-file/{config_params[comm_head_rev]}/mail/locales/l10n-changesets.json"
FLATPAK_BRANCH:
by-project:
comm-esr.*: stable
@ -58,7 +66,6 @@ task-defaults:
by-project:
comm-esr.*: "https://www.thunderbird.net/en-US/thunderbird/{config_params[app_version]}esr/releasenotes/"
default: "https://www.thunderbird.net/en-US/thunderbird/{config_params[app_version]}beta/releasenotes/"
RAW_FILE_URL: "{config_params[comm_head_repository]}/raw-file/{config_params[comm_head_rev]}"
chain-of-trust: true
tasks:

Просмотреть файл

@ -8,10 +8,12 @@ transforms:
- gecko_taskgraph.transforms.release:run_on_releases
- gecko_taskgraph.transforms.release_deps:transforms
- gecko_taskgraph.transforms.release_snap_repackage:transforms
- comm_taskgraph.transforms.packaging_l10n:transforms
- gecko_taskgraph.transforms.task:transforms
kind-dependencies:
- post-beetmover-dummy
- shippable-l10n-pre
task-defaults:
description: Generates snap by repackaging the existing .tar.bz2
@ -19,6 +21,13 @@ task-defaults:
run-on-releases: [beta, esr128]
shipping-phase: promote
scopes: []
package-locales-file: comm/mail/locales/onchange-locales
desktop-locales-file: comm/mail/locales/shipped-locales
dependencies:
shippable-l10n-pre: shippable-l10n-pre-shippable-l10n-pre/opt
fetches:
shippable-l10n-pre:
- strings_all.tar.zst
treeherder:
platform: linux64-shippable/opt
kind: build
@ -48,7 +57,6 @@ task-defaults:
https://archive.mozilla.org/pub/{task[shipping-product]}/candidates
LC_ALL: C.UTF-8
LANG: C.UTF-8
RAW_FILE_URL: "{config_params[comm_head_repository]}/raw-file/{config_params[comm_head_rev]}"
chain-of-trust: true
tasks: