Commit Graph

185 Commits

Author SHA1 Message Date
Christoph Reiter 26903d7b12 main: Make the msys/python check work again, in some cases
msys/python in MSYS2 pretends to be cygwin in all cases for some time
now, so this check was impossible to hit.

The underlying confusion it tried to prevent is still there, namely trying
to build with mingw but wrongly using a msys/cygwin python/meson.

We can use the MSYSTEM env var to detect if we are in a mingw shell, and
in case the Python doesn't match we suggest installing mingw variants of both
python and meson.

Using msys/python + meson in a MSYS environment works fine on the other hand,
so no need to error out in that case.

Fixes #8726

Also addresses the concern raised in
https://github.com/mesonbuild/meson/issues/3653#issuecomment-474122564
2022-04-01 13:15:33 -04:00
Elliott Sales de Andrade 969ae6e0e1 Correctly handle --version argument to runpython
Followup to #10204.
2022-03-29 21:57:46 -04:00
Eli Schwartz 80192aa577
runpython: support --version
argparse is the gift that keeps on giving, hahaha. Suppress the script
argument when --version is specified to avoid "required argument not
provided" errors, and print the python version.

The version argument is required in order to make this baseline
functional as a resolved python for find_program, which may specify a
version and expect this to work with python itself. Our incomplete CLI
wrapper over the python CLI interface was missing this.

Fixes #10162
2022-03-29 01:26:18 -04:00
Jussi Pakkanen 04ef7ec45d Add new env2mfile command. 2022-03-09 18:02:04 -05:00
Eli Schwartz 7cc4ca2cbb
Revert "Add new env2cross command."
This reverts commit e257a870fe.

The PR adding this command had infinitely hanging CI, and now that it is
merged to master we cannot get any CI on any PR to succeed.
2022-03-08 21:34:39 -05:00
Jussi Pakkanen e257a870fe Add new env2cross command. 2022-03-08 23:40:03 +02:00
Eli Schwartz a6e08e8fa7
use a more sane check instead of run_custom_lint
Unfortunately, checking for strings without context is exceedingly prone
to false positives, while missing anything that indirectly opens a file.

Python 3.10 has a feature to warn about this though -- and it uses a
runtime check which runs at the same time that the code fails to open
files in the broken Windows locale. Set this up automatically when
running the testsuite.

Sadly, Python's builtin feature to change the warning level, e.g. by
setting EncodingWarning to error at startup, is utterly broken if you
want to limit it to only certain modules. This is tracked in order to be
more efficiently ignored at https://bugs.python.org/issue34624 and
https://github.com/python/cpython/pull/9358

It is also very trigger happy and passing stuff around via environment
variable either messes with the testsuite, or with thirdparty programs
which are implemented in python *such as lots of gnome*, or perhaps
both.

Instead, add runtime code to meson itself, to add a hidden "feature".
In the application source code, running the 'warnings' module, you can
actually get the expected behavior that $PYTHONWARNINGS doesn't have. So
check for a magic testsuite variable every time meson starts up, and if
it does, then go ahead and initialize a warnings filter that makes
EncodingWarning fatal, but *only* when triggered via Meson and not
arbitrary subprocess scripts.
2022-03-01 21:42:52 -05:00
Eli Schwartz 078175314a
fine-tune the logic for reporting context on tracebacks
Do not report a MesonBugException if the command is `runpython`, because
that is 100% other people's code, not ours. It's only used as an
alternative to sys.executable for reporting a path to python, in the
event of a Windows MSI install.

While we are at it, refactor the logic for PermissionError to be a bit
more unified (and sadly use isinstance instead of except, but it is what
it is).
2022-02-15 23:51:46 -05:00
Eli Schwartz 0db2de2b0a
do not report context on python traceback, for PermissionError
It's not a MesonBug which needs to be reported, and the existing error
already adequately points out the problematic file.

