Commit Graph

112 Commits

Author SHA1 Message Date
Xavier Claessens 842504d614 mlog: Log once should not take location into account 2024-10-11 17:16:30 -04:00
Benoit Pierre 3f4957c713 rewriter: don't output target info to stderr
Send the info to stdout, where it belongs.
2024-09-20 19:57:40 -07:00
Eli Schwartz 2b80d4cca1
When configuring fails in Github Actions, print folded logs
A common, and challenging, issue in CI runners is debugging issues when
you know the information you want to check, but it's in the log file
which you don't have because remote CI machines.

There are various edge cases where this is especially hard to solve,
such as inside of `pip install` where the build directory with the log
file is automatically cleaned up. But it's never really *easy* when you
don't expect it, and the best case scenario is your iteration time gets
cut in half as you hurriedly go add some `cat`s to your CI scripts.

Meson can, at least sometimes, detect platforms where text can be
emitted inside of "folds", which are auto-collapsed and don't obscure
the general output, but when clicked will expand the logfile contents.
Hook this up.

We start off with a Github Actions implementation. We had some internal
code used by our own project tests runner, which can be utilized.

Also permit forcing it via an environment variable, in case
autodetection fails and you just want to force *something*, especially
when meson is called a couple layers deep inside some other tool.
2024-09-15 19:25:10 -04:00
Dylan Baker e991c4d454 Use SPDX-License-Identifier consistently
This replaces all of the Apache blurbs at the start of each file with an
`# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing
uses to be consistent in capitalization, and to be placed above any
copyright notices.

This removes nearly 3000 lines of boilerplate from the project (only
python files), which no developer cares to look at.

SPDX is in common use, particularly in the Linux kernel, and is the
recommended format for Meson's own `project(license: )` field
2023-12-13 15:19:21 -05:00
Xavier Claessens 319b41b4c9 mlog: Catch OSError when closing pager
For some reasons, with msys2 it sometimes raises OSError instead of
BrokenPipeError.

Fixes: #12541
2023-11-26 01:37:02 -05:00
Eli Schwartz 90ce084144
treewide: automatic rewriting of all comment-style type annotations
Performed using https://github.com/ilevkivskyi/com2ann

This has no actual effect on the codebase as type checkers (still)
support both and negligible effect on runtime performance since
__future__ annotations ameliorates that. Technically, the bytecode would
be bigger for non function-local annotations, of which we have many
either way.

So if it doesn't really matter, why do a large-scale refactor? Simple:
because people keep wanting to, but it's getting nickle-and-dimed. If
we're going to do this we might as well do it consistently in one shot,
using tooling that guarantees repeatability and correctness.

Repeat with:

```
com2ann mesonbuild/
```
2023-08-11 13:41:03 -04:00
Charles Brunet a84a082b1a Prevent summary displaying timestamp twice
Before:

[117.000]   Subprojects
[117.000]     OptelMessagingApi  : [117.000] YES
[117.000]     Python27           : [117.000] YES
[117.000]     op300rtos          : [117.000] YES
[117.000]     optel-common-protos: [117.000] YES

After:

[38.938]   Subprojects
[38.938]     OptelMessagingApi  : YES
[38.938]     Python27           : YES
[38.938]     op300rtos          : YES
[38.938]     optel-common-protos: YES
2023-07-21 09:31:21 -04:00
Charles Brunet 047c2d644c Display more timestamps when profiling ninja
When running setup with `--profile-self` option,
there are currently no logs after "Found ninja...". However, there are
still some lengthy processes for generating targets and ninja.build.

This add more log entries, when profiling, only for the purpose of
displaying the timestamps of the different steps in ninja generation.
2023-07-21 09:31:21 -04:00
Dylan Baker cb0b6352b5
mlog: put the module docstring at the top of the file
Where it belongs. Otherwise it isn't rendered correctly
2023-05-31 17:20:46 -04:00
Dylan Baker 11fab771b1
mlog: use StringProtocol where we said we should
Replace a long comment explaining that we need StringProtocol, with
StringProtocol
2023-05-31 17:20:46 -04:00
Dylan Baker ada2a976f0
mlog: use a hidden class for state
This is a pretty common pattern in python (the standard library uses it
a ton): A class is created, with a single private instance in the
module, and then it's methods are exposed as public API. This removes
the need for the global statement, and is generally a little easier to
reason about thanks to encapsulation.
2023-05-31 17:20:44 -04:00
Dylan Baker 1e79553c36
mlog: remove out-of-date comment
This comment is out of date, we have StringProtocol which is exactly
what we wanted, and it's part of TV_Loggable already
2023-05-31 17:19:48 -04:00
Dylan Baker 73c054ced6
mlog: remove direct calls to log_once
This was never meant to be public API, log(once=True) is for that.
2023-05-31 17:19:45 -04:00
Eli Schwartz a21af43200
micro-optimize: define typing-only objects in TYPE_CHECKING
Union types that exist solely for use as annotations don't need to be
created in normal runs.
2023-02-01 17:01:30 -05:00
Eli Schwartz 680b5ff819
treewide: add future annotations import 2023-02-01 17:01:30 -05:00
Eli Schwartz 7b0a590c1b
mlog: do not squelch console output for errors
We have functionality to squelch logging, and we use this for situations
where we run a fake interpreter and then emit output. e.g. `introspect`.

It's reasonable to avoid logging your bog-standard noisy `mlog.log()`
here, but unfortunately, we also avoided logging the output of
`mlog.exception()` followed by `sys.exit(2)`, because that went through
mlog! :P Special-case this to keep on printing, even if mlog.disable()
was used -- in such a case, we really do want to emit log output no
matter what. Users need this info to ensure they have any clue why Meson
returned a non-zero exit code.
2023-01-29 14:51:07 -05:00
Dylan Baker 7460ab20cd mlog: move code for printing code with a caret to the mlog module
We need this outside the constructor for the ParseException class, so
let's pull it out. mlog seemed like a good place since it's a text
formatting function, and has no dependencies.
2023-01-03 14:49:02 -05:00
Dylan Baker 900677cdb2 mlog: use an enum instead of strings
enum comparisons are ultimately ints, so they're faster, plus they're
exhaustive, so mypy can statically determine that we've passed a valid
value rather than via an assertion at runtime.
2023-01-03 14:49:02 -05:00
Dylan Baker d9dc5a7f74 mlog: Remove using of `**kwargs: T.Any`
This is annoying because we can't get proper auto-completion of mlog,
and because ultimately it was allowing keyword arguments to be silently
dropped on the floor. This does make the code a little more verbose, but
I think the trade-offs of completion + better safety are worth it.

PEP692, which will be part of python 3.12, provides a more elegant
solution using `TypedDicts` to annotate `**kwargs`, which we should
consider in the future.
2023-01-03 14:49:02 -05:00
Phil Jones 41ab2ef8af mlog: set LV environment variable for pager. 2022-12-12 08:14:18 -05:00
Phil Jones 8bfc29f91f mlog: set LESS environment variable for pager.
Rather than passing arguments directly to less, set the LESS environment
variable to contain the desired arguments instead. This allows passing
arguments in case the user has PAGER=less set in their environment.
2022-12-12 08:14:18 -05:00
Xavier Claessens 05da4b087c mlog: Use less from git on Windows 2022-09-28 12:48:22 +03:00
Xavier Claessens bed5b31079 mlog: disable usage of global for log_pager 2022-09-23 11:40:53 -04:00
Dylan Baker f5283dd63f pylint: enable global-statement
This does force a number of uses of `# pylint: disable` comments, but it
also finds a couple of useless global uses and one place (in the
previous commit) that an easy refactor removes the use of global. Global
is a code smell, so forcing adding a comment to disable helps force
developers to really consider if what they're doing is a good idea.
2022-09-22 18:17:43 -04:00
Dylan Baker 3ef332e89a pylint: enable global-variable-not-assigned
The `global` statement is only needed to assign to global variables, not
read or mutate them. So calling `global.mutate()` is fine, but not
`var = foo`, which would otherwise shadow `var`.
2022-09-22 18:17:43 -04:00
Xavier Claessens 59d561d4c1 mlog: Add support for pager
It is useful to redirect some outputs, such as "meson configure" to a
pager (e.h. less). This is similar to most git commands.
2022-09-22 11:29:03 -04:00
Hemmo Nieminen a9e25f4765 mlog: add support for italic/emphasized text in AnsiText 2022-06-09 18:58:33 -04:00
Eli Schwartz a009eacc65
treewide: string-quote the first argument to T.cast
Using future annotations, type annotations become strings at runtime and
don't impact performance. This is not possible to do with T.cast though,
because it is a function argument instead of an annotation.

