Commit graph

3656 commits

Author SHA1 Message Date
hi-rustin 731ae05ae3 Dedup the same version binaries
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-27 09:16:18 +08:00
hi-rustin 397f446dcd Add test for installing the same binary twice
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-27 09:16:12 +08:00
Jacob Finkelman 6644828028 add test 2023-10-19 18:44:42 +00:00
bors b227fe137a Auto merge of #12857 - epage:unstable, r=weihanglo
fix(cli): Provide next steps for bad -Z flag

In #5546, they suggested we have a list of them but that would be hard to keep up and works well enough to just always mention it.

Fixes #5546
2023-10-19 16:34:17 +00:00
bors c26943919a Auto merge of #12837 - epage:remove, r=weihanglo
fix(remove): Preserve feature comments

### What does this PR try to resolve?

We've been having a hard time balancing leaving the feature list in a good looking start and preserving formatting.  With our new formatting policy (#12836), we can just choose to preserve formatting instead.

Fixes #11743

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

The first commit copies an existing test.  The second is where the fun begins, customizing the test for some weird cases.  The follow up commits do the slow walk for improving it.

We ended up preserving some line-trailing comments because they come after the comma and toml_edit treats that as part of the prefix of the next item.  Tracking removal of that was going to require us to determine if the newline existed in the suffix or in the next item's prefix and edit accordingly and I decided to skip that to keep this initial implementation simpler.

### Additional information
2023-10-19 15:36:20 +00:00
Ed Page 51aeeb01ff fix(cli): Provide next steps for bad -Z flag
In #5546, they suggested we have a list of them but that would be hard
to keep up and works well enough to just always mention it.

Fixes #5546
2023-10-19 09:29:05 -05:00
bors 141667875e Auto merge of #12841 - epage:help, r=weihanglo
fix(help):Clarify install's positional

### What does this PR try to resolve?

- That a version is accepted
- That you are selecting from the source a package which led to part of
  the confusion in #4830

I wonder if we should rename our `CRATE` value names to `PKG`/`PACKAGE`

While doing this, I decided to fix the inconsistency in how we handle value names in help.

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

### Additional information
2023-10-18 17:45:08 +00:00
bors 16629e6a5a Auto merge of #12845 - Urgau:check-cfg-adjust-for-rustc, r=epage
Adjust `-Zcheck-cfg` for new rustc syntax and behavior

https://github.com/rust-lang/rust/pull/111072 introduced a new syntax for `rustc` `--check-cfg` argument. This PR adjust cargo `-Zcheck-cfg` for new that new syntax and behavior.

This PR removes all the `-Zcheck-cfg` options (`features`, `names`, `values`, `output`), as they don't make much sense now since with the new `rustc` behavior: `features`, `names` and `values` are all combine together and the `output` option was only here because the other were.

Now the new behavior from cargo is to always pass one `--check-cfg` argument to rustc for the `feature`s which implicitly enables well known names and values.
2023-10-18 16:29:03 +00:00
bors 67271fd7a9 Auto merge of #12806 - epage:replace, r=Eh2406
fix(replace): Partial-version spec support

### What does this PR try to resolve?

#12614 changed package ID specs to allow fields in the version number to be optional.  This earliest branch with this change is `rust-1.74.0` (beta).  While `@Eh2406` was investigating version metadata issues in #12772, problems with the partial version change were found
- `replace`s that specify version metadata were ignored **(fixed with this PR)**
  - This also extends out to any other place a PackageIDSpec may show up, like `cargo check -p <name>`@<spec>``
  - We explicitly kept the same semantics of version requirements that pre-releases require opt-in.  If nothing else, this gives us more room to change semantics in the future if we ever fix the semantics for pre-release.
- `replace`s that don't specify version metadata when the `Cargo.lock` contained a version metadata, it would previously be ignored (with a warning) but now match **(unchanged with this PR)**
  - When the version metadata in `Cargo.lock` differed from the overriding `Cargo.toml`, cargo would panic **(now an error in this PR)**

