summaryrefslogtreecommitdiffstats
path: root/comm/taskcluster/docker/tb-flatpak
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--comm/taskcluster/docker/tb-flatpak/Dockerfile18
-rw-r--r--comm/taskcluster/docker/tb-flatpak/build_desktop_file.py159
-rw-r--r--comm/taskcluster/docker/tb-flatpak/close_range.c12
-rw-r--r--comm/taskcluster/docker/tb-flatpak/distribution.ini13
-rw-r--r--comm/taskcluster/docker/tb-flatpak/extract_locales_from_l10n_json.py18
-rw-r--r--comm/taskcluster/docker/tb-flatpak/fluent_requirements.txt2
-rwxr-xr-xcomm/taskcluster/docker/tb-flatpak/launch_script.sh3
-rwxr-xr-xcomm/taskcluster/docker/tb-flatpak/make_venv.sh12
-rw-r--r--comm/taskcluster/docker/tb-flatpak/org.mozilla.Thunderbird.appdata.xml.in83
-rw-r--r--comm/taskcluster/docker/tb-flatpak/org.mozilla.Thunderbird.desktop.jinja233
-rwxr-xr-xcomm/taskcluster/docker/tb-flatpak/runme.sh198
11 files changed, 551 insertions, 0 deletions
diff --git a/comm/taskcluster/docker/tb-flatpak/Dockerfile b/comm/taskcluster/docker/tb-flatpak/Dockerfile
new file mode 100644
index 0000000000..0ec129c9f3
--- /dev/null
+++ b/comm/taskcluster/docker/tb-flatpak/Dockerfile
@@ -0,0 +1,18 @@
+FROM freedesktopsdk/flatpak:22.08-x86_64
+MAINTAINER tb-builds@thunderbird.net
+
+RUN mkdir /scripts/
+WORKDIR /scripts/
+
+# Copy everything in the docker/tb-flatpak folder but the Dockerfile
+COPY [^D]* /scripts/
+
+# Set up Python virtual environment
+RUN /scripts/make_venv.sh
+
+# Manually add close_range syscall to image
+RUN ["gcc", "-Wall", "-shared", "-o", "/scripts/close_range.so", "/scripts/close_range.c"]
+ENV LD_PRELOAD /scripts/close_range.so
+
+# Set a default command useful for debugging
+CMD ["/bin/bash", "--login"]
diff --git a/comm/taskcluster/docker/tb-flatpak/build_desktop_file.py b/comm/taskcluster/docker/tb-flatpak/build_desktop_file.py
new file mode 100644
index 0000000000..65ed76eeb8
--- /dev/null
+++ b/comm/taskcluster/docker/tb-flatpak/build_desktop_file.py
@@ -0,0 +1,159 @@
+#!/usr/bin/python3 -u
+# 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 https://mozilla.org/MPL/2.0/.
+
+"""
+Build the Flatpak .desktop file. Needs to run in the Python virtualenv
+due to dependencies.
+
+python3 /scripts/build_desktop_file.py -o "$WORKSPACE/org.mozilla.Thunderbird.desktop" \
+ -t "/scripts/org.mozilla.Thunderbird.desktop.jinja2" \
+ -l "$WORKSPACE/l10n-central" \
+ -L "$WORKSPACE/shipped-locales" \
+ -f "mail/branding/thunderbird/brand.ftl" \
+ -f "mail/messenger/flatpak.ftl"
+"""
+
+import argparse
+import json
+import os
+import urllib.request
+import zipfile
+from pathlib import Path
+from typing import List, Union
+
+import jinja2
+from fluent.runtime.fallback import FluentLocalization, FluentResourceLoader
+
+COMM_L10N_ZIP = "https://hg.mozilla.org/projects/comm-l10n/archive/{rev}.zip"
+COMM_L10N_ZIP_PREFIX = "comm-l10n-{rev}"
+
+
+class FluentTranslator:
+ """
+ FluentTranslator is an enhanced FluentLocalization
+ """
+
+ def __init__(self, l10n_base: Path, locales: List[str], resource_ids: List[str]):
+ self._locales = locales
+ self._localizations = self._populate(l10n_base, resource_ids)
+
+ @property
+ def locales(self):
+ return sorted([l for l in self._locales if l != "en-US"])
+
+ def _populate(self, l10n_path, resource_ids):
+ loader = FluentResourceLoader(str(l10n_path / "{locale}"))
+
+ rv = {}
+ for locale in self._locales:
+ rv[locale] = FluentLocalization([locale], resource_ids, loader)
+
+ return rv
+
+ def get_message(self, locale, message_id) -> Union[str, None]:
+ rv = self._localizations[locale].format_value(message_id)
+ if rv == message_id:
+ return None
+ return rv
+
+
+def get_multi_translate(l10n_strings: FluentTranslator):
+ def translate_multi(key: str, fluent_id: str):
+ for locale in l10n_strings.locales:
+ translated = l10n_strings.get_message(locale, fluent_id)
+ if translated is not None:
+ yield f"{key}[{locale}]={translated}"
+
+ return translate_multi
+
+
+def build_template(
+ output: Path,
+ template: Path,
+ l10n_base: Path,
+ locales: List[str],
+ fluent_resources: List[str],
+ is_beta: bool,
+):
+ wmclass = "thunderbird"
+ if is_beta:
+ wmclass = wmclass + "-beta"
+ locales_plus = locales + ["en-US"]
+ 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
+ )
+
+ with open(output, "w") as fp:
+ 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()
+
+ parser.add_argument("-o", dest="output", type=Path, required=True, help="Output file")
+ parser.add_argument(
+ "-t", dest="template", type=Path, required=True, help="Jinja2 template file"
+ )
+ parser.add_argument(
+ "-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"
+ )
+ parser.add_argument(
+ "-f", dest="fluent_files", type=str, required=True, action="extend", nargs="+"
+ )
+ parser.add_argument(
+ "--beta",
+ dest="is_beta",
+ action="store_true",
+ default=False,
+ help="Mark this build a beta version",
+ )
+
+ args = parser.parse_args()
+
+ with open(args.locales_file) as fp:
+ locale_data = json.load(fp)
+ locales = [l for l in locale_data.keys() if l != "ja-JP-mac"]
+ comm_l10n_rev = locale_data.get("en-GB", {}).get("revision")
+
+ get_strings(args.l10n_base, comm_l10n_rev, args.fluent_files)
+
+ build_template(
+ args.output, args.template, args.l10n_base, locales, args.fluent_files, args.is_beta
+ )
+
+
+if __name__ == "__main__":
+ main()
diff --git a/comm/taskcluster/docker/tb-flatpak/close_range.c b/comm/taskcluster/docker/tb-flatpak/close_range.c
new file mode 100644
index 0000000000..d786e78e3b
--- /dev/null
+++ b/comm/taskcluster/docker/tb-flatpak/close_range.c
@@ -0,0 +1,12 @@
+/*
+ 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/.
+*/
+
+#include <errno.h>
+
+int close_range(unsigned int first, unsigned int last, unsigned int flags) {
+ errno = ENOSYS;
+ return -1;
+}
diff --git a/comm/taskcluster/docker/tb-flatpak/distribution.ini b/comm/taskcluster/docker/tb-flatpak/distribution.ini
new file mode 100644
index 0000000000..d7793363a1
--- /dev/null
+++ b/comm/taskcluster/docker/tb-flatpak/distribution.ini
@@ -0,0 +1,13 @@
+[Global]
+id=thunderbird-flatpak
+version=1.0
+about=Mozilla Thunderbird Flatpak
+about.en-US=Mozilla Thunderbird Flatpak en-US
+
+[Preferences]
+intl.locale.requested=""
+app.update.auto=false
+app.update.enabled=false
+app.update.autoInstallEnabled=false
+mail.shell.checkDefaultClient=false
+spellchecker.dictionary_path=/usr/share/hunspell
diff --git a/comm/taskcluster/docker/tb-flatpak/extract_locales_from_l10n_json.py b/comm/taskcluster/docker/tb-flatpak/extract_locales_from_l10n_json.py
new file mode 100644
index 0000000000..b1eb745d7f
--- /dev/null
+++ b/comm/taskcluster/docker/tb-flatpak/extract_locales_from_l10n_json.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python3
+
+"""
+/* 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/. */
+"""
+
+
+import json
+import sys
+
+l10n_changesets_json_path = sys.argv[1]
+with open(l10n_changesets_json_path) as f:
+ locales = json.load(f).keys()
+linux_locales = [l for l in locales if l != "ja-JP-mac"]
+
+print("\n".join(sorted(linux_locales)))
diff --git a/comm/taskcluster/docker/tb-flatpak/fluent_requirements.txt b/comm/taskcluster/docker/tb-flatpak/fluent_requirements.txt
new file mode 100644
index 0000000000..4b9fde4a30
--- /dev/null
+++ b/comm/taskcluster/docker/tb-flatpak/fluent_requirements.txt
@@ -0,0 +1,2 @@
+fluent.runtime==0.4.0
+jinja2==3.1.2
diff --git a/comm/taskcluster/docker/tb-flatpak/launch_script.sh b/comm/taskcluster/docker/tb-flatpak/launch_script.sh
new file mode 100755
index 0000000000..27875568b9
--- /dev/null
+++ b/comm/taskcluster/docker/tb-flatpak/launch_script.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+export TMPDIR="$XDG_RUNTIME_DIR/app/$FLATPAK_ID"
+exec /app/lib/thunderbird/thunderbird --name org.mozilla.Thunderbird "$@"
diff --git a/comm/taskcluster/docker/tb-flatpak/make_venv.sh b/comm/taskcluster/docker/tb-flatpak/make_venv.sh
new file mode 100755
index 0000000000..6b807e64f4
--- /dev/null
+++ b/comm/taskcluster/docker/tb-flatpak/make_venv.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+# 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 https://mozilla.org/MPL/2.0/.
+
+set -xe
+
+cd /scripts || exit 1
+
+python -m venv --system-site-packages venv
+source ./venv/bin/activate
+python -m pip install -r fluent_requirements.txt
diff --git a/comm/taskcluster/docker/tb-flatpak/org.mozilla.Thunderbird.appdata.xml.in b/comm/taskcluster/docker/tb-flatpak/org.mozilla.Thunderbird.appdata.xml.in
new file mode 100644
index 0000000000..5a103650ce
--- /dev/null
+++ b/comm/taskcluster/docker/tb-flatpak/org.mozilla.Thunderbird.appdata.xml.in
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<component type="desktop-application">
+ <id>org.mozilla.Thunderbird</id>
+ <launchable type="desktop-id">org.mozilla.Thunderbird.desktop</launchable>
+ <metadata_license>CC0-1.0</metadata_license>
+ <name>Thunderbird</name>
+ <summary>Thunderbird is a free and open source email, newsfeed, chat, and calendaring client</summary>
+
+ <description>
+ <!-- From https://www.thunderbird.net/en-US/about/ -->
+ <p>
+ Thunderbird is a free and open source email, newsfeed, chat, and
+ calendaring client, that’s easy to set up and customize. One of the core
+ principles of Thunderbird is the use and promotion of open standards -
+ this focus is a rejection of our world of closed platforms and services
+ that can’t communicate with each other. We want our users to have freedom
+ and choice in how they communicate.
+ </p>
+ <p>
+ Thunderbird is an open source project, which means anyone can contribute
+ ideas, designs, code, and time helping fellow users.
+ </p>
+ </description>
+
+ <releases>
+ <release version="$VERSION" date="$DATE">
+ <url>$RELEASE_NOTES_URL</url>
+ </release>
+ </releases>
+
+ <keywords>
+ <keyword>mozilla</keyword>
+ <keyword>mail</keyword>
+ <keyword>email</keyword>
+ <keyword>calendar</keyword>
+ </keywords>
+
+ <categories>
+ <category>Calendar</category>
+ <category>Chat</category>
+ <category>ContactManagement</category>
+ <category>Email</category>
+ <category>Feed</category>
+ <category>InstantMessaging</category>
+ <category>IRCClient</category>
+ <category>Network</category>
+ <category>News</category>
+ <category>Office</category>
+ </categories>
+
+ <provides>
+ <mediatype>message/rfc822</mediatype>
+ <mediatype>x-scheme-handler/mailto</mediatype>
+ <mediatype>text/calendar</mediatype>
+ <mediatype>text/vcard</mediatype>
+ <mediatype>text/x-vcard</mediatype>
+ <mediatype>x-scheme-handler/webcal</mediatype>
+ <mediatype>x-scheme-handler/webcals</mediatype>
+ <mediatype>x-scheme-handler/mid</mediatype>
+ </provides>
+
+ <content_rating type="oars-1.1" />
+ <url type="homepage">https://www.thunderbird.net/</url>
+ <url type="bugtracker">https://bugzilla.mozilla.org/</url>
+ <url type="faq">https://support.mozilla.org/kb/thunderbird-faq/</url>
+ <url type="help">https://support.mozilla.org/products/thunderbird/</url>
+ <url type="donation">https://give.thunderbird.net/</url>
+ <url type="translate">https://www.thunderbird.net/en-US/get-involved/#translation</url>
+ <url type="contact">https://www.thunderbird.net/contact/</url>
+
+ <screenshots>
+ <screenshot type="default">https://raw.githubusercontent.com/thunderbird/flatpak-screenshots/main/image_1.png</screenshot>
+ <screenshot>https://raw.githubusercontent.com/thunderbird/flatpak-screenshots/main/image_2.png</screenshot>
+ </screenshots>
+
+ <custom>
+ <value key="flathub::manifest">$MANIFEST_URL</value>
+ </custom>
+
+ <project_group>Mozilla</project_group>
+ <project_license>MPL-2.0</project_license>
+ <developer_name>MZLA Technologies, part of the Mozilla Foundation</developer_name>
+</component>
diff --git a/comm/taskcluster/docker/tb-flatpak/org.mozilla.Thunderbird.desktop.jinja2 b/comm/taskcluster/docker/tb-flatpak/org.mozilla.Thunderbird.desktop.jinja2
new file mode 100644
index 0000000000..3623c55302
--- /dev/null
+++ b/comm/taskcluster/docker/tb-flatpak/org.mozilla.Thunderbird.desktop.jinja2
@@ -0,0 +1,33 @@
+[Desktop Entry]
+Name={{ strings.get_message("en-US", "flatpak-desktop-name") }}
+Comment={{ strings.get_message("en-US", "flatpak-desktop-comment") }}
+{%- for line in translate("Comment", "flatpak-desktop-comment") %}
+{{ line }}
+{%- endfor %}
+GenericName={{ strings.get_message("en-US", "flatpak-desktop-generic-name") }}
+{%- for line in translate("GenericName", "flatpak-desktop-generic-name") %}
+{{ line }}
+{%- endfor %}
+Exec=thunderbird %u
+Terminal=false
+Type=Application
+Icon=org.mozilla.Thunderbird
+Categories=Network;Email;
+MimeType=message/rfc822;x-scheme-handler/mailto;text/calendar;text/vcard;text/x-vcard;x-scheme-handler/webcal;x-scheme-handler/webcals;x-scheme-handler/mid;
+StartupNotify=true
+StartupWMClass={{ wmclass }}
+Actions=ComposeMessage;OpenAddressBook;
+
+[Desktop Action ComposeMessage]
+Name={{ strings.get_message("en-US", "flatpak-desktop-action-compose") }}
+{%- for line in translate("Name", "flatpak-desktop-action-compose") %}
+{{ line }}
+{%- endfor %}
+Exec=thunderbird -compose
+
+[Desktop Action OpenAddressBook]
+Name={{ strings.get_message("en-US", "flatpak-desktop-action-addressbook") }}
+{%- for line in translate("Name", "flatpak-desktop-action-addressbook") %}
+{{ line }}
+{%- endfor %}
+Exec=thunderbird -addressbook
diff --git a/comm/taskcluster/docker/tb-flatpak/runme.sh b/comm/taskcluster/docker/tb-flatpak/runme.sh
new file mode 100755
index 0000000000..389929a124
--- /dev/null
+++ b/comm/taskcluster/docker/tb-flatpak/runme.sh
@@ -0,0 +1,198 @@
+#!/bin/bash
+set -xe
+
+# Future products supporting Flatpaks will set this accordingly
+: PRODUCT "${PRODUCT:=thunderbird}"
+
+# Required environment variables
+test "$VERSION"
+test "$BUILD_NUMBER"
+test "$CANDIDATES_DIR"
+test "$L10N_CHANGESETS"
+test "$FLATPAK_BRANCH"
+test "$MANIFEST_URL"
+test "$RELEASE_NOTES_URL"
+
+# Optional environment variables
+: WORKSPACE "${WORKSPACE:=/home/worker/workspace}"
+: ARTIFACTS_DIR "${ARTIFACTS_DIR:=/home/worker/artifacts}"
+
+# Populate remaining environment variables
+SCRIPT_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+TARGET_TAR_XZ_FULL_PATH="$ARTIFACTS_DIR/target.flatpak.tar.xz"
+SOURCE_DEST="${WORKSPACE}/source"
+DISTRIBUTION_DIR="$SOURCE_DEST/distribution"
+FREEDESKTOP_VERSION="23.08"
+FIREFOX_BASEAPP_CHANNEL="23.08"
+
+# Create alias for ideal curl command
+CURL="curl --location --retry 10 --retry-delay 10"
+
+# Get current date
+#
+# This is used to populate the datetime in org.mozilla.Thunderbird.appdata.xml
+DATE=$(date +%Y-%m-%d)
+export DATE
+
+# Prepare directories
+#
+# This command is temporary, there's an upcoming fix in the upstream
+# Docker image that we work on top of, from 'freedesktopsdk', that will
+# make these two lines go away eventually.
+mkdir -p /root /tmp /var/tmp
+mkdir -p "$ARTIFACTS_DIR"
+rm -rf "$SOURCE_DEST" && mkdir -p "$SOURCE_DEST"
+
+# Ensure a clean slate in the local Flatpak repo
+rm -rf ~/.local/share/flatpak/
+
+# Download en-US linux64 (English, 64-bit Linux) Thunderbird binary
+$CURL -o "${WORKSPACE}/thunderbird.tar.bz2" \
+ "${CANDIDATES_DIR}/${VERSION}-candidates/build${BUILD_NUMBER}/linux-x86_64/en-US/thunderbird-${VERSION}.tar.bz2"
+
+# Fetch list of Thunderbird locales
+$CURL -o "${WORKSPACE}/l10n-changesets.json" "$L10N_CHANGESETS"
+locales=$(python3 "$SCRIPT_DIRECTORY/extract_locales_from_l10n_json.py" "${WORKSPACE}/l10n-changesets.json")
+
+# Fetch langpack extension for each locale
+mkdir -p "$DISTRIBUTION_DIR"
+mkdir -p "$DISTRIBUTION_DIR/extensions"
+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.
+(
+source /scripts/venv/bin/activate
+python3 /scripts/build_desktop_file.py -o "$WORKSPACE/org.mozilla.Thunderbird.desktop" \
+ -t "/scripts/org.mozilla.Thunderbird.desktop.jinja2" \
+ -l "$WORKSPACE/l10n-central" \
+ -L "$WORKSPACE/l10n-changesets.json" \
+ -f "mail/branding/thunderbird/brand.ftl" \
+ -f "mail/messenger/flatpak.ftl"
+)
+
+# Generate AppData XML from template, add various
+envsubst < "$SCRIPT_DIRECTORY/org.mozilla.Thunderbird.appdata.xml.in" > "${WORKSPACE}/org.mozilla.Thunderbird.appdata.xml"
+cp -v "$SCRIPT_DIRECTORY/distribution.ini" "$WORKSPACE"
+cp -v "$SCRIPT_DIRECTORY/launch_script.sh" "$WORKSPACE"
+cd "${WORKSPACE}"
+
+# Fetch and install Firefox base app (as user, not system-wide)
+flatpak remote-add --user --if-not-exists --from flathub https://dl.flathub.org/repo/flathub.flatpakrepo
+flatpak install --user -y flathub org.mozilla.firefox.BaseApp//${FIREFOX_BASEAPP_CHANNEL} --no-deps
+
+# Create build directory and add Firefox base app files
+#
+# This command is temporary, there's an upcoming fix in the upstream
+# Docker image that we work on top of, from 'freedesktopsdk', that will
+# make these two lines go away eventually.
+mkdir -p build
+cp -r ~/.local/share/flatpak/app/org.mozilla.firefox.BaseApp/current/active/files build/files
+
+# Create Flatpak build metadata file for Thunderbird
+ARCH=$(flatpak --default-arch)
+cat <<EOF > build/metadata
+[Application]
+name=org.mozilla.Thunderbird
+runtime=org.freedesktop.Platform/${ARCH}/${FREEDESKTOP_VERSION}
+sdk=org.freedesktop.Sdk/${ARCH}/${FREEDESKTOP_VERSION}
+base=app/org.mozilla.firefox.BaseApp/${ARCH}/${FIREFOX_BASEAPP_CHANNEL}
+[Extension org.mozilla.Thunderbird.Locale]
+directory=share/runtime/langpack
+autodelete=true
+locale-subset=true
+EOF
+
+# Create Flatpak build metadata file for locales
+cat <<EOF > build/metadata.locale
+[Runtime]
+name=org.mozilla.Thunderbird.Locale
+
+[ExtensionOf]
+ref=app/org.mozilla.Thunderbird/${ARCH}/${FLATPAK_BRANCH}
+EOF
+
+# Install Thunderbird files into appdir
+appdir=build/files
+install -d "${appdir}/lib/"
+(cd "${appdir}/lib/" && tar jxf "${WORKSPACE}/thunderbird.tar.bz2")
+install -D -m644 -t "${appdir}/share/appdata" org.mozilla.Thunderbird.appdata.xml
+install -D -m644 -t "${appdir}/share/applications" org.mozilla.Thunderbird.desktop
+for size in 16 32 48 64 128; do
+ install -D -m644 "${appdir}/lib/thunderbird/chrome/icons/default/default${size}.png" "${appdir}/share/icons/hicolor/${size}x${size}/apps/org.mozilla.Thunderbird.png"
+done
+
+# Generate AppStream metadata and add screenshots from Flathub
+appstream-compose --prefix="${appdir}" --origin=flatpak --basename=org.mozilla.Thunderbird org.mozilla.Thunderbird
+appstream-util mirror-screenshots "${appdir}"/share/app-info/xmls/org.mozilla.Thunderbird.xml.gz "https://dl.flathub.org/repo/screenshots/org.mozilla.Thunderbird-${FLATPAK_BRANCH}" build/screenshots "build/screenshots/org.mozilla.Thunderbird-${FLATPAK_BRANCH}"
+
+# Install locales, distribution, and launch_script.sh into appdir
+#
+# We must install each locale individually, since we're symlinking
+# each one.
+#
+# We put the langpacks in /app/share/locale/$LANG_CODE and symlink that
+# directory to where Thunderbird looks them up; this way only the subset
+# 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
+ 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
+install -D -m644 -t "${appdir}/lib/thunderbird/distribution" distribution.ini
+install -D -m755 launch_script.sh "${appdir}/bin/thunderbird"
+
+# Build Flatpak
+#
+# We use features=devel to enable ptrace, which we need for the crash
+# reporter. The application is still confined in a pid namespace, so
+# that won't let us escape the flatpak sandbox. See bug 1653852.
+#
+# We use own-name to ensure Thunderbird has access to DBus, as app ID
+# (org.mozilla.Thunderbird) does not match bus names
+# (org.mozilla.thunderbird, lowercase "t"). The app ID may be updated
+# in the future to match the default bus names.
+flatpak build-finish build \
+ --allow=devel \
+ --share=ipc \
+ --share=network \
+ --socket=pulseaudio \
+ --socket=wayland \
+ --socket=x11 \
+ --socket=pcsc \
+ --socket=cups \
+ --require-version=0.10.3 \
+ --persist=.thunderbird \
+ --filesystem=xdg-download:rw \
+ --filesystem=~/.gnupg \
+ --filesystem=xdg-run/gnupg:ro \
+ --filesystem=xdg-run/speech-dispatcher:ro \
+ --filesystem=/run/.heim_org.h5l.kcm-socket \
+ --device=dri \
+ --own-name="org.mozilla.thunderbird.*" \
+ --own-name="org.mozilla.thunderbird_beta.*" \
+ --talk-name="org.gtk.vfs.*" \
+ --talk-name=org.a11y.Bus \
+ --system-talk-name=org.freedesktop.NetworkManager \
+ --command=thunderbird
+
+# Export Flatpak build into repo
+flatpak build-export --disable-sandbox --no-update-summary --exclude='/share/runtime/langpack/*/*' repo build "$FLATPAK_BRANCH"
+flatpak build-export --disable-sandbox --no-update-summary --metadata=metadata.locale --files=files/share/runtime/langpack repo build "$FLATPAK_BRANCH"
+
+# Commit screenshots to repo
+ostree commit --repo=repo --canonical-permissions --branch=screenshots/x86_64 build/screenshots
+flatpak build-update-repo --generate-static-deltas repo
+
+# Package Flatpak repo as tar
+tar cvfJ flatpak.tar.xz repo
+mv -- flatpak.tar.xz "$TARGET_TAR_XZ_FULL_PATH"
+
+# Build Flatpak bundle (.flatpak) from repo
+flatpak build-bundle "$WORKSPACE"/repo org.mozilla.Thunderbird.flatpak org.mozilla.Thunderbird "$FLATPAK_BRANCH"
+
+# Move bundle to artifacts
+mv org.mozilla.Thunderbird.flatpak "$ARTIFACTS_DIR/"