Commit Graph

67 Commits

Author SHA1 Message Date
Dylan Baker e8a88f5320 modules: add type annotations to the `__init__` module 2023-01-10 09:53:22 -08:00
Dylan Baker 3a0d6f65b0 modules: Add a method to the state object for include_dirs
The Interpreter has a method for this, and the module state just wraps
it.
2022-12-05 15:20:09 -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
David Ward 68add86f7b i18n: Fix source root in Gettext targets for subprojects
Gettext should search for input files relative to the (sub)project
source root, not the global source root.

This change exposes a root_subdir member in ModuleState.
2022-09-12 00:27:21 -04:00
Dylan Baker c32f83a829 modules: Add stabilization information to ModuleInfo
We're going to do more with this in the next commit, but this just adds
the information for now. This allows the next commit have 100% mv
changes for some of the modules, which makes review easier
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 0703ee0aef
move various unused typing-only imports into type-checking blocks 2022-07-03 14:11:31 -04:00
Xavier Claessens 0aeb61bd52 wayland: Lookup for wayland-scanner using pkgconfig
Just like some of glib tools, wayland-scanner can be defined in the
pkgconfig dependency variables. Share code between gnome and wayland
modules into ModuleState.
2022-06-10 00:48:25 -04:00
Dylan Baker a2def550c5 modules: move gnome targets into gnome module
They're not used outside of the gnome module anyway, and they create
some annoying potentials for dependency loops
2022-06-01 22:49:10 -04:00
Eli Schwartz e5aa47d8af Revert "wayland: Also lookup scanner in pkgconfig"
This reverts commit 7954a4c9cb.
2022-04-07 23:44:34 -04:00
Xavier Claessens 7954a4c9cb wayland: Also lookup scanner in pkgconfig
This moves generally useful logic from GNOME module's
_get_native_binary() into find_program() implementation. We could decide
later to expose it as public API.
2022-04-04 09:17:34 -04:00
Xavier Claessens c4b8c23eb1 Add API for modules that wants to define their devenv 2022-02-28 09:03:27 -05:00
Xavier Claessens ad75a2bfec modules: Make ExtensionModule inherit from NewExtensionModule
It reduces duplicated code.
2022-02-28 09:03:27 -05:00
Mark Bolhuis 5a4177523e modules/wayland: Add unstable_wayland module 2022-02-27 14:33:33 -05:00
Eli Schwartz e8375d20a9
modules: add ModuleState API to check whether an option was user-specified
Needed to check exclusivity of module options.
2022-02-22 22:22:15 -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
Eli Schwartz 81fbcd1df4
fix broken module tests which caused gtkdoc-check to traceback on assert
Regression in commit 566c2c9a9c.

The interpreter details are a bit of black magic. Functions expect
tuples, but they receive lists and then the type-checking decorators
convert those to tuples.

So, directly manhandling a self._interpreter.func_*() but passing it the
tuple it nominally expected, actually explodes in your face by way of
failing an assert, then dumping 'ERROR: Unhandled python exception'.

