Commit graph

68 commits

Author SHA1 Message Date
Sebastian Thiel c7ff94fce8
Enable shallow clones and fetches for registry and git dependencies.
The implementation hinges on passing information about the kind of clone
and fetch to the `fetch()` method, which then configures the fetch accordingly.

Note that it doesn't differentiate between initial clones and fetches as
the shallow-ness of the repository is maintained nonetheless.
2023-04-27 14:18:22 +02:00
Jacob Finkelman 2c712d5d46 patch can conflict on not activated packages 2023-03-01 20:56:00 -05:00
Scott Schafer 730e2196b7 chore: update patch tests to use check 2023-02-20 12:21:27 -06:00
Ed Page 6007f05a85 chore: Update to toml v0.6, toml_edit v0.18
`toml` replaces `toml_edit::easy`, using `toml_edit` as its parser.
2023-01-19 15:26:28 -06:00
Scott Schafer ab18bd40d5 refactor(testsuite): Replace [project] with [package] 2022-09-26 09:51:16 -06:00
lucas 02e606d799 Grammar fixup unused patch message 2022-08-03 02:22:50 +01:00
Ed Page 320c279f43 Port cargo from toml-rs to toml_edit
Benefits:
- A TOML 1.0 compliant parser
- Unblock future work
  - Have `cargo init` add the current crate to the workspace, rather
    than error
  - #5586: Upstream `cargo-add`
2022-01-13 09:27:27 -06:00
Weihang Lo 91791c4fb1
Improve unused patch message when source URLs mismatched
`Resolve.unused_patches` does not contains info about which source
URLs they are going to patch. As a result, we cannot provide a precise
message but only list all possible URLs of the packages with the same
name in the resolved graph.

There is a little flaw that if multiple patches are patching the same
package, the source URL of the used one would be shown as a possible
URL in the warning.
2021-11-28 09:20:06 +08:00
bors 72aee9e815 Auto merge of #9839 - jonhoo:prefer-cargo-toml-patch, r=ehuss
Stabilize patch-in-config (and prefer config over manifest)

Tracking issue: https://github.com/rust-lang/cargo/issues/9269

---

