aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter
AgeCommit message (Collapse)AuthorFilesLines
2023-07-20intepreter: add kwargs annotations for build_target classesDylan Baker2-9/+55
This doesn't do much yet, but with my advanced knowledge of what's coming this lays out most of what we're going to need
2023-07-19fix implicit_reexport issues and enforce them going forwardEli Schwartz4-26/+24
This detects cases where module A imports a function from B, and C imports that same function from A instead of B. It's not part of the API contract of A, and causes innocent refactoring to break things.
2023-07-14compiler.compiles/links: fix failure when compiling a built File objectEli Schwartz1-2/+8
In order to pass a File object down into the compiler impl and compile it, we cannot pass a string with the filename, and we cannot either pass the File object as-is, since it relies on being given Environment attributes to calculate the relative location. So we build a fresh File object as an absolute path. But the code to do this was totally broken. Instead of using the File method to get an absolute path, we used one that expected to create builddir-relative paths... and then gave it the absolute source dir as the "relative path portion" prefix. This worked by accident as long as it wasn't a built File, but if it was a built file then we intentionally didn't include that prefix -- which was wrong anyway, since we need the build directory! Use the correct method to get an absolute path in all cases, and emit a warning if it was a built file. This never worked. Sometimes it crashed, sometimes it silently returned false. Fixes #11983
2023-07-12string: Add missing FeatureNew tags to methodsMarco Trevisan (Treviño)1-0/+4
There are some new(er) methods that have not version reference, so add the missing ones in order to be properly notified when targetting older meson versions. Co-authored-by: Tristan Partin <tristan@partin.io>
2023-07-05Merge pull request #11742 from xclaesse/link-whole-casesJussi Pakkanen1-3/+2
Fix niche cases when linking static libs
2023-06-28Experimental 'genvslite' WIP. (#11049)GertyP1-6/+13
* 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-27Fix pylint.Jussi Pakkanen1-1/+0
2023-06-27interpreter: use os.listdir instead of os.scandir to avoid ResourceWarningNathan Goldbaum1-1/+2
2023-06-26stop importing cmake when it isn't usedEli Schwartz1-1/+1
We don't need a CMakeInterpreter until and unless we actually attempt to use a cmake subproject via the cmake module. Minus 10 files and 3679 lines of code imported at startup.
2023-06-20interpreter: Accept more types in default_options dict valuesXavier Claessens2-12/+15
2023-06-20interpreter: allow default_options and override_options as a dictDylan Baker4-37/+46
2023-06-20add str.splitlines methodMartin Dørum1-0/+7
The new splitlines method on str is intended to replace usage of fs.read('whatever').strip().split('\n'). The problem with the .strip().split() approach is that it doesn't have a way to represent empty lists (an empty string becomes a list with one empty string, not an empty list), and it doesn't handle Windows-style line endings.
2023-06-19Add kernel and subsystem properties to machine objects.Jussi Pakkanen1-0/+17
2023-06-19Alphabetize methods in MesonMain.Jussi Pakkanen1-21/+21
2023-06-15Interpreter: Using executable in run_command/configure_file is not aXavier Claessens1-1/+1
bug Fixes: #11382
2023-06-14convert some FeatureDeprecated for totally broken stuff, to FeatureBrokenEli Schwartz1-6/+6
We now warn everyone equally that totally ignored sources are bad and should not be used.
2023-06-14detect and warn on non-commutative int/bool operationsEli Schwartz1-7/+9
an int only accepts operations on other ints, just like other primitive types only accept operations on values of the same type. But due to using isinstance in baseobjects "operator_call", an int primitive allowed operations on a bool, even though reversing the operator and having a bool perform operations on an int, would fail with a type error. Really, we should fail with a type error in both directions. But for stability reasons, make this a loud warning and break --fatal-meson-warnings builds.
2023-06-14add new FeatureBroken check class for annotating features that are really brokenEli Schwartz1-1/+2
This is useful for totally terrible stuff that we really dislike, but for some reason we are afraid to just use `mlog.deprecation()` and unconditionally tell people so. Apparently this is because it is totally absolutely vital that, when telling people something is so broken they should never ever ever use it no matter what, ever... we can't actually tell them that unless they bump the minimum version of Meson, because that's our standard way of introducing a **version number** to tell them when we first started warning about this. Sigh. We really want to warn people if they are doing totally broken stuff no matter what version of Meson they support, because it's not like fixing the thing that never worked is going to suddenly break old versions of meson. So. Here's some new functionality that always warns you, but also tells you when we started warning.
2023-06-13Allow targetting Meson 1.2.0 when version is 1.1.99Xavier Claessens1-1/+1
When a project targets a dev version of Meson (e.g. 1.1.99) for experimenting, this allows to use: project(..., meson_version: '>=1.2.0') It avoids getting warnings when using FeatureNew for features introduced in 1.2.0.
2023-06-06Override find_program('meson')Tristan Partin1-0/+4
This override transparently upgrades anyone using it to this better functionality. Fixes #8511
2023-05-31mlog: use a hidden class for stateDylan Baker1-6/+3
This is a pretty common pattern in python (the standard library uses it a ton): A class is created, with a single private instance in the module, and then it's methods are exposed as public API. This removes the need for the global statement, and is generally a little easier to reason about thanks to encapsulation.
2023-05-31mlog: remove direct calls to log_onceDylan Baker1-1/+1
This was never meant to be public API, log(once=True) is for that.
2023-05-29avoid clearing the dependency cache unnecessarily based on wrap-modeEli Schwartz1-0/+2
We actually do not and should not care about wrap-mode at all for this. We want to cache dependency lookups whenever humanly possible, but only use them in cases where we would anyways be using them -- which in particular means if we said to force a subproject fallback for this dep, we want to bypass the cache. Currently, we handle this by always looking up the cache for all dependencies, but clearing the cache at startup if a reconfigure means we are changing our resolution strategy. This is bad -- we might have many dependencies that are worth caching, and only one dependency that should stop being cached and use a subproject instead. The simple solution is to handle the forcefallback case when doing a cache lookup, and not do a cache lookup at all. Now we don't have to nuke the entire cache. In fact, if a future reconfigure changes the forcefallback state back to not being forced, we can reuse the original cached dependency, which is still there. Closes #11828
2023-05-24repair install_mode support for uid/gid effectively everywhereEli Schwartz1-2/+11
We silently dropped all integer values to install_mode since the original implementation of doing this in KwargInfo, in commit 596c8d4af50d0e5a25ee0ee1e177e46b6c7ad22e. This happened because install_mode is supposed to convert False (exactly) to None, and otherwise pass all arguments in place. But a generator is homogeneous and attempting to do this correctly produced a mypy error that FileMode arguments were allowed to be ints -- well of course they are -- so that resulted in the convertor... treating ints like False instead, to make mypy happy. Fixes #11538
2023-05-24remove inaccurate commentEli Schwartz1-6/+1
This convertor was initially implemented doing all the things the TODO says it doesn't yet do. The freestanding interpreter function is what doesn't do this.
2023-05-23deprecate the buildtarget.get_id() methodEli Schwartz1-0/+3
This has never been undocumented and there's no obvious value to having it or using it. We're not even sure anyone ever has used it. Closes #6061
2023-05-17summary: Add from which subproject each subproject have been calledXavier Claessens2-6/+12
2023-05-13During reconfigure, show that no compiler was found, if compiler fails ↵Volker Weißmann1-5/+4
sanity check.
2023-05-01build: Process compilers before calling link() and link_whole()Xavier Claessens1-3/+2
To take good decisions we'll need to know if we are a Rust library which is only know after processing source files and compilers. Note that is it not the final list of compilers, some can be added in process_compilers_late(), but those are compilers for which we don't have source files any way.
2023-04-21rust: Add new `rust_dependency_map` target configurationSebastian Dröge1-0/+1
This allows changing the crate name with which a library ends up being available inside the Rust code, similar to cargo's dependency renaming feature or `extern crate foo as bar` inside Rust code.
2023-04-20extra_files keyword in declare_dependency()Charles Brunet1-2/+4
2023-04-11fix various spelling issuesJosh Soref5-17/+17
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-03-29Make --vsenv a readonly builtin optionXavier Claessens1-3/+3
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-28Add support for meson.options as a replacement for meson_options.txtDylan Baker1-6/+22
We will still try to load `meson_options.txt` if `meson.options` doesn't exist. Because there are some advantages to using `meson.options` even with older versions of meson (such as better text editor handling) we will not warn about the existence of a `meson.options` file if a `meson_options.txt` file or symlink also exists. The name `meson.options` was picked instead of alternative proposals, such as `meson_options.build` for a couple of reasons: 1. meson.options is shorter 2. While the syntax is the same, only the `option()` function may be called in meson.options, while, it may not be called in meson.build 3. While the two files share a syntax and elementary types (strings, arrays, etc), they have different purposes: `meson.build` declares build targets, `meson.options` declares options. This is similar to the difference between C's `.c` and `.h` extensions. As an implementation detail `Interpreter.option_file` has been removed, as it is used exactly once, in the `project()` call to read the options, and we can just calculate it there and not store it. Fixes: #11176
2023-03-28Make backend option read-onlyXavier Claessens1-1/+3
2023-03-20backends: add a new "none" backendEli Schwartz1-0/+2
It can only be used for projects that don't have any rules at all, i.e. they are purely using Meson to: - configure files - run (script?) tests - install files that exist by the end of the setup stage This can be useful e.g. for Meson itself, a pure python project.
2023-03-17Better error message when custom_targets has duplicates in the output kwargVolker Weißmann1-0/+7
2023-03-09configure_file: emit FeatureNew when a cmake-formatted file has too many tokensEli Schwartz1-1/+1
In commit 97a72a1c53e68cf53541285075b4000f7c85ccc6 we started to allow cmakedefine with 3 tokens, as cmake expects (unlike mesondefine). This would silently start working even if the declared minimum version was older than 0.54.1
2023-03-09emit FeatureNew warning for compiler.preprocess used multiple timesEli Schwartz1-0/+3
In commit c2a55bfe43fae1b44cf49a083297d6755c89e1cc multiple bugs were fixed, but a FeatureNew was only added for the one that was mentioned in the commit message. Make sure to warn users about the reliability of the one that wasn't mentioned, too.
2023-03-09compiler.preprocess should only update the private name per directoryEli Schwartz1-2/+5
We add a unique ID to each rule we create, to work around the use of an entire build target with private directory named "preprocess" per use of the preprocess() method. But this ID doesn't need to increment every time it is used anywhere -- only when it is used in the same subdir as a previous time. That is the only case where it could conflict. By making the increment counter per-subdir, we can avoid potential frivolous rebuilds when a new preprocess() is added in a different directory, the build is reconfigured, and all uses in the entire project tree suddenly get new output paths even if they haven't changed.
2023-03-09build: fully type CompileTargetDylan Baker1-7/+3
Which is pretty trivial
2023-03-09interpreter: Add missing Union annotationDylan Baker1-1/+1
2023-03-04typed_kwargs: Extend since_values and deprecated_values for typesXavier Claessens1-9/+0
2023-03-01interpreter: report FeatureNew for kwargs to project()Eli Schwartz1-1/+1
We need to know the project minimum version before evaluating the rest of the function. There's three basic approaches: - try to set it inside KwargInfo - just run a minimal version of func_project for this, then load everything after - drop down to the AST and set it before anything else In order to handle FeatureNew emitted by a FunctionNode evaluated before project() due to being inlined, such as `version: run_command()`, only option 3 suffices, the rest all happen way too late. Since we have just added AST handling support for erroring out, we can do that to set the version as well.
2023-03-01handle meson_version even when the build file fails to parseEli Schwartz1-4/+19
If the meson.build file is sufficiently "broken", even attempting to lex and parse it will totally fail, and we error out without getting the opportunity to evalaute the project() function. This can fairly easily happen if we add new grammar to the syntax, which old versions of meson cannot understand. Setting a minimum meson_version doesn't help, because people with a too-old version of meson get parser errors instead of advice about upgrading meson. Examples of this include adding dict support to meson. There are two general approaches to solving this issue, one of which projects are empowered to do: - refactor the project to place too-new syntax in a subdir() loaded build file, so the root file can be interpreted - teach meson to catch errors in building the initial AST, and just load enough of the AST to check for meson_version advice This implements the latter, allowing to future-proof the build grammar.
2023-03-01interpreter: Add testcase..endtestcase clause supportXavier Claessens1-1/+21
This is currently only enabled when running unit tests to facilitate writing failing unit tests. Fixes: #11394
2023-02-27Use caching in Compiler.sizeof() and Compiler.alignment()Andres Freund1-7/+11
2023-02-27interpreter: bolden result of compiler.alignment(), compiler.sizeof()Andres Freund1-2/+2
This is more in line with other tests. It also looks better when introducing caching, as a subsequent commit will.
2023-02-20interpreter/mesonmain: Add build_options methodL. E. Segovia1-1/+11
This method allows meson.build to introspect on the changed options. It works by merely exposing the same set of data that is logged by MesonApp._generate. Fixes #10898
2023-02-20interpreter: Do not ignore all exceptions when adding compilerXavier Claessens1-1/+1
Suppressing all exceptions was hidding even syntax errors in compiler source code. If a compiler cannot be found, a MesonException is raised, we should only expect that type.