Fix DBus warning when running mach (#37818)

I get the following warning message I run ./mach build:
```console
Could not generate notification: No module named 'dbus'
```

I asked in the Zulip chat[1] if anyone was still using the feature and
it sounds like most people do not use it anymore. It has been broken a
while too and no one has stepped up to fix it.

Gnome Terminal will automatically show a notification when a long
running command is done. Some other terminals can also be configured to
automatically show a notification when a long running command is done.

I think it is safe to remove the feature.

[1]
https://servo.zulipchat.com/#narrow/channel/263398-general/topic/DBus.20warning.20when.20running.20.60.2E.2Fmach.20build.60

Testing: I manually tested it on Linux by running ./mach bootstrap
followed by ./mach build

Signed-off-by: Michael Mc Donnell <michael@mcdonnell.dk>
This commit is contained in:
Michael Mc Donnell 2025-07-02 19:17:01 -04:00 committed by GitHub
parent 6e8a0518d7
commit 9aa06b2c17
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 2 additions and 63 deletions

View file

@ -19,8 +19,6 @@ import sys
from time import time from time import time
from typing import Optional, List, Dict from typing import Optional, List, Dict
import notifypy
from mach.decorators import ( from mach.decorators import (
CommandArgument, CommandArgument,
CommandProvider, CommandProvider,
@ -33,7 +31,7 @@ import servo.platform.macos
import servo.util import servo.util
import servo.visual_studio import servo.visual_studio
from servo.command_base import BuildType, CommandBase, call, check_call from servo.command_base import BuildType, CommandBase, check_call
from servo.gstreamer import windows_dlls, windows_plugins, package_gstreamer_dylibs from servo.gstreamer import windows_dlls, windows_plugins, package_gstreamer_dylibs
from servo.platform.build_target import BuildTarget from servo.platform.build_target import BuildTarget
@ -189,12 +187,10 @@ class MachCommands(CommandBase):
except ImportError: except ImportError:
pass pass
# Generate Desktop Notification if elapsed-time > some threshold value # Print how long the build took
elapsed = time() - build_start elapsed = time() - build_start
elapsed_delta = datetime.timedelta(seconds=int(elapsed)) elapsed_delta = datetime.timedelta(seconds=int(elapsed))
build_message = f"{'Succeeded' if status == 0 else 'Failed'} in {elapsed_delta}" build_message = f"{'Succeeded' if status == 0 else 'Failed'} in {elapsed_delta}"
self.notify("Servo build", build_message)
print(build_message) print(build_message)
return status return status
@ -287,56 +283,6 @@ class MachCommands(CommandBase):
env["TARGET_CFLAGS"] += " -fsanitize=thread" env["TARGET_CFLAGS"] += " -fsanitize=thread"
env["TARGET_CXXFLAGS"] += " -fsanitize=thread" env["TARGET_CXXFLAGS"] += " -fsanitize=thread"
def notify(self, title: str, message: str):
"""Generate desktop notification when build is complete and the
elapsed build time was longer than 30 seconds.
If notify-command is set in the [tools] section of the configuration,
that is used instead."""
notify_command = self.config["tools"].get("notify-command")
# notifypy does not know how to send transient notifications, so we use a custom
# notifier on Linux. If transient notifications are not used, then notifications
# pile up in the notification center and must be cleared manually.
class LinuxNotifier(notifypy.BaseNotifier):
def __init__(self, **kwargs):
pass
def send_notification(self, **kwargs):
try:
import dbus
bus = dbus.SessionBus()
notify_obj = bus.get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
method = notify_obj.get_dbus_method("Notify", "org.freedesktop.Notifications")
method(
kwargs.get("application_name"),
0, # Don't replace previous notification.
kwargs.get("notification_icon", ""),
kwargs.get("notification_title"),
kwargs.get("notification_subtitle"),
[], # actions
{"transient": True}, # hints
-1, # timeout
)
except Exception as exception:
print(f"[Warning] Could not generate notification: {exception}", file=sys.stderr)
return True
if notify_command:
if call([notify_command, title, message]) != 0:
print(f"[Warning] Could not generate notification: Could not run '{notify_command}'.", file=sys.stderr)
else:
try:
notifier = LinuxNotifier if sys.platform.startswith("linux") else None
notification = notifypy.Notify(use_custom_notifier=notifier)
notification.title = title
notification.message = message
notification.icon = path.join(self.get_top_dir(), "resources", "servo_64.png")
notification.send(block=False)
except notifypy.exceptions.UnsupportedPlatform as e:
print(f"[Warning] Could not generate notification: {e}", file=sys.stderr)
def copy_windows_dlls_to_build_directory(servo_binary: str, target: BuildTarget) -> bool: def copy_windows_dlls_to_build_directory(servo_binary: str, target: BuildTarget) -> bool:
servo_exe_dir = os.path.dirname(servo_binary) servo_exe_dir = os.path.dirname(servo_binary)

View file

@ -5,12 +5,6 @@
# Tool options # Tool options
[tools] [tools]
# If uncommented, this command is used instead of the platforms default
# to notify at the end of a compilation that took a long time.
# This is the name or path of an executable called with two arguments:
# the summary and content of the notification.
#notify-command = "notify-send"
[build] [build]
# Set "mode = dev" or use `mach build --dev` to build the project with warning. # Set "mode = dev" or use `mach build --dev` to build the project with warning.
# or Set "mode = release" or use `mach build --release` for optimized build. # or Set "mode = release" or use `mach build --release` for optimized build.

View file

@ -89,7 +89,6 @@ stdenv.mkDerivation (androidEnvironment // {
# Ensure the Python version is same as the one in `.python-version` file so # Ensure the Python version is same as the one in `.python-version` file so
# that `uv` will just symlink to the one in nix store. Otherwise `uv` will # that `uv` will just symlink to the one in nix store. Otherwise `uv` will
# download a pre-built binary that won't work on nix. # download a pre-built binary that won't work on nix.
# FIXME: dbus python module needs to be installed into the virtual environment.
python311 python311
uv uv