12629 Commits

Author SHA1 Message Date
Dawid Ciężarkiewicz
c712f08862 Do not add home bin path to PATH if it's already there
This is to allow users to control the order via PATH if they so desire.

Fix #11020
2022-09-08 09:37:41 -07:00
bors
404889d869 Auto merge of #11044 - Eh2406:file_hash, r=weihanglo
Cache index files based on contents hash

Since #10507 Cargo has known how to read registry cached files whose index version starts with the hash of the file contents. Git makes it very cheap to determine the hash of a file. This PR switches cargo to start writing the new format.

Cargoes from before #10507 will not know how to read, and therefore overwrite, cached files written by Cargos after this PR.

Cargos after this PR can still read, and will consider up-to-date cached files written by all older Cargos.

As I'm writing this out I'm thinking that there may not be any point in writing a file that has both. An alternative implementation just writes the file contents hash. 🤔
2022-09-08 01:14:07 +00:00
bors
9ecc7f8c40 Auto merge of #11051 - EstebanBorai:fix/specify-crate-name-maxlength, r=weihanglo
fix: specifies the max length for crate name

Provides the maximum length on the crate name as is defined
in the [crate's validation source code from crates.io][1].

[1]: 3fc08ba57e/src/models/krate.rs (L74)
2022-09-08 00:35:22 +00:00
Esteban Borai
98ccc09eb5 fix: remove wrapping for sentence 2022-09-05 21:01:56 -04:00
Esteban Borai
1175ee81bf
fix: add periods to list items
Co-authored-by: Weihang Lo <weihanglo@users.noreply.github.com>
2022-09-05 21:57:30 -03:00
Esteban Borai
8913cbfc66 fix: list under restrictions 2022-09-04 15:53:16 -04:00
Esteban Borai
622124f940 fix: specifies the max length for crate name
Provides the maximum length on the crate name as is defined
in the [crate's validation source code from crates.io][1].

[1]: 3fc08ba57e/src/models/krate.rs (L74)
2022-09-04 14:46:50 -04:00
Jacob Finkelman
e24222e11c only wright contents hash 2022-09-02 14:56:58 +00:00
bors
646e9a0b9e Auto merge of #10511 - weihanglo:issue-10477, r=ehuss
Support inheriting jobserver fd for external subcommands
2022-09-02 14:29:28 +00:00
Jacob Finkelman
898e508afd Cache based on contents hash 2022-09-01 19:47:52 +00:00
bors
04a4081f11 Auto merge of #11029 - epage:config, r=weihanglo
refactor(cli): Lazy load config

This is trying to clarify `-C` support when it is implemented in #10952

Cargo currently has two initialization states for Config, `Config::default` (process start) and `config.configure` (after parsing args).  The most help we provide for a developer touching this code is a giant `CAUTION` comment in one of the relevant functions.

Currently, #10952 adds another configuration state in the middle where the `current_dir` has been set.

The goal of this PR is to remove that third configuration state by
- Lazy loading `Config::default` so it can be called after parsing `-C`
- Allowing `-C` support to assert that the config isn't loaded yet to catch bugs with it

The hope is this will make the intent of the code clearer and reduce the chance for bugs.

In doing this, there are two intermediate refactorings
- Make help behave like other subcommands
  - Before, we had hacks to intercept raw arguments and to intercept clap errors and assume what their intention was to be able to implement our help system.
  - This flips it around and makes help like any other subcommand,
simplifying cargo initialization.
  - We had to upgrade clap because this exposed a bug where `Command::print_help` wasn't respecting `disable_colored_help(true)`
- Delay fix's access to config

Personally, I also find both changes make the intent of the code clearer.

To review this, I recommend looking at the individual commits.   As this is just refactors, this has no impact on testing.
2022-09-01 06:05:27 +00:00
Ed Page
eda1652b40 refactor(cli): Lazily do first-pass config loading
This will be a help for cases like #10952 which I would expect would
assert that the config is not loaded before changing the current_dir.
2022-08-31 19:23:35 -05:00
Ed Page
ddc21ea4cd refactor(cli): Delay fix's access to config
My hope is to make it so we can lazy load the config.  This makes it so
we only load the config for the fix proxy if needed.

I also feel like this better clarifies the intention of the code that we
are running in a special mode.
2022-08-31 19:19:37 -05:00
Ed Page
d674c2294b refactor(cli): Make help behave like other subcommands
Before, we had hacks to intercept raw arguments and to intercept clap
errors and assume what their intention was to be able to implement our
help system.

This flips it around and makes help like any other subcommand,
simplifying cargo initialization.
2022-08-31 19:18:26 -05:00
bors
d2ea9af0ff Auto merge of #11040 - epage:confusion, r=ehuss
chore: Don't show genned docs in ripgrep

The goal is to help new (and existing) users more quickly find the
appropriate files to edit (like in #11033).  The main downside is for
someone trying to find output to verify what it looks like, a simple
search won't turn up results but there are other ways around that
(`--no-ignore`, `git status` after doing a man generation, etc).
2022-09-01 00:00:35 +00:00
bors
f126ea4a83 Auto merge of #11019 - weihanglo:doc-private-items-cargo-itself, r=epage
Document private items for Cargo and publish under contributor guide
2022-08-31 21:57:00 +00:00
bors
5276a04a25 Auto merge of #11039 - ehuss:ci-names, r=epage
Add names to CI jobs

This adds names to the CI jobs. I've often found the existing auto-generated names to be confusing, and I think it would help to make them a little more succinct and clearer.

Before:
<img width="314" alt="image" src="https://user-images.githubusercontent.com/43198/187777515-6237f765-d747-4d74-8e06-baa86fbe8b2f.png">

After:
<img width="295" alt="image" src="https://user-images.githubusercontent.com/43198/187777559-6e21f08a-cf4c-4aaf-86ba-201bdd90c84f.png">
2022-08-31 21:14:13 +00:00
Ed Page
ffaf4b119e chore: Don't show genned docs in ripgrep
The goal is to help new (and existing) users more quickly find the
appropriate files to edit (like in #11033).  The main downside is for
someone trying to find output to verify what it looks like, a simple
search won't turn up results but there are other ways around that
(`--no-ignore`, `git status` after doing a man generation, etc).
2022-08-31 16:13:32 -05:00
Eric Huss
783ec2ea7c Add names to CI jobs 2022-08-31 13:36:42 -07:00
bors
d705fb35f2 Auto merge of #11028 - ehuss:test-errors, r=weihanglo
Rework test error handling

This reworks how errors are handled when running tests and benchmarks. There were some cases where Cargo was eating the actual error and not displaying it. For example, if a test process fails to launch, it only displayed the `could not execute process` message, but didn't explain why it failed to execute. This fixes it to ensure that the full error chain is displayed.

This also tries to simplify how the errors are handled, and makes them more uniform across `test` and `bench`, and with doctests.

This also changes the `--no-fail-fast` behavior to report errors as they happen instead of grouped at the end (and prints a summary at the end). This helps to make it clearer when a nonstandard error happens. For example, before:

```
     Running tests/t1.rs (target/debug/deps/t1-bb449dfa37379ba1)

running 1 test
     Running tests/t2.rs (target/debug/deps/t2-1770ae8367bc97ce)

running 1 test
test bar ... FAILED

failures:

---- bar stdout ----
thread 'bar' panicked at 'y', tests/t2.rs:3:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    bar

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed.

Caused by:
  process didn't exit successfully: `/Users/eric/Temp/z12/target/debug/deps/t1-bb449dfa37379ba1` (signal: 11, SIGSEGV: invalid memory reference)
  process didn't exit successfully: `/Users/eric/Temp/z12/target/debug/deps/t2-1770ae8367bc97ce` (exit status: 101)
```

and the changes to that are:

```diff
`@@` -1,6 +1,10 `@@`
      Running tests/t1.rs (target/debug/deps/t1-bb449dfa37379ba1)

 running 1 test
+error: test failed, to rerun pass `--test t1`
+
+Caused by:
+  process didn't exit successfully: `/Users/eric/Temp/z12/target/debug/deps/t1-bb449dfa37379ba1` (signal: 11, SIGSEGV: invalid memory reference)
      Running tests/t2.rs (target/debug/deps/t2-1770ae8367bc97ce)

 running 1 test
`@@` -18,8 +22,7 `@@`

 test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

-error: test failed.
-
-Caused by:
-  process didn't exit successfully: `/Users/eric/Temp/z12/target/debug/deps/t1-bb449dfa37379ba1` (signal: 11, SIGSEGV: invalid memory reference)
-  process didn't exit successfully: `/Users/eric/Temp/z12/target/debug/deps/t2-1770ae8367bc97ce` (exit status: 101)
+error: test failed, to rerun pass `--test t2`
+error: 2 targets failed:
+    `--test t1`
+    `--test t2`
```

In the first example, when it says `Running tests/t1.rs`, there is no error message displayed until after all the tests finish, and that error message is not associated with the original test. This also includes the "to rerun" hint with `--no-fail-fast`.
2022-08-30 22:59:43 +00:00
bors
f75aee0a79 Auto merge of #11033 - buggymcbugfix:buggymcbugfix/cargo-add-docs, r=epage
Very slight `cargo add` documentation improvements

As discussed in https://github.com/rust-lang/book/pull/3331, a quick explanation of the `Features` part of the message that gets printed to stdout when adding some dependency.

Consider the following example:

```
cargo add my-crate
    Updating crates.io index
      Adding my-crate v0.1.0 to dependencies.
             Features:
             + foo
             - bar
```

It was not clear to me what `+foo` and `-bar` meant until `@carols10cents'` kindly explained it to me. Hopefully the documentation now clarifies this.

TODO:

- [x] Run `./build-man.sh`
2022-08-30 21:50:14 +00:00
Vilem Liepelt
9c8a8ea2ca Document cargo-add's feature message
This refers to the `Features` part of the message that gets printed to
stderr after successfully adding some dependency, e.g.:

```
cargo add my-crate
    Updating crates.io index
      Adding my-crate v0.1.0 to dependencies.
             Features:
             + foo
             - bar
```

This tells us that the `foo` feature is enabled and `bar` is disabled.
2022-08-30 22:58:34 +02:00
bors
996a6363ce Auto merge of #11030 - ehuss:update-installation-requirements, r=epage
Update compiling requirements.

This updates the requirements for building cargo itself. It adds a little more clarification on exactly what is needed, and what some of the options are.

This may be a little bit too much detail, as usually I suspect most users will just run `cargo build` and follow the error message instructions on what to install next.
2022-08-30 00:26:35 +00:00
Eric Huss
c2a5be7657 Update compiling requirements. 2022-08-29 16:10:09 -07:00
Eric Huss
23735d4c09 Rework test error handling 2022-08-27 19:23:30 -07:00
bors
4ed54cecce Auto merge of #11027 - tshepang:patch-1, r=ehuss
doc: pause, for readability
2022-08-27 18:41:39 +00:00
Tshepang Mbambo
1f88ef37ee
pause, for readability 2022-08-27 19:57:40 +02:00
bors
e5ec3a8ff9 Auto merge of #11004 - jonhoo:bump-git2, r=weihanglo
Bump git2 to 0.15 and libgit2-sys to 0.14

This will allow cargo to avoid vendored builds of git2 in up-to-date
environments going forward, and brings in the [libgit2 1.4.4 CVE fix].

[libgit2 1.4.4 CVE fix]: https://github.com/libgit2/libgit2/releases/tag/v1.4.4
2022-08-27 09:22:12 +00:00
bors
bcf18e5cf5 Auto merge of #11025 - hi-rustin:rustin-patch-typo, r=Eh2406
Fix typo

Just fix a typo. bacwkards -> backwards
2022-08-27 04:27:39 +00:00
hi-rustin
c1d1246eb7 Fix typo
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-08-27 11:20:52 +08:00
bors
716d401227 Auto merge of #11021 - 4TT1L4:patch-1, r=weihanglo
Update cargo-toml-vs-cargo-lock.md

 - Improved wording ('rev' is not a line)
2022-08-25 12:30:53 +00:00
4TT1L4
7e6c487b9c
Update cargo-toml-vs-cargo-lock.md
- Improved wording ('rev' is not a line)
2022-08-25 13:50:11 +02:00
Weihang Lo
1c82d9c8c3 Make CI build API doc 2022-08-25 12:19:49 +01:00
Weihang Lo
d12a8e7504 Add rustdoc for lib.rs 2022-08-25 12:19:49 +01:00
Weihang Lo
2e596d52f0 Fix rustdoc warnings when documenting private items 2022-08-25 12:19:49 +01:00
bors
9ded34a558 Auto merge of #10807 - dtolnay-contrib:sha256, r=weihanglo
Apply GitHub fast path even for partial hashes

### What does this PR try to resolve?

As flagged in https://github.com/rust-lang/cargo/pull/10079#issuecomment-1170940132, it's not great to assume that git SHAs would always be 40-character hex strings. In the future they will be longer.

> Git is on a long-term trajectory to move to SHA256 hashes ([current status](https://lwn.net/SubscriberLink/898522/f267d0e9b4fe9983/)). I suppose when that becomes available/the default it's possible for a 40-digit hex-encoded hash not to be the full hash. Will this fail for that case?

The implementation from #10079 fails in that situation because it turns dependencies of the form `{ git = "…", rev = "[…40 hex…]" }` into fetches with a refspec `+[…40 hex…]:refs/commit/[…40 hex…]`. That only works if the 40 hex digits are the *full* long hash of your commit. If it's really a prefix ("short hash") of a 64-hex-digit SHA-256 commit hash, you'd get a failure that resembles:

```console
error: failed to get `dependency` as a dependency of package `repro v0.0.0`

Caused by:
  failed to load source for dependency `dependency`

Caused by:
  Unable to update https://github.com/rust-lang/dependency?rev=b30694b4d9b29141298870b7993e9aee10940524

Caused by:
  revspec 'b30694b4d9b29141298870b7993e9aee10940524' not found; class=Reference (4); code=NotFound (-3)
```

This PR updates the implementation so that Cargo will curl GitHub to get a resolved long commit hash *even if* the `rev` specified for the git dependency in Cargo.toml already looks like a SHA-1 long hash.

### Performance considerations

 This reverses a (questionable, negligible) benefit of #10079 of skipping the curl when `rev` is a long hash and is not already present in the local clone. These curls take 200-250ms on my machine.

🟰 We retain the much larger benefit of #10079 which comes from being able to precisely fetch a single `rev`, instead of fetching all branches and tags in the upstream repo and hoping to find the rev somewhere in there. This accounts for the entire performance difference explained in the summary of that PR.

🟰 We still skip the curl when `rev` is a **long hash** of a commit that is already previously fetched.

🥳 After this PR, we also curl and hit fast path when `rev` is a **short hash** of some upstream commit. For example `{ git = "https://github.com/rust-lang/cargo", rev = "b30694b4d9" }` would previously have done the download-all-branches-and-tags codepath because `b30694b4d9` is not a long hash. After this PR, the curl to GitHub informs us that `b30694b4d9` resolves to the long hash `b30694b4d9b29141298870b7993e9aee10940524`, and we download just that commit instead of all-branches-and-tags.

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

I tested with the following dependency specs, using `/path/to/target/release/cargo generate-lockfile`.

```toml
# Before: slow path (fetch all branches and tags; 70K git objects)
# After: fast path (20K git objects)
cargo = { git = "https://github.com/rust-lang/cargo", rev = "b30694b4d9b2914129" }
```

```toml
# Before and after: fast path
cargo = { git = "https://github.com/rust-lang/cargo", rev = "b30694b4d9b29141298870b7993e9aee10940524" }
```

```toml
# Before and after: fast path
cargo = { git = "https://github.com/rust-lang/cargo", rev = "refs/heads/rust-1.14.0" }
```

```toml
# Before and after: same error "revspec 'rust-1.14.0' not found"
# You are supposed to use `branch = "rust-1.14.0"`, this is not considered a `rev`
cargo = { git = "https://github.com/rust-lang/cargo", rev = "rust-1.14.0" }
```

I made sure these all work both with and without `rm -rf ~/.cargo/git/db/cargo-* ~/.cargo/git/checkouts/cargo-*` in between each cargo invocation.

FYI `@djc`
2022-08-24 07:05:49 +00:00
bors
6da726708a Auto merge of #11017 - BlackHoleFox:non-ascii-names, r=weihanglo
Update non-ASCII crate name warning message

This PR fixes an outdated warning when initializing crates sometimes.

### What does this PR try to resolve?
Per [a Zulip convo](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Non-ASCII.20crate.20name.20status/near/294876491) on the topic, non-ASCII crate names are no longer allowed on any toolchain since https://github.com/rust-lang/rust/pull/73305, during the `non_ascii_idents` feature's development. Cargo however tells the user that they are accepted on Nightly. Rust and Cargo should agree on this point to avoid future confusion.

### How should we test and review this PR?
This should be covered by the existing test that was changed but if desired its easy to test with a checkout:

```
Running `/Users/fox/x/Forks/cargo/target/release/cargo init 'ああああ'`
warning: the name `ああああ` contains non-ASCII characters
Non-ASCII crate names are not supported by Rust.
```
2022-08-23 21:39:56 +00:00
BlackHoleFox
b676088572 Update non-ASCII crate name warning message 2022-08-23 14:23:59 -05:00
bors
fee1c7f285 Auto merge of #11011 - hi-rustin:rustin-patch-tests, r=epage
Add more tests for aggressive or precise update

### What does this PR try to resolve?

When I was working on https://github.com/rust-lang/cargo/pull/10988, I found there is no test for the aggressive update. So I added it.

Also, I added a test for precise update to make sure it won't force update the deps of SPEC.
### How should we test and review this PR?

Unit tests.
2022-08-22 16:51:27 +00:00
hi-rustin
64e3991907 Remove useless log deps and add more test for precise update
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-08-21 17:16:01 +08:00
hi-rustin
f0b5bdad65 Add test for aggressive update
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-08-21 17:14:07 +08:00
bors
1ac83ba696 Auto merge of #11008 - weihanglo:issue-10917, r=epage
Ignore broken but excluded file during traversing
2022-08-21 01:45:41 +00:00
Weihang Lo
c0110c6382
Ignore broken but excluded file during traversing
Walkdir's [`filter_entry()`][1] won't call the predicate if the entry
is essentially an `Err` from its underyling `IntoIter`. That means
Cargo hasn't had a chance to call `filter` on an entry that should be
excluded but eventually return an `Err` and cause the loop to stop.
For instance, a broken symlink which should bee excluded by `filter`
will generate an error since `filter` closure is not called with it.

The solution is calling `filter` if an error occurs with a path
(because it has yet been called with that path).
If it's exactly excluded, ignore the error.

[1]: abf3a15887/src/lib.rs (L1042-L1058)
2022-08-20 00:56:43 +01:00
Weihang Lo
52a418c516
test: ignore broken but excluded file during traversing 2022-08-20 00:56:43 +01:00
Weihang Lo
09ff1944ca
Remove unnecessary mutability 2022-08-20 00:56:39 +01:00
bors
6066463e27 Auto merge of #10999 - hi-rustin:rustin-patch-wrong-names, r=epage
Improve error message for wrong target names

### What does this PR try to resolve?

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

We can print all available targets for users.

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

- [x] unit test
2022-08-19 14:35:26 +00:00
hi-rustin
99b3564d0d Update old tests
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-08-19 10:56:29 +08:00
hi-rustin
abb463a7aa Improve error message for wrong target names 2022-08-19 10:53:09 +08:00
bors
0c57749ca3 Auto merge of #11005 - jonhoo:bump-snapbox, r=epage
Bump snapbox to 0.3

0.3 has a small number of [breaking changes], but makes diffs much
easier to visually parse by eliding large sections of unchanged content.

[breaking changes]: https://github.com/assert-rs/trycmd/blob/main/crates/snapbox/CHANGELOG.md#030---2022-08-01

r? `@epage`
2022-08-18 01:16:09 +00:00
Jon Gjengset
222e0e51ff Disable owner validation for Cargo-as-a-binary 2022-08-17 23:46:27 +00:00