Fixes use of gnome.gtkdoc(..., check: true), for example when building
glib.
2022-01-10 23:06:51 -05:00
Eli Schwartz 6be258137e
modules: let the proxy state find_program do silent lookups 2021-12-20 16:03:43 -05:00
Dylan Baker eafed4b8ad modules: use IncludeDirs.to_string_list instead of open coding
This both allows more cod re-use, and simplifies the code.
2021-11-01 12:24:25 -07:00
Dylan Baker fec7b2c07f interpreter/modules: ModuleReturnValue can hold ExecutableSerialisation
The code for this exists and works, but the type annotations don't allow
it. This fixes the annotations
2021-11-01 12:24:25 -07:00
Dylan Baker 09a1528ce0 modules: remove harmful forwarding init methods
There is no reason for these inititializers to exist, all they do is
defer to the parent initializer. Worse, since they are not type
annotated thy prevent the parent type annotations from being used
2021-11-01 12:24:25 -07:00
Xavier Claessens 5316c7df62 ModuleState: Add wrapper to get option 2021-10-08 17:47:35 -04:00
Dylan Baker c4aa8c2521 modules: make ReturnValue.new_objects covariant
Otherwise we have to do a lot of casting to ensure that we get the
appropriate invariant type
2021-09-30 16:09:14 -07:00
Dylan Baker d661a0cd96 build: use an object rather than a dict for the dep_manifest
This really is more of a struct than a dict, as the types are disjoint
and they are internally handled, (ie, not from user input). This cleans
some things up, in addition I spotted a bug in the ModuleState where the
dict with the version and license is passed to a field that expects just
the version string.
2021-09-24 10:36:05 -07:00
Eli Schwartz 87e13af1c8
apply flake8 fixes for unused imports and missing imports 2021-09-14 15:55:07 -04: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
Tristan Partin cd9db63bfb Add typing to ModuleState machine members 2021-08-22 07:57:29 -07:00
Eli Schwartz c2592bc921
correct a copy-pasted comment 2021-08-15 09:36:18 -04:00
Xavier Claessens 59478ce2da modules: Fix typo in state.test()
Fixes: #9081
2021-08-09 14:11:09 -04:00
Xavier Claessens 1dcde9da61 modules: Add API to add test
This fix kwargs not going through typed_kwargs() decorator that sets
defaults.

Fixes: #9009
2021-08-06 15:04:38 -04:00
Dylan Baker bc4201a7f1 interpreter: add required and disabled to import
This is useful both from the perspective of optional functionality that
requires a module, and also as I continue to progress with Meson++,
which will probably not implement all of the modules that Meson itself
does.
2021-06-30 16:28:14 -07:00
Dylan Baker 1416ba0b8d modules: add classes with the found method
These will be needed for checking whether a module is found or not if it
is required false.
2021-06-30 14:06:30 -07:00
Daniel Mensinger 34c28dc92c holders: remove unholder 2021-06-18 23:48:33 +02:00
Dylan Baker ce3a7ec19d modules: pass all proxied arguments 2021-06-15 12:35:15 -07:00
Dylan Baker e23f78141a modules: Fix type annotation imports 2021-06-15 12:35:15 -07:00
Dylan Baker 2322804a4d modules/qt: Add a compile_moc method
This method only compiles moc resources, nothing else
2021-06-15 12:35:15 -07:00
Xavier Claessens 8abbc5cc5d modules: Replace find_program_impl() by state.find_program() 2021-05-28 15:17:10 -04:00
Xavier Claessens 2e02ef6592 modules: Add methods dict everywhere
This fix calling random internal methods from meson.build as long as
they were not prefixed by underscore.
2021-05-28 15:17:10 -04:00
Xavier Claessens 3340284805 modules: Stop using InterpreterObject
Custom objects returned by modules must be subclass of ModuleObject and
have the state argument in its methods.

Add MutableModuleObject base class for objects that needs to be deep
copied on assignation.
2021-05-28 15:17:10 -04:00
Xavier Claessens 723c5227a4 modules: Remove snippet methods
The only advantage they have is they have the interpreter in arguments,
but it's already available as self.interpreter. We should discourage
usage of the interpreter API and rely on ModuleState object instead in
the future.

This also lift the restriction that a module method cannot add build
targets, but that was not enforced for snippet methods anyway (and some
modules were doing it) and it's really loose restriction as it should
check for many other things if we wanted to make it consistent.
2021-05-28 15:17:10 -04:00
Xavier Claessens 4e312c19e6 gnome: Fix gtkdoc generation
install_scripts used to replace @BUILD_ROOT@ and @SOURCE_ROOT@ but it
was not documented and got removed in Meson 0.58.0. gnome.gtkdoc() was
relying on that behaviour, but it has always been broken in the case the
source or build directory contains spaces.

Fix this by changing get_include_args() to substitue paths directly
which will then get escaped correctly.

