summaryrefslogtreecommitdiff
path: root/mesonbuild/msetup.py
AgeCommit message (Collapse)Author
2025-10-29replace "in d.keys()" with "in d"Paolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29coredata: move cmd_line.txt and command line handling to a new modulePaolo Bonzini
cmd_line.txt is not related to serialized data, in fact it's a fallback for when serialized data cannot be used and is also related to setting up argparse for command line parsing. Since there is no code in common with the rest of coredata, move it to a new module. Fixes: #15081 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-16intro: compute meson_variables for dependencies at setup timePaolo Bonzini
Another place where the interpreter is accessed surreptitiously is dependency introspection, which looks at the variables. Do that at setup time instead while the interpreter is alive. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-16build, backend: store build_def_files in BuildPaolo Bonzini
The interpreter's build_def_files are the only remaining piece of interpreter state used by the backend. Compute it once and store it in build, using a property to ensure that it's initialized and accessed correctly. This also removes one of the cases in which introspection uses the interpreter object. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-09-09msetup: not-found subprojects do not have known optionsPaolo Bonzini
If a subproject had its SubprojectHolder created, but was disabled, its options were not parsed; therefore the subproject should not be checked for unknown options. Fixes: #14969 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-17options: parse -D and -U arguments directly into a Dict[OptionKey, ↵Paolo Bonzini
Optional[str]] As a side effect, this deduplicates -D and -U arguments passed to meson configure, taking into account the relative ordering of -D and -U options. Fixes: #14754 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-07msetup: keep pending optionsPaolo Bonzini
New languages and subprojects can appear in subsequent configurations. Subproject options are kept for later now that they are not stored in pending_options, but compiler options for example are not. Drop OptionStore.clear_pending so that they are preserved as well. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-07msetup, options: reverse direction of unknown options checkPaolo Bonzini
Remove knowledge of the internal pending_options from msetup; operate on the command line and check against the option store. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-18coredata: use OptionKey for the keys of cmd_line_optionsPaolo Bonzini
The cmd_line_options dictionary is described as having OptionKey keys, so make sure that cmd_the keys do have the correct type. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-03utils: Replace BuildDirLock with generic DirectoryLockFlorian "sp1rit"​
DirectoryLock provides a generic locking implementation the replaces the previously used BuildDirLock.
2025-05-21options: commonize code to accept unknown optionsPaolo Bonzini
The check for unknown options is duplicated in OptionStore and MesonApp. Place the better version of the two as a new method of OptionStore, and use it in OptionStore.validate_cmd_line_options. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-05-15msetup: update coredata if options are passed together with --reconfigurePaolo Bonzini
This makes "meson setup --reconfigure" behave quite literally the same as "meson configure" + "meson setup"; except that saving coredata and cmdline file is delayed until the setup succeeds. Fixes: #14575 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-02options: we need to skip build options for machine files as wellDylan Baker
When doing a host == build configuration. This allows us to remove the ignore in check_unused_options, which was papering over this bug.
2025-04-02options: Rename BASE_OPTIONS -> COMPILER_BASE_OPTIONSDylan Baker
Which better describes their purpose, especially now that this is in the options module rather than the compilers module.
2025-04-02options: rename OptStore.pending_project_options -> pending_optionsDylan Baker
It's not just project options, it's all options that can end up on here.
2025-04-02options: move BASE_OPTIONS to the options moduleDylan Baker
This makes more sense from a "group all options together" It also allows us to remove a bunch of imports in functions, a clear code smell.
2025-03-04msetup: remove bad warning about unused optionsDylan Baker
This is just a bad warning, while it *could* give the user useful information, it often doesn't since it can get values to warn about from: - environment variables - the command line - machine files - `project(default_options : ...)` - `subproject(default_options : ...)` - `dependency(default_options : ...)` The problem of course is that user may have no control over these values. 3 of them are hardcoded into the meson.build files, so the user can't do anything about them. And there are legitimate reasons to have unused values in those, like setting defaults for a language only used on specific platforms. Environment variables may be set by the distro (NixOS sets them for any enabled language, so just having a D compiler causes `DFLAGS` to be set, for example). They likely don't want to special case "only set the environment variables if the project is going to use them". For machine files it limits the utility of the files, since the user needs to be sure that they don't include any options that wont be used. Finally, the command line could be altered by wrapper scripts, or simply programmed to insert options that *may* be used but aren't required. like setting `objc_args` regardless of whether ObjectivC bindings are generated. However, passing completely unknown builtin options should be an error, as it was before the optionrefactor
2025-02-22Permit all unknown b_ options.Jussi Pakkanen
Closes #14254.
2025-02-15Permit more missing b options. Closes #14254.Jussi Pakkanen
2025-02-13Make all Meson level options overridable per subproject.Jussi Pakkanen
2024-10-31msetup: Correction of the message textx1z53
2024-09-11Fix typosspaette
2024-07-11Move OptionKey in the option source file.Jussi Pakkanen
2024-06-23msetup: fix regression under py3.13 causing profile.runctx to not write locals()Eli Schwartz
"PEP 667: Consistent views of namespaces" caused locals() to be inconsistent between uses since it is now created afresh every time you invoke it and writes to it are dropped. `sys._getframe().f_locals` is equivalent but preserves writes (it doesn't create a new dict) and unfortunately doesn't help at all as it's documented to be a private implementation detail of CPython that "should be used for internal and specialized purposes only". Work around this by saving locals to a variable reference and both passing it into runctx and reusing it in lookups of the result. This works okay for both new and older versions of python. Per the documentation for locals(): > The contents of this dictionary should not be modified; changes may > not affect the values of local and free variables used by the > interpreter. So... lesson learned? :) This was introduced in commit c34ee374a77fb2dffff90364506ac0cbbb1f00de; before that, we still used locals() but only to pass local variables *in*. Bug: https://github.com/python/cpython/pull/115153
2024-06-14Replace direct indexing with named methods.Jussi Pakkanen
2024-06-14Rename option variable to optstore to make it unique.Jussi Pakkanen
2024-02-23mconf|msetup: use Protocol for argparse optionsDylan Baker
These are much easier to handle as one commit since msetup calls mconf internally. This has found one case where things are being carefully crafted to work in mconf even though msetup has slightly different options
2023-12-22stop using the interpreter holders for the MachineInfoDylan Baker
Anywhere we have that, we also have the Environment object, which is just wrapped by the Interpreter methods anyway. This avoids inderections that are unnecessary.
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-11-01Add comments suggesting to keep shell completion scripts up-to-date near cmd ↵Luke Elliott
line argument code
2023-08-25msetup: Update options when builddir is already configuredXavier Claessens
`meson setup -Dfoo=bar builddir` command was returning success ignoring new option values. This now also update options. It is useful because it means `meson setup -Dfoo=bar builddir && ninja -C builddir` works regardless whether builddir already exists or not, and when done in a script, changing options in the script will automatically trigger a reconfigure if needed. This was already possible by always passing --reconfigure argument, but that triggers a reconfigure even when options did not change.
2023-07-24fix a few miscellaneous implicit-optional typing issuesEli Schwartz
2023-07-21Display more timestamps when profiling ninjaCharles Brunet
When running setup with `--profile-self` option, there are currently no logs after "Found ninja...". However, there are still some lengthy processes for generating targets and ninja.build. This add more log entries, when profiling, only for the purpose of displaying the timestamps of the different steps in ninja generation.
2023-07-03fix the use of setup --profile-self in combination with --genvsliteDan Hawson
After the recent change to the backend `generate(...)` signature for '--genvslite', `profile.runctx('...')` needs to construct the correct cmd string and also extract the return result from `locals()`.
2023-07-02genvslite: greatly simplify the implementation of non-genvslite backendsEli Schwartz
By avoiding Java-style variable naming, the code becomes considerably more readable while simultaneously becoming *more* easy to understand. It's no longer necessary to ask questions like "what's a captured buildtype" when trying to read through the code for a backend, because it can be dismissed as not relevant to the current context by re-reading it as "context for vslite". The primary goal here has been to revert regressions in the developer experience for users of the ninja backend, so there may still be issues in vs2010backend.py Post-facto application of issues that were raised during review, ignored, and merged despite such.
2023-07-02genvslite: fix badly overflowing line lengthsEli Schwartz
Function comments that overflow the screen width by coming after code, instead of on their own line, are hard to read. Same applies to message strings that are all on one line. Fix by reflowing them. Post-facto application of issues that were caught during post-merge review, after the genvslite PR was merged without a full review.
2023-06-28Experimental 'genvslite' WIP. (#11049)GertyP
* Capture all compile args from the first round of ninja backend generation for all languages used in building the targets so that these args, defines, and include paths can be applied to the .vcxproj's intellisense fields for all buildtypes/configurations. Solution generation is now set up for mutiple build configurations (buildtypes) when using '--genvslite'. All generated vcxprojs invoke the same high-level meson compile to build all targets; there's no selective target building (could add this later). Related to this, we skip pointlessly generating vcxprojs for targets that aren't buildable (BuildTarget-derived), which aren't of interest to the user anyway. When using --genvslite, no longer inject '<ProjectReference ...>' dependencies on which a generated .vcxproj depends because that imposes a forced visual studio build dependency, which we don't want, since we're essentially bypassing VS's build in favour of running 'meson compile ...'. When populating the vcxproj's shared intellisense defines, include paths, and compiler options fields, we choose the most frequent src file language, since this means more project src files can simply reference the project shared fields and fewer files of non-primary language types need to populate their full set of intellisense fields. This makes for smaller .vcxproj files. Paths for generated source/header/etc files, left alone, would be added to solution projects relative to the '..._vs' build directory, where they're never generated; they're generated under the respective '..._[debug/opt/release]' ninja build directories that correspond to the solution build configuration. Although VS doesn't allow conditional src/header listings in vcxprojs (at least not in a simple way that I'm aware of), we can ensure these generated sources get adjusted to at least reference locations under one of the concrete build directories (I've chosen '..._debug') under which they will be generated. Testing with --genvslite has revealed that, in some cases, the presence of 'c:\windows\system32;c:\windows' on the 'Path' environment variable (via the make-style project's ExecutablePath element) is critical to getting the 'meson compile ...' build to succeed. Not sure whether this is some 'find and guess' implicit defaults behaviour within meson or within the MSVC compiler that some projects may rely on. Feels weird but not sure of a better solution than forcibly adding these to the Path environment variable (the Executable Path property of the project). Added a new windows-only test to windowstests.py ('test_genvslite') to exercise the --genvslite option along with checking that the 'msbuild' command invokes the 'meson compile ...' of the build-type-appropriate-suffixed temporary build dir and checks expected program output. Check and report error if user specifies a non-ninja backend with a 'genvslite' setup, since that conflicts with the stated behaviour of genvslite. Also added this test case to 'WindowsTests.test_genvslite' I had problems tracking down some problematic environment variable behaviour, which appears to need a work-around. See further notes on VSINSTALLDIR, in windowstests.py, test_genvslite. 'meson setup --help' clearly states that positional arguments are ... [builddir] [sourcedir]. However, BasePlatformTests.init(...) was passing these in the order [sourcedir] [builddir]. This was producing failures, saying, "ERROR: Neither directory contains a build file meson.build." but when using the correct ordering, setup now succeeds. Changed regen, run_tests, and run_install utility projects to be simpler makefile projects instead, with commands to invoke the appropriate '...meson.py --internal regencheck ...' (or install/test) on the '[builddir]_[buildtype]' as appropriate for the curent VS configuration. Also, since the 'regen.vcxproj' utility didn't work correctly with '--genvslite' setup build dirs, and getting it to fully work would require more non-trivial intrusion into new parts of meson (i.e. '--internal regencheck', '--internal regenerate', and perhaps also 'setup --reconfigure'), for now, the REGEN project is replaced with a simpler, lighter-weight RECONFIGURE utility proj, which is unlinked from any solution build dependencies and which simply runs 'meson setup --reconfigure [builddir]_[buildtype] [srcdir]' on each of the ninja-backend build dirs for each buildtype. Yes, although this will enable the building/compiling to be correctly configured, it can leave the solution/vcxprojs stale and out-of-date, it's simple for the user to 'meson setup --genvslite ...' to fully regenerate an updated, correct solution again. However, I've noted this down as a 'fixme' to consider implementing the full regen behaviour for the genvslite case. * Review feedback changes - - Avoid use of 'captured_compile_args_per_buildtype_and_target' as an 'out' param. - Factored a little msetup.py, 'run(...)' macro/looping setup steps, for genvslite, out into a 'run_genvslite_setup' func. * Review feedback: Fixed missing spaces between multi-line strings. * 'backend_name' assignment gets immediately overwritten in 'genvslite' case so moved it into else/non-genvslite block. * Had to bump up 'test cases/unit/113 genvslites/...' up to 114; it collided with a newly added test dir again. * Changed validation of 'capture' and 'captured_compile_args_...' to use MesonBugException instead of MesonException. * Changed some function param and closing brace indentation.
2023-06-26pkgconfig: move uninstalled devenv handling from setup to the module hookEli Schwartz
msetup.py doesn't need to know the gory details of PkgConfigDependency, or directly import it at program startup. It's also slightly wasteful to generate a devenv for the -uninstalled directory when a project doesn't even, in the end, use the pkgconfig module anyway.
2023-06-26add profiling startup import check and testcase to count itEli Schwartz
2023-06-25msetup: place profiling logs in the log directoryEli Schwartz
2023-05-02update the devenv module hooks to support generic modifications to BuildEli Schwartz
We may want to do things like update install scripts as well, which have to happen before generating the backend. Instead of adding one module method per thing to do, use a single function that allows for modifying the Build object directly.
2023-03-30msetup: Allow (re)configure of not empty builddirXavier Claessens
Also prevent from using a parent directory as builddir by mistake. Co-authored-by: Volker Weißmann <volker.weissmann@gmx.de> Co-authored-by: Charles Brunet <charles.brunet@optelgroup.com>
2023-03-30msetup: use more consistent exceptions on exitXavier Claessens
- MesonException for errors is clearer than SystemExit('error message') and provides meson-formatted "ERROR: ..." - `raise SystemExit` with no parameter isn't obvious that it intends to exit successfully While clarifying the latter, it was observed to cause test_preprocessor_checks_CPPFLAGS() failure to be ignored. That test checks get_define() on both c and cpp compilers, which means we need to define either CPPFLAGS or both CFLAGS+CXXFLAGS.
2023-03-29Make --vsenv a readonly builtin optionXavier Claessens
We need to remember its value when reconfiguring, but the Build object is not reused, only coredata is. This also makes CLI more consistent by allowing `-Dvsenv=true` syntax. Fixes: #11309
2023-03-27Allow --reconfigure and --wipe of empty builddirXavier Claessens
This allows to run setup command regardless whether the builddir has been configured or not previously. This is useful for example with scripts that always repeat all options. meson setup builddir --reconfigure -Dfoo=bar
2023-02-28msetup: clarify error message when wrong directories are specifiedEli Schwartz
This can happen from typos, which then confusingly claim that neither build directory has a meson.build file because the implicit . directory was not actually one of the directories. Instead a random command line argument was interpreted as a directory name. Fixes #11472
2023-02-01treewide: add future annotations importEli Schwartz
2023-01-03msetup: do some stupid casting to make mypy happyDylan Baker
mypy is pretty dumb when it comes to unions of callables (pylance is also dumb in this regard), and can't figure out that our use of `mlog.debug | mlog.log` is perfectly safe. We also can't annotate them properly to cast them to a valid subset of arguments because you can't have splats in `typing.Callable`, so I've done enough to make it work.
2022-11-29pylint: enable used-before-assignmentDylan Baker
The one case of this was a false-positive, but what we were doing (checking locals()) is not idiomatic. I've replaced the call to `locals()` with the obvious `var: T.Optional[str] = None` with check instead.
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.