Commit Graph

57 Commits

Author SHA1 Message Date
Eli Schwartz ae7a9b0f44 fix the repr for OrderedSet to actually execute correctly
Old:
```
OrderedSet("'foo'", "'bar'", "'baz'")
```

New:
```
OrderedSet(['foo', 'bar', 'baz'])
```

The old one looked nasty *and* was totally non-functional.
2023-10-20 18:07:05 -04:00
Xavier Claessens dacd11a624 pkgconfig: Cache the implementation instance 2023-09-18 13:51:27 -04:00
Nicholas Vinson b51bce070e Add macro_name option to configure_file
Allow macro_name to be speficied as a parameter to configure_file().
This allows C macro-style include guards to be added to
configure_file()'s output when a template file is not given. This change
simplifies the creation of configure files that define macros with
dynamic names and want the C-style include guards.
2023-09-09 07:30:56 -04:00
Xavier Claessens d5f17bc9ff Rename OptionOverrideProxy to OptionsView and move to coredata
Coredata is where all option handling is done so it makes sense there.
It is a view on a list of options for a given subproject and with
optional overrides. This change prepare for using that view in a more
generic way in the future.
2023-09-07 06:55:07 -04:00
Charles Brunet cf5adf0c64 add json output format to configure file 2023-08-31 07:52:41 -04:00
Xavier Claessens b4b1395ef5 Suggest using --reconfigure only when not already using it 2023-08-24 19:09:20 -04:00
Eli Schwartz 3ebd570bd5
consistently use Literal annotation from typing_extensions
This is our standard annotation policy, and makes mypy safe under python
3.7
2023-08-18 15:37:52 -04: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
Xavier Claessens 13b626b67b Popen_safe_logged: Also log exceptions
Popen can raise OSError when program is not found, or PermissionError if
not executable, etc.
2023-08-10 10:36:35 -04:00
Jan200101 b91244c3b7 correct cmakedefine behavior
- allow defines with leading whitespace
- always do replacement for cmakedefine
- output boolean value for cmakedefine01
- correct unittests for cmakedefine
- add cmakedefine specific unittests
2023-08-08 14:53:43 -07:00
Christoph Reiter ec10816665 tests: fix test_vsenv_option with Python 3.11+ on Windows
meson tests enable PYTHONWARNDEFAULTENCODING by default and
make EncodingWarning fatal too.

Starting with Python 3.11 CPython not only warns if no encoding is passed
to open() but also to things like subprocess.check_output(). This made
the call in vsenv.py fail and in turn made test_vsenv_option fail.

check_output() here calls a .bat file which in turn calls vcvars. I don't
know what the encoding is supposed to be used there, so just be explicit
with the locale encoding to silence the warning.
2023-08-08 16:32:39 -04:00
Xavier Claessens f077cb2ee3 MachineChoice: Implement __str__ for easier debug 2023-08-03 16:27:52 -04:00
Xavier Claessens 28e6d2be96
ExecutableSerialisation: capture and feed are optional strings
capture is the optional filename stdout is redirected to.
feed is the optional filename stdin reads from.
2023-08-03 15:42:13 -04:00
Eli Schwartz 7afc69254d
fix implicit_reexport issues and enforce them going forward
This detects cases where module A imports a function from B, and C
imports that same function from A instead of B. It's not part of the API
contract of A, and causes innocent refactoring to break things.
2023-07-19 18:31:37 -04:00
Jussi Pakkanen 0dba7340ec
Merge pull request #11976 from tristan957/cleanups
Some various type related cleanups
2023-07-17 00:29:37 +03:00
Andres Freund d2d31c3cc2 macos: map arm64e to aarch64, map "whole" architecture strings
Some macos libraries use arm64e instead of arm64 as architecture. Due to the
string replace approach taken so far, we'd end up with aarch64e as
architecture, which the rest of meson doesn't know.

Move architecture mapping to map whole architecture names and add arm64e ->
aarch64 mapping.

This change doesn't touch the case for armv7[s], where we add arm, rather than
replace armv7[s], but it's certainly not in line with the other mappings.

Fixes: #9493