Add a unit test that builds GObject documentation which is where this
issue has been spotted.

Fixes: #8744
2021-05-12 15:54:37 -04:00
Eli Schwartz 6a0fabc647
mass rewrite of string formatting to use f-strings everywhere
performed by running "pyupgrade --py36-plus" and committing the results
2021-03-04 17:16:11 -05:00
Xavier Claessens ba9bfd2bd8 Simplify module API
- ModuleState is now a real class that will have methods in the future
  for actions modules needs, instead of using interpreter internal API.
- New ModuleObject base class, similar to InterpreterObject, that should
  be used by all objects returned by modules. Its methods gets the
  ModuleState passed as first argument. It has a `methods` dictionary to
  define what is public API that can be called from build definition.
- Method return value is not required to be a ModuleReturnValue any
  more, it can be any type that interpreter can holderify, including
  ModuleObject.
- Legacy module API is maintained until we port all modules.

In the future modules should be updated:
- Use methods dict.
- Remove snippets.
- Custom objects returned by modules should all be subclass of
  ModuleObject to get the state iface in their methods.
- Modules should never call into interpreter directly and instead state
  object should have wrapper API.
- Stop using ModuleReturnValue in methods that just return simple
  objects like strings. Possibly remove ModuleReturnValue completely
  since all objects that needs to be processed by interpreter (e.g.
  CustomTarget) should be created through ModuleState API.
2021-03-04 11:33:22 -05:00
Daniel Mensinger 23818fc5a3
typing: more fixes 2020-09-08 20:15:58 +02:00
Nirbheek Chauhan b1e3440e59 ninjabackend: Treat GNOME gir/typelib as libraries
When classifying generated sources, we were treating gir/typelib files
generated by gobject-introspection as headers. This is bad because it
serializes the build by adding order-only dependencies to every target
even though sources will never actually use them for anything.

Treat them as libraries, which is somewhat more accurate.
2020-05-15 08:39:25 +00:00
Dylan Baker 06b1a317d2 Make use of unholder
We have a lot of cases of code like:
```python
if hasattr(var, 'held_object'):
    var = var.held_object`
```

replace that with the unholder function.
2020-03-05 09:58:52 -08:00
Jussi Pakkanen 46788d1b5b Created the filesystem module. 2019-11-08 00:44:45 +02:00
Jussi Pakkanen 5dc613d618 Revert "gnome.compile_resources: Add ld binary method"
This reverts commit 59791fc569, reversing
changes made to e26b5a119e.
2019-03-28 23:23:01 +02:00
Ninja-Koala b4f04a67de
gnome.compile_resources: Add ld binary method
Instead of generating a c file that gets compiled,
directly create object file with ld.

See https://gitlab.gnome.org/GNOME/glib/issues/1489
2019-02-01 22:02:19 +01:00
Jon Turney b387ab1ee1 Fix flake8 issues (#3834)
* Fix flake8 whitespace reports

$ flake8 | grep -E '(E203|E221|E226|E303|W291|W293)'
./mesonbuild/coredata.py:337:5: E303 too many blank lines (2)

* Fix flake8 'variable assigned value but unused' reports

$ flake8 | grep -E F841
./mesonbuild/modules/gnome.py:922:9: F841 local variable 'target_name' is assigned to but never used

* Fix flake8 'imported but unused' reports

$ flake8 | grep F401
./mesonbuild/compilers/__init__.py:128:1: F401 '.c.ArmclangCCompiler' imported but unused
./mesonbuild/compilers/__init__.py:138:1: F401 '.cpp.ArmclangCPPCompiler' imported but unused
./mesonbuild/modules/__init__.py:4:1: F401 '..mlog' imported but unused

PR #3717 imports ARMCLANG compilers in __init__, but does not add them to
__all__, so they are not re-exported by the compilers package like
everything else.

* More details about flake8 in Contributing.md

Mention that Sider runs flake8
Suggest seting flake8 as a pre-commit hook
2018-07-05 18:08:04 +00:00