Commit Graph

307 Commits

Author SHA1 Message Date
Eli Schwartz 4c55947c47
pylint 2.16: raise a more intentional exception
Include a frivolous error message too. We never see it, but if someone
reads the code and wonders why on *earth* there's a DSL function to
raise a RuntimeError, the message string will clue them in.
2023-02-01 17:01:31 -05:00
Dylan Baker c49552ffb2 interpreter: use typed_pos_args for build_targets
We have to allow through build.BuildTarget and build.ExtractedObjects,
which is what our previous level of checking did, even though they are
ignored. I've used FeatureDeprecated calls here, so that we have a clear
time of "this was officially deprecated in 1.1.0"
2023-01-18 17:55:41 -05:00
Paolo Bonzini b3fc3cd6b5 add objects keyword argument to declare_dependencies 2023-01-04 09:44:32 -08:00
Dylan Baker b9ef662926 reformat some warnings for better code readability 2023-01-03 14:49:02 -05:00
Eli Schwartz 2fa0749175
add license_files kwarg to project
Hook this up to installed dependency manifests. This is often needed
above and beyond just an SPDX string -- e.g. many licenses have custom
copyright lines.
2022-12-27 20:29:46 -05:00
Dylan Baker 2fd5bd934e interpreter: use static_lib's already calculated pic value
Instead of re-calculating it when building both libraries
2022-12-24 13:21:18 -08:00
Eli Schwartz e5a9272034
typing: fix some broken Sequence annotations
T.Sequence is a questionable concept. The idea is to hammer out generic,
maximally forgiving APIs that operate on protocols, which is a fancy way
of saying "I don't care if you use tuples or lists". This is rarely
needed, actually, and in exchange for this fancy behavior you get free
bugs.

Specifically, `somestr` is of type `T.Sequence[str]`, and also
`somestr[0]` is another string of type you guessed it. It's ~~turtles~~
strings all the way down.

It's worth noting that trying to code for "protocols" is a broken
concept if the contents have semantic meaning, e.g. it operates on
"the install tags of this object" rather than "an iterable that supports
efficient element access".

The other way to use T.Sequence is "I don't like that T.List is
invariant, but also I don't like that T.Tuple makes you specify exact
ordering". This sort of works. In fact it probably does work as long as
you don't allow str in your sequences, which of course everyone allows
anyway.

Use of Sequence has cute side effects, such as actually passing lists
around, knowing that you are going to get a list and knowing that you
need to pass it on as a list, and then having to re-allocate as
`list(mylist)` "because the type annotations says it could be a str or
tuple".

Except it cannot be a str, because if it is then the application is
fatally flawed and logic errors occur to disastrous end user effects,
and the type annotations:
- do not enforce their promises of annotating types
- fail to live up to "minimal runtime penalties" due to all the `list()`

Shun this broken concept, by hardening the type annotations. As it turns
out, we do not actually need any of this covariance or protocol-ism for
a list of strings! The whole attempt was a slow, buggy waste of time.
2022-12-11 18:28:39 -05:00
Eli Schwartz 9e8a3b9cbd when generating optional utility targets in ninja, skip existing aliases too
When auto-generating e.g. a `clang-format` target, we first check to see
if the user has already defined one, and if so we don't bother creating
our own. We check for two things:

- if a ninja target already exists, skip
- if a run_target was defined, skip

The second check is *obviously* a duplicate of the first check. But the
first check never actually worked, because all_outputs was only
generated *after* generating all utility rules and actually writing out
the build.ninja file. The check itself compares against nothing, and
always evaluates to false no matter what.

Fix this by reordering the target creation logic so we track outputs
immediately, but only error about them later. Now, we no longer need to
special-case run_target at all, so we can drop that whole logic from
build.py and interpreter.py, and simplify the tracked state.

Fixes defining an `alias_target()` for a utility, which tried to
auto-generate another rule and errored out. Also fixes doing the same
thing with a `custom_target()` although I cannot imagine why anyone
would want to produce an output file named `clang-format` (unless clang
itself decided to migrate to Meson, which would be cool but feels
unlikely).
2022-12-05 12:33:17 -08:00
Dylan Baker 010f525cc5 interpreter: move TEST_KW from interpreter.py to type_checking.py
Since it's also used in the rust module, it should be in a common place.
Also rename from `TEST_KWARGS` to `TEST_KWS`, which is more in line with
the `*_KW` naming scheme used in the type_checking module.
2022-12-05 15:20:09 -05:00
Michael Champanis f194413f87
dependencies: only print not_found_message once
Due to an accidentally repeated line it would print twice unless
required.

