Auto merge of #15013 - servo:notify-command, r=emilio

Add config to do desktop notifications by running an abitrary command.

<!-- Please describe your changes on the following line: -->

I now have an usual setup where I use a (fast) remote machine for building, and I’m adding a hack to forward end-of-build notifications back to my laptop. This is the motivation for this change, but I kept it general enough that it could be used in other situations.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15013)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-01-13 11:49:16 -08:00 committed by GitHub
commit 414e2e907d
2 changed files with 35 additions and 14 deletions

View file

@ -92,24 +92,39 @@ def notify_darwin(title, text):
raise Exception("Optional Python module 'pyobjc' is not installed.")
def notify_build_done(elapsed, success=True):
def notify_with_command(command):
def notify(title, text):
if call([command, title, text]) != 0:
raise Exception("Could not run '%s'." % command)
return notify
def notify_build_done(config, elapsed, success=True):
"""Generate desktop notification when build is complete and the
elapsed build time was longer than 30 seconds."""
if elapsed > 30:
notify("Servo build", "%s in %s" % ("Completed" if success else "FAILED", format_duration(elapsed)))
notify(config, "Servo build",
"%s in %s" % ("Completed" if success else "FAILED", format_duration(elapsed)))
def notify(title, text):
def notify(config, title, text):
"""Generate a desktop notification using appropriate means on
supported platforms Linux, Windows, and Mac OS. On unsupported
platforms, this function acts as a no-op."""
platforms = {
"linux": notify_linux,
"linux2": notify_linux,
"win32": notify_win,
"darwin": notify_darwin
}
func = platforms.get(sys.platform)
platforms, this function acts as a no-op.
If notify-command is set in the [tools] section of the configuration,
that is used instead."""
notify_command = config["tools"].get("notify-command")
if notify_command:
func = notify_with_command(notify_command)
else:
platforms = {
"linux": notify_linux,
"linux2": notify_linux,
"win32": notify_win,
"darwin": notify_darwin
}
func = platforms.get(sys.platform)
if func is not None:
try:
@ -324,7 +339,7 @@ class MachCommands(CommandBase):
pass
# Generate Desktop Notification if elapsed-time > some threshold value
notify_build_done(elapsed, status == 0)
notify_build_done(self.config, elapsed, status == 0)
print("Build %s in %s" % ("Completed" if status == 0 else "FAILED", format_duration(elapsed)))
return status
@ -375,7 +390,7 @@ class MachCommands(CommandBase):
elapsed = time() - build_start
# Generate Desktop Notification if elapsed-time > some threshold value
notify_build_done(elapsed)
notify_build_done(self.config, elapsed)
print("CEF build completed in %s" % format_duration(elapsed))
@ -430,7 +445,7 @@ class MachCommands(CommandBase):
elapsed = time() - build_start
# Generate Desktop Notification if elapsed-time > some threshold value
notify_build_done(elapsed)
notify_build_done(self.config, elapsed)
print("GeckoLib build completed in %s" % format_duration(elapsed))

View file

@ -27,6 +27,12 @@ system-cargo = false
# Defaults to true
rustc-with-gold = true
# 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]
# 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.