summaryrefslogtreecommitdiff
path: root/mesonbuild/utils
AgeCommit message (Collapse)Author
2025-11-26vsenv: Use a python script to pickle envXavier Claessens
This is safer than parsing env from stdout
2025-11-14Add `os2_emxomf' option to generate OMF files on OS/2KO Myung-Hun
1. Generate OMF objs with `-Zomf' compiler flags 2. Generate OMF libs with `.lib' suffix using `emxomfar' as a librarian
2025-11-14Add functions to determine if OS/2KO Myung-Hun
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-29Add snippets.symbol_visibility_header() methodXavier Claessens
Defining public API in a cross platform library is painful, especially on Windows. Since every library have to define pretty much the same macros, better do it in Meson.
2025-10-20Add reconstructed authorship information to mesonbuild/utils/vsenv.pyVlad-Stefan Harbuz
2025-10-17make wrap search custom subprojects dirsCharlie Hutcheson
Changes from Dylan: - Don't use Path - merge the lint fixes - Fix some typing issues - Handle non-meson projects - Remove some code duplication by putting `get_subproject_dir` in utils
2025-10-05deprecate variable substitution with boolean valuesJan200101
2025-10-04utils/platform: Use a type declaration instead of default valueDylan Baker
We don't want to have an `Optional` type here, we just want to tell mypy that the value will be a FileLike object.
2025-10-04utils: merge per-platform utils into `platform.py`Dylan Baker
This allows us to simplify running mypy, as we can just mypy the entire utils module regardless of the platform we're using. As an added bonus, this means we open one less module.
2025-09-22utils, backends: add and use unique_listPaolo Bonzini
backends.py has an interesting idiom for keeping the unique elements of a list. This is much faster than OrderedSet: * dict.fromkeys() vs. OrderedSet.__init__(): 35% faster on Python 3.13, 50-60% faster on Python 3.10 * list(d) (d is a dict) vs. list(os) (os is an OrderedSet): up to 25% faster on Python 3.13, up to 15% faster on Python 3.10 though it tapers out after a few hundred elements. Add a function to mesonlib to encapsulate this idiom. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-09-06vsenv: Ignore errors when parsing multiline env valuesXavier Claessens
2025-08-29utils: make .wraplock optionalPaolo Bonzini
.wraplock is nice to have, but prevents Meson from operating on a read-only source directory. If the source directory is read-only, there is no possible conflict so in that case it is acceptable to return without any actual locking. Fixes: #14948 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-18Use os.path.normpath to make paths prettierVolker Weißmann
`meson.py introspect build --targets` should show `/path/to/project/hello.c` instead of `/path/to/project/subdir/../hello.c` if /path/to/project/meson.build contains subdir('subdir') and /path/to/project/subdir/meson.build contains executable('hello', '../hello.c').
2025-06-08replace regex implementation for cmake with a parserJan200101
cmake does preprocessing in a linear pass through the entire file this allows recursive variable lookups which cannot be supported by a basic regex implementation.
2025-06-08handle empty curly braces correctlyJan200101
in cmake variables are pure strings with no minimal required length so an empty string is a valid key and ${} needs to be handled accordingly.
2025-06-08handle spacing between # and cmakedefineJan200101
just as with C defines cmakedefine supports a variable amount of whitespace between the # symbol and the actual token.
2025-06-04utils: Support VCSs that can have file repodirsDylan Baker
When git is used with worktrees, `.git` will be a file containing a link to the original repo. Currently, we say that this is not git because `.git` isn't a directory.
2025-06-03utils: Replace BuildDirLock with generic DirectoryLockFlorian "sp1rit"​
DirectoryLock provides a generic locking implementation the replaces the previously used BuildDirLock.
2025-05-22gnome.mkenums: Allow passthrough of ExternalPrograms to enable converting ↵L. E. Segovia
only the real arguments to response file
2025-05-07options: fix "deprecated" with dictionary argument and non-string typesPaolo Bonzini
Since opt.deprecated is a dictionary with string keys, the lookup must use str() around the user-provided value; with some care because booleans will be the meson-ic 'true' and 'false' instead of Python's 'True' and 'False'. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-09Move get_rsp_threshold function to mesonlibCharles Brunet
Because we will need to call it from a module in a followup commit.
2025-03-09mesonlib: extract and optimize is_parent_pathPaolo Bonzini
Introduce an alternative to os.path.commonpath(name, path) == path, which is a common idiom throughout Meson. Call it is_parent_path just like the existing static method in Generator. It is a bit faster and handles drives on Windows without the need for an exception handler. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-03-06mesonlib: allow using lazy_property with "__"-named propertiesPaolo Bonzini
These are given a name that is different from __func.__name__, so store the name when the descriptor is placed in the class. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-02-28Skip symlinks in _make_tree_writable()Daan De Meyer
Trying to chmod a symlink results in trying to chmod the file or directory it points to, not the symlink itself which has no permissions. Either a symlink points to within the tree we're making writable in which case it'll be handled eventually by os.walk() or it points outside of the tree we're making writable in which case we don't want to touch it. Let's avoid touching files outside of the tree by simply skipping symlinks in _make_tree_writable().
2025-01-31utils: Use dataclasses for PerMachine classesDylan Baker
This allows us to simplify the initializers, as well as remove our custom repr methods.
2025-01-31utils: Fix nullability of PerMachine from default_missingDylan Baker
A Defaultable PerMachine has a type of `None | T`, in other words, they have a base type of `PerMachine[None | T]`, but the purpose of `PerMachine.default_missing()` is to get a `PerMachine[T]` from that `PerMachine[None | T]`, therefore we should ensure that and annotate that.
2025-01-28Detect files with trailing spaceCharles Brunet
On Windows, if you accidently add a space at the end of a file name, like `files('myfile.txt ')`, the file is not reported as missing, because of the normalization performed by the OS. However, ninja will reference it with the trailing space, and will fail because the file does not exist. See https://github.com/python/cpython/issues/115104 for reference.
2025-01-08utils: Add a lazy property decoratorDylan Baker
2025-01-08optimize Version.__init__Paolo Bonzini
Version objects are created thousands of times by the check_version method of decorators. Creation is inefficient, resulting in five calls to re.match() that do not even use precompiled regex. The use of re.match() however is fully redundant, as finditer() can provide the same information with a better use of groupings. Do that and precompile the tokenization regex. This saves about 3% in the "meson setup" run of QEMU. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-01-08Store commands as arrays.Jussi Pakkanen
2024-12-29utils: cache build directory filesPaolo Bonzini
get_target_generated_sources often calls File.from_built_relative on the same file, if it is used by many sources. This is a somewhat expensive call both CPU- and memory-wise, so cache the creation of build-directory files as well. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
2024-12-19do @ variable substitution when parsing cmake formatJan200101
the upstream behavior of configure_file in cmake parses both @VAR@ and ${VAR} and only supports disabling the bracket variables through the `@ONLY` argument, meson needs to follow this behavior for compatibility
2024-12-19mtest: move determine_worker_count to utils, generalizePaolo Bonzini
It is useful to apply a limit to the number of processes even outside "meson test", and specifically for clang tools. In preparation for this, generalize determine_worker_count() to accept a variable MESON_NUM_PROCESSES instead of MESON_TESTTHREADS, and use it throughout instead of multiprocessing.cpu_count(). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-12-19utils: optimize PerMachinePaolo Bonzini
There is no need to create and look up a dictionary when MachineChoice is an enum, and there is no need to create a PerMachine object on every __setitem__ of another PerMachine object. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-12-10separate mesondefine and cmakedefine logicJan200101
2024-08-30Feature checks: fall back to reporting insufficiently portable featuresEli Schwartz
When projects do not specify a minimum meson version, we used to avoid giving them the benefit of the Feature checks framework. Instead: - warn for features that were added after the most recent semver bump, since they aren't portable to the range of versions people might use these days - warn for features that were deprecated before the upcoming semver bump, i.e. all deprecated features, since they aren't portable to upcoming semver-compatible versions people might be imminently upgrading to
2024-07-21Remove the exe_exists functionMads Andreasen
This function is no longer used since shutil.which() is used instead.
2024-07-11Move OptionKey in the option source file.Jussi Pakkanen
2024-07-11Move compiler option check into OptionStore.Jussi Pakkanen
2024-07-11Move builtin option check into OptionStore.Jussi Pakkanen
2024-07-11Move backend option check into OptionStore.Jussi Pakkanen
2024-07-11Move base option check into OptionStore.Jussi Pakkanen
2024-07-11Move project option detection into OptionStore.Jussi Pakkanen
2024-07-10Replace exe_exists function with shutil.which()Mads Andreasen
The documentation for subprocess.run at https://docs.python.org/3/library/subprocess.html#popen-constructor has a warning, pointing to using shutil.which() instead of subprocess.run for detecting if exe files exists on the path. shutil.which() is used in many places already.
2024-07-10tests: Clean up leftover files from source dirs.Jussi Pakkanen
2024-06-23limit wrapped-due-to-env special case for `env` to only apply for env.setEli Schwartz
In commit 2cb7350d1679fb61826bf4aebfb0f75a9b9103e3 we added a special case for environment() objects to allow skipping `meson --internal exe` overhead when /usr/bin/env exists and can be used to set environment variables instead of using a pickled wrapper. This special case assumed that environment is used for setting variables, but it is also possible, albeit less common, to append/prepend to them, in which case `meson --internal exe` will compute the final value as an offset from whatever the current environment variables inherited from ninja are. It is not possible to precompute this when generating command lines for ninja, so using arguments to /usr/bin/env is not possible. All it can do is set (override) an environment variable. In this case, we have to use the python wrapper and cannot optimize it away. Add a tracking bit to the env object and propagate it to the backend.
2024-06-23`configure_file`: update \@ escape logicMatt Jolly
When configuring a 'meson' or 'cmake@' style file, add a case for escaped variables using matched pairs of `\@` i.e. `\@foo\@ -> @foo@`. The match for @var@ has been amended with a negative lookbehind to ensure that any occurrances of `\@foo@` are not evaluated to `\bar`. The previous behaviour, matching `\@` and escaping only that character, had undesirable side effects including mangling valid perl when configuring files. Closes: https://github.com/mesonbuild/meson/issues/7165
2024-05-09implement @PLAINNAME0@ and @BASENAME0@Stas Sergeev
@PLAINNAME@ and @BASENAME@ cannot be used in custom_target() with multiple inputs. For those, similar macros are needed with an index. Fixes #13164
2024-04-15allow any alternative python freeze tool to work with mesonEli Schwartz
Any code that needs to know mesonlib.python_command currently assumes the PyInstaller bundle reference is added to the sys module, which means that it assumes the only freeze tool used is PyInstaller. Really, all we need to check is sys.frozen as it's never normally set, but always set for a freeze. We don't care if it was PyInstaller specifically, and we don't need its bundle directory. See https://github.com/mesonbuild/meson/discussions/13007