Commit Graph

228 Commits

Author SHA1 Message Date
L. E. Segovia 9797f7682b cmake: Fix blunt target filtering skipping GENERATED dependencies
GENERATED files can be used as dependencies for other targets, so it's
misguided (at best) to filter them with a blunt whitelist.

However, there does exist an extension that needs to be skipped: on Windows +
MSVC, CMake will by default try to generate a Visual Studio project, and
there dependencies with no inputs are instead tied to a dummy .rule
input file which is created by the generation step. The fileapi will
still report those, so it will cause Meson to bail out when it realises
there's no such file in the build tree.

Fixes #11607
2024-01-16 11:00:26 -08:00
Dylan Baker 8bc8f93436 cmake/interperter: Add missing type annotation
Which mypy is suddenly complaining about.
2023-12-21 13:15:23 -08: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
Nicolas Werner ebf5757c59 cmake: parse project version
This properly sets the project version in projects meson generates from
cmake projects. This allows dependency fallbacks to properly check the
version constraints in dependency calls when falling back to a cmake
subproject. Before this would fail, because the project version was
undefined.
2023-12-12 20:14:26 -05:00
Dylan Baker a85353cd83 cmake: Handle compiler.find_library returning None
I'm not 100% sure that warning is the appropriate action, but it's
better than failing with a backtrace.

Fixes: #12555
2023-12-01 16:19:16 -08:00
Tristan Partin 1991ad8706
Remove type comments in run_project_tests.py 2023-10-04 15:23:00 -04:00
Xavier Claessens e9369be086 CMakeInterpreter: Remove useless arguments 2023-09-22 15:50:26 -04:00
Charles Brunet 5b29eff8ad parser: simplify other node constructors 2023-09-11 07:51:18 -04:00
Charles Brunet 0f4891cdf4 parser: simplify Assignment and PlusAssignment nodes 2023-09-11 07:51:18 -04:00
Charles Brunet 02ff9553db parser: add SymbolNode to preserve operators 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
Charles Brunet 5707d39017 parser: preserve number base 2023-09-11 07:51:17 -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
kiwixz 4fab71f481 cmake: fix empty BOOL generator expression evaluating to true 2023-07-19 15:26:29 -07:00
kiwixz 727b737bc3 cmake: find dependencies with bare library names on all platforms 2023-07-19 15:04:09 -07:00
Eli Schwartz 3c5d46267f
WIP: cmake: do not re-export unused top-level objects
We should try to figure out what is a cross-submodule object and what
isn't.
2023-06-26 13:10:33 -04:00
Eli Schwartz 5a9b2cb8f8
cmake module: use more typed_pos_args for consistency
It's shorter and more descriptive. Although we always enforce the same
rules either way, a unified decorator is one less line of code for each
location, and also tells you how many "too few" arguments you *did*
pass.
2023-05-03 16:24:20 -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 4d7a72b6db cmake: check that `re.search` returned a non-None value
If an re call fails to find a match it returns None. We're not checking
that, and crashing.

Fixes: #11376
2023-02-13 13:30:06 -05:00
Eli Schwartz a21af43200
micro-optimize: define typing-only objects in TYPE_CHECKING
Union types that exist solely for use as annotations don't need to be
created in normal runs.
2023-02-01 17:01:30 -05:00
Eli Schwartz 680b5ff819
treewide: add future annotations import 2023-02-01 17:01:30 -05:00
Eli Schwartz dcefe1f8fd
pyupgrade: use set literal 2023-02-01 17:01:30 -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 d5e899c768
pylint: enable the bad_builtin checker
This finds uses of deny-listed functions, which defaults to map and
filter. These functions should be replaced by comprehensions in
idiomatic python because:
    1. comprehensions are more heavily optimized and are often faster
    2. They avoid the need for lambdas in some cases, which make them
       faster
    3. you can do the equivalent in one statement rather than two, which
       is faster
    4. They're easier to read
    5. if you need a concrete instance (ie, a list) then you don't have
       to convert the iterator to a list afterwards
2022-11-29 23:26:05 -05:00
SmallWood-D d32ee583ad Fix crash when toolchain is missing
Add a MissingCompiler class returned by compiler detecting methods
intead of None - accessing such an object raises a DependencyException

Fixes #10586