Co-authored-by: Tristan Partin <tristan@partin.io>
2023-07-13 11:44:57 -07:00
Tristan Partin 9b86c67e19 Remove do_conf_str(encoding:)
It wasn't being used.
2023-07-12 18:56:06 -05:00
Tristan Partin 020692b9d9 Use underscore for variables that we don't reference
This pleases pyright/pylance and is a pattern that we use in other
portions of the code.
2023-07-12 18:56:06 -05:00
Tristan Partin d732e27e46 Use more specific types
Added type arguments where needed.
2023-07-12 18:56:06 -05:00
Tristan Partin 33c8362a1c Match the method signatures of parent classes
Names and types of some methods did not match their parent methods.
2023-07-12 18:56:06 -05:00
Tristan Partin d4bcf05c39 Annotate naked fundamental Python types
Although mypy wasn't complaining, pyright was.
2023-07-12 18:56:06 -05:00
Tristan Partin 921c2370a7 Replace some type comments with annotations 2023-07-12 18:56:06 -05:00
Eli Schwartz a63ed40191
genvslite: fix the core option being listed as one of the per-project options
Post-facto application of issues that were caught during post-merge
review, after the genvslite PR was merged without a full review.
2023-07-02 18:03:18 -04:00
Eli Schwartz aa13c46822
WIP: refactor loggable popen calls for consistency 2023-06-14 01:04:55 -04:00
Xavier Claessens 1a9f20d44a vcs_tag: Add --always to git describe
This fallbacks to short commit id in case the git repository does
not contain any annotated tag, for example before the first release of a
project.
2023-06-01 15:44:46 -04:00
Xavier Claessens 11521c6db7 ProgressBar: Fix some rendering issues
- Do not hardcode terminal width of 100 chars, that breaks rendering on
  smaller terminal. It already uses current console width by default.
- Disable progress bar when downloading from msubprojects because it
  fetches multiple wraps in parallel.
- Scale unit when downloading e.g. MB/s.
- Do not display rate when it's not a download.
- Do not display time elapsed to simplify the rendering.
2023-05-25 11:06:09 -04:00
Eli Schwartz 6823cabb83
extend install scripts to allow specific directory variable exports
This is useful for internal scripts that want to know about something
other than MESON_INSTALL_PREFIX and MESON_INSTALL_DESTDIR_PREFIX, which
is very specific to the prefix.
2023-05-02 19:28:35 -04:00
Volker Weißmann 38b35eca30 Add env kwarg to gnome.generate_gir().
Fixes #384
2023-04-26 14:51:10 -04:00
Eli Schwartz c39ee881a1 select the correct python_command for pyinstaller builds, even on not-Windows
Checking the executable basename sort of works, at least for Windows,
since Windows always happens to use exactly this approach. However, the
official pyinstaller documentation suggests a very different approach:

https://pyinstaller.org/en/stable/runtime-information.html

This approach is more robust since it works on any OS, and in particular
it allows me to test the PyInstaller bundle functionality on Linux, even
though we don't officially distribute it as such.
2023-04-17 11:36:55 +03:00
Josh Soref cf9fd56bc9 fix various spelling issues
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-11 19:21:05 -04:00
Xavier Claessens b30cd5d2d5 Make --vsenv a readonly builtin option
We need to remember its value when reconfiguring, but the Build object
is not reused, only coredata is.

This also makes CLI more consistent by allowing `-Dvsenv=true` syntax.

Fixes: #11309
2023-03-29 09:33:41 -04:00
Eli Schwartz a410bbdf12 configure_file: emit FeatureNew when a cmake-formatted file has too many tokens
In commit 97a72a1c53 we started to allow
cmakedefine with 3 tokens, as cmake expects (unlike mesondefine). This
would silently start working even if the declared minimum version was
older than 0.54.1
2023-03-09 21:32:14 -08:00
Dylan Baker 7c2ac4f8fe utils: fix annotation of pickle_load
It's actually Generic, and we should use Generic annotations to get the
correct result. This means that we don't have to assert or cast the
return type, because mypy just knowns
2023-03-09 19:03:44 -05:00
Eisuke Kawashima f0335dc7dd
handle more corner cases where locking the build directory fails
This can raise any OSError, but we only caught two of them that indicate
a particular failure case. Also catch the generic error form with a more
generic message.

This produces better error messages in cases where e.g. exclusive lock
is not supported.
2023-02-19 12:28:33 -05:00
Charles Brunet 04f233a80d allow install script to run in dry-run mode 2023-02-14 10:50:10 -05:00
Eli Schwartz c9ac73a4da
simplify instantiation of builtin type using builtins instead of functions 2023-02-01 17:01:30 -05: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
X512 3074731797 haiku: set default prefix and library paths 2023-01-20 14:57:33 -05:00
Eli Schwartz dd83d5e4a1 remove dead code
We shouldn't be hardcoding library dirs anyway. And we usually get this
from the compiler.

