Bug 1901703 - Update 'repackage-snap' to generate desktop file r=sergesanspaille

Differential Revision: https://phabricator.services.mozilla.com/D216373
This commit is contained in:
Alexandre Lissy 2024-08-05 15:01:01 +00:00
parent 5c0642c9bc
commit b1eb8a5dea
4 changed files with 27 additions and 32 deletions

View File

@ -2853,6 +2853,7 @@ def repackage_mar(command_context, input, mar, output, arch, mar_channel_id):
"repackage",
"snap",
description="Repackage into Snap format for developer testing",
virtualenv_name="repackage-snap",
)
@CommandArgument(
"--snapcraft",
@ -3024,6 +3025,7 @@ def repackage_snap(
# Create the package
snappath = repackage_snap(
log=command_context.log,
srcdir=command_context.topsrcdir,
objdir=command_context.topobjdir,
snapdir=snapdir,

View File

@ -11,8 +11,8 @@ from urllib.request import urlretrieve
from mozbuild.repackaging.application_ini import get_application_ini_values
from mozbuild.repackaging.snapcraft_transform import (
DesktopFileTransform,
SnapcraftTransform,
SnapDesktopFile,
)
UPSTREAM = "https://github.com/{}/raw/{}/"
@ -25,6 +25,7 @@ DEPS = [
def repackage_snap(
log,
srcdir,
objdir,
snapdir,
@ -60,12 +61,9 @@ def repackage_snap(
shutil.copy(
os.path.join(srcdir, "browser/branding/nightly/default256.png"), snapdir
)
source_desktop = os.path.join(
srcdir, "taskcluster/docker/firefox-snap/firefox.desktop"
)
with open(os.path.join(snapdir, "firefox.desktop"), "w") as desktop_file:
desktop_file.write(
DesktopFileTransform(source_desktop, icon="default256.png").repack()
SnapDesktopFile(log, appname=appname, branchname=branchname).repack()
)
source_yaml = os.path.join(snapdir, "original.snapcraft.yaml")

View File

@ -4,10 +4,10 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# vim: set expandtab tabstop=4 shiftwidth=4:
from configparser import ConfigParser
from io import StringIO
import yaml
from fluent.runtime.fallback import FluentLocalization, FluentResourceLoader
from mozbuild.repackaging.desktop_file import generate_browser_desktop_entry
# We need to change string representation of YAML such that when dumping the
# modified representation we end up with the same way to represent blocks
@ -144,29 +144,22 @@ class SnapcraftTransform:
return snap
class DesktopFileTransform:
DESKTOP_ENTRY = "Desktop Entry"
def __init__(self, source_file, icon):
self.desktop = ConfigParser()
# required to keep case on entries
self.desktop.optionxform = lambda option: option
self.desktop.read(source_file)
self.icon = icon
class SnapDesktopFile:
def __init__(self, log, appname, branchname):
build_variables = {
"DEB_PKG_NAME": appname,
"DBusActivatable": "false",
"Icon": "/default256.png",
"StartupWMClass": "{}-{}".format(appname, branchname),
}
self.desktop = generate_browser_desktop_entry(
log,
build_variables,
appname, # release_product,
branchname, # release_type,
FluentLocalization,
FluentResourceLoader,
)
def repack(self):
assert self.desktop.has_section(self.DESKTOP_ENTRY)
self.disable_dbus_activatable()
self.change_icon()
output = StringIO()
self.desktop.write(output)
return output.getvalue()
def disable_dbus_activatable(self):
if "DBusActivatable" in self.desktop[self.DESKTOP_ENTRY]:
self.desktop[self.DESKTOP_ENTRY]["DBusActivatable"] = "false"
def change_icon(self):
self.desktop[self.DESKTOP_ENTRY]["Icon"] = "/{}".format(self.icon)
return "\n".join(self.desktop)

View File

@ -0,0 +1,2 @@
pypi:fluent.runtime==0.4.0
vendored:third_party/python/redo