With this PR, we are acknowledging that we changed behavior in taking ignored replaces (because of differences with version metadata) and applying them.  Seeing as version metadata is relatively rare, replaces are relatively rare, and differences in it for registries is unsupported, the impact seems very small.

The questions before us are
- Do we revert #12614 in `master` and `rust-1.74.0` or merge this PR into `master`
- If we merge this PR into `master`, do we cherry-pick this into `rust-1.74.0` or revert #12614, giving ourselves more time to find problems

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

The initial commit adds tests that pass as of #12614.  Prior to #12614, these tests would have warned that the `replace` was unused and failed because `bar::bar` didn't exist.  Each commit then changes the behavior (or not) and updates the corresponding test.

### Additional information
2023-10-18 15:42:23 +00:00
Urgau 4b93690c9d Adjust -Zcheck-cfg for new rustc syntax and behavior
This commit removes all the -Zcheck-cfg options (features, names,
values, output), as they don't make much sense now since features, names
and values are all combine together for upstream rustc and the output
option was only here because the other were.

Now the new behavior from cargo is to always pass one `--check-cfg`
argument to rustc for the `feature`s which implicitly enables well known
names and values.
2023-10-18 15:10:25 +02:00
bors a275529de2 Auto merge of #12829 - Nilstrieb:verbosebuildrs, r=weihanglo
Print environment variables for build script executions with `-vv`

### What does this PR try to resolve?

When debugging complicated builds (I was trying to figure out how  `cargo-miri` cross-compiles compiler_builtins without needing a C cross compiler), it's useful to see all the environment variables passed to the build script.

This is also consistent with other commands.

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

I tested it locally by creating a small crate with an empty `build.rs` and building it. Additionally, a test is included.
2023-10-18 02:52:14 +00:00
bors 709ac17f62 Auto merge of #12840 - epage:suggest, r=hi-rustin
fix(cli): Suggest cargo-search on bad commands