It is impossible to get a PermissionError for files created by meson
itself, once the build directory has been created, anyway.
2022-01-27 18:49:17 -05:00
Eli Schwartz ad525dcce4
bump minimum required version of python to 3.7
Comment out the pending deprecation notice. It cannot be reached
anymore, but is still useful for the next time we do a version bump.
2022-01-10 18:36:56 -05:00
Eli Schwartz 09f03a8424 add pending deprecation notice for python 3.6 2022-01-10 01:36:46 +02:00
Eli Schwartz 3c039f42a0
report the context, if possible, on python tracebacks
The interpreter tries to catch any exception and add the latest node
information to it, but currently we only used that to print better
formatted error messages on MesonException.

Since we should theoretically have that property for most/all
exceptions, let's percolate that upward, and message the user that an
unexpected traceback was encountered, that it should be reported as a
bug, and the helpful information of "how far into parsing this
meson.build did we get before erroring out, anyway?"
2021-11-29 16:36:51 -05:00
Xavier Claessens 928078982c Add --vsenv command line option and active VS only when needed 2021-10-10 23:15:18 +03: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
xth a79980da6b fix bat_info UTF-8 string error
" bat_info = json.loads(bat_json) " may produce error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 ...
Because the vswhere.exe's output is not utf-8 by default
Use UTF-8 encoding for vswhere.exe can fixing it .
2021-08-03 00:16:11 +03:00
Daniel Mensinger 3e396b3782
fix: Always explicitly set encoding for text files (fixes #8263) 2021-06-29 11:28:08 +02:00
Daniel Mensinger 28175bbee2
pathlib: Patch pathlib to work around some bugs (fixes #7295) 2021-06-29 11:28:08 +02:00
Daniel Mensinger 7fc755b334 typing: Fully annotate run_project_tests.py 2021-06-09 13:25:36 +02:00
Xavier Claessens 25fa2d4f7b vsenv: Recommend using "meson compile" wrapper
When meson has setup the VS environment, running ninja to build won't
work, user should use meson wrapper to compile.
2021-05-28 17:34:25 -04:00
Naveen M K 495e76d10a Remove `Microsoft.VisualStudio.Workload.WDExpress` 2021-05-28 15:16:37 -04:00
Naveen M K 7ec5267939 Find Visual Studio Build Tools 2019
Got the Idea from setuptools
a5131f0b82/setuptools/msvc.py (L176)
2021-05-28 15:16:37 -04:00
Jussi Pakkanen 799b96f753 Also skip VS activation if gcc is found. 2021-05-23 21:33:24 +01:00
Jacob Nielsen 3e5ec00a40
Better detection of Visual Studio compiler 2021-05-22 01:05:18 +03:00
Jussi Pakkanen 0b2a7300c0 Set up VS environment automatically when run. 2021-05-13 11:03:10 +03:00
Xavier Claessens 598e968993 Add `meson devenv` command and meson.add_devenv() 2021-03-16 09:00:50 -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
Jussi Pakkanen bca90722ec Bump minimum supported Python version to 3.6. Closes #6297. 2020-10-30 11:18:11 +02:00
Nirbheek Chauhan 4ad4565ddd Add a notice about Python 3.5 support
This will be printed in bold at the end of interactive meson
sub-commands that won't be parsed by a program. Specifically: setup,
compile, test, and install.

NOTICE: You are using [...]
2020-09-02 10:37:40 +00:00
Michael c53b637959 switch python2 %s for python3 .format 2020-04-21 00:16:21 +03:00
Dylan Baker 1210a67f66 mesonbuild: Add mcompile command
This is tested working with both msbuild and ninja/samu. Since our xcode
support is pretty much broken I didn't bother.

Fixes #6670
2020-03-04 14:07:27 -05:00
Wolfgang Stöggl f037e7ef45 Fix typos found by codespell
- Typos were found by codespell v1.16.0
2019-11-06 09:55:30 -05:00
Jussi Pakkanen f2e018c7f3 Create multiple different archive types with dist. 2019-07-23 23:26:46 +03:00
Jussi Pakkanen 7ce2a24f42 Made dist a top level command. 2019-07-23 23:26:46 +03:00
Daniel Mensinger e75211d321
Fix builtin variable names 2019-04-29 12:17:40 +02:00
Dylan Baker 5678468c2c Don't use len() to test for container emptiness
I ran the numbers once before (it's in the meson history) but it's
*much* faster to *not* use len for testing if a container is empty or
not.
2019-04-25 12:28:51 -07:00
Dylan Baker add821db64 Don't use mutable types as default arguments
This isn't safe given the way python implements default arguments.
Basically python store a reference to the instance it was passed, and
then if that argument is not provided it uses the default. That means
that two calls to the same function get the same instance, if one of
them mutates that instance every subsequent call that gets the default
will receive the mutated instance. The idiom to this in python is to use
None and replace the None,

def in(value: str, container: Optional[List[str]]) -> boolean:
   return src in (container or [])

if there is no chance of mutation it's less code to use or and take
advantage of None being falsy. If you may want to mutate the value
passed in you need a ternary (this example is stupid):

def add(value: str, container: Optional[List[str]]) -> None:
    container = container if container is not None else []
    container.append(value)

I've used or everywhere I'm sure that the value will not be mutated by
the function and erred toward caution by using ternaries for the rest.
2019-04-23 02:03:19 +03:00
Jussi Pakkanen 4e4f97edb3 Can run argument strings with internal Python. Closes #5217. 2019-04-21 15:14:34 +03:00
Jussi Pakkanen ee863d33c1
Merge pull request #2601 from 1ace/feature/completion
Add completion scripts for Bash and Zsh
2019-03-04 18:40:13 +02:00
Daniel Mensinger 90b557e38a
rewriter: Remove command alias 2019-03-04 13:00:07 +01:00
Daniel Mensinger 9874ce81f0
rewriter: make flake8 happy 2019-03-04 13:00:06 +01:00
Daniel Mensinger c4708c28f2
better formating of the help output 2019-03-04 13:00:06 +01:00
Eric Engestrom b758f0a953 add note to keep completion scripts updated 2019-02-20 18:48:39 +00:00
Andrei Alexeyev 51dadb92d0 runpython: insert script's dir into import path
Fixes #4947
2019-02-18 22:09:32 +02:00
Michael Hirsch, Ph.D da34bea893 pep8 py37 2019-01-29 22:06:11 +02:00
Jussi Pakkanen e6df5a7586
Merge pull request #4719 from ocrete/fix-posix-lang
Replace surrogates with valid codepoints to print env
2019-01-17 00:40:56 +02:00
Olivier Crête 92b343f2f7 mesonmain: Force to output UTF-8 even when the locale isn't
Otherwise Python gets all confused and it makes testing difficult.

Also minimally emulate the behaviour of the normal object to make the rest
of the code happy.
2019-01-15 14:01:32 -05:00
Martin Hostettler 768fa502ac Add new meson.py unstable-coredata subcommand.
This adds a hidden option to dump the current otherwise hidden peristant
state in coredata.dat.

This interface is unstable as meson has no compatibility promises about
coredata.dat.
2019-01-07 22:55:45 +02:00
Xavier Claessens 60b58e056f Add 'meson subprojects update' command
This is inspired by gst-build's git-update script.
2018-12-02 08:37:32 -05:00
Xavier Claessens adae6b56de Hide 'rewrite' and 'runpython' commands from help 2018-10-04 09:40:21 -04:00
Xavier Claessens 37067a53c4 Use a single ArgumentParser for all subcommands
This has the adventage that "meson --help" shows a list of all commands,
making them discoverable. This also reduce the manual parsing of
arguments to the strict minimum needed for backward compatibility.
2018-10-04 09:40:21 -04:00