Commit Graph

194 Commits

Author SHA1 Message Date
Eli Schwartz 28103614ef
refactor errorhandler for deduplication of logic
Mostly just move a comment around back to where it's more relevant, and
handle MESON_FORCE_TRACEBACK once instead of twice.
2022-09-22 15:24:56 -04:00
Eli Schwartz d364985365
fix regression in handling errors during reconfigure
In commit 9ed5cfda15 we refactored
startup to be a bit faster and import less. But this had the side effect
of moving out of our errorhandler. Refactor this so it can be easily
used elsewhere.
2022-09-22 15:23:39 -04:00
Eli Schwartz 9ed5cfda15
avoid importing the entire codebase at first startup
We want to optimize out some internal codepaths used at build time by
avoiding work such as argparse. This doesn't work particularly well when
the argparse arguments are imported before then. Between them, they
indirectly import pretty much all code anywhere, and msetup alone
imports most of it.

Also make sure the regenerate internal script goes directly to msetup.
2022-09-19 15:19:00 -04:00
Eli Schwartz 2fe07adc0e
fixup! deprecate running "meson builddir" without setup subcommand
Also pass the setup command when rewriting --internal regenerate. This
avoids the issue where `ninja` triggers a reconfigure, and this warning
gets printed as a side effect.
2022-08-16 23:39:37 -04:00
Eli Schwartz 3c7ab542c0
deprecate running "meson builddir" without setup subcommand
This is ambiguous, if the build directory has the same name as a
subcommand then we end up running the subcommand. It also means we have
a hard time adding *new* subcommands, because if it is a popular name of
a build directory then suddenly scripts that try to set up a build
directory end up running a subcommand instead.

The fact that we support this at all is a legacy design. Back in the
day, the "meson" program was for setting up a build directory and all
other tools were their own entry points, e.g. `mesontest` or
`mesonconf`. Then in commit fa278f351f we
migrated to the subcommand mechanism. So, for backwards compatibility,
we made those tools print a warning and then invoke `meson <tool>`. We
also made the `meson` tool default to setup.

However, we only warned for the other tools whose entry points were
eventually deleted. We never warned for setup itself, we just continued
to silently default to setup if no tool was provided.

`meson setup` has worked since 0.42, which is 5 years old this week.
It's available essentially everywhere. No one needs to use the old
backwards-compatible invocation method, but it continues to drag down
our ability to innovate. Let's finally do what we should have done a
long time ago, and sunset it.
2022-08-16 17:40:03 -04:00
Omer Pereg fa044e011d handle OSError exception in run function 2022-07-31 14:54:44 +03:00
Prathamesh 7af0078d4e Resolve KeyError while executing help command with unknown param 2022-07-17 00:45:26 -04:00
Xavier Claessens 1a3d29dd0e Move python version check as first thing 2022-06-22 09:13:05 -07:00
Eli Schwartz bb171c2dff
pyupgrade --py37-plus
Some more old style code crept in again.

Additionally, pyupgrade learned to catch more if/elsed code based on the
python version, and delete it.
2022-04-14 18:37:03 -04:00
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