Commit Graph

42 Commits

Author SHA1 Message Date
Daniel Mensinger 86f70c873a interpreter: Introduce operators support for InterpreterObjects 2021-08-31 23:01:21 +02:00
Daniel Mensinger a6c9a151d3 interpreter: Make comparisons of different types a hard error 2021-08-31 23:01:21 +02:00
Dylan Baker 4d7031437c pylint: turn on superflous-parens
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-31 16:28:54 -04:00
Xavier Claessens 88a1bed81b decorators: Make unknown kwarg fatal 2021-08-30 14:00:54 -04:00
Xavier Claessens f8cfd91d71 Simplify get_callee_args 2021-08-30 14:00:54 -04:00
Dylan Baker ce392acad4 interpreterbase: ensure that the default vaule to KwargInfo is a valid type
Because currently you can write something like:
```python
KwargInfo('capture', bool)
```
Which proclaims "this must be bool", but the default is then not valid.
2021-08-27 14:54:30 -07:00
Eli Schwartz 2a7125928e
use even more informative error message for invoking meson in a subdir
Follow-up on commit 5a7b8d86d0

Sometimes, we find a parent meson.build which is also malformed, and we
shouldn't suggest that maybe the user meant to use that, if it isn't a
valid project() either. Do a rough and dirty check to see if the very
first line is a project() declaration, and if not, don't try to be
clever and suggest using it.

The "invalid source tree" error suffices here, since we're not
absolutely sure meson can be successfully run in that parent directory
and actually advising people about the wrong location is a lot more
confusing than just saying "please figure this out yourself, here is
what to look for".

Granted, we miss cases where project() comes after blank lines and/or
comments, but doing a full AST parse here is excessively overkill and
probably too painful to do, and we don't need to be *that* clever. So
let's be content with merely going above and beyond the call of duty.
2021-08-22 12:12:26 -04:00
Eli Schwartz 5a7b8d86d0 use a more informative error message for invoking meson in a subdir
Explicitly mention that the project definition is invalid, and clarify
that project is `project()` -- a function.

Also try to walk the directory tree upward, and if there are parent
meson.build files, just say this isn't the project root, and "maybe you
meant to run meson there instead?"

This won't catch calls to subdir('foo/bar') but we can't be perfect,
only better than before and catch the *majority* of such cases, and
hopefully it's a lot more clear if meson protests that the project is
"invalid, there is no project() function", where the user should look
for a potential solution.

