Commit graph

3918 commits

Author SHA1 Message Date
Ed Page
64f5b0c869 feat(spec): Track git ref 2023-12-01 15:16:26 -06:00
Ed Page
9b9c683810 feat(spec): Track source kind 2023-12-01 15:16:26 -06:00
Ed Page
e7ca585445 test(pkgid): Demonstrate ambiguos specs 2023-12-01 15:16:26 -06:00
Urgau
f32f43d879 Avoid fingerprint invalidation when reordering the declared features 2023-12-01 22:07:03 +01:00
Urgau
7d1fc45a29 Include declared list of features in fingerprint for -Zcheck-cfg
Otherwise changing (add, removing, ...) features from the `[features]`
table would not cause rustc to be called with the new `--check-cfg`,
showing potentially outdated warnings.
2023-12-01 22:05:22 +01:00
Urgau
6c4069b4b5 Add test showing the buggy behavior of check-cfg and the fingerprint 2023-12-01 21:59:26 +01:00
Ed Page
e46df98241 refactor(schemas): Pull out mod for proposed schemas package
Originally for #12801 we talked about a `cargo-util-manifest-schema` package
- `util` in the name to not clash with plugins
- manifest specific to keep the scope down

The problem is we have types that aren't manifest specific, like
- `PartialVersion` (currently slated for `cargo-util-semverext`)
- `RustVersion`
- `PackageIdSpec`
- `SourceKind` (soon)

Things get messy if we try to break things down into common packages.
Instead, I think it'd be useful to have a schemas package that has mods
for each type of schema, re-exporting what is needed.

Normally, componentizing your package by the layer in the stack is a
recipe for pain.
I don't think that'll apply here because these are meant to be so low
level.

The other big concern could be compile times.  My hope is it won't be
too bad.

So this moves the `util/toml` types into the module and we can add more
in the future.
2023-12-01 13:31:30 -06:00
bors
78109c0d2c Auto merge of #13071 - LuuuXXX:issue-11010, r=epage
Have cargo add --optional <dep> create a <dep> = "dep:<dep> feature

### What does this PR try to resolve?

`cargo add --optional <dep>` would create a `<dep> = "dep:<dep>` feature iff

- `rust-version` is unset or is new enough for the syntax
- `dep:<dep>` doesn't already exist

Fixes https://github.com/rust-lang/cargo/issues/11010

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

As the `dep:` syntax is only available starting with Rust 1.60. this pr maintains the previous usage convention in the earlier version.

run

```shell
cargo add --optional <dep>
```

with different rust-version to verify.
2023-12-01 18:13:54 +00:00
LuuuX
036a03709b Fix issue-11010 2023-12-02 01:36:16 +08:00
bors
60e65eefb2 Auto merge of #13046 - linyihai:cargo-add-public, r=epage
Add `--public` for `cargo add`

## What does this PR try to resolve?
Complete https://github.com/rust-lang/cargo/issues/13037

This PR want to add `--public/--no public` flag for `cargo add`

Note: this assumes we'll remove workspace inheritance support for `public` as it sounds like we'll be reverting it https://github.com/rust-lang/rust/issues/44663#issuecomment-1826474620.  If we decide to keep workspace inheritance, we'll need to come back and update this.

## How should we test and review this PR?
Most of Code were reference `cargo add --optional`, So can reviewed the new code based on the part of  `optional` code.

The new testcases were origin from the `cargo add --optional` part.
- `public` testcase:there is no dependencies and will be add `public` dependencies.
- `no_public` testcase:  there is no dependencies  and will be add `no_public` dependencies.
- `overwrite_public` testcase: the dependencies already exists but will be overwrite with `public`.
- `overwrite_no_public` testcase: the dependencies already exists but will be overwrite with `no_public`.
- `overwrite_public_with_no_public` testcase: the dependencies already marked as `no_public` and will be overwrite with `public`.
- `overwrite_no_public_with_public` testcase: the dependencies already marked as `public` and will be overwrite with `no_public`.
2023-12-01 17:33:20 +00:00
Ed Page
378502bf20 refactor: Try to make PackageId conversion clearer 2023-12-01 10:48:14 -06:00
bors
c192d989b3 Auto merge of #13091 - weihanglo:trim-paths-lldb, r=epage
test(trim-paths): exercise with real world debugger
2023-12-01 15:47:10 +00:00
bors
847958971b Auto merge of #13053 - linyihai:cargo-uninstall-fixed, r=weihanglo
Fixed uninstall a running binary failed on Windows

### What does this PR try to resolve?
 Fixes https://github.com/rust-lang/cargo/issues/3364

The problem reproduce when you try to uninstall a running binary and it will failed on Windows,  this is because that cargo had already remove the installed binary tracker information in disk,  and next to remove the running binary but it is not allowed in Windows.  And to the worst,  you can not uninstall the binary already and only to reinstall it by the `--force` flag.

### How to solve the issue?
This PR try to make the uninstall a binary more reasonable that  only after remove the binary sucessfully then remove the tracker information on binary and make the remove binary one by one.

### How should we test and review this PR?
Add testcase 0fd4fd357b
- install the `foo`
- run `foo` in another thread.
- try to uninstall running `foo` and only failed in Windows.
- wait the `foo` finish, uninstall `foo`
- install the `foo`

### Additional information
2023-12-01 15:10:56 +00:00
Lin Yihai
db144c9d0a Add tracker verification for test case uninstall_running_binary 2023-12-01 22:23:40 +08:00
Weihang Lo
5c32fe0432
test(trim-paths): exercise with real world debugger 2023-12-01 08:48:24 -05:00
Lin Yihai
48c998fec7 Add detect_workspace_inherit_public test case. 2023-12-01 11:22:26 +08:00
Lin Yihai
a6ca281948 chore: add lib.rs for new test cases 2023-12-01 10:21:33 +08:00
bors
1ef8575839 Auto merge of #13077 - GuillaumeGomez:filter-workspace-scrape-example, r=epage
Don't filter on workspace members when scraping doc examples

