gecko-dev/python/mach
Ted Mielczarek 54b3bbd1ce bug 1505205 - don't write telemetry for recursive mach command invocations. r=firefox-build-system-reviewers,chmanchester
This change tries to ensure that we don't write telemetry data for mach
commands invoked recursively as part of other mach commands. The intent of
build system telemetry is to only collect data about commands that users are
invoking directly.

There are two ways that we found mach commands can be recursively invoked:
* By running a python subprocess to recursively invoke mach (used in
  `mach bootstrap` to call `mach artifact toolchain`)
* By using `Registrar.dispatch` to delegate to a sub-command (used by many
  build system commands to invoke `mach build`).

The subprocess case is handled here by having mach set a `MACH_MAIN_PID`
environment variable whose value is the current process' pid on startup if it
does not already exist in the environment. Telemetry code then checks that the
value of that variable matches the current pid and skips writing telemetry data
if not.

The dispatch case is handled by making `MachRegistrar` store the current depth
of the command stack and pass it to the `post_dispatch_handler` which will skip
writing telemetry data if depth != 1.

Additionally the `should_skip_dispatch` function in mach_bootstrap is renamed
to `should_skip_telemetry_submission`, which was its original intent. The
combination of checks added in this change should be sufficient for deciding
when to write telemetry data, and we were not collecting telemetry for the set
of mach commands in that function (which included `mach bootstrap`).

In order to facilitate writing a test for the dispatch case this change adds a
`mach python --exec-file` option to execute Python code directly in the context
of the `mach python` command.

Differential Revision: https://phabricator.services.mozilla.com/D11207

--HG--
extra : moz-landing-system : lando
2018-11-10 19:04:30 +00:00
..
docs Bug 1393590 - [mach] Use description field for settings instead of gettext locales, r=gps 2017-08-24 16:17:40 -04:00
mach bug 1505205 - don't write telemetry for recursive mach command invocations. r=firefox-build-system-reviewers,chmanchester 2018-11-10 19:04:30 +00:00
bash-completion.sh
README.rst
setup.py Backed out 3 changesets (bug 1388013) for build bustages e.g. ../python/mozbuild/mozpack/test/test_files.py on a CLOSED TREE 2018-05-31 11:48:19 +03:00

====
mach
====

Mach (German for *do*) is a generic command dispatcher for the command
line.

To use mach, you install the mach core (a Python package), create an
executable *driver* script (named whatever you want), and write mach
commands. When the *driver* is executed, mach dispatches to the
requested command handler automatically.

To learn more, read the docs in ``docs/``.