Commit Graph

168 Commits

Author SHA1 Message Date
Jussi Pakkanen c0d86024f5 Rename option variable to optstore to make it unique. 2024-06-14 17:19:53 +03:00
Jussi Pakkanen 5365d9a842 Refactor option classes to their own file. 2024-05-23 21:26:45 +03:00
Eli Schwartz aa9b7b9445
pylint: fix useless-return
A bare return at the end of a function doesn't do anything. And in the
case of a try/except, it's really just an elaborate "pass" anyway.
2024-05-19 15:49:45 -04:00
Eli Schwartz e5f32b7414 catch build files that cannot be opened in utf8 mode and emit useful error
Previously, if a junked meson.build or native.ini was used we got a
lengthy traceback ending in UnicodeDecodeError.

Fixes: #13154
Fixes: #13156
2024-04-28 22:51:08 +03:00
Charles Brunet bd4fd90730 parser: revert to single StringNode type
this will allow transforming string types in the formater
2024-04-08 10:43:57 -07:00
Charles Brunet 728fcdaab3 simplify astprinter by using operator value 2024-04-08 10:43:57 -07:00
Charles Brunet 0bc51d5221 simplify RawPrinter using FullAstVisitor 2024-04-08 10:43:57 -07:00
Charles Brunet 2a962ffd63 visit full ast for AstConditionLevel
Use the new `FullAstVisitor` for `AstConditionLevel`. This will allow
proper formatting of `if / else / endif` and `foreach / endforeach`
blocks.
2024-04-08 10:43:57 -07:00
Charles Brunet be9e9af15a Add ast visitor for whitespaces and symbols
The `AstVisitor` intentionally ignores whitespaces and symbols,
as they are not useful for tne interpreter. However, when formatting a
build file, we need them. This commit introduces a `FullAstVisitor` that
visits every Nodes, including whitespaces and symbols.
2024-04-08 10:43:57 -07:00
Charles Brunet 154b9e78d5 fix colon wrongly named column in parser
In #02ff955, I used the word `columns` instead of `colons`, but the
meaning really was about the ':' symbol.
2024-04-08 10:43:57 -07:00
Charles Brunet bec84aced5 Fix type checking in ast.printer
- Wrong types were used for MultilineStringNode and
  FormatMultilineStringNode
- Simplify the `escape` method to avoid use of T.Cast
2024-04-08 10:43:57 -07:00
Dylan Baker 8a10c8a539 coredata: remove extraneous keys when updating project_options
This can happen when a project's meson.options file is updated, and an
old option is removed.
2024-03-18 16:06:37 -07:00
Charles Brunet f9479787a0 fix reconfigure subproject base options 2024-03-10 13:09:32 -07:00
Xavier Claessens cbf23f5eba printer: Add a newline after "else" 2024-02-26 10:03:51 -05:00
Xavier Claessens c25f0b1d54 printer: notin operator should be printed as "not in" 2024-02-26 10:03:51 -05:00
Dylan Baker 95b3b9f710 coredata: use a Protocol for shared options between setup configure and dist
These are all passed around interchangably inside Meson, so use a shared
protocol for them.
2024-02-23 08:47:01 -08:00
Dylan Baker c41fbf5076 ast/interpreter: fix some low hanging type issues 2024-01-08 19:33:05 -05:00
Dylan Baker 7d0d610045 ast/introspection: make mypy clean 2024-01-08 19:33:05 -05:00
Dylan Baker 5cd1147354 ast/printer: fix mypy issues
Other than one case that I think cannot be actually hit (or it would
fail).
2024-01-08 19:33:05 -05:00
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 ef5931f12d fix undefined StringNode from previous commit 2023-09-13 16:56:42 +05:30
Charles Brunet 8caf40e5ae Allow unit test to parse testcase blocks
When a unittest introspect a meson.build file from a test case,
the file may contain a testcase block. We should ignore this block.
2023-09-13 16:55:38 +05:30
Jussi Pakkanen d2dfef5205
Merge pull request #12152 from bruchar1/ast-preserve-all
Preserve whitespaces and comments in AST
2023-09-12 17:50:13 +03:00
Xavier Claessens 1b6c9ad02a msubprojects: Speedup subproject_dir extraction
The interpreter takes significant amount of time to initialize
everything in project() function. We only need to extract a string from
AST, just like we do in handle_meson_version_from_ast().
2023-09-12 17:32:17 +05:30
Charles Brunet d3a26d158e raw printer
this printer preserves all whitespaces and comments in original meson.build file. It will be useful for rewrite and potential auto-formatter
2023-09-11 07:51:19 -04:00
Charles Brunet 6a18ae48b3 ast: fully resolve nodes for add operation
Otherwise, string + stringmethod results in a list of two strings instead of the concatenation of the strings
2023-09-11 07:51:19 -04:00
Charles Brunet 02ff9553db parser: add SymbolNode to preserve operators 2023-09-11 07:51:18 -04:00
Charles Brunet f13260dd43 parser: add ElseNode 2023-09-11 07:51:18 -04:00
Charles Brunet 8d357ba62c parser: use IdNode for foreach varnames 2023-09-11 07:51:18 -04: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
Liam Beguin 983562c66e
syntax-highlighting: vim: update builtin function list
Update builtin function list using the refman

	python docs/genrefman.py \
		-g vim \
		-o data/syntax-highlighting/vim/syntax/