Co-authored-by: duckflyer <duckflyer@gmail.com>
2022-11-29 01:48:27 +02:00
Eli Schwartz 9d1b59fa7f
migrate some type comments to modern type annotations
flake8 6 upgrades to pyflakes 3, and in turn this means that support for
parsing `# type: ` style annotations has been removed.

https://github.com/PyCQA/pyflakes/pull/684

This caused one file to fail linting, because it had a typing import
which was only used by a type comment.

```
mesonbuild/cmake/interpreter.py:55:5: F401 '.common.CMakeConfiguration' imported but unused
```

Updating it to actual annotations allows pyflakes to detect its usage
again, and flake8 passes. Do the whole file while we are here.
2022-11-24 11:50:20 -05:00
Eli Schwartz f645bcf68d
remove a couple of unneeded type annotations
These are trivially inferred based on their initialized values.
2022-11-24 11:50:20 -05:00
Dylan Baker a72840cd2e
pylint: enable use-a-generator
This catches some optimization problems, mostly in the use of `all()`
and `any()`. Basically writing `any([x == 5 for x in f])` vs `any(x == 5
for x in f)` reduces the performance because the entire concrete list
must first be created, then iterated over, while in the second f is
iterated and checked element by element.
2022-10-04 00:33:04 -04:00
Dylan Baker 20d76b8353
pylint: enable unnecessary-comprehension 2022-10-03 00:14:43 -04:00
Dylan Baker 4da14918cd pylint: enable consider-using-in 2022-09-19 20:57:52 -04:00
Eli Schwartz 0a9048e554
compilers: don't use instance checks to determine properties
In various situations we want to figure out what type of compiler we
have, because we want to know stuff like "is it the pgi one", or "does
it use msvc style". The compiler object has this property already, via
an API specifically designed to communicate this info, but instead we
performed isinstance checks on a compiler class.

This is confusing and indirect, and has the side effect of requiring
more imports everywhere. We should do away with it.
2022-09-19 15:18:59 -04:00
Alf Henrik Sauge 06bf9a5cda Fix purely white space issues reported by flake8 2022-08-26 17:12:40 -04:00
Volker Weißmann 5f3c7125cc Applied tristan957's suggestions 2022-07-18 13:46:26 +02:00
Volker Weißmann cdd2dca174 cmake module: Better warnings and error messages in some cases. 2022-07-18 13:46:26 +02: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
Daniel Mensinger ac31eb49d6 cmake: fix detecting directories as input files (fixes #10244) 2022-05-24 18:00:49 -04:00
Daniel Mensinger 1b9c4b7192 Fix generator expression list problems (fixes #10288) 2022-04-18 22:59:44 -04:00
Daniel Mensinger 4dd6cb8469 cmake: Better error message when configuring a CMake subproject fails. 2022-04-03 12:04:21 -04:00
Tristan Partin d93fe56e89 Fix CMake deprecation warning generated from interpreter 2022-03-29 22:01:48 +03:00
Jussi Pakkanen 219f40c1e4
Merge pull request #9743 from mensinda/cmakeGeneratorFixed
cmake: Add TARGET_ generator expression support (fixes #9305)
2022-03-07 16:12:19 +02:00
Eli Schwartz 07d9c72e17
flake8: fix wrong numbers of blank line separators 2022-02-16 18:19:13 -05:00
Daniel Mensinger 63870da449 cmake: Deprecate CMake <3.17 support 2022-02-03 11:25:59 -05:00
Daniel Mensinger 78619e2c40 cmake: Drop CMake server support and bump min. CMake to >= 3.14 2022-02-03 11:25:59 -05:00
Daniel Mensinger 42843c4cf6
cmake: Add TARGET_ generator expression support (fixes #9305) 2022-01-23 13:22:59 +01:00
Daniel Mensinger 99aae9b4df
cmake: Move generator expression evaluation to the end of the traceparser 2022-01-23 13:22:47 +01:00
Eli Schwartz 140097faf0
port from embedded data to importlib.resources 2022-01-10 18:36:57 -05:00
Daniel Mensinger 3f1519f2e7
cmake: Deprecate CMake <3.14 and warn for <3.17 (#9677)
* cmake: Deprecate CMake <3.14 and warn for <3.17

See:

- #7832
- #9676

* cmake: Add deprecation release note snippet
2021-12-02 00:41:48 +02:00