Commit Graph

64 Commits

Author SHA1 Message Date
Daniel Mensinger 95b70bcb97 deps: Split dependencies.base
Split the Factory and dependency classes out
of the base.py script to improve maintainability.
2021-06-03 10:23:27 -07: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 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 ed57646475 interpreter: 'embed' kwarg is only valid in python module 2021-05-08 21:31:55 +03:00
Xavier Claessens 7ffe1b4a66 interpreter: Split permitted_kwargs dict 2021-04-12 21:30:00 +03:00
Dylan Baker 40e3577a65 split program related classes and functions out of dependencies
Dependencies is already a large and complicated package without adding
programs to the list. This also allows us to untangle a bit of spaghetti
that we have.
2021-03-19 08:47:10 -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
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
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
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 f6672c7a19 use real pathlib module
We added the _pathlib module to work around defeciencies in python 3.5's
implementation, since we now rely on 3.6 lets drop this
2020-11-20 15:08:40 -08:00
Xavier Claessens 8b20852b0f python.dependency() is not respecting 'required' kwarg 2020-10-06 19:15:59 -04:00
Daniel Mensinger 1dfaccfd91 pathlib: Fix resolve() by overriding it in Python 3.5 2020-10-04 10:45:48 +02:00
Marc-André Lureau efb86088bc python: install_sources() should default to pure, following the doc
As stated by the doc, default to install python sources to purelib
location, as they should not depend on platform.

This also fixes discrepancy between get_install_dir() and
install_sources() locations.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-05-10 20:08:41 +03:00
Xavier Claessens 39a69d1fb0 find_program: Fixes when the program has been overridden by executable
- ExternalProgramHolder has path() method while CustomTargetHolder and
  BuildTargetHolder have full_path().
- The returned ExternalProgramHolder's path() method was broken, because
  build.Executable object has no get_path() method, it needs the
  backend.
- find_program('overridden_prog', version : '>=1.0') was broken because
  it needs to execute the exe that is not yet built. Now assume the
  program has the (sub)project version.
- If the version check fails, interpreter uses
  ExternalProgramHolder.get_name() for the error message but
  build.Executable does not implement get_name() method.
2020-04-28 01:39:56 +03:00
John Ericson 3a4388e51d Fix legacy env var support with cross
Fix #3969
2020-03-23 17:51:36 +02:00
Nirbheek Chauhan 40b58be100 modules/python: Do not error out if positional args are passed
Also update the documentation.

Fixes https://github.com/mesonbuild/meson/issues/6470
2020-02-17 00:38:57 +02:00
Dylan Baker fd892ad7ce dependencies: Make Dependency initializer signatures match
Currently PkgConfig takes language as a keyword parameter in position 3,
while the others take it as positional in position 2. Because most
dependencies don't actually set a language (they use C style linking),
using a positional argument makes more sense. ExtraFrameworkDependencies
is even more different, and duplicates some arguments from the base
ExternalDependency class.

