Граф коммитов

84 Коммитов

Автор SHA1 Сообщение Дата
Alex Lopez 2da2365f75 Bug 1388894 - Replace list of mach modules to load with a dict of mach commands r=mhentges
This starts a centralized place to keep track of mach commands with some essential
metadata.

Differential Revision: https://phabricator.services.mozilla.com/D136790
2022-02-02 20:25:21 +00:00
Alex Lopez e39b3c93d9 Bug 1388894 - Add function in Mach to load commands from files in bulk. r=mhentges
This reduces some code duplication and paves the way for modifying how
Mach loads modules.

The plan is to follow this up by making this function take a more fleshed out 'spec'
that maps command names to the files they're defined at and possibly more metadata.
Since this may affect how Mach works internally (e.g. with lazy loading in the roadmap),
it makes sense to move this logic inside the Mach class.

Differential Revision: https://phabricator.services.mozilla.com/D136789
2022-02-02 20:25:20 +00:00
Mitchell Hentges 92a19e0eb9 Bug 1740123: Allow invoking Mach outside of MozillaBuild r=glandium
Assuming that the `MOZILLABUILD` environment variable is set, allow
invoking Mach from non-MozillaBuild terminals.

Note that MozillaBuild still needs to be installed, and the
`MOZILLABUILD` environment variable will have to be set.

For future reference: when I tried setting this up with Windows
Store's Python 3.9, I encountered issues when running binaries installed
via `pip`: it would fail with `abort: failed to load Python DLL
python3x.dll`.

Differential Revision: https://phabricator.services.mozilla.com/D133936
2022-01-06 06:49:47 +00:00
Mitchell Hentges 0445e1ce71 Bug 1740123: Move Python version check earlier r=ahal
Move Python version check as early as possible so that more code can
safely depend on modern behaviour while out-of-date Python versions still
get graceful error messages.

Without this change, Python 2 usages fail on importing `importlib.util`
before the nice "out-of-date version" warning is printed.

Differential Revision: https://phabricator.services.mozilla.com/D134185
2022-01-06 00:32:49 +00:00
Marian-Vasile Laza 7262acfd88 Backed out 2 changesets (bug 1725895, bug 1740123) for causing build bustages.
Backed out changeset a6eabd95e31d (bug 1740123)
Backed out changeset bfd5211060b4 (bug 1725895)
2022-01-05 03:46:17 +02:00
Mitchell Hentges 8fff83d33d Bug 1740123: Move Python version check earlier r=ahal
Move Python version check as early as possible so that more code can
safely depend on modern behaviour while out-of-date Python versions still
get graceful error messages.

Without this change, Python 2 usages fail on importing `importlib.util`
before the nice "out-of-date version" warning is printed.

Differential Revision: https://phabricator.services.mozilla.com/D134185
2022-01-04 21:07:32 +00:00
Mitchell Hentges 0fb9e1cb04 Bug 1743592: Don't resolve/create scoped state_dir in CI r=ahal
We only need a workdir-scoped state_dir when an on-disk virtualenv will
be created for the Mach site.

This change defers the resolution of the state_dir until we know that a
VENV will be created.

Also modify "telemetry.py" so that it isn't creating a
scoped state-dir to compare "sys.executable" against.

Differential Revision: https://phabricator.services.mozilla.com/D132706
2021-12-03 16:26:45 +00:00
Mitchell Hentges 6571032077 Bug 1739067: Scope Mach virtualenv to be checkout-specific r=perftest-reviewers,ahal,sparky
Build and run the Mach virtualenv from a `state_dir` that is
"specific-to-topsrcdir".

As part of this, move `get_state_dir()` to `mach` so that it's usable
before `sys.path` entries are fully set up.

Differential Revision: https://phabricator.services.mozilla.com/D130383
2021-11-29 22:33:54 +00:00
Mitchell Hentges abeedf3bbd Bug 1717051: Automatically create and activate Mach virtualenv r=ahal
Consolidate Mach virtualenv management to the front of the
Mach process. This obsoletes `./mach create-mach-environment`
and simplifies the `sh` portion of the top-level `./mach` script.