This function has been unused since its users were moved to use the
compiler method, in the following commits:
- a1a4f66e6d
- a3856be1d5
- 08224dafcb
2023-01-20 00:15:44 +02:00
Xavier Claessens 1a0eff0054 devenv: Allow dumping into file and select a format
It is often more useful to generate shell script than dumping to stdout.
It is also important to be able to select the shell format.

Formats currently implemented:
- sh: Basic VAR=prepend_value:$VAR
- export: Same as 'sh', but also export VAR
- vscode: Same as 'sh', but without substitutions because they don't
  seems to work. To be used in launch.json's envFile.
2023-01-18 11:06:48 -05:00
Eli Schwartz 2d0c9ce5f2
properly type utils/core.py and add it to mypy
EnvironmentVariables was always broken, it used MutableMapping because
everyone <3 abstract interfaces, especially when they are broken and
don't actually do what you want.

This needs a dict interface, exposing `.copy()`. We either use a dict or
os._Environ, and the latter also supports that.

Also fix a broken import, and the fallout from forgetting to update the
signature of self.envvars in commit b926374205.
2023-01-16 15:30:12 -05:00
Dylan Baker 2a64ffd1e6 mesonlib: remove filename parameter to mlog.warning
After tracing all the way down to the bottom of this (or really, adding
annotations so mypy can) it turns out that passing file would just be
ignored at the end of the mlog call stack, so it should be removed
2023-01-03 14:49:02 -05:00
Eli Schwartz 0544ffabf1
add builtin option to install licenses
Unless `meson.install_dependency_manifest()` is explicitly used, this
will cause a default implied one to be installed.
2022-12-27 20:29:46 -05:00
Eli Schwartz 2ef94a71f8
delay importing ctypes unless it is actually used
ctypes uses FFI, and surprisingly often people's Python installations
will be broken because ctypes is broken (e.g. the system libffi has been
updated and Python needs to be recompiled). That is not our fault, but
it does manifest as Meson failing to run. It turns out we aren't even
using it though. At least, pretty often.

We have two uses of ctypes, and both of them are for Windows. One of
them is already conditionally imported in the function that uses it, but
the other is imported at startup. Move this down into the invoking
function.

On non-Windows systems, it is now impossible for Meson to fail to run
when ctypes is broken, because we don't use it. Anecdotally, this issue
tends to come up on Linux systems primarily.

Fixes #11111
Closes #11112
2022-12-15 16:44:35 -05:00
Eli Schwartz e5a9272034
typing: fix some broken Sequence annotations
T.Sequence is a questionable concept. The idea is to hammer out generic,
maximally forgiving APIs that operate on protocols, which is a fancy way
of saying "I don't care if you use tuples or lists". This is rarely
needed, actually, and in exchange for this fancy behavior you get free
bugs.

Specifically, `somestr` is of type `T.Sequence[str]`, and also
`somestr[0]` is another string of type you guessed it. It's ~~turtles~~
strings all the way down.

It's worth noting that trying to code for "protocols" is a broken
concept if the contents have semantic meaning, e.g. it operates on
"the install tags of this object" rather than "an iterable that supports
efficient element access".

The other way to use T.Sequence is "I don't like that T.List is
invariant, but also I don't like that T.Tuple makes you specify exact
ordering". This sort of works. In fact it probably does work as long as
you don't allow str in your sequences, which of course everyone allows
anyway.

Use of Sequence has cute side effects, such as actually passing lists
around, knowing that you are going to get a list and knowing that you
need to pass it on as a list, and then having to re-allocate as
`list(mylist)` "because the type annotations says it could be a str or
tuple".

Except it cannot be a str, because if it is then the application is
fatally flawed and logic errors occur to disastrous end user effects,
and the type annotations:
- do not enforce their promises of annotating types
- fail to live up to "minimal runtime penalties" due to all the `list()`

Shun this broken concept, by hardening the type annotations. As it turns
out, we do not actually need any of this covariance or protocol-ism for
a list of strings! The whole attempt was a slow, buggy waste of time.
2022-12-11 18:28:39 -05:00
Jussi Pakkanen 2ec3fe7a4a
Merge pull request #10990 from xclaesse/devenv
devenv: various improvements
2022-12-09 15:26:06 +02:00
L. E. Segovia d490636328 utils: Fix pylint warning using-constant-test 2022-12-07 13:29:04 -05:00
Xavier Claessens b926374205 devenv: Do not include system values in --dump
This makes --dump print variables like `FOO=/path:$FOO:/another/path`.
2022-12-07 11:58:35 -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