Fixes #3426
2021-08-22 12:49:11 +03:00
Dylan Baker 580f316043 interperterbase: help type checkers do better type deduction
This assert causes several type checkers (both mypy and pyright) to
force `obj` to be a base `HoldableObject` instead of the specialized
object. Since the check itself may still be valuable as we don't have
fully type annotation coverage it's simply been removed when type
checking to aid in type specialization.
2021-08-16 16:21:51 -07:00
Dylan Baker d8d09138c7 interpreter: allow KwargInfo.evolve to change the name as well 2021-08-16 16:21:51 -07:00
Tristan Partin 1dc13e9951 Add unset_variable()
This should be useful for helping to control variable scope within
Meson. CMake has something similar for controlling scope.
2021-08-16 14:05:13 -04:00
Daniel Mensinger 5c87167a34 interpreter: Fix list contains for Holders (fixes #9020 #9047) 2021-08-09 09:40:35 -04:00
Dylan Baker 386b312fa9 interpreterbase/decorators: fix typed_kwargs return type
Because of the convertor function we have no guarantee that what we're
getting is in fact a `Dict[str, TYPE_var]`, it might well be anything in
the values, so we need to do some casting and set the return type to
object. This works out fine in practice as our declared `TypeDict`
inputs in the actual function signatures will be used instead.
2021-08-04 19:09:08 -04:00
Xavier Claessens 0183954ea1 Fix meson.version().version_compare() regression in subproject 2021-07-21 13:33:06 -04:00
Daniel Mensinger ca6683095d fix: Fix recursive _unholder permissive kwarg (fixes #8977) 2021-07-10 22:30:06 +03:00
Eli Schwartz bd6f46e723 condense lines 2021-07-05 17:55:04 +03:00
Eli Schwartz dd31891c1f more f-strings too complex to be caught by pyupgrade 2021-07-05 17:55:04 +03:00
Daniel Mensinger 971a0b1775 fix: get_variable default variables are not ObjectHolders (fixes #8936) 2021-07-02 17:14:44 +03:00
Daniel Mensinger 3e396b3782
fix: Always explicitly set encoding for text files (fixes #8263) 2021-06-29 11:28:08 +02:00
Daniel Mensinger 8f7343831b refactor: Refactor BothLibraries logic
This commit introduces a new type of `HoldableObject`: The
`SecondLevelHolder`. The primary purpose of this class is
to handle cases where two (or more) `HoldableObject`s are
stored at the same time (with one default object). The
best (and currently only) example here is the `BothLibraries`
class.
2021-06-26 12:49:35 +02:00
Jussi Pakkanen 6e0a0fd1da
Merge pull request #8884 from dcbaker/submit/type-and-annotate-install-functions
Add annotations for the various install_* functions
2021-06-23 01:00:59 +03:00
Jussi Pakkanen 39f25ec6aa
Merge pull request #8905 from mensinda/refactorFix
fix: Fix set_variable not holderifying (fixes #8904)
2021-06-22 21:26:38 +03:00
Dylan Baker dd296f321b interpreterbase: Add evolve to KwargInfo
This works just like OptionKey.evolve, pass new keyword arguments to
override old ones, otherwise the original versions are copied to the new
one.
2021-06-22 09:12:54 -07:00
Daniel Mensinger 5cd9f88d6c fix: Ensure that build targets have all methods from ExternalProgram
As a side-effect from #8885 `find_program()` returns now `Executable`
objects when `meson.override_find_program` is called with an
executable target. To resolve this conflict the missing methods
from `ExternalProgram` are added to `BuildTarget`.
2021-06-21 20:19:06 +03:00
Daniel Mensinger 0358445b6e
fix: dicts and list need _holderify for fallback 2021-06-20 00:26:06 +02:00
Daniel Mensinger f1ac7db2e6
fix: Fix set_variable not holderifying (fixes #8904) 2021-06-20 00:26:02 +02:00
Daniel Mensinger 34c28dc92c holders: remove unholder 2021-06-18 23:48:33 +02:00
Daniel Mensinger c2c7f7c9d7 holders: Ensure that InterpreterBase is the sole instance for (un)holderifying 2021-06-18 23:48:33 +02:00
Daniel Mensinger 66b32a4591 holders: Introduce HoldableObject 2021-06-18 23:48:33 +02:00
Daniel Mensinger d601227cb2 interpreter: Add FileHolder and remove specical case for File 2021-06-18 23:48:33 +02:00
Daniel Mensinger 7be172fe16 interpreter: Meson does not have floats --> remove them 2021-06-18 23:48:33 +02:00
Daniel Mensinger 63ade7d937 interpreter: Add a new MesonInterpreterObject for non-elementary objects 2021-06-18 23:48:33 +02:00
Daniel Mensinger 202e345dfb interpreter: Refactor interpreter.compiler to use ObjectHolder 2021-06-18 23:48:33 +02:00
Daniel Mensinger 2b09af834a interpreter: Refactor ObjectHolder to extend InterpreterObject 2021-06-18 23:48:33 +02:00
Daniel Mensinger 8f997efc8b decorators: Add not_set_warning to KwargInfo 2021-06-18 23:48:33 +02:00
Daniel Mensinger bad14b23d2 decorators: Fix typo 2021-06-18 23:48:33 +02:00
Dylan Baker 5bb75dc3af interpreterbase: Add deprecated_values and since_values to KwargInfo
This allows checking specific values that are added or deprecated, which
we do a surprising amount of. This works with both containers and scalar
values
2021-06-14 12:30:02 -07:00
Daniel Mensinger e686545fce interpreter: Split decorators from interpreterbase.py 2021-06-11 10:42:18 +02:00
Daniel Mensinger fc0397b309 interpreter: Split Disabler from interpreterbase.py 2021-06-11 10:42:18 +02:00
Daniel Mensinger 687eebee29 interpreter: Split base objects and helpers from interpreterbase.py 2021-06-11 10:42:18 +02:00
Daniel Mensinger 2e3550db14 interpreter: Split exception calsses from interpreterbase.py 2021-06-11 10:42:18 +02:00
Daniel Mensinger ad584f022d interpreter: Move interpreterbase.py into a new package 2021-06-11 10:42:18 +02:00