133 Commits

Author SHA1 Message Date
Ed Page
5df493ecd9 fix(add): Don't select yanked versions when normalizing names
Fixes #14893
2024-12-05 09:48:21 -06:00
Ed Page
737a5e8325 test(add): Verify yanked behavior 2024-12-05 09:24:46 -06:00
Ed Page
e008a39f47 test(add): Check normalization with a yanked package 2024-12-05 09:21:24 -06:00
Ed Page
9bdc777951 test(add): Make name normalization test names consistent 2024-12-05 09:15:17 -06:00
Ed Page
26844a3331 feat(toml): Allow adding/removing from cargo scripts 2024-11-26 12:23:48 -06:00
Ed Page
589d09917c test(script): Verify manifest modification commands 2024-11-26 12:23:48 -06:00
Ed Page
0498e84f89 feat: Stabilize MSRV-aware resolver config
This includes
- `cargo generate-lockfile --ignore-rust-version`
- `cargo update --ignore-rust-version`

This does not include
- `edition = "2024"`
- `resolver = "3"`
2024-10-04 12:49:28 -05:00
Weihang Lo
b4253e5057
fix(help): mention --config <PATH> in help text 2024-10-01 14:54:52 -04:00
Weihang Lo
5dfdd59009
feat: make lockfile v4 the default
This commit makes lockfile version 4 the default version when Cargo
tries to write to a lockfile.

The lockfile version 4 has been stabilized since 1.78.0,
and will become default in 1.83.0.
the length of transition period is pretty similar as before.

One caveat is that in other output from Cargo,
e.g., `cargo metatada`, status messages,
`SourceID` will display in the v4 URL encoded format.
This shouldn't affect the majority of Rust users,
as `SourceId` representation should be opaque to them,
unless comparing `SourceId` across different version of toolchains.
2024-09-24 20:43:02 -04:00
Daniel Paoliello
8de55540f0 Implement path-bases (RFC 3529) 2/n: cargo add support
RFC: https://github.com/rust-lang/rfcs/pull/3529
Tracking Issue: https://github.com/rust-lang/cargo/issues/14355

This PR adds the `--base` option to `cargo add` to allow adding a path dependency with a path base.
2024-09-06 10:01:49 -07:00
bors
40b6638df6 Auto merge of #13765 - dohse:fix-13702, r=epage
Fix cargo add behaving different when translating package name

Fixes #13702
Fixes #10680

TODOs

- [x] ~Fuzzy match registry dependencies in `cargo remove` as well~
     `cargo remove` does not need fuzzy matching, because there is no unexpected behavior for the user
- [x] ~Don't duplicate name permutation generation~
     Unsure whether this is worth it
- [ ] Shall we reject cases where multiple different permutations match?
- [x] Add comments that explain the behavior
2024-09-04 00:17:46 +00:00
Jonas Dohse
9391bfb34d Fix #10680, Fix #13702 2024-09-01 15:49:34 +02:00
Ed Page
911f5e17b6 feat(resolve): Report MSRV compatible version instead of incomptible
This expands on #14461 to where only MSRV-compatible versions are
"actionable".  MSRV-incompatible versions are therefore unstyled.

We report the MSRV needed so people can choose to unblock by updating
their MSRV.  I had wondered if we should report the the absolute latest
MSRV-incompatible version or the one with the next higher MSRV from
where the user is at.  Both are reasonable use cases, so I erred with
absolute latest version.
2024-08-30 09:40:54 -05:00
Ed Page
ded3f004a4 fix(resolve): Generalize term describing updates
`latest` was easy.  `latest compatible` was ok.  But how do I talk about
"latest compatible with your MSRV".  That gets messy.
2024-08-30 09:26:56 -05:00
Jonas Dohse
140911cc12 Add test case for feature adding with fuzzy name #10680 2024-08-30 12:16:29 +02:00
Jonas Dohse
cdab0c0058 Add test case for fuzzy package adding issue #13702 2024-08-30 12:16:29 +02:00
Ed Page
3c19a8cb7b feat(resolve): Report incompatible with rustc when MSRV-resolve disabled 2024-08-26 14:12:54 -05:00
Ed Page
d2ec764995 fix(resolve): Dont show locking workspace members
This is for `cargo generate-lockfile` and when syncing the lockfile with
the manifest.
We still show it for `cargo update` because of `cargo update
--workspace`.