This helps ensure that the Mach virtualenv doesn't become
out-of-sync and simplifies the mental model of the Mach
virtualenv situation.

Differential Revision: https://phabricator.services.mozilla.com/D120401
2021-11-24 20:06:33 +00:00
Mitchell Hentges cea54423c4 Bug 1738848: Handle virtualenv case where metadata file is missing r=ahal
At Mach initialization time, it needs to know if it's not running from
the Mach virtualenv so it can decide to insulate itself from the
external sys.path.

However, the current mechanism of detecting the Mach virtualenv
struggles if the venv is old, and therefore missing its metadata file.
In such a case, it's recognized as "not the Mach venv" rather than "an
out-of-date Mach venv".

As part of this, I'm realizing that simply using the metadata file as a
"virtualenv has finished building" marker is insufficient, because it
will cause similar confusion here. This is solved with a "finalization"
key in in the metadata.

Differential Revision: https://phabricator.services.mozilla.com/D130794
2021-11-24 20:06:31 +00:00
Mitchell Hentges 84e16b0d9c Bug 1730712: Split site manager into command and mach managers r=ahal
The command site manager needs to be able to do ad-hoc pip
installations, while the Mach site manager needs to manage
the system `sys.path` and conditionally create an on-disk
virtualenv.

By splitting the class into two, we can now give each use case the
attention it deserves.

Differential Revision: https://phabricator.services.mozilla.com/D129529
2021-11-17 20:54:27 +00:00
Mitchell Hentges 876c31175a Bug 1730712: Remove pip package check in site.up_to_date() r=ahal
Sorry for the flip-flop on technique here :S

`validate_environment_packages()` was originally run when checking if a
site is up-to-date to ensure that ad-hoc pip installs didn't replace
needed packages with those of different versions.

However, since it was added, a few notes have come up:
1. The case where requirements change isn't caught by this - that is
  caught earlier by the cheap "a requirements file has changed on-disk"
  check.