For later changes I'm planning to make having all of the dependencies
use the same signature is really, really helpful.
2020-01-29 09:11:24 -08:00
Daniel Mensinger 09b53c534f types: import typing as T (fixes #6333) 2020-01-08 15:28:17 +01:00
Daniel Mensinger c4649704c8 python: add embed to the python dependency function 2019-12-18 01:19:16 +02:00
Jussi Pakkanen 5b422fce87 Make Python 2 tests optional(er) to prepare for py2 purge in Debian. 2019-10-01 21:12:04 +03:00
Ross Burton ad368cfc07 modules/python: improve log when probing Python binary
If the Python binary that we find doesn't return valid JSON when asked to run a
small script, show the command being ran and stdout/stderr in meson-log.txt.

Fixes: #5914
2019-09-12 15:09:40 +03:00
Jussi Pakkanen af1a81fffc Improve error message when Python is not usable. [skip ci] 2019-06-27 20:45:58 +03:00
Dylan Baker 15ab1f64f9 modules/python: add a modules keyword argument
This mirrors the modules keyword argument that some dependencies (such
as qt and llvm) take. This allows an easier method to determine if
modules are installed.
2019-06-12 14:13:20 +03:00
John Ericson 07777e15d4 Purge `is_cross` and friends without changing user interfaces
In most cases instead pass `for_machine`, the name of the relevant
machines (what compilers target, what targets run on, etc). This allows
us to use the cross code path in the native case, deduplicating the
code.

As one can see, environment got bigger as more information is kept
structured there, while ninjabackend got a smaller. Overall a few amount
of lines were added, but the hope is what's added is a lot simpler than
what's removed.
2019-06-09 13:13:25 -04:00
Daniel Mensinger e75211d321
Fix builtin variable names 2019-04-29 12:17:40 +02:00
Jussi Pakkanen 4e4f97edb3 Can run argument strings with internal Python. Closes #5217. 2019-04-21 15:14:34 +03:00
Dylan Baker a710b83a67 modules/python: normalize output for disabled by feature
Instead of printing a message about how python was skipped, print the
normal 'Program foo found:' message, with a "disabled by feature"
message added.
2019-04-03 14:48:29 -07:00
Dylan Baker de48e887b8 modules/python: Do disabler check after validating inputs
This will help developers not introduce bugs (say putting 3 instead of
"python3"), and will be useful for the next patch.
2019-04-03 14:48:29 -07:00
Dylan Baker 82346a2bd2 modules/python: Report program found in find_installation()
Currently find_installation is silent, which is pretty annoying. Let's
log it.
2019-04-03 14:48:29 -07:00
Dylan Baker 3d04e5a150 modules/python: Remove spaces around keyword arguments
just small style cleanups.
2019-04-02 15:34:55 -07:00
Nacho García 222a973918 dependencies: fix Python linking for windows+mingw
For dynamic linking, some mingw releases don't link
correctly with pythonXX.lib in all cases.
This patch forces mingw to link against
pyhthonXX.dll instead of the .lib file, which has
a better compatiblity.

Note that msys 1.0 old platform is detected
as windows instead of 'mingw'
2019-03-18 09:51:31 +00:00
Christoph Reiter 1bd14b52b2 python: don't require a Python lib in case we don't link against it. Fixes #4841
In case extensions aren't linked against libpython we can't assume one exists at
all or is available in a known directory.
2019-02-04 20:27:26 +01:00
Xavier Claessens 83766b3687 Fix flake8 errors 2019-01-16 11:16:46 -05:00
John Ericson 2b22576fb6 Remove cross_info; cross file is parsed up front and discarded 2019-01-02 16:22:47 -05:00
guruDanny67 ee555e37c9 Avoid exception looking for python on windows if the launcher (py.exe) is not installed 2019-01-02 22:18:11 +02:00
Dylan Baker f6405adc2d modules/python: Add path method
This would normally be exposed by the ExternalProgramHolder, but wasn't
due to the implementation of the PythonInstallation module. Because of
that I've duplicated the method so that we can add the FeatureNew
decorator.

Fixes #4070
2018-12-12 12:23:37 -08:00
Dylan Baker d536a6f018 modules/python: Refactor the PythonInstallation object
Into a generic interpreter object. This isn't a module, it's an object
returned by a module, it also happens to be a special case of an
ExternalProgram, which is a normal interpreter object. Let's treat it
like one.
2018-12-12 12:23:37 -08:00
Dylan Baker 3d322b3381 modules/python: don't inherit from InterpreterObject
Because ExternalProjectHolder already does
2018-12-12 12:23:37 -08:00
Dylan Baker 03805287e5 modules/python: Don't pass instance variable to instance method 2018-12-12 12:23:37 -08:00
Christoph Reiter 8e85a7b7b8 python: only link extension modules against libpython when distutils does too. Fixes #4117
Windows requires things to be linked, on macOS distutils doesn't link by default.
On Linux etc. things are not so clear, some distros like Debian patch distutils to not link,
some don't. In addition the manylinux wheels spec prohibits linking against libpython
and upstream is thinking about changing the default:
https://bugs.python.org/issue34814

Call into distutils to figure out what distutils does and in case it doesn't link
against libpython replace the passed in Python dependency with a partial one.
2018-12-10 20:25:33 +02:00
Philippe Normand 4db1b3a09f modules/python: Do not override link_args with None largs
None is not iterable so it would trigger a TypeError later when link_args are
passed on to CompilerArgs.extend_direct().
2018-12-05 22:18:53 +02:00
Dylan Baker 71a5f990d0 modules/python: Allow use of the native file
Currently this just allows setting a "python" variable that always
overrides, probably we want to have the option for "python2" and
"python3" as well.
2018-11-14 15:57:37 -08:00
Xavier Claessens 61348da069 Add 'disabler' argument to functions returning not-found objects
When dependency(), find_library(), find_program(), or
python.find_installation() return a not-found object and disabler is
true, they return a Disabler object instead.
2018-10-23 22:09:55 +03:00
Xavier Claessens 4ff7b65f9b python module: Only run command once to get all info 2018-09-18 08:50:49 -04:00
Xavier Claessens 6112e6a815 Fix version check when passing feature option to find_installation() 2018-09-17 11:37:14 -04:00
Xavier Claessens 3cf03ec6d6 find_installation: Add support for feature option in required kwarg
Closes: #4165.
2018-09-16 15:07:43 +03:00
David Seifert ab01db177b Make python module more robust
* Lookup is now performed according to the following order:
  1. use `pkg-config` with `PKG_CONFIG_LIBDIR=LIBPC` from python
  2. use plain `PKG_CONFIG_{LIBDIR,PATH}` from the environment
  3. try to extract the information from SYSCONFIG

The second step is necessary for relocated python installations
and cross compilation scenarios, where the value of `LIBPC` might
be wrong.
2018-08-09 06:27:53 -07:00
Christoph Reiter 6b9fdfe67b python.find_installation: only try to find python with the py launcher if it isn't in PATH
Meson tries to find the interpreter path through the "py" launcher on Windows in all
cases which breaks if meson is run under MSYS2 and an official CPython is installed as well.
MSYS2 Python doesn't install a py launcher which results in meson finding the system one instead
even though python2/python3 is in PATH.

Always check if the interpreter name is in PATH before falling back to checking the py launcher.
2018-07-27 18:10:13 +03:00
Nirbheek Chauhan 907a68bcf1 FeatureNew: Fix method names for some feature checks 2018-07-02 07:05:08 +00:00