Quote the type argument everywhere in order to have the same effect as
future annotations. This also allows linters to better detect in some
cases that a given import is typing-only.
2022-03-07 19:01:04 -05:00
Eli Schwartz 812ad2e6d1
fix type annotations for mlog nesting
In commit 8cd4d0b283 we added a feature
that took True/False but said it took str.
2021-12-30 15:15:25 -05:00
Eli Schwartz f4b91c4306 Revert "mark a couple of typing-only imports as noqa, to appease pyflakes"
This reverts commit 6cc1b8441c.

The latest version of pyflakes learned to detect that correctly.
2021-10-27 09:51:52 -04:00
Eli Schwartz 8947352889 fix various flake8 whitespace errors 2021-10-27 09:51:52 -04:00
Eli Schwartz b1f0eec38f
fix lgtm.com "Use of the return value of a procedure"
we return _log even though this entire family of functions returns None,
because a side effect of returning is that the other version of the
function is not run.

We can do that more obviously, using an else clause that doesn't attach
meaning to return values.
2021-10-26 20:53:43 -04:00
Paolo Bonzini 65b144bc85 Revert "mtest: fix test output issues (in console)"
This reverts commit 5fcb0e6525.
The commit is a massive change that should have been split in
separate pieces, and it also removes a few features:

