Commit Graph

83 Commits

Author SHA1 Message Date
Dylan Baker e991c4d454 Use SPDX-License-Identifier consistently
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-12-13 15:19:21 -05:00
Charles Brunet 306562b466 parser: use IdNode for function name and assignment name 2023-09-11 07:51:18 -04:00
Charles Brunet 35936283d2 parser: preserve escape chars in strings
use separate Node for multiline strings
2023-09-11 07:51:18 -04:00
JCWasmx86 79ed2415e9 Add ParenthesizedNode 2023-09-11 07:51:17 -04:00
Xavier Claessens 82a8c72187 c_std, cpp_std: Change to a list of desired versions in preference order
Projects that prefer GNU C but can fallback to ISO C can now set for
example `default_options: 'c_std=gnu11,c11'` and it will use gnu11 when
available, fallback to c11 otherwise. It is an error only if none of the
values are supported by the current compiler.

This allows to deprecate gnuXX values from MSVC compiler, that means
that `default_options: 'c_std=gnu11'` will now print warning with MSVC
but still fallback to 'c11' value. No warning is printed if at least one
of the values is valid, i.e. `default_options: 'c_std=gnu11,c11'`.

In the future that deprecation warning will become an hard error because
`c_std=gnu11` should mean GNU is required, for projects that cannot be
built with MSVC for example.
2023-08-07 08:28:00 -04:00
Xavier Claessens 48c17b7ae6 UserArrayOption: Remove user_input argument
The only place it can be set to False is from optinterpreter. Better
check value there and deprecate string usage.
2023-08-06 09:39:55 -04:00
Xavier Claessens 0f67913dee typed_kwargs: Extend since_values and deprecated_values for types 2023-03-04 14:19:27 -05:00
Eli Schwartz 680b5ff819
treewide: add future annotations import 2023-02-01 17:01:30 -05:00
Dylan Baker 7c1f53f3b1 optinterpreter: pass deprecated keyword directly to Option initializer 2023-01-20 00:18:42 -05:00
Dylan Baker 43a2404707 Deprecate passing strings to non-string options
Currently Meson allow the following (Muon does not):
```meson
option('foo', type : 'boolean', value : 'true')
option('bar', type : 'integer', value : '42')
```

This is possibly a holdover from very old code, but it's a bad idea and
we should stop doing it. This deprecation is the first stop on that
journey.
2023-01-20 00:18:42 -05:00
Dylan Baker f5eaebb4b4 use typed_kwargs for the various option subparsers
We make use of allow_unknown=True here, which allows us to only look at
the common arguments in the main option parser, and then look at the
specific options in the dispatched parsers. This allows us to do more
specific checking on a per overload basis.
2023-01-20 00:18:42 -05:00
Dylan Baker 93e370c7dd coredata: use DEFAULT_YIELDING as the default value for Options
Instead of setting it to `Optional[bool] = None`, and then in the
initializer replacing `None` with `DEFAULT_YIELDING`, just set to to
`bool = DEFAULT_YIELDING`
2023-01-20 00:18:42 -05:00
Xavier Claessens 3c8343b483 Allow deprecating an option for a new one 2022-04-21 14:18:29 -04:00
Xavier Claessens 06d12064d0 OptionOverrideProxy: Make it immutable to avoid copies
It is always used as an immutable view so there is no point in doing
copies. However, mypy insist it must implement the same APIs as
Dict[OptionKey, UserOption[Any]] so keep faking it.
2022-03-22 17:20:48 -04:00
Eli Schwartz c0b8e02d9f
FeatureNew: add mypy type annotations for subproject arg
Use a derived type when passing `subproject` around, so that mypy knows
it's actually a SubProject, not a str. This means that passing anything
other than a handle to the interpreter state's subproject attribute
becomes a type violation, specifically when the order of the *four*
different str arguments is typoed.
2022-02-14 20:40:41 -05:00
Eli Schwartz cf3a1d31f8 fix some flake8 violations for unused imports
And one undefined T.cast name in a file that isn't yet mypy-ready
anyway.
2022-01-27 10:48:01 -08:00
Xavier Claessens 8a0d12ec29 optinterpreter: Fix builtin option names not being reserved anymore 2021-10-14 14:17:50 -04:00
Xavier Claessens 4f7c0d0b62 optinterpreter: Downgrade error to deprecation 2021-10-13 08:07:25 -04:00
Xavier Claessens 77ef437cc4 optinterpreter: Add deprecated kwarg
It can be either:
- boolean: the option is completely deprecated.
- list: some choices are deprecated.
- dict: some choices are deprecated and replaced by another.

