A build project prefix ("build.") was introduced in 499f73da1 to separate build
files from host and build targets when cross compiling subprojects.
Additional work was done in 83fba12da. However, this prefix was missing from
some places:
- for generated files, with or without `build_subdir`: those files were
generated at the same place for both host and build targets.
- for include dirs: was erroring if it was only available in the build
tree.
- for subdirs
- for generated ast
Additionally, extra_build_dirs were double-prefixed.
BuildTarget.__init__ assigned self.extra_files after add_deps().
The assignment discarded files that add_deps() had appended from
declare_dependency(extra_files: ...); prior to commit 97a1c567c,
files from the interpreter were added with self.extra_files.append,
instead now it has to be assigned before add_deps().
Fixes: 97a1c567c ("interpreter: Move validation of BuildTarget(extra_files) to Interpreter", 2025-11-05)
Fixes: #15863
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
When a subproject failed, sub-subprojects were left in self.subprojects
but rolled back from the Build object. This caused different issues
in previous versions of Meson.
Until 1.10, and specifically until commit 1eac5a5, the rollback was partly
ineffective because Build instances shared the content of PerMachine fields
(e.g. dependency_overrides) by reference. Thus, the content of the
fields propagated to the superproject even without a merge()!
Subprojects-of-failed-subprojects were still included in the build,
because process_target_dependencies() saved the day while still leaving
behind tests, installed files and targets other than used libraries.
Since 1eac5a5 (and 1.11) the sharing bug was fixed, but on the other hand
the overrides were lost, causing warnings such as:
glib| WARNING: Subproject 'pcre2' did not override 'libpcre2-8' dependency and no variable name specified
Rolling back sub-subprojects ensures that Meson tries them again and
that their expceted overrides are recorded in Build.
The attached test covers both failure modes.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This has two effects. First, it makes it possible to track summaries
separately for host- and build-machine subprojects, which was a bug
in the 1.12 implementation of build-machine subprojects.
Second, it rolls back summaries on failed subprojects, instead of having
to skip them at the end of the run.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
With the `cpp_importstd` option and the MSVC compiler, meson now builds the
module with the arguments of the targets that matter to the compiler when it
imports the module: the C runtime, the character set, the C++ standard, the
exception and floating point options, the macros read by the standard library,
and so on. This prevents reporting a C5050 warning, which would become an error
if using `werror`. Arguments that do not matter, such as warnings, optimization
and include directories, are ignored. A module is built for each different set
of arguments, and shared by the targets that have the same one, so the files in
the build directory are named `std.<id>.ifc`.
The module is no longer built through a compiler cache, which cannot restore it.
A new `sticky_parens` option for the `meson format` command now sticks the
parentheses to the outer expression instead of putting them on their own line,
and double-indents continuation lines of the expression.
Fixes#13570.
When bindir and libexecdir are set to the same path, a binary named
(e.g.) 'p11-kit' can be installed first, and then a helper directory
also named 'p11-kit/' is attempted by DirMaker.makedirs(). Because
os.makedirs exist_ok=True only suppresses errors for existing
directories, not files, a cryptic FileExistsError was raised with no
hint about the root cause.
Check each path component inside DirMaker.makedirs() and raise a
MesonException with an actionable message when a component exists but
is not a directory, pointing to the likely cause of mismatched
install-dir options.
Fixes#6254
There is only one fix here, and it's safe in this case, as it's just
removing an unused variable.
Generated with: `ruff check --select F --unsafe-fixes --fix`
`meson format` now leaves untouched the lines between
`# meson-format off` and `# meson-format on` comments. When
`# meson-format off` is not followed by `# meson-format on`, formatting
is disabled until the end of the file.
```meson
sources = files(
'a.c', 'b.c',
'c.c', 'd.c',
)
```
Fixes#15922.
This change allows the found version number to include additional
hyphens and periods after the first hyphen. This is needed to understand
`clang --version` in some older Ubuntu versions, which prints:
Ubuntu clang version 14.0.0-1ubuntu1.1
This logic also accepts any pre-release version following SemVer 2.0.0
syntax, bullet 9.
Fixes: https://github.com/mesonbuild/meson/issues/16286
Signed-off-by: Jonathon Anderson <anderson.jonathonm@gmail.com>
shutil.copy2 copies not only the contents of the file but also its metadata, including the permissions; if the source file is read-only (with mode 0444) the destination file becomes read-only as well and this causes the next reconfigure to fail with a PermissionError when Meson attempts to overwrite the output file.
Use shutil.copyfile rather than shutil.copy2 when in copy mode, and preserve timestamps separately. The output file ends up with its default writable permissions, because shutil.copyfile only copies the contents of the file and does not preserve the source permissions, and restoring the modification time ensures that dependents are not rebuilt unnecessarily after each reconfigure. The existing test case 14 already checks that this is the case.
A backend option from the machine file that the backend does not have
must be an error. This is currently detected by OptionStore.set_option().
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Add a test that covers the intersection of $CFLAGS and command line
arguments, and rewrite the old test so that it can check both
cl.exe and gcc on all systems.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
The validator ran on the flat key/value list, so a single pair (two items) already triggered the FeatureNew warning for 'more than one pair' and a project targeting meson < 1.3.0 got a false warning. Compare against 2 items instead, and add a unit test.
Avoid errors like the following when invoking subprojects with a build directory that is on a different drive than the source:
G:\tmp\meson-test>python \repos\meson\meson.py subprojects update
Traceback (most recent call last):
File "\\server\share\repos\meson\mesonbuild\mesonmain.py", line 193, in run
return options.run_func(options)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "\\server\share\repos\meson\mesonbuild\msubprojects.py", line 723, in run
source_dir = os.path.relpath(os.path.realpath(options.sourcedir))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen ntpath>", line 783, in relpath
ValueError: path is on mount '\\\\server\\share', start on mount 'G:'
ERROR: Unhandled python exception
This is a Meson bug and should be reported!
Fixes: #13814
CMakeDependency._preliminary_find_check looks for ~/.cmake/packages/<Name>
with Path.exists(), which only swallows ENOENT/ENOTDIR/EBADF/ELOOP. On a
host where the build user's home directory exists but is not traversable
(CI service accounts, a root-owned 0700 $HOME, HOME pointing at another
user's directory) the probe raises PermissionError and meson setup dies
with "Unhandled python OSError" on the first dependency() that reaches the
CMake finder.
CMake itself silently ignores an unreadable user package registry. Do the
same: route the check through the existing _cached_isdir helper, which
already turns OSError into "not found".
The path is built with os.path.expanduser() rather than Path.home().
Path.home() raises RuntimeError when the home directory cannot be
determined (HOME unset and no passwd entry for the uid, as in containers
running under an arbitrary uid), so it would have needed its own handler
for a case that should also just mean "not registered".
os.path.expanduser() returns the string unchanged in that case, and a
path starting with '~' is never an existing directory, so no extra
handling is needed.
Paths in a depfile are relative to the working directory, not the target directory or
even less so the source directory. If the depfile that is produced by the configure_file's
command includes relative paths, make them relative to the build directory.
Fixes: #9851
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
When find_program is given multiple names and a version constraint,
continue trying later names if an earlier match fails the version
check. For each name, a machine-file entry is authoritative and
blocks PATH lookup for that name.
False was left alone and later changed to 0 due to bool returning
true for isinstance(x, int). As a result, using "false" for the uid
and gid caused an error starting with Meson 1.2.0:
Unable to set owner False and group 'mygroup': Operation not permitted, ignoring...
Similarly, the validator was blocking "1" because it is equal to True.
Fix by checking for bool specifically when turning it into none, and
using "is True" in the validator.
Fixes: #16225
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
@OUTPUT@ in depfile is the output filename, not the full path.
Joining the target directory with an unexpanded @OUTPUT@ token, then
substituting the full output path, doubled the subdirectory in both
@DEPFILE@ and ninja's depfile (include/include/foo.d).
Fixes#14140
Summary now prints failed/skipped subtests in case
--print-errorlogs/--verbose is specified.
With --verbose on the console, all subtests are
listed, including passed ones.
Signed-off-by: Paul Meyer <katexochen0@gmail.com>
Previously skipped subtests weren't visible. Print
the count of skipped subtest so we get a better
impression on the coverage of the result.
Signed-off-by: Paul Meyer <katexochen0@gmail.com>
While at it, run patch validation after building the set of dependencies.
Otherwise, it is not able to match patches against dependencies and will
incorrectly warn.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This simplifies the parsing and makes it possible to handle correctly
dependency-named features, which apply equally to all dependencies,
even those that are disabled. In other words, even if a "win"
dependency is only declared under [target.'cfg(windows)'.dependencies],
"cargo build --features win" succeeds on non-Windows platforms as well.
Due to the new representation, move the merged table into
PackageConfiguration. This is cleaner, because it doesn't modify the
manifest, and it makes it possible to fully separate dependencies for
the host and build machines.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Introduce a new function that can be used to join and normalize paths,
and canonicalize them to forward slashes. It avoids (or rather
hides) use of pathlib for string->string operations.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Setting cpp_rtti=false had no effect on .mm files: only C++ compilations got -fno-rtti.
I mapped the rtti compiler option to cpp_rtti for Objective-C++ (the same way cpp_std
is already shared) and added get_option_compile_args so the flag is emitted.
I also registered the option for projects that only enable objcpp.
Fixes#16189.
Some builds of Python leave platform.processor() to an empty string.
Check platform.machine() as well.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
QNX is a commercial POSIX real-time operating system built for safety-critical embedded use (automotive, medical, industrial) and certified to standards like ISO 26262 and IEC 61508.
qcc/q++ are its compiler driver frontends that wrap an underlying toolchain to produce binaries for QNX Neutrino targets.
Adding qcc support to Meson lets projects targeting QNX use Meson as their build system directly,
which is necessary for building components of a safety-certified OS and the safety-critical software that runs on it.
The configured-builddir path called the option listing without the set
of subprojects, so the per-subproject replication of non-yielding
builtin options only happened for source-only introspection and no
sub: rows were emitted at all. Augments (per-subproject values such as
-Dsub:c_args=...) were additionally never consulted, so even the
source-only rows reported the parent project's value.
Pass coredata.initialized_subprojects on the configured path, add
per-subproject rows for base and compiler options that have an augment
set, and resolve replicated keys through the option store so augments
and yielding are reflected in the reported value. Project options keep
their stored value as before.
Fixes#15993.
Add BuildCache as a supported compiler cache. Also autodetect
the presence of BuildCache as part of detect_compiler_cache().
The order of preference is:
1. sccache
2. ccache
3. buildcache
Thus, when either sccache or ccache is present in the PATH the
compiler cache selection is unaffected by this change.
determine_windows_extra_paths() on non-Windows is not used for too much.
It is used in two instances. In those two instances, extra_paths has very
narrow use cases.
- Backend::get_devenv(): we add to extra_paths for every
build.Executable. This also happens on Windows.
- Backend::get_executable_serialisation(): extra_paths is empty on
non-Windows.
It is important to remember that Windows has no equivalent to
{DY,}LD_LIBRARY_PATH. Instead it looks up DLLs on PATH. Performing this
filter will have an adverse effect on adding build outputs from
build.CustomTarget to PATH. However, when setting {DY,}LD_LIBRARY_PATH,
we filter for build.SharedLibrary explicitly, so it was an oversight in
the original patch[0] to include this additional behavior.
Link: https://github.com/mesonbuild/meson/pull/14649 [0]
Fixes: https://github.com/mesonbuild/meson/issues/16010
Supersedes: https://github.com/mesonbuild/meson/pull/16011
Signed-off-by: Tristan Partin <tristan@partin.io>