Commit Graph

171 Commits

Author SHA1 Message Date
Eli Schwartz 7fa09ecd1c wrap: detect network timeouts 20x faster
When downloading wrap content, we need to know at some point if the
server is going to respond with "hello, yes, I'm here and I have data
for you". The alternative is to sometimes infinitely hang.

In commit 8f7781f1d6 we added such a
timeout, but using an extremely generously high number -- ten minutes.
We don't need to wait this long just to find out if the other end
exists, so decrease that time to 30 seconds, whch is still ludicrously
generous but not quite as much so.
2023-07-10 17:48:58 +03: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
Xavier Claessens 6f4973abad wrap: Check for common "provides" typo
It is a common mistake that is hard to find because Meson silently
ignore unknown sections. Better have an explicit error message.
2023-05-20 13:31:05 +03:00
Nirbheek Chauhan f71c9aebfb wrap: Always pass posix paths to patch
patch on Windows is provided by MSYS, which only understands POSIX
paths, with `/`. Using Windows paths with `\` results in a "file not
found" error.

We got a little lucky here because the path is relative, so the drive
letter difference doesn't affect us.
2023-04-29 08:35:51 -04:00
Denis Fortin 0c91c474d3 Write wrap-redirect filename as posix path 2023-03-27 21:49:37 +03:00
Eli Schwartz 7ab2892eb0 wrap: ensure the tempfile used for downloading is closed
This is generally a good idea, and the tempfile is already instructed to
not auto-delete on close. It also fixes a bug on PyPy, where the file
isn't valid because it's not explicitly closed. This is probably due to
the garbage collection modes -- in CPython, the object goes out of scope
and gets automatically closed before we actually attempt to unpack it.

Fixes #11246
2023-02-13 09:09:10 -05:00
Eli Schwartz 680b5ff819
treewide: add future annotations import 2023-02-01 17:01:30 -05:00
Dylan Baker 0a873f6470 wrap: use log once instead of hand rolling 2023-01-03 14:49:02 -05:00
L. E. Segovia 35599c5362 wrap: Don't use --branch with shallow clones against HEAD
Fixes #10931
2022-12-07 13:29:04 -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
Xavier Claessens cd82804533 Move some code from wraptool.py to wrap.py 2022-10-10 17:09:26 -04:00
Xavier Claessens 312bede496 wrap: Ignore directories that have a .wrap with the same name
If we update e.g. glib.wrap from wrap-git with directory=glib to
wrap-file with directory=glib-2.70 we could still have the glib
directory that is not referenced by any .wrap file any more. We should
still ignore that directory otherwise it overrides the glib.wrap we
parsed.
2022-10-10 17:01:51 -04:00
Xavier Claessens ced9efb579 Get wrap from wrapdb when not found locally
Download wrap file from wrapdb automatically when it is not found
locally but we have it in wrapdb.json.

This makes for example `dependency('glib-2.0')` work out of the box
simply by running `meson wrap update-db`, even if the project does not
provide any wraps.
2022-10-09 13:04:03 -04:00
Xavier Claessens ed129a5311 wrap: If the directory exists in a sub-subproject, uses it inplace
A subproject could have a sub-subproject as a git submodule, or part of
the subproject's release tarball, and still have a wrap file for it
(e.g. needed for [provide] section). In that case we need to use the
source tree for the sub-subproject inplace instead of downloading a new
copy into the main project.

This is the case with GLib 2.74, it has a subproject "gvdb" as git
submodule, and part of release tarball, it ships gvdb.wrap file as well.
2022-09-28 00:17:42 -04:00
Xavier Claessens b9e382835e wrap: Small simplification 2022-09-28 00:17:42 -04:00
Xavier Claessens b314d1f7c1 wrap: Set self.directory only once
It can wait until after parsing the wrap file to set it.
2022-09-28 00:17:42 -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
Daniel Carson 004575874f Warn if wrap file changes
Save off the hash of the wrap file when first configuring a subproject.
When reconfiguring a subproject, check the hash of the wrap file
against the stored hash. If they don't match then warn the user.
2022-09-18 22:48:50 -04:00
Daniel Carson 97f248db24 Move up dangling comment
The comment and some settings that appear to be related to the comment
were introduced in f21685a833 and appears
to be documenting some of the fields added in that commit. This commit
moves the comment back to the field it appears to be documenting.
2022-09-18 22:48:50 -04:00
Eli Schwartz 7bdfe7ccb2 wrap: correctly override dependency names with capital letters
When we do wrap resolution, we do a case-insensitive lookup because
keys, i.e. `dep_name = variable_name`, are case insensitive. In order to
check whether we should process a subproject, we need to know if the
lowercased dependency name matches.

We do this by looking up the lowercase name, and assuming that the
stored name is also lowercase. But for dependency_names, this isn't "case
insensitive and stored in lowercase" so we need to manually force it to
be consistent.

Likewise, when looking up the wrap name (which works like
dependency_names and doesn't need a provide section at all) the disk
filename of the wrap file is case sensitive, but needs to be manually
forced for consistency.
2022-09-07 16:19:09 -04:00
Eli Schwartz ff7d86d05f flake8: fix unnecessary f-strings without any format placeholders
These can just be ordinary strings.
2022-08-29 23:32:43 +03:00
Fabian Orccon 83c6fc5b02 wrap: Support netrc files 2022-08-25 10:18:04 -04:00
Nirbheek Chauhan c19773c0bc wrap: Fix diff_files not finding the patch to apply
When `self.wrap.filesdir` is a relative path, which happens when
`meson subprojects update` is run, the path to the patch must be
provided relative to the working directory in which `patch` or `git`
is run.

`self.wrap.filesdir` is absolute when `Resolve()` is invoked by the
Meson interpreter, which is why this wasn't detected by the tests.
2022-07-16 00:30:43 +03:00
Paweł Marczewski 9061c3a52d wrap: Add support for applying a list of patch files
Co-authored-by: Xavier Claessens <xavier.claessens@collabora.com>
2022-06-07 06:43:39 -04:00
zxey b30d04f52b Ignore detached head warning while cloning subprojects with tags 2022-04-30 22:44:21 +03:00
Eli Schwartz b28e6aead4 wrap: add functionality to specify whether insecure downloads should be used
We have a fallback route in `meson subprojects download` and friends,
which tries to retrieve wrapdb urls via http, if Python was not built
with SSL support.

Stop doing this. Replace it with a command line option to specify that
insecure downloads are wanted, and reference it in the error message if
downloading fails due to SSL issues.
2022-03-27 18:57:07 -04:00
Eli Schwartz 4934b9968a
fix missing encodings
These were caught by the testsuite erroring out with a fatal
EncodingWarning due to the previous commit.

Fixes #9996
2022-03-01 21:42:52 -05:00
Eli Schwartz 0d6972887f
flake8: do not use bare exceptions
In one case, we actually specifically want to catch IndexError only. In
the other case, excepting Exception rather than BaseException is quite
fine.
2022-02-16 23:00:31 -05:00
Eli Schwartz c0b8e02d9f
FeatureNew: add mypy type annotations for subproject arg
Use a derived type when passing `subproject` around, so that mypy knows
it's actually a SubProject, not a str. This means that passing anything
other than a handle to the interpreter state's subproject attribute
becomes a type violation, specifically when the order of the *four*
different str arguments is typoed.
2022-02-14 20:40:41 -05:00
Will Toohey 22a998188b Checkout subproject submodules even when nested 2022-01-27 11:13:40 -05:00
Eli Schwartz 4b9ec4f6d5 wraps: implement exponential backoff for downloading files
Implementation modeled after mesonlib.windows_proof_rmtree().

Implements the other half of #9688
2022-01-18 16:47:05 +02:00
Eli Schwartz 7deeb293b6 wraps: on failure to apply a patch, delete the subproject directory
This code path is only called on initial download of a subproject, but
if we raise an error and abort while downloading/applying a patch
overlay we still have the upstream sources extracted... which appears to
be a subproject, then turns out to be broken due to missing meson.build

Partially implements #9688
2022-01-18 16:47:05 +02:00
Eli Schwartz 4b351aef26
first pass at migrating to dataclasses
In some cases, init variables that accept None as a sentinel and
immediately overwrite with [], are migrated to dataclass field
factories. \o/

Note: dataclasses by default cannot provide eq methods, as they then
become unhashable. In the future we may wish to opt into declaring them
frozen, instead/additionally.
2022-01-10 18:36:57 -05:00
Randy 79c3e9ca4d Fix typo in wrap.py 2021-11-30 20:12:04 +01:00
Xavier Claessens d23ae8b58e wrap: Fix concurrent os.mkdir()
Since 0.59.0 Meson downloads multiple wraps in parallel, so the
packagecache directory could be created by one then the 2nd would hit
error when calling os.mkdir() because it already exists.
2021-11-02 17:27:00 -04:00
Eli Schwartz 6ed1332603 wrap: fix support for git < 2.28
both of these do the same thing:

init -b <branchname>
-c init.defaultBranch=<branchname> init

The latter contributes to unreadably long lines of code, but has the
advantage of working on older versions of git.

Fixes #9449
2021-10-27 10:44:11 -04:00
Eli Schwartz 8947352889 fix various flake8 whitespace errors 2021-10-27 09:51:52 -04:00
Eli Schwartz f52a5a7cd3
wrap: move FeatureNew checks to a more natural place
Now, warnings are unconditionally raised when parsing the wrap file,
whether they are used or not. That being said, these warnings literally
just check for a couple of keys used in the .wrap ini file.

Moving these checks from the time of use to the time of loading, means
that we no longer report warnings only when originally downloading or
extracting the file or VCS repo.

It also means we no longer report warnings in one subproject, when a
wrap file is picked up from a different subproject because the first
subproject actually does a dependency lookup. This caused issues for the
WrapDB tooling, which uses patch_directory everywhere and the
superproject requires a suitable minimum version of meson for this...
but individual wraps might use a much lower version, and would then
raise a warning (in strict mode, converted to an error) when it resolved
a dependency from another WrapDB project.

Fixes #9118
2021-10-15 14:38:44 -04:00
Eli Schwartz b57b1050a6
wrap clone: be less noisy when doing automated code checkouts
There are two possible issues, both of which emit very long messages
from git:
- when shallow cloning via depth + a pinned commit we locally init
  rather than cloning; use an almost-certainly not conflicting dummy
  branch name
- any time a checkout of a revision is performed, it might not be a
  branch name, in which case it will be a detached HEAD. By default git
  is very noisy about this -- it wants you to know what happened and how
  not to mess up. But wraps aren't per default intended for user editing
  and development, it's just part of the internal transport which meson
  uses. So, temporarily squelch this advice. Do not permanently
  configure the repo like this though, because the user *might* cd in
  and start developing on the subproject; in this case, any additional
  git advice they trigger is their responsibility (and they probably do
  want it).

Fixes #9318
2021-10-04 22:48:09 -04:00
Eli Schwartz 800c3462f0
condense lines 2021-10-04 17:01:03 -04:00
Eli Schwartz d06cc042eb
f-strings 2021-10-04 16:29:32 -04:00
Eli Schwartz 4745037f4b log a more informative error when wrap-git subprojects cannot be downloaded
"ERROR: Git program not found" is both highly true, and somewhat
inscrutable. Sure, looking at the line number you can basically figure
out that subproject('something') must somehow need git to operate, but
that may not be immediately obvious.

Make mention of the fact that it is needed to "download foo.wrap".

Fixes #7764
2021-09-03 08:02:02 -04:00
Tristan Partin f21685a833 Delete redirected wrap files in subprojects purge
We need to store the original filename as well as whether the wrap was
redirected in order to properly purge the redirected wrap.
2021-07-03 13:14:20 +03:00
Daniel Mensinger 3e396b3782
fix: Always explicitly set encoding for text files (fixes #8263) 2021-06-29 11:28:08 +02:00
Xavier Claessens b6d754a40c interpreter: Extract dependency() logic into its own helper class
The dependency lookup is a lot of complex code. This refactor it all
into a single file/class outside of interpreter main class. This new
design allows adding more fallbacks candidates in the future (e.g. using
cc.find_library()) but does not yet add any extra API.
2021-06-16 19:04:03 -04:00
Xavier Claessens 62c53b834d wrap: Port to v2 protocol
Fixes: #8754.
2021-06-04 15:35:29 -04:00
Dan fde305e359 Add trailing -- parameter to git checkouts. 2021-04-22 16:23:48 -04:00
Seungha Yang 448b11cb7f wrap: Tell which wrap-redirect file is missing
Otherwise user cannot understand which wrap file is missing or wrong
2021-03-29 10:57:17 -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