Fixes https://github.com/rust-lang/cargo/issues/13074.

I confirmed locally that it fixed the issue in docs.rs.

cc `@willcrichton`
r? `@epage`
2023-11-30 16:42:35 +00:00
Guillaume Gomez
689d9a7e4f Don't filter on workspace members when scraping doc examples 2023-11-30 17:38:49 +01:00
Guillaume Gomez
95a27cdbd1 Add regression test for scraped examples in crates without [workspace] 2023-11-30 17:36:46 +01:00
Lin Yihai
1e3b4231da chore: fixed clippy 2023-11-30 15:46:02 +08:00
bors
430effa37d Auto merge of #12484 - adrianEffe:fix/error-count, r=weihanglo
Fixes error count display is different when there's only one error left

### What does this PR try to resolve?

When there's only 1 error left, the number 1 appears in the output so that it scans the same as the output when there's more than 1 error, so:

```
error: could not compile `crate` (lib test) due to 1 previous error
```
instead of the current:
```
error: could not compile `crate` (lib test) due to a previous error
```

Fixes #12390

rustc related PR [#114759](https://github.com/rust-lang/rust/pull/114759)
2023-11-29 19:07:16 +00:00
bors
07f1208a9f Auto merge of #13065 - weihanglo:remap-path-prefix-order, r=ehuss
fix: reorder `--remap-path-prefix` flags for `-Zbuild-std`

### What does this PR try to resolve?

Order of `--remap-path-prefix` flags is important for `-Zbuild-std`.
We want to show `/rustc/<hash>/library/std` instead of `std-0.0.0`.

Fixes rust-lang/rust#117839

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

Follow the steps in rust-lang/rust#117839, or run

```
CARGO_RUN_BUILD_STD_TESTS=true cargo +nightly t --test build-std
```

to verify.
2023-11-29 18:28:07 +00:00
Adrian
3e297a6803
Update test for override respects spec metadata 2023-11-29 18:47:27 +02:00
Adrian
b7b5a093a1
Fix cargo errors counter 2023-11-29 18:47:14 +02:00
belovdv
6b86f93713 remove jobserver in shim for tests in testsuite/fix 2023-11-29 15:30:58 +03:00
Lin Yihai
0fd4fd357b Add test case for cargo uninstall while try to uninstalling a running Bin. 2023-11-29 17:52:22 +08:00
Weihang Lo
8709835a01
fix: reorder --remap-path-prefix flags for -Zbuild-std
Order of `--remap-path-prefix` flags is important for `-Zbuild-std`.
We want to show `/rustc/<hash>/library/std` instead of `std-0.0.0`.
2023-11-28 15:29:03 -05:00
Lin Yihai
703446165b chore: add the missing flag for cargo add --public 2023-11-28 11:25:10 +08:00
Lin Yihai
07ba57dd8b Remove unnecessary code for cargo add --public testcases 2023-11-27 08:54:05 +08:00
Lin Yihai
509535675b Make the public/no-public next to the pair optional/no-optional 2023-11-27 08:09:54 +08:00
Lin Yihai
58e0ab825b reuse add_basic.in/lib.rs for testcase 2023-11-25 12:41:01 +08:00
Lin Yihai
9ac30323b3 Add not overwrite testcase for cargo add --public 2023-11-25 11:29:39 +08:00
Lin Yihai
7c8d997e26 Add overwrite testcase for cargo add --public 2023-11-24 15:11:51 +08:00
Lin Yihai
a1a75e81c9 Update cargo add --help testcase 2023-11-24 15:04:52 +08:00
bors
65d0eb536d Auto merge of #12997 - hi-rustin:rustin-patch-cargo-test-support, r=epage
cargo-test-support: Add features to the default Cargo.toml file
2023-11-22 01:47:31 +00:00
bors
71cd3a926f Auto merge of #13016 - dtolnay-contrib:messagetype, r=ehuss
Handle $message_type in JSON diagnostics

### What does this PR try to resolve?

Unblocks https://github.com/rust-lang/rust/pull/115691.

Without this change, Cargo's testsuite fails in `doc::doc_message_format` and `metabuild::metabuild_failed_build_json`.

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

Tested with and without https://github.com/rust-lang/rust/pull/115691.

In Cargo repo: `cargo test --test testsuite`
In Rust repo: `x.py test src/tools/cargo` (separately on master and $message_type PR)
2023-11-20 15:30:57 +00:00
David Tolnay
65bb09d434
Handle $message_type in JSON diagnostics 2023-11-19 20:37:16 -08:00
Urgau
4781592e18 Fix --check-cfg invocation with zero features 2023-11-19 18:08:32 +01:00
hi-rustin
12d7818192 Add features to the default Cargo.toml file
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-11-19 22:03:57 +08:00
Eric Huss
2eac6f5c0c Fix clippy-wrapper test race condition. 2023-11-18 17:23:29 -08:00
Yerkebulan Tulibergenov
e81d84cc17 feat: Add CARGO_RUSTC_CURRENT_DIR
This is an alternative to #12158's `CARGO_WORKSPACE_DIR` that was
implementing the solution to #3946 that previously discussed in the
cargo team meeting.

`CARGO_WORKSPACE_DIR` is a bit awkward to document / describe because
its the effective workspace directory of the thing being built.
If the thing being built doesn't have a workspace, it falls back to
`CARGO_MANIFEST_DIR`.

It would also be hard to take into account what the
`CARGO_WORKSPACE_DIR` would be for path dependencies into foreign
workspaces *and* it wouldn't solve the problem the user is having.

What the user really wants is the CWD of rustc when it is invoked.
This is much simpler to describe and is accurate when using a path
dependency to a foreign package.

Because the CWD is a much simpler mechanism to talk about, I figured we
could diverge from our prior consensus and make it always present,
rather than limiting it to tests.

Remaining work for #3946: get this stabilized
2023-11-17 09:25:46 -06:00
Ed Page
c75c456de4 test(compiler): Make inner test names more specific
This will make it easier to verify other env variables later
2023-11-17 09:25:34 -06:00
bors
22bbc95f3c Auto merge of #12995 - linyihai:issue_11383, r=weihanglo
Exited with hard error when custom build file no existence or not in package

## What does this PR try to resolve?
Fixed https://github.com/rust-lang/cargo/issues/11383

## How should we test and review this PR?
Add test `build_script_outside_pkg_root`,  this will check `custom_build.rs` existence and whether in the package root, if not then exited with a hard error

## Additional information
The code just handle the `custom build` target that i know how to test it.  Other target type is skipped.
2023-11-24 01:41:19 +00:00
Lin Yihai
75aaa40c78 Remove the unnecessary backticks 2023-11-22 11:09:55 +08:00
Lin Yihai
edfbcf0a6c Return a hard error when custom build outside package 2023-11-21 11:10:46 +08:00
Lin Yihai
92ce5a2b27 Change the logging level and other improvement. 2023-11-20 12:57:26 +08:00
Lin Yihai
ac1e66d947 Add testcase for custom build file warning 2023-11-17 17:11:57 +08:00
bors
9f3b4883e8 Auto merge of #12178 - weihanglo:dogfood-lints-table, r=epage
chore: dogfood Cargo `-Zlints` table feature
2023-11-16 19:40:13 +00:00
Mohammad AlSaleh
0bbabecbf3 Fix a rustflags test using a wrong buildfile name
The test seem to have always had the wrong buildfile `build.rs.rs`.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
2023-11-16 20:03:01 +03:00
Weihang Lo
7a4754a1d3
lint: allow print_stdout and print_stderr 2023-11-16 11:35:21 -05:00
Weihang Lo
870f9ea7b3
lint: allow disallow_methods 2023-11-16 11:35:21 -05:00
Weihang Lo
1539b3dfc1
lint: dogfood ourselves lints table in manifest
These lint rules are from src/lib.rs. We aim to remove
them in the source code once `Zlints` hit stable.
2023-11-16 11:35:21 -05:00
Eric Huss
0afd943dad Fix some test output validation. 2023-11-15 15:10:18 -08:00
bors
6658e1abe3 Auto merge of #12977 - Eh2406:bug_12941, r=epage
If the only path is a loop then counted as the shortest path.

This is a fix for #12941

This graph data structure is used to store dependency DAGs. Where each edge represents a dependency from a package to the package that fulfilled the dependency. Different parts of the resolver store this data in opposite directions, sometimes packages point at the things that depend on them other times packages point to the parents that required them. Error messages often need to report on why a package is in the graph, either by walking up toward parents or down toward children depending on how this graph is stored. #12678 unified the two different walking implementations, and replace them with a breadth first search so as to find the shortest path. This code ignored when edge pointed at a package that had already been reached, because that generally describes a longer path to an existing package.

Unfortunately, when I said this was a DAG that was a simplification. There can be cycles introduced as dev-dependencies. The existing code would reasonably ignore the cycles figuring that if we continue searching we would eventually find the root package (a package that nothing depended on). Missing the possibility that the root package created the cycle.

Now we search through the entire graph looking for a root package. If we do not find a root package we report the path to the last package we processed.
2023-11-15 16:09:00 +00:00
bors
0fcc90dc24 Auto merge of #12950 - epage:msrv, r=Eh2406
fix(resolver): Prefer MSRV, rather than ignore incompatible

### What does this PR try to resolve?

This is another experiment for #9930.

Comparing preferring over exclusively using MSRV compatible:

Benefits
- Better error messages
- `--ignore-rust-version` is implicitly sticky

Downsides
- Can't backtrack for MSRV compatible version
- Still requires workspace-wide MSRV (compared to our desired end state of declaring MSRV as yet another dependency)

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

### Additional information

Note: `--ignore-rust-version` is not yet implemented for the resolver.

This builds on #12930
2023-11-14 21:56:00 +00:00
Ed Page
0d29d3f71b fix(resolver): Prefer MSRV, rather than ignore incompatible
This is another experiment for #9930.

Comparing preferring over exclusively using MSRV compatible:

Benefits
- Better error messages
- `--ignore-rust-version` is implicitly sticky

Downsides
- Can't backtrack for MSRV compatible version
- Still requires workspace-wide MSRV (compared to our desired end state of declaring MSRV as yet another dependency)

This builds on #12930
2023-11-14 14:56:58 -06:00
Ed Page
0bc5d22285 test(resolver): Verify backtracking for MSRV resolver 2023-11-14 14:56:53 -06:00
Jacob Finkelman
d19273c04d If the only path is a loop then counted as the shortest path. 2023-11-14 20:18:43 +00:00
Jacob Finkelman
cd2e4e3912 add a test 2023-11-14 20:18:43 +00:00
Ed Page
9ca6376f29 fix(resolver): Don't do git fetches when updating workspace members
Before, when running `cargo update <member>`, we'd not reuse the
previous resolve result and when the resolver started walking into the
dependencies, it would do a git fetch.

Now, we won't even try to resolve the workspace members and so we won't
look at those dependencies and do git fetch.

This will make `cargo update <workspace-member>`
match `cargo update --workspace`.
I considered whether there were other ways of handling this but I
figured aiming for consistency in approaches was the best way.
We can investigate improving those approaches separately.

There are other discrepancies in the different code paths (handling of
patches, adding sources) but I'm deferring looking over those.

Between this and #12602, this should finnally resolve #12599.

Fixes #12599
2023-11-14 13:47:10 -06:00
Ed Page
80225bbf46 test(update): Verify --workspace behavior
Looks like `--workspace` and `-p <workspace-member>` behave differently.
2023-11-14 12:05:19 -06:00
David Hotham
962d89a8d8
fix error message for duplicate links 2023-11-14 17:53:58 +00:00
bors
dd94e9d9ce Auto merge of #12944 - linyihai:issue_12790, r=weihanglo
Only filter out target if its in the package root

### What does this PR try to resolve?
Only filter out target if its in the package root. Fixed https://github.com/rust-lang/cargo/issues/12790

### How should we test and review this PR?
Add two testcase in tests/testsuite/package.rs for this PR.

- `include_files_called_target_project` testcase test the logic for none git repository. By the way, our PR was based on git repository,  so this testcase was a little irrelevant.
-  `include_files_called_target_git` testcase was made for git repository.  There are two cases here, one is the target in the uncommitted state, at this time should not be included, and one is the target in the committed state, at this time should be included

### Additional information
2023-11-14 13:39:28 +00:00
Lin Yihai
b2b026bfbb Improve testcase include_files_called_target_git 2023-11-14 11:25:11 +08:00
Eric Huss
8161ba50cd Ignore changing_spec_relearns_crate_types on windows-gnu 2023-11-13 19:17:51 -08:00
bors
a4764b0dd8 Auto merge of #12962 - hi-rustin:rustin-patch-cargo-search, r=weihanglo
Improve about information of `cargo search`
2023-11-13 12:40:10 +00:00
hi-rustin
918d32b34d Improve about information of cargo search
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-11-13 19:50:21 +08:00
Eric Huss
80ffb1de1c Fix --quiet being used with nested subcommands.
This fixes an issue where `--quiet` doesn't work with commands that have
subcommands. This is because `config_configure` only looks at the global
and top-level subcommand, and not deeper subcommands. The issue was that
`--quiet` was not defined as a global flag. This was changed in
https://github.com/rust-lang/cargo/pull/6358 in order to give a better
help message for `cargo test --quiet`. I don't remember if clap just
didn't support overriding at the time, or if we just didn't know how it
worked. Anyways, it seems to work to override it now, so I think it
should be fine to mark it as global.

This should bring in `--quiet` more in-line with how `--verbose` works.
This means that `--quiet` is now accepted with `cargo report`,
`cargo help`, and `cargo config`.

This also fixes `--quiet` with `cargo clean gc`.

This should also help with supporting `--quiet` with the new `cargo
owner` subcommands being added in
https://github.com/rust-lang/cargo/pull/11879.

Fixes #12957
2023-11-12 11:17:43 -08:00
Eric Huss
0cd970b1c0 Move gc options under a cargo clean gc subcommand.
This was requested to separate the interaction of `cargo clean` and the
cleaning of global cache data, and to minimize the impact of this
initial implementation.
2023-11-11 12:36:25 -08:00
Eric Huss
9a41a6110c Remove shared-target gc kind.
This kind is unlikely to be implemented in the foreseeable future, and
we don't really know what it is going to look like.
2023-11-11 10:56:58 -08:00
Eric Huss
ead7904ad4 Add gc tracing target. 2023-11-11 10:56:58 -08:00
Eric Huss
da3ca05677 Add a global cache garbage collector.
This adds a garbage collector which will remove old files from cargo's
global cache.

A general overview of the changes here:

- `cargo::core::global_cache_tracker` contains the `GlobalCacheTracker`
  which handles the interface to a sqlite database which stores
  timestamps of the last time a file was used.
- `DeferredGlobalLastUse` is a type that implements an optimization for
  collecting last-use timestamps so that they can be flushed to disk all
  at once.
- `cargo::core::gc` contains the `Gc` type which is the interface for
  performing garbage collection. It coordinates with the
  `GlobalCacheTracker` for determining what to delete.
- Garbage collection can either be automatic or manual. The automatic
  garbage collection supports some config options for defining when
  it runs and how much it deletes.
- Manual garbage collection can be performed via options to `cargo
  clean`.
- `cargo clean` uses the new package cache locking system to coordinate
  access to the package cache to prevent interference with other cargo
  commands running concurrently.
2023-11-11 10:56:58 -08:00
Lin Yihai
722d8f1c1d Add target folder but not committed 2023-11-10 15:49:57 +08:00
Lin Yihai
4577c0ec61 Correct the situation with git repository test cases 2023-11-10 14:22:03 +08:00
Karel Peeters
2c503f89c4 Add unit test for files called target.
https://github.com/rust-lang/cargo/issues/12790
2023-11-10 10:38:26 +08:00
bors
2ef56214b3 Auto merge of #12939 - hi-rustin:rustin-patch-feature-msg, r=epage
Fix the invalidate feature name message
2023-11-08 17:15:01 +00:00
hi-rustin
976835d045 Update the test for the msg change
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-11-08 23:40:24 +08:00
hi-rustin
d61816465f Add test for empty feature name
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-11-08 22:52:35 +08:00
Ed Page
e70e310ce0 fix: Report more detailed semver errors
For `cargo install` we'll now show a more specific parse error for
semver, much like other parts of cargo.

This came out of my work on #12801.  I was looking at what might be
appropriate to put in a `cargo-util-semver` crate and realized we have
the `ToSemver` trait that exists but doesn't do much, so I dropped it.
2023-11-06 15:24:32 -06:00
hi-rustin
fb0bbe36f1 Search dep in other tables and update tests
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-11-07 09:33:44 +08:00
bors
f095603db0 Auto merge of #12923 - Eh2406:bug_12920, r=epage
Bug 12920

Fix for #12920, a regression introduced in #12749.

This also as a test case for an existing Terrible error message.
2023-11-06 20:58:55 +00:00
Jacob Finkelman
7997306a0b restore error message 2023-11-06 20:16:26 +00:00
Jacob Finkelman
2352cbd1f9 add a test 2023-11-06 20:13:56 +00:00
bors
4300dd7394 Auto merge of #12911 - epage:manifest-schema, r=weihanglo
refactor(toml): Pull out the schema

### What does this PR try to resolve?

On its own, this PR is a net negative for readability / complexity.  It moves all of the serde types related to manifest from `toml/mod.rs` to `toml/schema.rs`, leaving a lot of the functions and some trait implementations back in `toml/mod.rs` (some basic functions that made sense for the type on their own were also moved).

So why do this?  This is an ooch towards having the schema broken out into a separate package (#12801).  To do this, we need to
- Identify what all types need to be put in the package.  This refactor highlights the dependence on `RustVersion` and `PackageIdSpec`
- Highlights what functionality we need to find a new home for

Follow up PRs would
- Find better homes for the logic in `toml/mod.rs`, moving us away from having `impl schema::Type` blocks.
- Pull out a `src/cargo/util_semver` package to own `PartialVersion` (at least) as prep for making a `cargo-util-semver` package
- Move `RustVersion` to `manifest-toml/schema.rs`, deciding what functionality needs to move with the type
- Move or copy `PackageIdSpec` into `manfest-toml/schema.rs`, deciding what functionality remain in `core/` and what moves over
- Move `toml/schema.rs` to `src/cargo/util_schema`
- Actually make `cargo-util-semver` and `cargo-util-manifest-schema` packages

So why do this now? This is a big change!  By being incremental
- Reduce churn for me and others
- Be easier to review
- Collect feedback as we go on the whole plan to avoid more painful changes later

We *can* back this out if needed but the further we go, the more painful it will be.

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

### Additional information
2023-11-06 19:49:14 +00:00
Ed Page
c12c4c3f8d tests: Remove plugin tests
Compiler plugins were removed in rust-lang/rust#116412, so we don't need
these tests.

As for the `plugin` field on build-targets, it appears to be
[stable-but-deprecated](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-plugin-field),
so I left it alone
2023-11-06 09:55:31 -06:00
bors
65e297d1ec Auto merge of #12915 - epage:test-targets, r=weihanglo
fix(cli): Clarify --test is for targets, not test functions

We already refer to test targets as "test targets" instead of "tests" in `--test` but not `--tests` or in the error output.  This makes it uniformly refer to them as "test targets", making it clearer that these aren't test functions.

Fixes #7864
2023-11-03 20:56:31 +00:00
Ed Page
76918a0e99 fix(cli): Clarify --test is for targets, not test functions
We already refer to test targets as "test targets" instead of "tests" in
`--test` but not `--tests` or in the error output.  This makes it
uniformly refer to them as "test targets", making it clearer that these
aren't test functions.

Fixes #7864
2023-11-03 15:45:00 -05:00
bors
6354bb3d81 Auto merge of #12908 - weihanglo:profile-merge-trim-paths, r=epage
fix: merge `trim-paths` from different profiles
2023-11-02 12:29:20 +00:00
Weihang Lo
7535971d8b
fix(trim-paths): merge trim-paths from different profiles
In 4d29af1 we forgot to add trim-paths to `fn merge()`.
This commit follows how `-Zprofile-rustflags` works ---
overriding instead of merging array.
2023-11-01 23:24:15 -04:00
Weihang Lo
618701921d
test(trim-paths): profile merge doesn't work
This demonstrate the buggy behavior that
profile merge on `trim-paths` doesn't work as expected.
2023-11-01 23:19:49 -04:00
Ed Page
9a1bbc9625 refactor(toml): Pull out schema
Remaining steps
- Decouple `toml/mod.rs` functionality from `toml/schema.rs`
- Pull out `core/` types referenced by `toml/schema.rs`
2023-11-01 20:59:46 -05:00
David Tolnay
649a14d470
Add regression test for issue 6915: features and transitive dev deps 2023-11-01 14:22:16 -07:00
renovate[bot]
b4efcdbf32 chore(deps): update rust crate gix to 0.55.2 2023-11-01 00:12:37 +00:00
Weihang Lo
dd0aea350c
feat(trim-paths): set env CARGO_TRIM_PATHS for build scripts 2023-10-31 12:00:48 -04:00
bors
4aee12c1f8 Auto merge of #12625 - weihanglo:rfc3127, r=epage
feat: implement RFC 3127 `-Ztrim-paths`
2023-10-31 02:23:00 +00:00
Weihang Lo
63cef2c4fc
feat(trim-paths): rustc invocation integration 2023-10-30 16:38:56 -04:00
Weihang Lo
557fc4fd3e
test(trim-paths): verify current behavior with -Ztrim-paths 2023-10-30 16:38:55 -04:00
Weihang Lo
08c5e35f60
test(trim-paths): parsing in mainfest and config 2023-10-30 16:38:55 -04:00
Weihang Lo
4d29af1d81
feat(trim-paths): parsing in mainfest and config 2023-10-30 16:38:55 -04:00
bors
04621e2e0f Auto merge of #12779 - calavera:workspace_adds_implicit_members, r=epage
Add new packages to [workspace.members] automatically

### What does this PR try to resolve?

If a new package is created in a workspace, this change adds the package's path to the workspace's members list automatically.

It doesn't add the package to the list if the path is in the workspace's exclude list, or if the members list doesn't exist already. I noticed that a `cargo_new` test broke if I create the members list when it doesn't exist. This is because the workspace's manifest can be used for package templating. I think it's better to not break that use case.

Fixes #6378

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

I've included tests in the `cargo_new` suite.
2023-10-29 03:02:08 +00:00
David Calavera
1a8bfdf0cf Update workspace manifest with new members.
When a user runs `cargo new` or `cargo init` within a workspace, Cargo will automatically add the new package to the members list in the workspace if necessary. The heuristic to add the new package is as follows:

- If there is no `members` list in the workspace yet, a new `members` list is created.
- If there is an `exclude` statement, Cargo checks if the new package should be excluded. If it doesn't match the `exclude` list, the package is added to the `members` list.
- If there is a glob expression in the `members` list that matches the new package, the package is not added to the `members` list.
- If the existent `members` list is sorted, Cargo tries to preserve the ordering when it adds the new package.

This change doesn't try to format the resulting `members` list in any way, leaving the formatting decissions to the user.

Signed-off-by: David Calavera <david.calavera@gmail.com>
2023-10-28 07:42:23 -07:00
Ed Page
acc52f362b refactor(toml): Decouple parsing from interning system
To have a separate manifest API (#12801), we can't rely on interning
because it might be used in longer-lifetime applications.

I consulted https://github.com/rosetta-rs/string-rosetta-rs when
deciding on what string type to use for performance.

Originally, I hoped to entirely replacing string interning.  For that, I
was looking at `arcstr` as it had a fast equality operator.  However,
that is only helpful so long as the two strings we are comparing came
from the original source.  Unsure how likely that is to happen (and
daunted by converting all of the `Copy`s into `Clone`s), I decided to
scale back.

Concerned about all of the small allocations when parsing a manifest, I
assumed I'd need a string type with small-string optimizations, like
`hipstr`, `compact_str`, `flexstr`, and `ecow`.
The first three give us more wiggle room and `hipstr` was the fastest of
them, so I went with that.

I then double checked macro benchmarks, and realized `hipstr` made no
difference and switched to `String` to keep things simple / with lower
dependencies.

When doing this, I had created a type alias (`TomlStr`) for the string
type so I could more easily swap it out if needed
(and not have to always write out a lifetime).
With just using `String`, I went ahead and dropped that.

I had problems getting the cargo benchmarks running, so I did a quick
and dirty benchmark that is end-to-end, covering fresh builds, clean
builds, and resolution.  I ran these against a fresh clone of cargo's
code base.
```console
$ ../dump/cargo-12801-bench.rs run
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/cargo -Zscript -Zmsrv-policy ../dump/cargo-12801-bench.rs run`
warning: `package.edition` is unspecified, defaulting to `2021`
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `/home/epage/.cargo/target/0a/7f4c1ab500f045/debug/cargo-12801-bench run`
$ hyperfine "../cargo-old check" "../cargo-new check"
Benchmark 1: ../cargo-old check
  Time (mean ± σ):     119.3 ms ±   3.2 ms    [User: 98.6 ms, System: 20.3 ms]
  Range (min … max):   115.6 ms … 124.3 ms    24 runs

Benchmark 2: ../cargo-new check
  Time (mean ± σ):     119.4 ms ±   2.4 ms    [User: 98.0 ms, System: 21.1 ms]
  Range (min … max):   115.7 ms … 123.6 ms    24 runs

Summary
  ../cargo-old check ran
    1.00 ± 0.03 times faster than ../cargo-new check
$ hyperfine --prepare "cargo clean" "../cargo-old check" "../cargo-new check"
Benchmark 1: ../cargo-old check
  Time (mean ± σ):     20.249 s ±  0.392 s    [User: 157.719 s, System: 22.771 s]
  Range (min … max):   19.605 s … 21.123 s    10 runs

Benchmark 2: ../cargo-new check
  Time (mean ± σ):     20.123 s ±  0.212 s    [User: 156.156 s, System: 22.325 s]
  Range (min … max):   19.764 s … 20.420 s    10 runs

Summary
  ../cargo-new check ran
    1.01 ± 0.02 times faster than ../cargo-old check
$ hyperfine --prepare "cargo clean && rm -f Cargo.lock" "../cargo-old check" "../cargo-new check"
Benchmark 1: ../cargo-old check
  Time (mean ± σ):     21.105 s ±  0.465 s    [User: 156.482 s, System: 22.799 s]
  Range (min … max):   20.156 s … 22.010 s    10 runs

Benchmark 2: ../cargo-new check
  Time (mean ± σ):     21.358 s ±  0.538 s    [User: 156.187 s, System: 22.979 s]
  Range (min … max):   20.703 s … 22.462 s    10 runs

Summary
  ../cargo-old check ran
    1.01 ± 0.03 times faster than ../cargo-new check
```
2023-10-27 12:09:44 -05:00
Ed Page
293f2250d6 feat(doc): Print the generated docs links
I've wanted something like this myself.  I dislike using `--open`
because I tend to move up to re-run my `cargo doc` run but then have to
edit it to remove `--open`.
Also makes it annoying when opening docs when `cargo doc` is wrapped by
a tool like `make`.

This was previously attempted in #5592:
- Unlike the request in #5562, this aligns with #5592 in always printing
  rather than using a flag as this seems generally useful
- Unlike #5592, this prints as an alternative to "Opening" to keep
  things light
- Unlike #5592, this prints afterwards as the link is only valid then

Fixes #5562
2023-10-19 10:51:56 -05:00
bors
307486ed18 Auto merge of #12786 - epage:version, r=weihanglo
feat(toml): Allow version-less manifests

### What does this PR try to resolve?

Expected behavior with this PR:
- `package.version` defaults to `0.0.0`
- `package.publish` is defaulted to `version.is_some()`

This also updates "cargo script" to rely on this new behavior.

My motivation is to find ways to close the gap between "cargo script" and `Cargo.toml`.  With "cargo script", we want to allow people to only write however much of a manifest is directly needed for the work they are doing (which includes having no manifest).  Each difference between "cargo script" and `Cargo.toml` is a cost we have to pay in our documentation and a hurdle in a users understanding of what is happening.

There has been other interest in this which I also find of interest (from #9829):
- Lower boilerplate, whether for [cargo xtasks](https://github.com/matklad/cargo-xtask), nested packages (rust-lang/rfcs#3452), etc
- Unmet expectations from users because this field is primarily targeted at registry operations when they want it for their marketing version (#6583).
- Make "unpublished" packages stand out

This then unblocks unifying `package.publish` by making the field's default based on the presence of a version as inspired by the proposal in #9829.  Without this change, we were trading one form of boilerplate (`version = "0.0.0"`) for another (`publish = false`).

Fixes #9829
Fixes #12690
Fixes #6153

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

The initial commit has test cases I thought would be relevant for this change and you can see how each commit affects those or existing test cases.  Would definitely be interested in hearing of other troubling cases to test

Implementation wise, I made `MaybeWorkspaceVersion` deserializer trim spaces so I could more easily handle the field being an `Option`.  This is in its own commit.

### Additional information

Alternatives considered
- Making the default version "stand out more" with it being something like `0.0.0+HEAD`.  The extra noise didn't seem worth it and people would contend over what the metadata field *should be*
- Make the default version the lowest version possible (`0.0.0-0`?).  Unsure if this will ever really matter especially since you can't publish
- Defer defaulting `package.publish` and instead error
  - Further unifying more fields made this too compelling for me :)
- Put this behind `-Zscript` and make it a part of rust-lang/rfcs#3502
  - Having an affect outside of that RFC, I wanted to make sure this got the attention it deserved rather than getting lost in the noise of a large RFC.
- Don't just default the version but make packages versionless
  - I extended the concept of versionless to `PackageId`'s internals and saw no observable difference
  - I then started to examine the idea of version being optional everywhere (via `PackageId`s API) and ... things got messy especially when starting to look at the resolver.  This would have also added a lot of error checks / asserts for "the version must be set here".  Overall, the gains seemed questionable and the cost high, so I held off.
2023-10-27 16:09:12 +00:00
Urgau
e396904b25 Add feature gate test for check-cfg config, build script and override 2023-10-27 17:10:49 +02:00
bors
fcc3786d73 Auto merge of #12868 - hi-rustin:rustin-patch-install, r=weihanglo
Remove duplicate binaries during install
2023-10-27 01:28:20 +00:00
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
bors
f5418fcfeb Auto merge of #12766 - shnaramn:WarnAboutNameCase, r=epage
Warn about crate name's format when creating new crate

### What does this PR try to resolve?
Warns about a crate's name during creation (`crate new ...`) if it doesn't follow the preferred snake_case format.

Fixes #2708

The warning message uses the language mentioned in [RFC 430](https://github.com/rust-lang/rfcs/blob/master/text/0430-finalizing-naming-conventions.md#general-naming-conventions).

### How should we test and review this PR?
Verified existing tests succeeded with updates.  Added new tests to verify fix.

### Additional information
The link to [API naming guidelines](https://rust-lang.github.io/api-guidelines/naming.html) was not used since it still stays `unclear` for naming convention for crates.
2023-10-23 17:17:58 +00: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
Shankar Mathiah Nanjundan
901018c3db Fixes #2708
Warns about not using snake_case or kebab-case format when creating new packages with `cargo new` command.
2023-10-16 23:39:19 -07: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
Ed Page
bfb5d1db0e fix(toml): Default package.publish based on presence of package.version
Before the default was hardcoded to `true`.  The problem was that means
that to remove the `package.version` boilerplate, you had to add
`package.publish = false` boilerplate.

To make the errors easier to understand in this situation, I err on the
side of encouraging people to put `publish = true` in their manifests.

By making this change, we also unblock "cargo script" /
`Cargo.toml` unifying the handling of `package.publish`.
2023-10-11 13:17:03 -05:00
Ed Page
1923b5b862 feat(toml): Allow versionless packages
This defaults the version to `0.0.0` for most of cargo.

It is an error to lack a version and have a package publishable.
That means you have to add `publish = false`.
2023-10-11 13:13:44 -05: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
Eric Huss
b4982adfd9 Add a new package cache locking system.
This introduces a new `CacheLocker` which manages locks on the package
cache. Instead of either being "locked" or "not locked", the new locker
supports multiple modes:

- Shared lock: Cargo can read from the package sources, along with any
  other cargos reading at the same time.
- Download exclusive lock: Only one cargo can perform downloads.
  Download locks do not interfere with Shared locks, since it is
  expected that downloading does not modify existing files (only adds
  new ones).
- Mutate exclusive lock: Only one cargo can have this lock, and it also
  prevents shared locks. This is so that the cargo can modify the
  package cache (such as deleting files) without breaking concurrent
  processes.
2023-10-08 14:16:51 -07:00
Eric Huss
b37c8f35c0 Add ConfigBuilder::root
This adds the `root` method to set the root directory to be able to
override paths::root().
2023-10-08 14:16:51 -07:00
hi-rustin
f9719dcf4e add unsupported lowercase flag suggestion for -Z flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-08 08:36:49 +08:00
hi-rustin
0108d5b0dc Add test for unsupported short unstable feature flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-08 08:36:09 +08:00
Ed Page
5c9a126911 test(toml): Verify existing version-less behavior 2023-10-06 12:21:07 -05:00
bors
fc790e7b2d Auto merge of #12781 - dvdhrm:pr/target-typo, r=epage
cargo/targets: fix error-message typo

Fix typo: "with with" -> "with"
2023-10-06 13:59:27 +00:00
David Rheinsberg
4aa1a95714 cargo/targets: fix error-message typo
Fix typo: "with with" -> "with"
2023-10-06 15:08:48 +02:00
hi-rustin
2400e42652 add unsupported short suggestion for --config flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-06 16:27:31 +08:00
hi-rustin
914119940b Add test for unsupported short config flag 2023-10-06 16:16:35 +08:00
Scott Schafer
b2b3cfa524
feat: Add Edition2024 2023-10-04 13:11:52 -06:00
hi-rustin
7bd0f81257 Add unsupported short suggestion for --out-dir flag 2023-10-04 13:15:09 +08:00
hi-rustin
f67b58f93f Add test for unsupported short out dir flag 2023-10-04 12:41:19 +08:00
bors
9a94183771 Auto merge of #12744 - tompscanlan:atomic-write, r=epage
fix bug: corruption when cargo killed while writing

### What does this PR try to resolve?

fix  #11386, superseding #12362

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

Added unit test showing basic equivalency to existing `write(path, content)`. Full test suite should exercise write.
Added tests for cargo add and remove. These are timing tests, so take a bit of time to run. 5-10s each.  They may not fail every time, but do so regularly.  Making the change to these two writes seems to prevent me from failing these tests at all.

### Additional information

This uses tempfile::persist which was an existing dependency. atomicwrites crate, an alternative option for this fix, indicates `tempfile::persist` is the same thing.  Since we already use tempfile as a dep, I stuck with that.
2023-10-02 13:34:00 +00:00
bors
1f94bf2db8 Auto merge of #12763 - ehuss:custom_bin_target-windows-gnu, r=weihanglo
Disable custom_target::custom_bin_target on windows-gnu

The `custom_target::custom_bin_target` test has been crashing frequently in CI on the x86_64-pc-windows-gnu target since the last LLVM 17 update. This disables the test to reduce the disruption in CI. The issue is being tracked in https://github.com/rust-lang/rust/issues/115985.
2023-10-02 04:12:23 +00:00
Eric Huss
704a5d32b5 Disable custom_target::custom_bin_target on windows-gnu 2023-10-01 19:14:46 -07:00
Tom Scanlan
aee8c75410
bug: corruption when killed while writing 2023-10-01 08:29:24 -04:00
bors
e3acdd321f Auto merge of #12723 - hi-rustin:rustin-patch-silent, r=weihanglo
Add better suggestion for the unsupported silent flag
2023-09-28 07:06:25 +00:00
hi-rustin
44d955b15d Fix test on windows 2023-09-28 10:10:19 +08:00
hi-rustin
5d8009a189 Better suggestion for unsupported silent flag 2023-09-28 09:25:17 +08:00
bors
25dc3bdc5d Auto merge of #12681 - epage:frontmatter, r=Muscraft
feat(embedded): Hack in code fence support

### What does this PR try to resolve?

This is to allow us to get feedback on the design proposed
[on zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Embedding.20cargo.20manifests.20in.20rust.20source/near/391427092)
to verify we want to make an RFC for this syntax.

````rust
#!/usr/bin/env cargo
```cargo
[dependencies]
clap = { version = "4.2", features = ["derive"] }
```

use clap::Parser;

#[derive(Parser, Debug)]
#[clap(version)]
struct Args {
    #[clap(short, long, help = "Path to config")]
    config: Option<std::path::PathBuf>,
}

fn main() {
    let args = Args::parse();
    println!("{:?}", args);
}
````

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

The tests were updated in a separate commit to ensure there was no regression while then migrating to the new syntax to make sure it worked.

This involves some future work
- Removing doc comment support
- Getting the syntax approved and implemented
- Migrating to rustc support for the syntax

#12207 was updated to record these items so we don't lose track of them
2023-09-26 15:35:38 +00:00
bors
0b6cc3c75f Auto merge of #12732 - tompscanlan:12576-registry-error-msg, r=epage
more specific registry index not found msg

### What does this PR try to resolve?

covers #12576

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

test covers exact text, so a review and passing tests.
2023-09-25 17:41:03 +00:00
Tom Scanlan
3393fdc528
more specific registry index not found msg 2023-09-24 15:43:18 -04:00
Eric Huss
ebea09d8f4 Fix spurious errors with networking tests. 2023-09-22 13:37:26 -07:00
hi-rustin
61648f583e Add test for unsupported silent flag 2023-09-22 10:50:23 +08:00
Weihang Lo
a30d9fde98
test: verify source replacement displays registry key 2023-09-21 12:53:24 +08:00
bors
5bf83d8146 Auto merge of #12693 - hi-rustin:rustin-patch-unsupported-flags, r=epage
Better suggestion for unsupported mode in build command
2023-09-21 02:40:07 +00:00
hi-rustin
97656fbf87 Correct the helper name and the tip message 2023-09-21 10:12:03 +08:00
hi-rustin
817c2cbbb5 Better suggestion for unsupported mode in install command 2023-09-20 11:31:36 +08:00
hi-rustin
7644a4bd96 Add test for using unsupported mode in install command 2023-09-20 11:27:56 +08:00
hi-rustin
ed86337492 Better suggestion for unsupported mode in build command 2023-09-20 11:24:44 +08:00
hi-rustin
f262297e9a Add test for using unsupported mode in build command 2023-09-20 11:23:01 +08:00
Eric Huss
c2047345bd Don't display paths with cargo clean --dry-run without --verbose
The paths themselves aren't particularly interesting.
2023-09-19 18:24:45 -07:00
Eric Huss
f61d42d5ef Add a warning to cargo clean --dry-run
This makes it more consistent with other `--dry-run` commands, and
makes it clearer to the user that cargo did not do anything.
2023-09-19 18:24:45 -07:00
Eric Huss
ebee726d8f Separately track files and directories removed.
The previous status line was a little awkward in the way it combined
both counts. I don't think showing the directories is particularly
interesting, so they are only displayed when no files are deleted.
2023-09-19 18:24:37 -07:00
Eric Huss
495ed7ebe2 Add a summary to cargo clean.
This adds a summary at the end when `cargo clean` finishes that displays
how many files and bytes were removed.
2023-09-19 18:16:40 -07:00
Eric Huss
45c5394703 Add a --dry-run option to cargo clean.
This adds a `--dry-run` option to have `cargo clean` display what it
would delete without actually deleting it.
2023-09-19 18:14:47 -07:00
bors
f9335babbc Auto merge of #12707 - epage:spell, r=ehuss
chore: Fix typos

This is a repeat of #11561
2023-09-19 22:07:03 +00:00
Ed Page
e4e10f2393 chore: Fix typos
This is a repeat of #11561
2023-09-19 15:28:48 -05:00
Angelo Ross
72dccecb19
Display only feature list or summarized on cargo add 2023-09-19 13:14:44 -03:00