* in verbose mode, subtests are not printed as they happen

* in non-verbose mode the progress report does not include the
number of subtests that have been run

* in non-parallel mode, output is batched rather than printed as
it happens

Furthermore, none of these changes are not documented in the release
notes.  Revert so that each proposal can be tested, evaluated and
documented individually.
2021-09-29 21:47:31 +03:00
Hemmo Nieminen 5fcb0e6525 mtest: fix test output issues (in console)
This change set aims to fix various "issues" seen with the current
implementation. The changes can be summarized with the following list:

* Replace emojis and spinners with multiline status displaying the name
  and running time of each currently running test.
* The test output (especially in verbose mode or when multiple failing
  tests' output gets printed out) can get confusing. Try to make the
  output easier to read and grasp. Most notable change here is the
  addition of the test number to the beginning of each printed line.
* Print exit details (i.e. exit code) of the test in verbose mode.
* Try to make the verbose "live" output from tests to match the look and
  feel of otherwise produced (verbose) test output.
2021-09-25 13:42:45 +03:00
Dylan Baker 9bca4a4b94 mlog: fix annotation 2021-09-24 09:44:40 -07:00
Eli Schwartz 6cc1b8441c
mark a couple of typing-only imports as noqa, to appease pyflakes
Since it cannot resolve `import typing as T` in order to figure out that
T.* is doing annotation-worthy stuff.

Since T.cast('Foo') is not actually using Foo except in an annotation
context (due to being a string) it requires extra work to resolve, and
the only thing that would currently work is actually using
'typing.cast'. However, we have decided to not use it except as T...

Since this import is only imported during mypy it's not so bad to noqa
it.
2021-09-14 15:55:03 -04:00
Paolo Bonzini 516c871bec summary: fix dependencies
Dependencies are currently printed as

   [<mesonbuild.mlog.AnsiDecorator object at 0x7faa85aeac70>, ' ', <mesonbuild.mlog.AnsiDecorator object at 0x7faa85aeab50>]

This was introduced in commit adb1b2f3f6, due to
an incorrect type annotation on the AnsiText constructor.  Fix both the
annotation and the usage.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-09-07 14:18:58 -04:00
Daniel Mensinger 3e396b3782
fix: Always explicitly set encoding for text files (fixes #8263) 2021-06-29 11:28:08 +02:00
Daniel Mensinger 27bb5f536a typing: mlog use StringProtocol 2021-06-05 12:35:48 +02:00
Daniel Mensinger f502a38d1c typing: mlog: Simplify some typing with a TV_ variables 2021-06-03 10:23:27 -07:00
Xavier Claessens 8cd4d0b283 mlog: Do not print 'subproject|' for the message 'Executing subproject'
It already contains the full callstack and it's more visible when it's
standing on its own line.
2021-03-22 21:29:14 -04:00
Xavier Claessens 60c2c25d5b mlog: Do not print 'subproject|' on empty lines 2021-03-22 21:29:14 -04:00
Xavier Claessens b33e7bca73 mlog: Add a space after 'subproject|' 2021-03-22 21:29:14 -04:00
Xavier Claessens 3c1ccb923f logs: Prepend current subproject name to all messages
Meson used to prepend '|' for each nested subproject to distinguish in
the logs where a subproject start and ends. It is more useful to print
the current subproject name.

Also print the call stack when starting a new subproject to better see
which subproject chain leads to to.
2021-03-22 21:29:14 -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
Paolo Bonzini adb1b2f3f6 interpreter: accept external programs and dependencies for summary 2021-01-21 08:54:35 -05:00
Paolo Bonzini 021068a8b7 mlog: add __len__ to AnsiDecorator 2021-01-21 08:54:35 -05:00
Paolo Bonzini 9ba7b0ebd0 mlog: add __str__ method to AnsiDecorator
Automatically colorize the text when printing the AnsiDecorator, based
on the result of mlog.colorize_console().  This is how AnsiDecorator
is used most of the time anyway.
2021-01-21 08:54:35 -05:00
Dylan Baker a9ff308d27 mlog: make mlog helper take once keyword argument
We really want to have this in the log method as well.

Fixes: #8002
2020-12-16 21:15:09 +00:00