Fixes: #7444
2021-10-09 18:13:34 -04:00
Xavier Claessens 953bbf5e19 optinterpreter: Refactor to use typed_pos_args() and typed_kwargs() 2021-10-09 18:13:34 -04:00
Xavier Claessens a844e9bdb0 optinterpreter: Add support for dictionaries 2021-10-09 18:13:34 -04:00
Daniel Mensinger 3e396b3782
fix: Always explicitly set encoding for text files (fixes #8263) 2021-06-29 11:28:08 +02:00
Eli Schwartz 4340bf34fa
various python neatness cleanups
All changes were created by running

"pyupgrade --py3-only --keep-percent-format"

and committing the results. I have not touched string formatting for
now.

- use set literals
- simplify .format() parameter naming
- remove __future__
- remove default "r" mode for open()
- use OSError rather than compatibility aliases
- remove stray parentheses in function(generator) scopes
2021-03-04 17:11:26 -05:00
Dylan Baker e81acbd606 Use a single coredata dictionary for options
This patches takes the options work to it's logical conclusion: A single
flat dictionary of OptionKey: UserOptions. This allows us to simplify a
large number of cases, as we don't need to check if an option is in this
dict or that one (or any of 5 or 6, actually).
2021-01-04 12:20:58 -08:00
Dylan Baker 51b361fdbe optinterpreter: organize the validation of arguments to be more readable 2020-11-20 14:48:35 -08:00
Dylan Baker 226945bbc7 optinterpreter: use PEP8 compliant names 2020-11-20 14:48:35 -08:00
Dylan Baker 49f8ff8410 optinterpreter: fix value being set in loop
This value shouldn't be set in the loop, it's probably been making
things slow, but also creates the potential that if choices is an empty
list that value would be unbound. While that's exteremly unlikly to
happen in practice, it is showing up as a warning from pylance.
2020-11-20 14:48:35 -08:00
Dylan Baker 93ecfa646b Add type annotations to optinterpreter 2020-11-20 14:48:35 -08:00
Dylan Baker f342efd080 pylint: turn on bad-indentation error
and fix all of the bad indentation
2020-09-22 17:57:03 -07:00
Daniel Mensinger 23818fc5a3
typing: more fixes 2020-09-08 20:15:58 +02:00
John Ericson 2447a1132a Capitalize some constants in coredata
I've been getting confused between them and similarly-named other
things, so I figured it was high time to clean this up.
2020-08-04 00:24:05 +03:00
Daniel Mensinger 534b340a56 opts: Add FeatureNew for '-' and 'not' introduced in 0.54.1 2020-05-26 13:48:26 -04:00
Daniel Mensinger 7e8f1de063 opts: Allow string concatenation (fixes #7199) 2020-05-26 13:48:26 -04:00
Dylan Baker c64715b99a optinterpreter: Enable and update FeatureNew to use_single
With the version information fixed we can use a FeatureNew inside the
optinterpreter, so let's do it.
2020-05-14 12:15:03 -07:00
Daniel Mensinger 03b86cdbed opts: Allow `-` and `not` in meson_options.txt (fixes #6948) 2020-04-11 18:58:26 -04:00
Daniel Mensinger c14aea2812
types: Annotate mparser.py
This also fixes that the keys in ArgumentNode.kwargs are
all of the type BaseNode now. Before this commit, it was
possible that both strings and Nodes where used as keys.
2020-03-02 10:34:55 +01:00
Jon Turney 346b5c4be7
Store filename in node location
Warnings have a location node object (with subdir and lineno
attributes), which is passed as a location: kwarg to mlog.warning() and
formatted in _log_error().

Re-purpose the subdir attribute (path relative to the source root dir,
with an implied filename of 'meson.build'), which is stored into the
node by parser(), to contain a pathname.

(Properly I should rename 'subdir' -> 'file' everywhere, but that's a
lot of churn just to see if this works)

Notes:
The warning location node may also have a colno attribute, which is
currently ignored by _log_error().

We can't currently issue warnings with locations in meson_options.txt
because the filename isn't part of the location (as it's assumed to be
'meson.build).
2020-02-28 11:54:04 +00:00
Jon Turney 534a974da7
Adjust all the other places MesonException file attribute is set
A MesonException has file, lineno and colno attributes, which get
formatted as a location in mlog.exception().

The file attribute got changed from a path relative to the root source
directory to a pathname (absolute or relative to cwd) in one place in
commit b8fbbf59.  Adjust all the other places the file attribute is set
to match.

Also:
Setting MesonException.file seems to be missing in the case where Parser
returned a non-CodeBlockNode object.  Fortunately, that looks like it's
unreachable, but add it just in case.
2020-02-28 11:54:04 +00:00
Jussi Pakkanen 6b5c1a4fc3 Refactor UserIntegerOption to work with BuiltinOption. 2020-02-12 22:31:08 +02:00
Daniel Mensinger 09b53c534f types: import typing as T (fixes #6333) 2020-01-08 15:28:17 +01:00
Jussi Pakkanen d7a682fded No need to reserve build_ because we use build. instead. 2019-07-15 14:13:55 -07:00
Jussi Pakkanen da1f663e8d Reserve build_ prefix in option names. 2019-05-20 22:53:06 +03:00
John Ericson 4030e7cb7a UserOption no longer has a name field.
This avoids the duplication where the option is stored in a dict at its
name, and also contains its own name. In general, the maxim in
programming is things shouldn't know their own name, so removed the name
field just leaving the option's position in the dictionary as its name.
2019-05-15 14:21:47 +03:00
Dylan Baker 068c3bf60a optinterpreter: Add a log argument to is_invalid_name
Since we're adding arguments that use the cross_ prefix but are valid
we don't want to print "warning invalid argument name!", as that will
confuse people by virtue of being wrong.
2019-04-05 09:26:42 -07:00
Dylan Baker 05ad69a1c7 optinterpreter: Add type annotations to is_invalid_name 2019-04-05 09:26:42 -07:00
Dylan Baker c6060d795c coredata: remove get_builtin_options
This returns a list out of th keys of a dict. In both cases of use
remaining though it's used for checking membership, checking for list
membership, lists are O(n) lookup, while dicts are O(1), so removing
the abstraction reduces typing and improves performance.
2019-04-04 15:02:20 -07:00
Jussi Pakkanen 3d0b110ec2 Reserve cross_ option prefix for Meson. 2019-03-19 06:28:21 +00:00
Xavier Claessens 5f9fda4acc UserFeatureOption: Default to 'auto' when no value specified
Closes #3938.
2018-07-25 09:55:16 -04:00
Nirbheek Chauhan a1d9adba09 FeatureNew: Make all checks subproject-specific
We now pass the current subproject to every FeatureNew and
FeatureDeprecated call. This requires a bunch of rework to:

1. Ensure that we have access to the subproject in the list of
   arguments when used as a decorator (see _get_callee_args).
2. Pass the subproject to .use() when it's called manually.
3. We also can't do feature checks for new features in
   meson_options.txt because that's parsed before we know the
   meson_version from project()
2018-07-02 19:52:53 +05:30
Xavier Claessens e565945253 Add UserFeatureOption type
This is a special type of option to be passed to most 'required' keyword
arguments. It adds a 3rd state to the traditional boolean value to cause
those methods to always return not-found even if the dependency could be
found.

Since integrators doesn't want enabled features to be a surprise there
is a global option "auto_features" to enable or disable all
automatic features.
2018-06-18 04:57:32 +00:00