2. This is really slow, and doing it for most Mach commands is not worth
  it (as evident by how the `skip_pip_package_check` was already added
  for the Mach site's use case).
3. Since the tree as-is doesn't have (common) cases where ad-hoc
  installations break an environment, then this check, though helpful,
  isn't adding a significant amount of value considering its performance
  cost.

However, these aren't to say that this won't be valuable in the future:
I'd like to reach a point where sites are considered "sealed" by
default: no ad-hoc pip installations are allowed.
However, add the ability to mark sites as unsealed/"allowing
ad-hoc pip installations". Then, re-add the pip package check, but only
for such flexible, unsealed virtualenvs.

Differential Revision: https://phabricator.services.mozilla.com/D129692
2021-11-17 20:54:26 +00:00
Mitchell Hentges 725792bd05 Bug 1730712: Update "Moz site" terminology r=ahal
The existing terminology had two issues:
* `VirtualenvManager` wasn't always associated with an on-disk
  `virtualenv`: for example, when running in automation, Mach
  "activates" a `VirtualenvManager`, updating its import scope,
  but without ever creating an on-disk `virtualenv`.
* An upcoming patch splits the `VirtualenvManager` class, pulling
  "on-disk virtualenv-handling functions" from the project-wide
  interface for managing Python's import scope.

After some good discussion with Ahal, I think we've struck
the terminology that handles this distinction well: we'll call
the "import scope"-handling part the "site", and we'll continue
to call on-disk virtualenvs (and their representative classes)
as, well, virtualenvs.

Differential Revision: https://phabricator.services.mozilla.com/D130391
2021-11-17 20:54:23 +00:00
Mitchell Hentges 67be954a8c Bug 1739177: Add `requirements.pths_as_absolute()` r=ahal
There were a bunch of locations where we were doing path shenanigans
with `requirements.pth/.vendored` items.

There was a bit of complexity because we were specifically making each
`pthfile` line be a relative path to support moving the Firefox
topsrcdir without causing issues.

However, now that we're more intelligent about checking if `pthfile`
lines are up-to-date (and since moving your topsrcdir will still require
re-generating the Mach virtualenv), this behaviour became less useful.

So, generalize `MachEnvRequirements` -> "sys.path lines" logic and
reuse it everywhere.

Differential Revision: https://phabricator.services.mozilla.com/D129693
2021-11-04 14:35:08 +00:00
Mitchell Hentges a9f396324f Bug 1717051: Always populate Mach pths r=firefox-build-system-reviewers,glandium
The previous behaviour was to:
* Never add a `pthfile` to the Mach virtualenv, and
* Always add Mach's paths to the `sys.path` when Mach initializes

However, this meant that `pip` would needlessly install packages
that already exist in the vendored environment.

Tweak `pth` behaviour so that `pip` behaves more efficiently.

Differential Revision: https://phabricator.services.mozilla.com/D120402
2021-11-01 21:34:03 +00:00
Mitchell Hentges 537d201bcc Bug 1732948: Assert that the Mach venv isn't out-of-date during init r=ahal
As we leverage the Mach environment more, it becomes increasingly
important that it isn't out-of-date on developer machines.

Add an `up_to_date()` check during Mach initialization.
To minimize the cost to startup, I'm skipping the "pip list" check.

This change required moving `virtualenv` from `mozbuild` to `mach` to
make it available during the early stage of Mach init.

Differential Revision: https://phabricator.services.mozilla.com/D127144
2021-11-01 21:34:02 +00:00
Mitchell Hentges f8a3e6458a Bug 1723031: In CI, assert Mach pypi package deps using system Python r=ahal
There's an existing algorithm to check if a virtualenv's installed
packages are up-to-date with its requirements. This patch
extracts that logic so that, in cases where we can't automatically
download needed pip packages, we can at least assert that the ones
installed to the system Python are sufficient to meet our requirements.

The current only case in which this system-checking logic is applied
is when starting the Mach virtualenv and the `MOZ_AUTOMATION` or
`MACH_USE_SYSTEM_PYTHON` environment variable is set.

Differential Revision: https://phabricator.services.mozilla.com/D122890
2021-10-13 15:57:40 +00:00
Mike Hommey c1bd50d07c Bug 1734754 - Remove the use of MozbuildObject.mozconfig in mach_initialize. r=firefox-build-system-reviewers,mhentges
Differential Revision: https://phabricator.services.mozilla.com/D127767
2021-10-12 04:05:32 +00:00
Alexandru Michis 820696d4a1 Backed out 2 changesets (bug 1734523) for causing python failures.
CLOSED TREE

Backed out changeset dcd0fedade7e (bug 1734523)
Backed out changeset cab1ceba09dd (bug 1734523)
2021-10-08 01:19:24 +03:00
Mike Hommey f2e2f3db8a Bug 1734523 - Remove the use of MozbuildObject.mozconfig in mach_initialize. r=firefox-build-system-reviewers,mhentges
Differential Revision: https://phabricator.services.mozilla.com/D127767
2021-10-07 21:22:19 +00:00
Narcis Beleuzu 7f08e7385e Backed out changeset 68940497078c (bug 1723031) for causing pip setup issues (bug 1733142) 2021-10-04 13:01:21 +03:00
criss 16f898657c Backed out changeset 894fc83e19a0 (bug 1717051) for causing busting macth commands. a=backout 2021-09-30 10:36:36 +03:00
Mitchell Hentges ab439e4045 Bug 1717051: Always populate Mach pths r=firefox-build-system-reviewers,glandium
The previous behaviour was to:
* Never add a `pthfile` to the Mach virtualenv, and
* Always add Mach's paths to the `sys.path` when Mach initializes

However, this meant that `pip` would needlessly install packages
that already exist in the vendored environment.

Tweak `pth` behaviour so that `pip` behaves more efficiently.

Differential Revision: https://phabricator.services.mozilla.com/D120402
2021-09-29 15:09:36 +00:00
Mitchell Hentges 6901d2f440 Bug 1723031: In CI, assert Mach pypi package deps using system Python r=ahal
There's an existing algorithm to check if a virtualenv's installed
packages are up-to-date with its requirements. This patch
extracts that logic so that, in cases where we can't automatically
download needed pip packages, we can at least assert that the ones
installed to the system Python are sufficient to meet our requirements.

The current only case in which this system-checking logic is applied
is when starting the Mach virtualenv and the `MOZ_AUTOMATION` or
`MACH_USE_SYSTEM_PYTHON` environment variable is set.

Differential Revision: https://phabricator.services.mozilla.com/D122890
2021-09-29 13:06:00 +00:00
Mitchell Hentges 9c77153d02 Bug 1723031: Allow flexible dependency-specification in the Mach venv r=ahal
There's some trade-offs in play here: the major issue is that we can't
pin `psutil`'s because it's pre-installed on some CI workers with a
different version (5.4.2).

Additionally, we can't "just" bump that version, because CI workers jump
between different revisions to do work, so a specific pinned version
won't work when we try to update such a package.

One option is that we could avoid validating package versions in CI, but
then that will cause surprises (heck, I didn't know we were still using
`psutil==5.4.2` instead of `5.8.0` until now). By doing validation, we
make it more explicit and avoid accidentally depending on behaviour of
too new of such a package.

However, in most cases, we manage the installation environment and can
pin dependencies. So, I've made the top-level Mach virtualenv the _only_
one that is able to use requirement specifiers other than "==".

Differential Revision: https://phabricator.services.mozilla.com/D122889
2021-09-28 14:59:29 +00:00
Mitchell Hentges ff01350ad5 Bug 1712151: Add test to verify virtualenv compatibility r=ahal
This adds two main compatibility guarantees:
1. Vendored dependencies <=> Pypi-downloaded dependencies
2. Global Mach dependencies <=> command-specific dependencies

As part of this, a new `vendored:` action was added to the virtualenv
definition format. Otherwise similar to `pth:` paths, `vendored:`
packages are assumed to be "pip install"-able.

Some validation (the `.dist-info`/`PKG-INFO` checks) was added to
`requirements.py` to verify that `pth:` and `vendored:` are correctly
used.

Differential Revision: https://phabricator.services.mozilla.com/D122900
2021-09-28 14:59:28 +00:00
Mitchell Hentges 0eb329a6f8 Bug 1717051: Reuse "requirements" logic in mach_initialize r=ahal
Rather than re-implementing it as `search_path()`, use the existing
`MachEnvRequirements` tool to parse `mach_virtualenv_requirements.txt`

Differential Revision: https://phabricator.services.mozilla.com/D126280
2021-09-28 14:59:28 +00:00
criss f2dcba95fa Backed out 10 changesets (bug 1712151, bug 1724279, bug 1730712, bug 1717051, bug 1723031, bug 1731145) for causing failures on test_yaml.py
Backed out changeset 7f64d538701b (bug 1723031)
Backed out changeset 394152994966 (bug 1723031)
Backed out changeset 9bfeb01bcc9a (bug 1723031)
Backed out changeset 3d283616a57d (bug 1730712)
Backed out changeset bc677b409650 (bug 1724279)
Backed out changeset 784c94c2f528 (bug 1723031)
Backed out changeset 6e1bde40e3b4 (bug 1723031)
Backed out changeset 7adf7e2136a3 (bug 1712151)
Backed out changeset 2aef162b9a1b (bug 1717051)
Backed out changeset 9beeb6d3d95b (bug 1731145)
2021-09-28 00:32:38 +03:00
Mitchell Hentges 99ad911a95 Bug 1723031: In CI, assert Mach pypi package deps using system Python r=ahal
There's an existing algorithm to check if a virtualenv's installed
packages are up-to-date with its requirements. This patch
extracts that logic so that, in cases where we can't automatically
download needed pip packages, we can at least assert that the ones
installed to the system Python are sufficient to meet our requirements.

The current only case in which this system-checking logic is applied
is when starting the Mach virtualenv and the `MOZ_AUTOMATION` or
`MACH_USE_SYSTEM_PYTHON` environment variable is set.

Differential Revision: https://phabricator.services.mozilla.com/D122890
2021-09-27 20:27:22 +00:00
Mitchell Hentges f3f13dfc13 Bug 1723031: Allow flexible dependency-specification in the Mach venv r=ahal
There's some trade-offs in play here: the major issue is that we can't
pin `psutil`'s because it's pre-installed on some CI workers with a
different version (5.4.2).

Additionally, we can't "just" bump that version, because CI workers jump
between different revisions to do work, so a specific pinned version
won't work when we try to update such a package.

One option is that we could avoid validating package versions in CI, but
then that will cause surprises (heck, I didn't know we were still using
`psutil==5.4.2` instead of `5.8.0` until now). By doing validation, we
make it more explicit and avoid accidentally depending on behaviour of
too new of such a package.

However, in most cases, we manage the installation environment and can
pin dependencies. So, I've made the top-level Mach virtualenv the _only_
one that is able to use requirement specifiers other than "==".

Differential Revision: https://phabricator.services.mozilla.com/D122889
2021-09-27 20:27:20 +00:00
Mitchell Hentges 74b09f92ce Bug 1712151: Add test to verify virtualenv compatibility r=ahal
This adds two main compatibility guarantees:
1. Vendored dependencies <=> Pypi-downloaded dependencies
2. Global Mach dependencies <=> command-specific dependencies

As part of this, a new `vendored:` action was added to the virtualenv
definition format. Otherwise similar to `pth:` paths, `vendored:`
packages are assumed to be "pip install"-able.

Some validation (the `.dist-info`/`PKG-INFO` checks) was added to
`requirements.py` to verify that `pth:` and `vendored:` are correctly
used.

Differential Revision: https://phabricator.services.mozilla.com/D122900
2021-09-27 20:27:19 +00:00
Mitchell Hentges b9d0572034 Bug 1717051: Reuse "requirements" logic in mach_initialize r=ahal
Rather than re-implementing it as `search_path()`, use the existing
`MachEnvRequirements` tool to parse `mach_virtualenv_requirements.txt`

Differential Revision: https://phabricator.services.mozilla.com/D126280
2021-09-27 20:27:19 +00:00
Mitchell Hentges 2b15db71aa Bug 1717051: Consolidate state_dir creation r=firefox-build-system-reviewers,glandium
We had logic in both `mach_bootstrap` and the Mach Bootstrapper to
create the state_dir.

This joins them and has the added benefit of creating the state dir
earlier in the Mach lifecycle (as will be needed for early instantiation
of the Mach virtualenv).

Differential Revision: https://phabricator.services.mozilla.com/D120400
2021-09-03 20:46:23 +00:00
Mitchell Hentges f5b0cb5bc1 Bug 1717051: Rename "mach_bootstrap.py" to "mach_initialize.py" r=firefox-build-system-reviewers,glandium
We've overloaded "bootstrap" to mean three different things:
* The "standalone bootstrap script": `python/mozboot/bin/bootstrap.py`.
  This is to freshly clone a new repo, then run `./mach bootstrap`.
* `./mach bootstrap`: Install necessary dependencies and set up the
  system for development.
* "Mach bootstrap": do the in-process initialization work Mach needs
  before it can run commands.

By using the term "initialize" instead, perhaps we can remove
ambiguity when discussing Mach.

I'm not attached to the name (or this change at all), but I'm interested
in reviewer thoughts :)

Differential Revision: https://phabricator.services.mozilla.com/D120410
2021-09-03 20:46:22 +00:00