This is a low-tech solution alternative to the options proposed in #4682
- Search `[[bin]]`s within all packages in the registry (which aren't tracked atm), suggesting to `cargo install` what is found
- Check if `cargo-<cmd>` is in the registry, suggesting `cargo install if it is

By suggesting `cargo search`, we are giving them a tool so they can verify if the package is what they want (a `cargo info` would help as a next step).

Is is needed?
- New users might not know of `cargo search` but they can search on crates.io
- New users might not be aware of the `cargo-<cmd>` naming pattern

Seems like this can still offer some benefit.

Fixes #4682
2023-10-18 01:51:13 +00:00
Ed Page 5f0596941f fix(help): Clarify install's positional
- That a version is accepted
- That you are selecting from the source a package which led to part of
  the confusion in #4830

I wonder if we should rename our `CRATE` value names to `PKG`/`PACKAGE`
2023-10-17 16:48:15 -05:00
Ed Page 99f917a67e fix(help): Consistently use SCREAMING_CASE for value names
- We have some positional value names that are SCREAMING_CASE and some
  that aren't
- All of the value names for our flags are already SCREAMING_CASE
2023-10-17 16:47:44 -05:00
Ed Page ec3ed20d2a fix(cli): Suggest cargo-search on bad commands
This is a low-tech solution alternative to the options proposed in #4682
- Search `[[bin]]`s within all packages in the registry (which aren't
  tracked atm), suggesting to `cargo install` what is found
- Check if `cargo-<cmd>` is in the registry, suggesting `cargo install
  if it is

By suggesting `cargo search`, we are giving them a tool so they can
verify if the package is what they want (a `cargo info` would help as a
next step).

Is is needed?
- New users might not know of `cargo search` but they can search on
  crates.io
- New users might not be aware of the `cargo-<cmd>` naming pattern

Seems like this can still offer some benefit

Fixes #4682
2023-10-17 14:46:30 -05:00
Ed Page 02dd917511 fix(add): Add back in some auto-formatting
This moves the auto-format to the correct place so it takes effect.
2023-10-17 12:48:45 -05:00
Ed Page 99e4847d78 fix(add): Stop auto-formatting content
Huh, overlooked the cargo side when I fixed this in killercup/cargo-edit#725

Fixes #10850
2023-10-17 12:48:08 -05:00
Ed Page 716ae6238f test(add): Check table formatting issues 2023-10-17 12:23:45 -05:00
Ed Page 6281109e5b fix(remove): Carry comments across removes 2023-10-17 11:56:54 -05:00
Ed Page 5374e8aa70 fix(remove): Leave formatting to the user
Fixes #11743
2023-10-17 11:51:45 -05:00
Ed Page b17a73df1d test(remove): Extend the formatting tested 2023-10-17 11:49:26 -05:00
Ed Page 253a944aca test(remove): Add a more extensive formatting test 2023-10-17 10:49:33 -05:00
Ed Page 1e34066360 test(replace): Clarify name for remaining new test 2023-10-17 10:09:45 -05:00
Ed Page 7502318a85 fix(replace): Error, rather than assert, on version mismatch 2023-10-17 10:09:45 -05:00
Ed Page 0ec3274326 fix(spec): Ensure PackageIdSpec respects version 'build' field 2023-10-17 10:09:41 -05:00
David Calavera 8849d25218 Update rm help to be specific about the section.
Signed-off-by: David Calavera <david.calavera@gmail.com>
2023-10-17 11:53:57 +02:00
Ed Page ae068fbf4c test(replace): Show behavior post-#12614
PR #12614
- Changed ignored replaces to not-ignored
- Has bugs in matching replaces
2023-10-16 11:09:27 -05:00
Nilstrieb d4044c9d01 Print environment variables for build script executions with -vv
This is consistent with other commands.
2023-10-15 19:50:11 +02:00
bors fadb3b1c60 Auto merge of #12822 - hi-rustin:rustin-patch-version, r=weihanglo
Add test for `-V` short argument

Just found it when I randomly jumped into this file :(
2023-10-14 15:46:11 +00:00
hi-rustin 267ae195e3 Add test for -V short argument
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-14 23:16:11 +08:00
Alex Crichton 756fc4084e Support public dependency configuration with workspace deps
This commit updates the processing of `workspace = true` dependencies in
the `[dependencies]` section to process the `public` field. Previously
this field was ignored and didn't get plumbed through as configured.
2023-10-13 00:32:05 -07:00
hi-rustin 497e1ee307 Better suggestion for unsupported -path flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-12 19:24:42 +08:00
hi-rustin 95d79094e0 Add test for unsupported --path flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-12 09:01:34 +08:00
bors 71de58d5cf Auto merge of #12799 - marchiore:warn_add_package_name, r=epage
feat: add package name and version to warning messages

### What does this PR try to resolve?

Hi, this PR Fixes #8018, where i add the package name and version on warning messages.
As this is my first contribution to the project, if anything is not in compliance in the PR let me know and I will be happy to correct it.
2023-10-11 19:59:57 +00:00
Matheus Z Marchiore 380719da35 feat: add package name and version to warning messages 2023-10-11 16:52:30 -03:00
bors 90fb62fc65 Auto merge of #12796 - dtolnay-contrib:switching, r=epage
Do not call it "Downgrading" when difference is only build metadata

### What does this PR try to resolve?

When a `cargo update --precise` changes a dependency between 2 versions which differ only in build metadata, Cargo prints a log referring to it as "Updating" or "Downgrading" the dependency, depending on a comparison between the build metadatas.

This is usually not meaningful, given that build metadata is often stuff like git commit hashes, which are not meaningfully ordered.

```console
    Updating crates.io index
 Downgrading foo v0.0.1+43ef4fe -> v0.0.1+2c65d16
    Updating bar v0.0.2+bc17664 -> v0.0.2+c144a98
```

~~This PR changes to the word "Switching" when the version major, minor, patch, and pre-release value are not being changed.~~
This PR uses the word "Updating" when the version major, minor, patch, and pre-release value are unchanged, regardless of whether the build metadata is going up or down.

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

- `cargo test`
- `cargo build --release`
- `/path/to/cargo/target/release/cargo add tonic_datastore_v1`
- `/path/to/cargo/target/release/cargo update -p tonic_datastore_v1 --precise 0.1.0+3562b6cb3`
- `/path/to/cargo/target/release/cargo update -p tonic_datastore_v1 --precise 0.1.0+ee9e8e4e6`

Before:
<img src="https://github.com/rust-lang/cargo/assets/1940490/93e377e7-928e-4cec-aff6-451166ef7c81" width="500">

~~After:~~
<img src="https://github.com/rust-lang/cargo/assets/1940490/bb71459e-469a-4e09-bb8a-4083f34bce79" width="500">

After:
<img src="https://github.com/rust-lang/cargo/assets/1940490/8804e2fe-d0de-4c9e-b463-a5742daf9446" width="500">
2023-10-11 14:21:44 +00:00
hi-rustin b514ca5e24 Add unsupported short flag suggestion for --exclude flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-11 09:41:05 +08:00
hi-rustin 718b69ce19 Add test for unsupported short exclude flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-11 09:39:13 +08:00
hi-rustin 819a836e9a Add unsupported short flag suggestion for --target flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-11 09:16:26 +08:00
hi-rustin 2f90430110 Add test for unsupported short target triple flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-11 09:13:55 +08:00
Weihang Lo a263a7dc31
test(build): generalize test assertion for non-rustup env 2023-10-10 17:52:46 -04:00
bors 8ba1c316ee Auto merge of #12798 - epage:msrv-install, r=ehuss
fix(install): Suggest an alternative version on MSRV failure

### What does this PR try to resolve?

Moves users from a bad error message, suggesting `--locked` which won't do anything, to suggesting a version of a package to use instead.

The side benefit is errors get reported sooner
- Before downloading the `.crate`
- When installing multiple packages, before building the first

This comes at the cost of an extra `rustc` invocation.

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

Per-commit this builds it up, from tests to the final design.

### Additional information

This is also written in a way to align fairly well with how we'd likely implement #10903.
This improved error message will still be useful after that issue is resolved when the MSRV compatible version is outside of the version req.
2023-10-10 20:03:41 +00:00
Michael Howell f0d3cdf191 rustdoc: remove the word "Version" from test cases
Needed for https://github.com/rust-lang/rust/pull/115948 to merge.
2023-10-10 11:19:57 -07:00
bors c97c906b79 Auto merge of #12788 - hi-rustin:rustin-patch-short-Z, r=epage
Add unsupported lowercase `-z` flag suggestion for `-Z` flag
2023-10-10 01:33:31 +00:00
Ed Page 9b32be7f89 fix(install): Suggest an alternative version on MSRV failure
The next step would be to also automatically install an MSRV compatible
version if compatible with the version req (#10903).
This improved error message will still be useful if the MSRV compatible
version is outside of the version req.

I did this as the first step
- Helps people now, not needing to wait on `-Zmsrv-policy` to be stabilized
- Has fewer questions on how it should be done (or if it should be)
2023-10-09 20:22:54 -05:00
Ed Page 2976e2ac66 fix(install): Don't suggest --locked for MSRV when its root package
This will also report the error without having to download the `.crate`
first.

If installing multiple packages, this will also report it immediately,
rather than waiting for the other packages to be installed first.

This also offers us more flexibility in the error we report,
like suggesting more appropriate fixes.
2023-10-09 16:31:30 -05:00
David Tolnay 985e1eeef5
Do not call it "Downgrading" when difference is only build metadata 2023-10-09 13:53:47 -07:00
Ed Page 699b30a5f4 test(install): Verify existing top-level MSRV behavior 2023-10-09 15:48:53 -05:00
David Tolnay 4d1bf29a2c
Add test of update with version that differ only in build metadata 2023-10-09 10:36:46 -07:00
Eric Huss fd6185193a Rewrite the cache locker to use functions instead of macros. 2023-10-08 14:16:51 -07:00