Files
chromium_depot_tools/caffeinate.py
Junji Watanabe 6d52c22ee3 autoninja: Do not show caffeinate warning
Discussed in
https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6596109/comments/217e68b5_bcf66ede

The warning message doesn't seem useful. This CL removes the warning
message for caffeinate, but adds help message instead. This CL also
refactors the help message for `autoninja --offline`.

```
> autoninja --help
autoninja:
  -o/--offline  temporary disable remote execution

caffeinate:
  --no-caffeinate  do not prepend `caffeinate` to ninja command

usage: ninja [options] [targets...]
...
```

Change-Id: I152a144efbb6002e3bfb03b23d1e0eb2d3b2af1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6620110
Auto-Submit: Junji Watanabe <jwata@google.com>
Reviewed-by: Nico Weber <thakis@google.com>
Commit-Queue: Junji Watanabe <jwata@google.com>
Reviewed-by: Adam Norberg <norberg@google.com>
2025-06-04 20:02:25 -07:00

25 lines
731 B
Python

# Copyright 2025 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import subprocess
import sys
_NO_CAFFEINATE_FLAG = '--no-caffeinate'
_HELP_MESSAGE = f"""\
caffeinate:
{_NO_CAFFEINATE_FLAG} do not prepend `caffeinate` to ninja command
"""
def run(cmd, env=None):
"""Runs a command with `caffeinate` if it's on macOS."""
if sys.platform == 'darwin':
if '-h' in cmd or '--help' in cmd:
print(_HELP_MESSAGE, file=sys.stderr)
if _NO_CAFFEINATE_FLAG in cmd:
cmd.remove(_NO_CAFFEINATE_FLAG)
else:
cmd = ['caffeinate'] + cmd
return subprocess.call(cmd, env=env)