This also drops gettext() and find_library() from the list of builtin
functions that have been deprecated since 2016.

Changes are squashed here because test_vim_syntax_highlighting() would
validate the file against the list of builtin functions that no longer
matches the yaml documentation.

Signed-off-by: Liam Beguin <liambeguin@gmail.com>
2023-09-07 19:14:03 -04:00
Eli Schwartz 90ce084144
treewide: automatic rewriting of all comment-style type annotations
Performed using https://github.com/ilevkivskyi/com2ann

This has no actual effect on the codebase as type checkers (still)
support both and negligible effect on runtime performance since
__future__ annotations ameliorates that. Technically, the bytecode would
be bigger for non function-local annotations, of which we have many
either way.

So if it doesn't really matter, why do a large-scale refactor? Simple:
because people keep wanting to, but it's getting nickle-and-dimed. If
we're going to do this we might as well do it consistently in one shot,
using tooling that guarantees repeatability and correctness.

Repeat with:

```
com2ann mesonbuild/
```
2023-08-11 13:41:03 -04:00
Eli Schwartz a01418db0a
remove useless type annotations
These annotations all had a default initializer of the correct type, or
a parent class annotation.
2023-08-11 13:37:17 -04:00
Jussi Pakkanen d391e5281c
Merge pull request #11742 from xclaesse/link-whole-cases
Fix niche cases when linking static libs
2023-07-05 01:10:58 +03:00
Volker Weißmann 2699fd4b8a During reconfigure, show that no compiler was found, if compiler fails sanity check. 2023-05-13 11:06:24 +03:00
Xavier Claessens 3162b901ca build: Process compilers before calling link() and link_whole()
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-05-01 12:57:45 -04:00
Josh Soref cf9fd56bc9 fix various spelling issues
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-11 19:21:05 -04:00
Dylan Baker 4a014d1724 Add support for meson.options as a replacement for meson_options.txt
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-28 15:01:10 +03:00
Charles Brunet 90b6d6dafb rewriter: fix warning about empty sources 2023-03-14 16:22:05 +02:00
Eli Schwartz 61d525cc16
refactor a few subsystem-relative imports that imported the wrong location
Inside of mesonbuild.ast.* we can and should import from .foobar, rather
than importing from .__init__'s re-exported version of that object.

Failing to do so results in an extremely brittle codebase where simply
changing the order of lines in __init__.py can result in ImportError.
2023-02-28 15:46:53 -05:00
Eli Schwartz 680b5ff819
treewide: add future annotations import 2023-02-01 17:01:30 -05:00
Eli Schwartz e990c5fdbd
introspect: avoid crashing when add_languages for an optional language fails
Because that is what the real interpreter does, too. It logs a failure
and carries on.
2023-01-29 14:51:07 -05:00
Dylan Baker 2d349eae8c
pylint: enable the set_membership plugin
Which adds the `use-set-for-membership` check. It's generally faster in
python to use a set with the `in` keyword, because it's a hash check
instead of a linear walk, this is especially true with strings, where
it's actually O(n^2), one loop over the container, and an inner loop of
the strings (as string comparison works by checking that `a[n] == b[n]`,
in a loop).

Also, I'm tired of complaining about this in reviews, let the tools do
it for me :)
2022-11-30 16:23:29 -05:00
Dylan Baker 20d76b8353
pylint: enable unnecessary-comprehension 2022-10-03 00:14:43 -04:00
Volker Weißmann 5fec9f5db9 Fixed string escaping in AstPrinter 2022-09-07 08:56:51 -04:00
Eli Schwartz 0703ee0aef
move various unused typing-only imports into type-checking blocks 2022-07-03 14:11:31 -04:00
Eli Schwartz 075ccc68be
sort imports for neatness 2022-07-03 14:11:30 -04:00
Eli Schwartz 462b35e4b1 flake8: fix various whitespace nits 2022-06-13 13:34:39 +03:00