This stabilizes the `patch-in-config` feature ([unstable entry](https://doc.rust-lang.org/cargo/reference/unstable.html#patch-in-config)) following the discussion in https://github.com/rust-lang/cargo/issues/9269#issuecomment-904913263.

As requested, this PR _also_ changes the precedence behavior such that a `[patch]` for the same dependency in both `.cargo/config.toml` and `Cargo.toml` prefers the patch from the configuration file over the one from the manifest, which matches the behavior of other overlapping configuration options. The corresponding test has also been updated to reflect this change in behavior.
2021-09-01 04:55:13 +00:00
Jon Gjengset 1e0d564ff0 Stabilize patch-in-config 2021-08-24 12:55:04 -07:00
Jon Gjengset d47c52e7c4 Prefer config [patch] over manifest [patch] 2021-08-24 12:54:49 -07:00
Weihang Lo 0afd40b4de
Update tests to display dep-req info for dep-chain 2021-08-24 00:39:38 +08:00
Weihang Lo 8c75e2ffa0
Update tests to use registry names 2021-07-22 00:50:30 +08:00
bors f8ba1cbfcb Auto merge of #9639 - djmitche:issue9535, r=Eh2406
Prefer patched versions of dependencies

When selecting among several versions of a paackage, prefer versions
from `[patch]` sections over other versions, similar to how locked
versions are preferred.

Patches come in the form of a Dependency and not a PackageId, so this
preference is expressed with `prefer_patch_deps`, distinct from
`try_to_use`.

Fixes #9535
2021-07-14 19:14:22 +00:00
Dustin J. Mitchell bd4a353e98 Prefer patched versions of dependencies
When selecting among several versions of a paackage, prefer versions
from `[patch]` sections over other versions, similar to how locked
versions are preferred.

Patches come in the form of a Dependency and not a PackageId, so this
preference is expressed with `prefer_patch_deps`, distinct from
`try_to_use`.
2021-07-09 18:23:21 +00:00
hi-rustin a846226f71 Remove unrelated cases
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2021-07-09 13:15:13 +08:00
hi-rustin 8d2103f212 Warning when using features in patch
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2021-07-08 15:25:13 +08:00
Alex Crichton fe484973f0 Fix loading branch=master patches in the v3 lock transition
This commit fixes an issue pointed out during #9352 where in the v2->v3
lock file transition (currently happening on nightly) Cargo will not
correctly use the previous lock file entry for `[patch]` directives that
point to git dependencies using `branch = 'master'` explicitly. The
reason for this is that Cargo previously, with the v2 format, considered
`branch=master` and `DefaultBranch` to be equivalent dependencies. Now
that Cargo treats those as distinct resolve nodes we need to load lock
files that use `DefaultBranch` and transparently use those for
`branch=master` dependencies.

These lock file nodes do not naturally unify so we have to go out of our
way to get the two to line up in modern Cargo. This was previously done
for the lock file at large, but the previous logic didn't take `[patch]`
into account. Unfortunately almost everything to do with `[patch]` and
lock files is pretty complicated, and this is no exception. The fix here
is wordy, verbose, and quite subtle in how it works. I'm pretty sure it
does work though and I think that this should be good enough to at least
transition most users off the v2 lock file format. Once this has baked
in Cargo for some time (on the scale of a year) I would hope that we
could just remove this logic since it's only really here for a
transitionary period.

Closes #9352
2021-04-22 08:33:03 -07:00
Jon Gjengset 6995e1dd1b Extract config patch on use 2021-03-08 13:53:29 -08:00
Jon Gjengset 140a7707ad Only apply config patches on resolve 2021-02-26 09:29:33 -08:00
Jon Gjengset 8178f22ee9 Support [patch] in .cargo/config files
This patch adds support for `[patch]` sections in `.cargo/config.toml`
files. Patches from config files defer to `[patch]` in `Cargo.toml` if
both provide a patch for the same crate.

The current implementation merge config patches into the workspace
manifest patches. It's unclear if that's the right long-term plan, or
whether these patches should be stored separately (though likely still
in the manifest). Regardless, they _should_ likely continue to be
parsed when the manifest is parsed so that errors and such occur in the
same place regardless of where a patch is specified.

Fixes #5539.
2021-02-24 14:34:21 -08:00
Eric Huss 340656e29d Add RegistryBuilder to help initializing test registries.
The intent here is to make it more flexible to create different registry
setups, and to reuse code a little more easily.
2021-02-02 15:48:48 -08:00
Eric Huss 6f8c7d5a87 Normalize raw string indentation. 2020-09-26 17:59:58 -07:00
Alex Crichton 6514c289d2 Improve git error messages a bit
This commit is targeted at further improving the error messages
generated from git errors. For authentication errors the actual URL
fetched is now printed out as well if it's different from the original
URL. This should help handle `insteadOf` logic where SSH urls are used
instead of HTTPS urls and users can know to track that down.

Otherwise the logic about recommending `net.git-fetch-with-cli` was
tweaked a bit and moved to the same location as the rest of our error
reporting.

Note that a change piggy-backed here as well is that `Caused by:` errors
are now automatically all tabbed over a bit instead of only having the
first line tabbed over. This required a good number of tests to be
updated, but it's just an updated in renderings.
2020-06-25 08:47:15 -07:00
Eric Huss 4f2bae9377 Revert change to automatically select the greatest patch match. 2020-05-20 10:18:45 -07:00
Eric Huss 5dde9cc911 Show patch location in error message. 2020-05-20 09:25:53 -07:00
Eric Huss 6fd11a7768 Don't include a special-case error for a locked patch matching 0 entries. 2020-05-20 08:44:26 -07:00
Eric Huss afa3acedf0 Make patches automatically update if updated. 2020-05-19 18:01:23 -07:00
Eric Huss b78cb373b8 Provide better error messages for a bad patch. 2020-05-16 13:39:51 -07:00
Eric Huss 501e580452 Fix cargo update with unused patch. 2020-05-14 15:56:01 -07:00
Eric Huss 4ae79d2ffd Use fs helpers instead of File functions. 2020-04-17 07:56:16 -07:00
Matthias Krüger 1d912002e9 fix most remaining clippy findings (mostly redundant imports) 2020-02-21 12:15:16 +01:00
Eric Huss 83571aee56 Minor testsuite organization. 2019-11-24 18:42:45 -08:00
Alex Crichton a92fd48fb4 Improve error message for cyclic dependencies
First reported in rust-lang/rust#65014 it looks like our error message
on cyclic dependencies may be confusing at times. It looks like this is
an issue because there are multiple paths through a graph for a
dependency, so using the generic `path_to_top` function isn't producing
the most useful path for this purpose.

We're already walking the graph though, so this commit adds an extra
parameter which collects the list of packages we've visited so far to
produce a hopefully always-accurate error message showing the chain of
dependencies end-to-end for what depends on what.
2019-10-07 16:50:42 -07:00
bors fdcc73fc69 Auto merge of #7452 - pyrrho:bug7346/transitive_patches, r=Eh2406
Bug7346/transitive patches

Fixes #7346.

A cursory comparison between current stable and nightly shows that projects with this topology resolve similarly. If there are other behaviors I should test, I'd be happy to expand that section. This is a pretty focused change, though, so I'm not sure what else there is to break.

Sorry about the delay in putting this PR together. Good news is I know more than I did last week.
2019-09-27 14:44:25 +00:00
Drew Pirrone-Brusse 4d094c080f Add a test to model the bug found in #7346 2019-09-26 18:34:36 -04:00
bors 35c55a9320 Auto merge of #7368 - alexcrichton:canonical-urls-omg, r=ehuss
Work with canonical URLs in `[patch]`

This commit addresses an issue with how the resolver processes `[patch]`
annotations in manifests and lock files. Previously the resolver would
use the raw `Url` coming out of a manifest, but the rest of resolution,
when comparing `SourceId`, uses a canonical form of a `Url` rather than
the actual raw `Url`. This ended up causing discrepancies like those
found in #7282.

To fix the issue all `patch` intermediate storage in the resolver uses a
newly-added `CanonicalUrl` type instead of a `Url`. This
`CanonicalUrl` is then also used throughout the codebase, and all
lookups in the resolver as switched to using `CanonicalUrl` instead of
`Url`, which...

Closes #7282
2019-09-17 16:42:36 +00:00
Alex Crichton e545412251 Work with canonical URLs in [patch]
This commit addresses an issue with how the resolver processes `[patch]`
annotations in manifests and lock files. Previously the resolver would
use the raw `Url` coming out of a manifest, but the rest of resolution,
when comparing `SourceId`, uses a canonical form of a `Url` rather than
the actual raw `Url`. This ended up causing discrepancies like those
found in #7282.

To fix the issue all `patch` intermediate storage in the resolver uses a
newly-added `CanonicalUrl` type instead of a `Url`. This
`CanonicalUrl` is then also used throughout the codebase, and all
lookups in the resolver as switched to using `CanonicalUrl` instead of
`Url`, which...

Closes #7282
2019-09-17 09:07:12 -07:00
Alex Crichton 9115b2c326 Extract support directory to its own crate
Extract out all our test support code to its own standalone crate so it
can be shared between multiple test suites if necessary.
2019-09-16 11:47:09 -07:00
Alex Crichton 803bf3296c Fixes around multiple [patch] per crate
This commit fixes a few bugs in handling of `[patch]` where multiple
version of the same crate name have been patched in. Two sub-issues were
discovered when investigating #7264:

* The first issue is that the source of the assertion, the logic in
  `lock`, revealed a fundamental flaw in the logic. The `lock` function
  serves the purpose of applying a lock file to a dependency candidate
  and ensure that it stays within locked versions of dependencies, if
  they're previously found. The logic here to handle `[patch]`, however,
  happened a bit too late and was a bit too zealous to simply lock a
  dependency by name instead of accounting for the version as well.

  The updated logic is to move the locking of dependencies here to
  during the normal iteration over the list of dependencies. Adjacent to
  `matches_id` we check `matches_ignoring_source`. If the latter returns
  `true` then we double-check that the previous dependency is still in
  `[patch]`, and then we let it through. This means that patches with
  multiple versions should be correctly handled where edges drawn with
  `[patch]` are preserved.

* The second issue, after fixing this, was found where if the exact same
  version was listed in `[patch]` multiple times then we would
  continuously update the original source since one of the replacements
  gets lost along the way. This commit adds a first-class warning
  disallowing patches pointing to the exact same crate version, since we
  don't have a way to prioritize amongst them anyway.

Closes #7264
2019-08-27 15:12:25 -07:00
Alex Crichton 2a391a77e3 Document that package can be used in [patch]
This works to `[patch]` multiple versions of a crate, and turns out this
has worked since the inception of `package`!

Closes #6169
2019-08-26 12:51:12 -07:00
Alex Crichton 0bd1d34cae Fix detection of cyclic dependencies through [patch]
This commit fixes detection of cyclic dependencies through the use of
`[patch]` by ensuring that `matches_id` isn't used because it returns a
false negative for registry dependencies when the dependency
specifications don't match but the resolve edges are still correct.

Closes #7163
2019-07-24 07:32:37 -07:00
Alex Crichton 83bb30cedf Handle activation conflicts for [patch] sources
This commit updates the resolver to ensure that it recognizes conflicts
when `[patch]` is used to augment an older version of what's already in
a source, for example. Previously the deduplication based on
semver-compatible versions didn't actually work when `[patch]` was used.
This meant that when you used `[patch]` it might not transitively affect
the entire crate graph, instead just giving you a version of a
dependency and everyone else. This violates the intention of `[patch]`!

The fix here is to catch this use case happening, when a `Dependency`
source specification mismatches an activated package we need to list a
second activation in the resolver to prevent major versions from being
selected from both the original source as well as the source of the id.

Closes #7117
2019-07-10 11:21:24 -07:00
Jethro Beekman 0e0d968825 Update #[test] attribute on all tests in the testsuite
sed -i 's/^#\[test\]/#[cargo_test]/' $(rg -l '^#\[test\]')

Manual fixes:
* proc_macro::proc_macro_doctest
2019-06-07 12:41:26 -07:00
Eric Huss 7d112803c5 Fix new unused patch warning. 2018-12-27 17:13:31 -08:00
Eric Huss e35ecbe7ac Warn on unused patches. 2018-12-21 18:54:03 -08:00
Eric Huss 7eaa1cf70a Support alt-registry names in [patch] table. 2018-12-17 20:50:42 -08:00
Alex Crichton fecb724643 Format with cargo fmt 2018-12-08 03:19:47 -08:00
Dale Wijnand 04ddd4d0fc
Upgrade to Rust 2018 2018-12-06 20:18:35 +01:00
Alex Crichton e2637b6599 Review comments! 2018-09-18 11:33:18 -07:00