Fixes #8150
2022-12-04 22:54:47 -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
David Robillard e85138fcc8 Fix various spelling errors
Found with codespell.
2022-11-24 15:17:23 -05:00
Xavier Claessens 8232665849 Fix deprecation message, the function name is fs.copyfile() 2022-11-16 11:58:16 -05:00
Tristan Partin bfc813200c Change the warning generated by importing an unstable module to non-fatal
Penalizing users for helping to test unstable modules really makes no
sense. As a fatal warning, users can no longer use
`--fatal-meson-warnings`.
2022-11-16 03:17:05 -05:00
Xavier Claessens 81763e610f both_libraries: Make sure to select the right linker for static lib
Regression test: libccpp has both C and C++ sources. The executable only
has C sources. It should still link using the C++ compiler. When using
both_libraries the static has no sources and thus no compilers,
resulting in the executable linking using the C compiler.
https://github.com/Netflix/vmaf/issues/1107
2022-10-31 20:21:07 -04:00
Eli Schwartz 8d8ce4fb77 emit a FeatureNew when using include_directories as a string
This was introduced in commit 3a6e2aeed9
as part of 0.50.0, but did not contain a FeatureNew. As a result, people
would use it without realizing that they broke support for versions of
Meson included in their minimum requirements.
2022-10-31 20:19:43 -04:00
Elliott Sales de Andrade 8c5838bfea Add missing since annotations in docs
This is based on searching for `@FeatureNew*` decorators.

There is also one correction to a version in a decorators;
`build_by_default` was added in #1303, which is 0.38.0, not 0.40.0.
2022-10-24 21:47:46 -04:00
Elliott Sales de Andrade 9c4d6088b1 Accept disablers in summary values
They are commonly used as a replacement for a `dependency`, and not
accepting them in `summary` breaks the last example in [1] when used as
a value.

[1] https://mesonbuild.com/Disabler.html#disabling-parts-of-the-build
2022-10-24 11:17:18 +02:00
Xavier Claessens eb731cda75 Add missing doc for NASM language 2022-10-24 11:06:57 +02:00
Xavier Claessens 064165485c Fix excluding sources for static lib in both_libraries()
When using both_libraries(), or library() with default_library=both, we
remove all sources from args and kwargs when building the static
library, and replace them by the objects from the shared library. But
sources could also come from any InternalDependency, in which case we
currently build them twice (not efficient) and link both objects into
the static library.

It also means that when we needlessly build those source for the static
library, it miss order dependency on generated headers that we removed
from args/kwargs, which can cause build errors in the case the source
from static lib is compiled before the header in shared lib gets
generated.

This happened in GLib:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2917.
2022-10-23 13:18:34 +03:00
Dylan Baker 6f7ea0cc28 pylint: enable use-sequence-for-iteration
This found a couple of places where we *don't* want to use set(), and
want to use list() instead.
2022-09-19 20:57:52 -04:00
Thomas Li a4d5442207 Fix install_subdirs not showing up in intro-install_plan.json 2022-09-06 02:09:38 -04:00
Eli Schwartz e6122ba786 interpreter: name typing-only kwargs import with an underscore
To differentiate it from the function parameter itself. Annotating a
function as

```
def func_foo(kwargs: kwargs.FooKwargs):
```

is confusing, both visually and to static linters.
2022-09-05 09:47:35 -07:00
Eli Schwartz c1182b3f74 interpreter: add a few small func annotations 2022-09-05 09:47:35 -07:00
Eli Schwartz ff7d86d05f flake8: fix unnecessary f-strings without any format placeholders
These can just be ordinary strings.
2022-08-29 23:32:43 +03:00
Eli Schwartz 520bb7abbc flake8: fix lingering whitespace errors 2022-08-29 23:32:43 +03:00
Alf Henrik Sauge 28dff2ca6d Fix indentation issues reported by flake8, requiring code restructuring
Strictly speaking code restructuring isn't needed, but making this PEP8
compliant results in indentation of the code that reduces the
readability. By moving the offending code on the outside of the method
call, the readability is maintained.
2022-08-26 17:12:40 -04:00
Alf Henrik Sauge 06bf9a5cda Fix purely white space issues reported by flake8 2022-08-26 17:12:40 -04:00
Eli Schwartz f8ebfdf7b1
install modes should not apply sticky bit to files
This is generally a bad idea, e.g. it causes OSError on freebsd.

It also gets ignored by solaris and thus causes unittest failures.

The proper solution is to simply reject any attempt to set this, and log a
warning.

The install_emptydir function does apply the mode as well, and since it
is a directory it actually does something. This is the only place where
we don't reset the mode.

Although install_subdir also installs directories, and in theory it
could set the mode as well, that would be a new feature. Also it doesn't
provide much granularity and has mixed semantics with files. Better to
let people use install_emptydir + install_subdir.

Fixes #5902
2022-08-23 21:07:00 -04:00
Eli Schwartz 3e73d4d77d
introspection: untangle install_plan implemetation, fix a bunch of wrong ones
Generally plumb through the values of get_option() passed to
install_dir, and use this to establish the install plan name. Fixes
several odd cases, such as:

- {datadir} being prepended to "share" or "include"

