summaryrefslogtreecommitdiff
path: root/mesonbuild/mesonmain.py
AgeCommit message (Collapse)Author
2025-10-17options: Fix long/short option mixture detectionTobias Stoeckmann
Take the key/value separator `=` into account when comparing long and short option names to avoid invalid matches.
2025-04-18fix prefix computation in validate_original_argsPaolo Bonzini
validate_original_args only checks whether an option is prefixed with the name of a built-in option that was also set. It does not check whether the prefix is the full name of the option specified with -D. Adding an "=" at the end fixes the test. Fixes: #14487 Reported-by: Alyssa Ross <hi@alyssa.is> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-03-26select the correct meson_command for pyinstaller builds, even on not-WindowsEli Schwartz
We have previously updated the python_command handling to correctly detect PyInstaller builds without assuming that it is only Windows, back in commit c39ee881a1959ae37aded8e0c24cec23b2bd6a90. But the fix was incomplete. This affects e.g. running --internal scripts such as symbolextractor. The issue in this case is slightly more subtle. While sys.executable won't be a valid python so it intuitively falls over quite badly when trying to run it as one, getting the original command is broken in a more interesting way. PyInstaller sets `sys.argv[0]` to the basename of the executable, which then got absolutized to a nonexistent file in the current working directory. Fixes: https://github.com/mesonbuild/meson/issues/14412
2025-03-05options: split UserOption -> Argparse conversion out of BuiltinOptionDylan Baker
This is the first step do deleting the BuiltinOption altogether.
2025-02-13Make all Meson level options overridable per subproject.Jussi Pakkanen
2024-10-01Add a simple reproducibility test command.Jussi Pakkanen
2024-09-15When configuring fails in Github Actions, print folded logsEli Schwartz
A common, and challenging, issue in CI runners is debugging issues when you know the information you want to check, but it's in the log file which you don't have because remote CI machines. There are various edge cases where this is especially hard to solve, such as inside of `pip install` where the build directory with the log file is automatically cleaned up. But it's never really *easy* when you don't expect it, and the best case scenario is your iteration time gets cut in half as you hurriedly go add some `cat`s to your CI scripts. Meson can, at least sometimes, detect platforms where text can be emitted inside of "folds", which are auto-collapsed and don't obscure the general output, but when clicked will expand the logfile contents. Hook this up. We start off with a Github Actions implementation. We had some internal code used by our own project tests runner, which can be utilized. Also permit forcing it via an environment variable, in case autodetection fails and you just want to force *something*, especially when meson is called a couple layers deep inside some other tool.
2024-06-23Suggest mingw Python URL instead of specific package namesTristan Partin
Suggested by @lazka in order to be clearer when delineating between mingw-w64-x86_64-python and mingw-w64-ucrt-x86_64-python. Fixes: #12772
2024-04-08meson format commandCharles Brunet
2024-02-12add type annotations to mesonmainEli Schwartz
An oddity: sys.stdout is statically defined as type TextIO instead of TextIOWrapper, and thus doesn't have a .reconfigure method. This is because they expect people to override sys.stdout with other objects, which we do not do. Instead, assume it is always correct. There are two final errors due to metaprogramming: ``` mesonbuild/mesonmain.py:196:13: error: Returning Any from function declared to return "int" [no-any-return] mesonbuild/mesonmain.py:225:9: error: Returning Any from function declared to return "int" [no-any-return] ```
2023-12-13Use SPDX-License-Identifier consistentlyDylan Baker
This replaces all of the Apache blurbs at the start of each file with an `# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing uses to be consistent in capitalization, and to be placed above any copyright notices. This removes nearly 3000 lines of boilerplate from the project (only python files), which no developer cares to look at. SPDX is in common use, particularly in the Linux kernel, and is the recommended format for Meson's own `project(license: )` field
2023-03-28do not resolve symlinks when calculating the meson commandEli Schwartz
We embed the route to executing meson in various cases, most especially regen rules in build.ninja. And we take care to ensure that it's a canonicalized path. Although the code has moved around over time, and adapted in ways both bad and good, the root of the matter really comes down to commit 69ca8f5b544f700210d9f18613311bcce3c2e37a which notes the importance of being able to run meson from any location, potentially not on PATH or anything else. For this reason, we switched from embedding sys.argv[0] to os.path.realpath, a very heavy stick indeed. It turns out that that's not actually a good thing though... simply resolving the absolute path is enough to ensure we can accurately call meson the same way we originally did, and it avoids cases where the original way to call meson is via a stable symlink, and we resolved a hidden location. Homebrew does this, because the version of a package is embedded into the install directory. Even the bugfix release. e.g. ``` /opt/homebrew/bin/meson ``` is symlinked to ``` /opt/homebrew/Cellar/meson/1.0.0/bin/meson ``` Since we went beyond absolutizing the path and onwards to canonicalizing symlinks, we ended up writing the latter to build.ninja, and got a "command not found" when meson was upgraded to 1.0.1. This was supposed to work flawlessly, because build directories are compatible across bugfix releases. We also get a "command not found" when upgrading to new feature releases, e.g. 0.64.x to 1.0.0, which is a terrible error message. Meson explicitly "doesn't support" doing this, we throw a MesonVersionMismatchException or in some cases warn you and then effectively act like --wipe was given. But the user is supposed to be informed exactly what the problem is, rather than getting "command not found". Since there was never a rationale to get the realpath anyways, downgrade this to abspath. Fixes #11520
2023-02-01treewide: add future annotations importEli Schwartz
2023-01-30runpython: make it work for -c as wellEli Schwartz
In commit 4e4f97edb3d475273108b203bc02b04bd6840b06 we added support for runpython to accept `-c 'code to execute'` in addition to just script files. However, doing so would mangle the sys.argv in the executed code -- which assumes, as python itself does, that argv is the stuff after the code to execute. We correctly handled this for script files, but the original addition of -c support pushed this handling into a script-file specific block.
2023-01-04add a hidden environment variable to make Meson complain hard on deprecationsEli Schwartz
Useful for running the testsuite with this environment variable and catching obscure issues. Just like with the encoding warning later down, we have to do this inside meson itself, not externally injected.
2022-11-30pylint: enable the set_membership pluginDylan Baker
Which adds the `use-set-for-membership` check. It's generally faster in python to use a set with the `in` keyword, because it's a hash check instead of a linear walk, this is especially true with strings, where it's actually O(n^2), one loop over the container, and an inner loop of the strings (as string comparison works by checking that `a[n] == b[n]`, in a loop). Also, I'm tired of complaining about this in reviews, let the tools do it for me :)
2022-11-03python 3.11: suppress an incorrect EncodingWarningEli Schwartz
python 3.11 adds a warning that in 3.15, UTF-8 mode will be default. This is fantastic news, we'd love that. Less fantastic: this warning is silly, we *want* these checks to be affected. Plus, the recommended alternative API would (in addition to warning people when UTF-8 mode removed the problem) also require using a minimum python version of 3.11 (in which the warning was added) or add verbose if/else soup. The simple, and obvious, approach is to add a warnings filter to hide it.
2022-09-28Move classes used by scripts to their own moduleXavier Claessens
Those classes are used by wrapper scripts and we should not have to import the rest of mesonlib, build.py, and all their dependencies for that. This renames mesonlib/ directory to utils/ and add a mesonlib.py module that imports everything from utils/ to not have to change `import mesonlib` everywhere. It allows to import utils.core without importing the rest of mesonlib.
2022-09-22clean up message for OSError errorhandlerEli Schwartz
Currently it repeats the text of the exception, which appeared immediately above. And strerror is already part of args, so that was then doubled. `str(e)` formats this much better anyway. While we are at it, point out that it is probably a build environment issue, rather than just saying "this is probably not a meson bug". The former comes across a bit more as constructive advice rather than just "idk but it's not our fault".
2022-09-22fix regression in logging runpython errorsEli Schwartz
In commit fa044e011d5d7a3525c9b3f2acfe1cbf4a0a96a1 we caught OSError and started emitting a special error message disclaiming that it probably isn't Meson's fault, and skipping the generic "This is a meson bug and should be reported" handler. But, we no longer did this after verifying that the command *isn't* runpython, so arbitrary scripts that raised OSError would start saying stuff about Meson, which was wrong. Start checking for runpython first.
2022-09-22refactor errorhandler for deduplication of logicEli Schwartz
Mostly just move a comment around back to where it's more relevant, and handle MESON_FORCE_TRACEBACK once instead of twice.
2022-09-22fix regression in handling errors during reconfigureEli Schwartz
In commit 9ed5cfda155c585f7aea896fe2f40d3a92eac43a we refactored startup to be a bit faster and import less. But this had the side effect of moving out of our errorhandler. Refactor this so it can be easily used elsewhere.
2022-09-19avoid importing the entire codebase at first startupEli Schwartz
We want to optimize out some internal codepaths used at build time by avoiding work such as argparse. This doesn't work particularly well when the argparse arguments are imported before then. Between them, they indirectly import pretty much all code anywhere, and msetup alone imports most of it. Also make sure the regenerate internal script goes directly to msetup.
2022-08-16fixup! deprecate running "meson builddir" without setup subcommandEli Schwartz
Also pass the setup command when rewriting --internal regenerate. This avoids the issue where `ninja` triggers a reconfigure, and this warning gets printed as a side effect.
2022-08-16deprecate running "meson builddir" without setup subcommandEli Schwartz
This is ambiguous, if the build directory has the same name as a subcommand then we end up running the subcommand. It also means we have a hard time adding *new* subcommands, because if it is a popular name of a build directory then suddenly scripts that try to set up a build directory end up running a subcommand instead. The fact that we support this at all is a legacy design. Back in the day, the "meson" program was for setting up a build directory and all other tools were their own entry points, e.g. `mesontest` or `mesonconf`. Then in commit fa278f351fe3d6924b4d1961f77b5b4a36e133f8 we migrated to the subcommand mechanism. So, for backwards compatibility, we made those tools print a warning and then invoke `meson <tool>`. We also made the `meson` tool default to setup. However, we only warned for the other tools whose entry points were eventually deleted. We never warned for setup itself, we just continued to silently default to setup if no tool was provided. `meson setup` has worked since 0.42, which is 5 years old this week. It's available essentially everywhere. No one needs to use the old backwards-compatible invocation method, but it continues to drag down our ability to innovate. Let's finally do what we should have done a long time ago, and sunset it.
2022-07-31handle OSError exception in run functionOmer Pereg
2022-07-17Resolve KeyError while executing help command with unknown paramPrathamesh
2022-06-22Move python version check as first thingXavier Claessens
2022-04-14pyupgrade --py37-plusEli Schwartz
Some more old style code crept in again. Additionally, pyupgrade learned to catch more if/elsed code based on the python version, and delete it.
2022-04-01main: Make the msys/python check work again, in some casesChristoph Reiter
msys/python in MSYS2 pretends to be cygwin in all cases for some time now, so this check was impossible to hit. The underlying confusion it tried to prevent is still there, namely trying to build with mingw but wrongly using a msys/cygwin python/meson. We can use the MSYSTEM env var to detect if we are in a mingw shell, and in case the Python doesn't match we suggest installing mingw variants of both python and meson. Using msys/python + meson in a MSYS environment works fine on the other hand, so no need to error out in that case. Fixes #8726 Also addresses the concern raised in https://github.com/mesonbuild/meson/issues/3653#issuecomment-474122564
2022-03-29Correctly handle --version argument to runpythonElliott Sales de Andrade
Followup to #10204.
2022-03-29runpython: support --versionEli Schwartz
argparse is the gift that keeps on giving, hahaha. Suppress the script argument when --version is specified to avoid "required argument not provided" errors, and print the python version. The version argument is required in order to make this baseline functional as a resolved python for find_program, which may specify a version and expect this to work with python itself. Our incomplete CLI wrapper over the python CLI interface was missing this. Fixes #10162
2022-03-09Add new env2mfile command.Jussi Pakkanen
2022-03-08Revert "Add new env2cross command."Eli Schwartz
This reverts commit e257a870fe5e676c55a2282b0e7fc9be34bba2ac. The PR adding this command had infinitely hanging CI, and now that it is merged to master we cannot get any CI on any PR to succeed.
2022-03-08Add new env2cross command.Jussi Pakkanen
2022-03-01use a more sane check instead of run_custom_lintEli Schwartz
Unfortunately, checking for strings without context is exceedingly prone to false positives, while missing anything that indirectly opens a file. Python 3.10 has a feature to warn about this though -- and it uses a runtime check which runs at the same time that the code fails to open files in the broken Windows locale. Set this up automatically when running the testsuite. Sadly, Python's builtin feature to change the warning level, e.g. by setting EncodingWarning to error at startup, is utterly broken if you want to limit it to only certain modules. This is tracked in order to be more efficiently ignored at https://bugs.python.org/issue34624 and https://github.com/python/cpython/pull/9358 It is also very trigger happy and passing stuff around via environment variable either messes with the testsuite, or with thirdparty programs which are implemented in python *such as lots of gnome*, or perhaps both. Instead, add runtime code to meson itself, to add a hidden "feature". In the application source code, running the 'warnings' module, you can actually get the expected behavior that $PYTHONWARNINGS doesn't have. So check for a magic testsuite variable every time meson starts up, and if it does, then go ahead and initialize a warnings filter that makes EncodingWarning fatal, but *only* when triggered via Meson and not arbitrary subprocess scripts.
2022-02-15fine-tune the logic for reporting context on tracebacksEli Schwartz
Do not report a MesonBugException if the command is `runpython`, because that is 100% other people's code, not ours. It's only used as an alternative to sys.executable for reporting a path to python, in the event of a Windows MSI install. While we are at it, refactor the logic for PermissionError to be a bit more unified (and sadly use isinstance instead of except, but it is what it is).
2022-01-27do not report context on python traceback, for PermissionErrorEli Schwartz
It's not a MesonBug which needs to be reported, and the existing error already adequately points out the problematic file. It is impossible to get a PermissionError for files created by meson itself, once the build directory has been created, anyway.
2022-01-10bump minimum required version of python to 3.7Eli Schwartz
Comment out the pending deprecation notice. It cannot be reached anymore, but is still useful for the next time we do a version bump.
2022-01-10add pending deprecation notice for python 3.6Eli Schwartz
2021-11-29report the context, if possible, on python tracebacksEli Schwartz
The interpreter tries to catch any exception and add the latest node information to it, but currently we only used that to print better formatted error messages on MesonException. Since we should theoretically have that property for most/all exceptions, let's percolate that upward, and message the user that an unexpected traceback was encountered, that it should be reported as a bug, and the helpful information of "how far into parsing this meson.build did we get before erroring out, anyway?"
2021-10-10Add --vsenv command line option and active VS only when neededXavier Claessens
2021-08-31pylint: turn on superflous-parensDylan Baker
We have a lot of these. Some of them are harmless, if unidiomatic, such as `if (condition)`, others are potentially dangerous `assert(...)`, as `assert(condtion)` works as expected, but `assert(condition, message)` will result in an assertion that never triggers, as what you're actually asserting is `bool(tuple[2])`, which will always be true.
2021-08-03fix bat_info UTF-8 string errorxth
" bat_info = json.loads(bat_json) " may produce error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 ... Because the vswhere.exe's output is not utf-8 by default Use UTF-8 encoding for vswhere.exe can fixing it .
2021-06-29fix: Always explicitly set encoding for text files (fixes #8263)Daniel Mensinger
2021-06-29pathlib: Patch pathlib to work around some bugs (fixes #7295)Daniel Mensinger
2021-06-09typing: Fully annotate run_project_tests.pyDaniel Mensinger
2021-05-28vsenv: Recommend using "meson compile" wrapperXavier Claessens
When meson has setup the VS environment, running ninja to build won't work, user should use meson wrapper to compile.
2021-05-28Remove `Microsoft.VisualStudio.Workload.WDExpress`Naveen M K
2021-05-28Find Visual Studio Build Tools 2019Naveen M K
Got the Idea from setuptools https://github.com/pypa/setuptools/blob/a5131f0b82e098da6c07a03a47f36f3a52f73fb6/setuptools/msvc.py#L176