We hacked around this previously by filtering out the `num_pkgs==1` case
for single packages but this didn't help with workspaces.
2024-08-22 16:57:06 -05:00
bors
3293d22f00 Auto merge of #14326 - Ifropc:5707-lock-path, r=weihanglo
Add `--lockfile-path` flag

This change implements a new `--lockfile-path` proposed in #5707 .

Functionality added:
- Add `--lockfile-path <PATH>` to all commands that support `manifest-path` with exception of:
   - `locate-project` (doesn't use lock file)
   - `verify-project` (is deprecated)
   - `read-manifest` (doesn't use lock file)
- Behind -Zunstable-options and docs
   - The flag's docs / `--help` has (unstable) in them
- `<PATH>` must end with `Cargo.lock`. If specified path doesn't exist (or parent director(ies), create all the parent directories and the lockfile itself

Implementation TLDR: add `requested_lockfile_path` into `Workspace` and set it on `workspace(gctx)` call (setting from the context)
Update `lockfile.lock_root()` to respect `requested_lockfile_path` (if set)
Add test cases covering all affected commands. Tested creating lockfile, reading lockfile, overriding default (`./Cargo.lock`) lockfile, symlink tests. Extra tests for package to make sure pinned versions from path's lockfile are respected (i.e. double check correct lockfile is used)
I doubt this flag will be used for any command that's not read-only, but I tried to cover all the commands.
2024-08-16 14:38:39 +00:00
Daniel Paoliello
4d49d2d179 Don't specify the depdency name in the inferred name test 2024-08-06 09:29:50 -07:00
Ifropc
bf7e2dcc1d
feat: lockfile path refactoring 2024-08-03 16:40:10 -07:00
Ifropc
3da56677e1
refactoring: lockfile-path documentation and implementation cleanup 2024-07-31 21:30:44 -07:00
Ed Page
8622918953 fix(config): Adjust MSRV resolve config field name / values
Fixes #13540
2024-07-31 15:27:01 -05:00
Ifropc
c25dcf00df
doc: add docs for lockfile-path 2024-07-30 21:20:17 -07:00
Scott Schafer
6a7b15a61e
test: Auto-redact host target and alt target 2024-06-12 13:27:08 -06:00
Ed Page
c00c5cd1cf fix(add): Avoid escaping double-quotes by using string literals
Fixes #14002
2024-06-03 11:22:00 -05:00
Ed Page
5c3b534101 test(add): Show quoting behavior for --target 2024-06-03 10:39:53 -05:00
Ed Page
9af864ee55 refactor: Resolve deprecations 2024-05-27 21:27:03 -05:00
Ed Page
4a6f25c112 refactor: Resolve snapbox deprecations 2024-05-27 10:28:13 -05:00
bors
7e9c2ef30f Auto merge of #13775 - epage:incomplete-dep, r=weihanglo
fix(toml)!: Disallow source-less dependencies

### What does this PR try to resolve?

This is part of #13629 addressing “dependency without path, version, git, workspace specified”.

This turns deps like
```toml
foo = { optional = true }
```
from `version="*"` deps with a warning into errors. This breaking change was deemed acceptable because this behavior has been considered a bug from the beginning.
We have gotten little to no feedback about people wanting this behavior.

This improves our forwards-compatibility story as we can add new dependency sources and they won't be considered a wildcard registry dependency on older cargo.

### How should we test and review this PR?

I removed the `cargo_add` test because it is redundant.

We no longer get the “unused key” warnings because those warnings get deferred to after this error gets reported.

### Additional information
2024-04-18 22:02:05 +00:00
Ed Page
cf23e4b538 fix(toml)!: Disallow source-less dependencies
This is part of #13629

This turns deps like
```toml
foo = { optional = true }
```
from `version="*"` deps with a warning into errors.
This breaking change was deemed acceptable because this behavior has
been considered a bug from the beginning.
We have gotten little to no feedback about people wanting this behavior.

This improves our forwards-compatibility story as we can add new
dependency sources and they won't be considered a wildcard registry
dependency on older cargo.
2024-04-18 12:55:27 -05:00
Ed Page
34afc4f1ff test(msrv): Prep for config to be added 2024-04-17 11:44:02 -05:00
Ed Page
1876326b6b feat(resolve): Tell the user the style of resovle done
This is to help with #9930

Example changes:
```diff
-[LOCKING] 4 packages
+[LOCKING] 4 packages to latest version
-[LOCKING] 2 packages
+[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions
-[LOCKING] 2 packages
+[LOCKING] 2 packages to earliest versions
```

Benefits
- The package count is of "added" packages and this makes that more
  logically clear
- This gives users transparency into what is happening, especially with
  - what rust-version is use
  - the transition to this feature in the new edition
  - whether the planned config was applied or not (as I don't want it to
    require an MSRV bump)
- Will make it easier in tests to show what changed
- Provides more motiviation to show this message in `cargo update` and
  `cargo install` (that will be explored in a follow up PR)

This does come at the cost of more verbose output but hopefully not too
verbose.  This is why I left off other factors, like avoid-dev-deps.
2024-04-13 20:39:59 -05:00
Ed Page
a0ba72918a fix(help): Generalize --ignore-rust-version 2024-04-11 13:45:39 -05:00
Josh Stone
a70f23c50b test: don't compress test registry crates
They are still nominally gzipped, but using `Compression::none()` makes
them consistent even across zlib and zlib-ng, and this fixes checksum
differences in the testsuite. There is a one-time update of all those
checksums to catch up with this change though.
2024-04-11 14:58:42 -07:00
Ed Page
6e4e31bec0 feat(add): Stabilize MSRV-aware version req selection
This is part of #9930 for rust-lang/rfcs#3537

This will make it easier to maintain an MSRV-compliant `Cargo.toml` but
leaves validation up to the user as the resolver will pick newer
versions.
This helps the MSRV-aware workflows enumerated in
rust-lang/rfcs#3537 though it could be confusing to the workflow with an
MSRV-compatible lockfile.
PR #13561 at least raises awareness of that discrepancy.

There is an unresolved question on differences in the resolver vs
`cargo add` for dealing with an unset `rust-version`.
However, we are only stabilizing the `cargo add` side which is a very
light two-way door as this is a UX-focused command and not a
programmatic command.

This hasn't gotten much end-user testing but, as its UX focused, that
seems fine.

As such, this seems like it is ready to stabilize.
2024-03-20 11:19:06 -05:00
Flowrey
318072f3cf preserve dependency features order 2024-04-01 19:26:09 +02:00
Flowrey
5b90c4bbde add tests for preserve features sorted and usorted 2024-04-01 13:56:04 +02:00
Weihang Lo
26b2e74e55
docs: clarify --locked disallows changes in Cargo.lock 2024-03-28 12:08:57 -04:00
Weihang Lo
e549bc809b
fix(cli): resolve confusion between --frozen and --locked 2024-03-27 22:05:03 -04:00
Ed Page
e476bd5254 fix(add): Preserve comments when updating simple deps
A case the tests showed but isn't covered here is when a `[features]`
table is created, the dependencies-end comment gets attached to that,
e.g. see cargo_add/overwrite_optional

Fixes #13645
2024-03-26 12:49:01 -05:00
Ed Page
8b7aca91b0 test(add): Show a bunch of cases 2024-03-26 12:35:03 -05:00
Ed Page
4ab2797f36 feat(lock): Print lockfile changes on all commands 2024-03-12 13:39:56 -05:00
Martin Robinson
8fa25ba41d chore: Fix minor grammar nit in command-line help
A *very* minor grammar correction. "Require" used in this way is
typically followed by the infinitive.
2024-03-18 14:32:28 +01:00
bors
9e6288efe0 Auto merge of #13516 - epage:msrv-add, r=ehuss
feat(add): Fallback to `rustc -v` when no MSRV is set

### What does this PR try to resolve?

#10653 made version-requirement selection respect MSRV as part of #9930.
This updates the implementation for the now-approved RFC specifies that we should respect `rustc -v` if there is no MSRV.

The messages also get a little bit of polish.

### How should we test and review this PR?

Tests are added in separate commits for easier viewing of behavior changes.

### Additional information
2024-03-03 22:07:46 +00:00
Scott Schafer
537cb3e9bc
feat: Use consistent colors when testing 2024-03-02 13:38:11 -07:00
Ed Page
55d3d65434 fix(add): Don't talk about rustc version as if its msrv 2024-03-01 16:27:51 -06:00
Ed Page
d756ff8882 feat(add): Fallback to rustc when rust-version is unset 2024-03-01 16:12:48 -06:00
Ed Page
a30652f2d4 test(add): Demonstrate version selection for old toolchains 2024-03-01 15:54:46 -06:00
Ed Page
d57b6f2f73 fix(add): Increase consistency between warning/error
This is aided by having the two next to each other.
2024-03-01 15:40:43 -06:00