- dissociating custom install directories and writing them out as
  {prefix}/share/foo or {prefix}/lib/python3.10/site-packages

This is the second half of #9478
Fixes #10601
2022-08-22 14:15:22 -04:00
Eli Schwartz e19e9ce6f1
interpreter: add a special class to track the lifecycle of get_option() strings 2022-08-22 11:46:34 -04:00
Dylan Baker e84f293f67 modules/pkgconfig: Use typed_kwargs 2022-08-18 21:57:36 -04:00
Dylan Baker 991baf56e9 modules/fs: Replace configure_file(copy:) with fs.copyfile
`configure_file` is both an extremely complicated implementation, and
a strange place for copying. It's a bit of a historical artifact, since
the fs module didn't yet exist. It makes more sense to move this to the
fs module and deprecate this `configure_file` version.

This new version works at build time rather than configure time, which
has the disadvantage it can't be passed to `run_command`, but with the
advantage that changes to the input don't require a full reconfigure.
2022-08-18 16:53:36 -04:00
Dylan Baker 429e7c1edc interpreter: deprecate the ability import unstable modules as `unstable_*`
This was never meant to work, it's an implementation detail of using
`importlib.import_module` and that our modules used to be named
`unstable_` that this ever worked.
2022-08-17 16:25:36 -04:00
Dylan Baker a78992dd81 interpreter: move handling of module stability to interpreter
Thanks to `ModuleInfo`, all modules are just named `foo.py` instead of
`unstable_foo.py`, which simplifies the import method a bit. This also
allows for accurate FeatureNew/FeatureDeprecated use, as we know when
the module was added and if/when it was stabilized.
2022-08-17 16:25:36 -04:00
Dylan Baker 6843f56f6b modules: use module level information about new and deprecation
Instead of using FeatureNew/FeatureDeprecated in the module.

The goal here is to be able to handle information about modules in a
single place, instead of having to handle it separately. Each module
simply defines some metadata, and then the interpreter handles the rest.
2022-08-17 16:25:36 -04:00
Eli Schwartz 33a5352e3c
make add_project_dependencies respect build version of include dirs
Fixes #10695
2022-08-15 23:27:27 -04:00
Daniel Mensinger ca40dda146 cmake: Add rule relaxations for CMake subprojects
fixes #10566
2022-08-10 22:24:02 -04:00
Dylan Baker 84d06a8f4b interpreter: Add return type to func_dependency 2022-07-17 12:58:17 -04:00
Eli Schwartz e7d87b6f58
implement the new preserve_path kwarg for install_data too
Primarily interesting to me because it is then available for the python
module's install_sources method.

Based on the new feature in install_headers.
2022-07-08 01:58:23 -04:00
Eli Schwartz b89451847a
fix incorrect type annotation
In my attempts at actually using this, I discovered that no, it actually
does take None.
2022-07-08 01:56:14 -04:00
Ralf Gommers 17936686d4 Improve error message for `include_directories(abs_path_intree)`
This error message was quite confusing when triggered by
use of an absolute path to the include dir of an external dependency
(numpy in my case). Changing that to a relative dir also isn't
a solution, because Meson will *not* do the "busywork to make paths
work" that the error message says it will.
2022-07-06 15:17:01 -04:00
Eli Schwartz 47426f3663
migrate declare_dependency to typed_kwargs 2022-06-17 14:33:02 -04:00
Eli Schwartz ca52dac38b
refactor logic for parsing dependency variables into type_checking module
We will momentarily use this to implement typed_kwargs, but not for all
usage sites.
2022-06-17 14:33:02 -04:00
Hemmo Nieminen b49b9f52b2 interpreter: fix a subproject check with symlinks
The check for whether or not a file is allowed to be accessed from a
subproject fails if the subproject is accessed via a symlink. Use the
absolute path of the subproject without resolving symlinks to fix the
check.

Extend unit test 106 to check for this in the future.
2022-06-17 14:18:05 -04:00
Xavier Claessens d85a9733e6 Fix crash when a reconfigure adds a new subproject
When a subproject is disabled on the initial configuration we should not
add it into self.coredata.initialized_subprojects because that will
prevent calling self.coredata.init_builtins() on a reconfigure if the
subproject gets enabled.

Fixes: #10225.
2022-06-14 16:01:20 -04:00
Eli Schwartz f380862284
add Feature checks for install_subdir creating an empty directory
Most importantly, tell people it's broken and to stop using it for
0.62.0
2022-06-10 17:56:02 -04:00
Dylan Baker 27bde338fb interpreter: add missing type annotation 2022-06-01 22:49:10 -04:00
Dylan Baker 2e5a2f6a48 interpreter: add location to a FeatureNew call 2022-06-01 22:49:10 -04:00
Dylan Baker 618b187f70 interpreter: use a shared KwargInfo for install_dir
CustomTarget allows multiple install dirs, while basically everything
else allows only one. So this provides a shared instance for that.
2022-06-01 22:49:10 -04:00