Commit graph

2717 commits

Author SHA1 Message Date
likzn b486ada19f clean err msg 2022-05-26 08:49:06 +08:00
likzn 52165e8c2d update 2022-05-25 18:17:08 +08:00
likzn 72d6c5411a cargo fmt 2022-05-24 09:15:44 +08:00
likzn 72457ef462 fix test stderr 2022-05-24 09:09:57 +08:00
likzn 1179e7ef6b cargo fmt 2022-05-23 21:06:34 +08:00
likzn 89c24bf811 refactor logic 2022-05-23 21:01:55 +08:00
likzn a5a0f6809d fix typo 2022-05-18 23:42:42 +08:00
likzn 95cb21d6a1 fix cargo -p 2022-05-18 22:40:55 +08:00
Eric Huss e952070946 Fix no_cross_doctests race condition. 2022-05-11 14:10:49 -07:00
bors 23ae8a0a0f Auto merge of #10650 - epage:install, r=ehuss
feat(install): Support `foo@version` like cargo-add

### What does this PR try to resolve?

This aims to make `cargo install` consistent with
- `cargo add foo@version` from #10472
- pkgid changes in #10582
- `cargo yank foo@version` from #10597

It also offers a shorthand for people installing a specific version.

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

#10582 acted as the FCP for this, see #10597

Documentation updates are split into their own commit to not clog up browsing the code.

Examine the tests to see if they make sense

### Additional information

While the `foo@vewrsion` syntax is the same, each's semantics are different.  We had decided it was better to have the same syntax with different semantics than having the user worry about what syntax they use where.  In `cargo install`s case, it has an
implicit-but-required `=` operand while `cargo-add` allows any operand.

This doesn't use the full `pkgid` syntax because that allows syntax that
is unsupported here.

This doesn't use `cargo-add`s parser because that is for version reqs.

I held off on reusing the parser from `cargo-yank` because they had
different type system needs and the level of duplication didn't seem
worth it (see Rule of Three).
2022-05-11 03:25:36 +00:00
bors 08bef9dfb7 Auto merge of #10649 - Muscraft:fix-typos, r=epage
fix typos found by the `typos-cli` crate

This fixes various typos inside `cargo`. They were found by [`typos-cli`](https://crates.io/crates/typos-cli). A few different typos were left out as they seemed either intentional or were needed. Typos found in `LICENSE-THIRD-PARTY` were left alone as well.

r? `@epage`
2022-05-10 23:58:15 +00:00
Scott Schafer cab6d30c1d fix typos found by the typos-cli crate 2022-05-10 16:47:28 -05:00
bors b3f6772a66 Auto merge of #10646 - koic:use_rust_2021_prelude, r=epage
Use the traits added to the Rust 2021 Edition prelude

Follow up https://github.com/rust-lang/rust/pull/96861.

This PR uses the traits added to the Rust 2021 Edition prelude.

> The `TryInto`, `TryFrom` and `FromIterator` traits are now part of the prelude.

https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html
2022-05-10 16:48:05 +00:00
bors cc9e3014a3 Auto merge of #10594 - weihanglo:issue-10560, r=ehuss
Pass `--target` to `rustdoc` for `cargo test` if specified with host target.
2022-05-10 15:56:03 +00:00
Koichi ITO 1626762fe4 Use the traits added to the Rust 2021 Edition prelude
Follow up https://github.com/rust-lang/rust/pull/96861.

This PR uses the traits added to the Rust 2021 Edition prelude.

> The `TryInto`, `TryFrom` and `FromIterator` traits are now part of the prelude.

https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html
2022-05-10 21:46:45 +09:00
Weihang Lo ba2b250c2e
test: pass --target to rustdoc even if specified with host target 2022-05-10 16:56:19 +08:00
bors 9fa2bba679 Auto merge of #10281 - Gnurfos:depinfo_relative, r=ehuss
Fix use of .. in dep-info-basedir

### Summary

This allows setting, in .cargo/config's dep-info-basedir, some relative path that goes above the crate's directory.

### Motivation

In a setup like this:

```
repo_root
├── Makefile
├── some_c_things
│   └── foo.c
└── rust_things
    ├── Cargo.toml
    └─── src
        └── lib.rs
```

If you want the generated .d files to be includable directly in the Makefile (without post-processing), you need them to mention paths relative to the root, like:

rust_things/target/....: rust_things/src/lib.rs

### Implementation

For this you need to have relative paths with parent directories (in this case ..) in dep-info-basedir, which does not work without the change in this PR (due to render_filename doing only strip_prefix, while the basedir still contains literal ..s).

Let me know if this change is acceptable. Another implementation could be to canonicalize in ConfigRelativePath::resolve_path instead, especially since that struct outputs absolute paths. But that would have it access the filesystem, while it currently doesn't.
2022-05-07 19:49:54 +00:00
cuishuang 6f13c466d2 fix some typos
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-05-08 01:07:28 +08:00
bors 9c61a3d10b Auto merge of #10638 - Muscraft:move-snapshot-tests, r=epage
Move snapshot tests into testsuite

This moves all tests from the `snapshot` folder into the `testsuite` folder as described by [this comment](https://github.com/rust-lang/cargo/pull/10631#discussion_r866306441). A macro was also added so there is no need to specify the path in a `snapshot` test just the file. This was done for ease of refactoring and ease of porting new tests to `snapshot`

close #10627

r? `@epage`
2022-05-07 02:14:00 +00:00
Scott Schafer 639f3bdea5 move all snapshot/init/ tests to testsuite/init/ 2022-05-06 20:51:49 -05:00
Scott Schafer 92fbc4e344 move all snapshot/cargo_add/ tests to testsuite/cargo_add/ 2022-05-06 20:51:29 -05:00
Loïc BRANSTETT cf496db45e Re-enable check-cfg tests under windows with a custom macro for escaping 2022-05-06 22:42:30 +02:00
Loïc BRANSTETT 2d0ca84b0e Move check cfg tests to their own module 2022-05-06 22:42:28 +02:00
Loïc BRANSTETT 6a9f094c8c Convert the testsuite to use the new -Zcheck-cfg flag and syntax 2022-05-06 22:40:08 +02:00
bors 08b8fe5c2d Auto merge of #10142 - jyn514:bin-private-link, r=ehuss
When documenting private items in a binary, ignore warnings about links to private items

Previously, rustdoc would warn about linking to private items in a binary, even
though cargo unconditionally documents private items in a binary.
This changes cargo to silence the warning, since it's only relevant in
cases where the private items might not be documented.

Fixes https://github.com/rust-lang/rust/issues/89600.
2022-05-06 19:48:59 +00:00
bors 0f75da631b Auto merge of #10582 - epage:pkgid, r=ehuss
Extend pkgid syntax with `@` support

In addition to `foo:1.2.3`, we now support `foo@1.2.3` for pkgids.  We
are also making it the default way of rendering pkgid's for the user.

### What does this PR try to resolve?

With cargo-add in #10472, we've decided to only use ``@`` in it and to add
it as an alternative to `:` in the rest of cargo.  `cargo-add`
originally used ``@`.`  When preparing it for merge, I switched to `:` to
be consistent with pkgids. When discussing this, it was felt ``@`` has
precedence in too many tools to switch to `:` but that we should instead
switch pkgid's to use ``@`,` in a backwards compatible way.  #10472 served
as the change proposal for this

See also
- https://internals.rust-lang.org/t/feedback-on-cargo-add-before-its-merged/16024/26?u=epage
- https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Multiple.20ways.20of.20specifying.20versions

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

The focus of the testing is on the parsers unit tests and on the end-to-end output.  We are not explicitly testing end-to-end input in this PR, assuming the unit tests are sufficient.

### Additional information

This only focuses on places we already accept pkgids.  Looking into supporting `foo@1.2.3` in `cargo install` and `cargo yank` is being left for a future PR.
2022-05-06 19:07:07 +00:00
Scott Schafer ea312988fb move a snapshot/add/ test into testsuite/cargo_add directory 2022-05-06 10:31:58 -05:00
bors 05a53e7293 Auto merge of #10629 - Muscraft:reorganize-snapshot-tests, r=epage
reorganize `snapshot` tests to better work in contexts that sort by extension

Changed snapshot file stricture from
```
<name>.in/
<name>.out/
<name>.stdout
<name>.stderr
```

To
```
<name>/in/
<name>/out/
<name>/stdout.log
<name>/stderr.log
```

This makes it easier to review and make changes when in contexts that sort by extension

close #10626

r? `@epage`
2022-05-04 14:42:24 +00:00
Scott Schafer 0602320c6a reorganize snapshot tests for init to better work in contexts that sort by extension 2022-05-04 08:58:30 -05:00
Scott Schafer 87833663f4 reorganize snapshot tests for cargo-add to better work in contexts that sort by extension 2022-05-04 08:55:55 -05:00
bors a44758ac80 Auto merge of #10129 - jyn514:fetch-build-std, r=weihanglo
Add support for `-Zbuild-std` to `cargo fetch`

This allows downloading the dependencies for libstd in advance, which
can be useful in e.g. sandboxed build environments.

Fixes https://github.com/rust-lang/wg-cargo-std-aware/issues/22.

r? `@ehuss`
2022-05-04 02:29:34 +00:00
Joshua Nelson 55b680c194 Add support for -Zbuild-std to cargo fetch
This allows downloading the dependencies for libstd in advance, which
can be useful in e.g. sandboxed build environments.

- Abstract check for `--target` out into a function
- Try to abstract `test` special-casing into a function

  This avoids hard-coding crate names in multiple places.

- Unify handling of checks for `--target` in `BuildConfig::new`

  This makes sure it's checked consistently, without requiring each new command to check it explicitly.

- Share more code between `fetch` and `build` by adding `std_crates()`
- Warn about `--build-plan` and `-Zbuild-std` consistently, not just for `build`

  Currently only `build` uses build-plan. But cargo may choose to add it to new commands in the future (e.g. check and doc).
  Future-proof it, since it's simple to do.
2022-05-03 20:07:14 -05:00
Joshua Nelson 727baf0db1 When documenting private items in a binary, ignore warnings about links to private items
Previously, rustdoc would warn about linking to items in a binary, even
though cargo unconditionally documents private items in a binary.
This changes cargo to silence the warning, since it's only relevant in
cases where the private items might not be documented.
2022-05-03 20:03:44 -05:00
Weihang Lo 20c0c581f8
Note that .git folder cannot be tracked under a git repo 2022-05-04 06:32:02 +08:00
Weihang Lo aff8e810d1
Use snapbox assertion instead of old Project::cargo 2022-05-03 09:53:53 +08:00
Weihang Lo 9171e18b72
Migrate tests of cargo-init to snapbox
Some redundant tests are merged or deleted.

- `gitignore_appended_not_replaced` -> `git_ignore_exists_no_conflicting_entries`
- `gitignore_added_newline_in_existing` -> `git_ignore_exists_no_conflicting_entries`
- `gitignore_no_newline_in_new` -> `simple_git`
- `terminating_newline_in_existing_git_ignore` -> `git_ignore_exists_no_conflicting_entries`
- `terminating_newline_in_new_git_ignore` -> `simple_git`
- `terminating_newline_in_new_mercurial_ignore` -> `simple_hg`
- `terminating_newline_in_existing_mercurial_ignore` -> `simple_hg_ignore_exists`
- `mercurial_added_newline_in_existing` -> `simple_hg_ignore_exists`
- `mercurial_no_newline_in_new` -> `simple_hg`
- `cargo_lock_gitignored_if_lib1` -> `simple_git`
- `cargo_lock_gitignored_if_lib2` -> `inferred_lib_with_git`
- `cargo_lock_not_gitignored_if_bin2` -> `inferred_bin_with_git`
- `cargo_lock_not_gitignored_if_bin1` -> `explicit_bin_with_git`
2022-05-02 08:16:06 +08:00
Ed Page d6e912ca32 feat(test-support): Make multi-argument strings avaialble to snapbox
This is something the existing test infrastructure supports, so I
figured I'd make it mirror it for snapbox.  I'm mixed.
- It reads more like what a user would type, making it easier to run a
  test locally or take a manual test case and automate it
- It can make it harder to parse the arguments when scanning tests
- Without using a crate like `shlex`, the syntax support is unclear
2022-04-27 20:57:19 -05:00
Ed Page 83d444040c feat(test-support): Make it easy to launch cargo 2022-04-27 20:57:17 -05:00
Ed Page c9e82ec197 feat(test-support): Expose test-env setup 2022-04-27 20:57:03 -05:00
Ed Page 79ef00c60b feat(test-support): Expose masquerade_as_nightly_cargo to snapbox users 2022-04-27 20:56:20 -05:00
Ed Page 0d135a0b43 feat(test-support): Share Project::from_template with all cargo tests
This was written for `cargo_add.rs`, based on `snapbox`.  This allows
creating a test from a known reproduction case or easily debugging on an
existing test case.
2022-04-27 20:53:25 -05:00
Ed Page 30451d2ffc feat(test-support): Allow reusing snapbox assertions 2022-04-27 20:45:36 -05:00
Ed Page 5eaec4fa2f refactor(test-support): Use snapbox to look up binaries 2022-04-27 20:45:36 -05:00
Ed Page 07681341da feat(install): Support foo@version like cargo-add
In #10472, cargo-add was merged with support for an inline version
syntax of `foo@version`.  That also served as the change proposal for
extending that syntax to `cargo install` for convinience and consistency.

While both commands are specifying a version-req, `cargo-install` has an
implicit-but-required `=` operand while `cargo-add` allows any operand.

This doesn't use the full `pkgid` syntax because that allows syntax that
is unsupported here.

This doesn't use `cargo-add`s parser because that is for version reqs.

I held off on reusing the parser from `cargo-yank` because they had
different type system needs and the level of duplication didn't seem
worth it (see Rule of Three).
2022-04-27 20:44:26 -05:00
Scott Schafer aa7d116a4a Support overwriting a foo.workspace = true with a dependency from a different source 2022-04-27 16:04:50 -05:00
Scott Schafer cf2202ca65 Error if any invalid keys are defined when inheriting a workspace dependency 2022-04-27 16:03:35 -05:00
Scott Schafer 9ee3cffb9e Detect cargo add foo will inherit a workspace dependency 2022-04-27 16:02:10 -05:00
Scott Schafer 1b70c2295f Show the merged set of activated features to the user when inheriting from a workspace dependency 2022-04-27 15:59:38 -05:00
Scott Schafer f217a6cd6d Allow running cargo add foo when a foo.workspace = true already exists 2022-04-27 15:58:30 -05:00
bors 7a3b56b486 Auto merge of #10553 - sourcefrog:cachedir, r=weihanglo
Mark .cargo/git and .cargo/registry as cache dirs

Fixes #10457

### What does this PR try to resolve?

As we previously discussed in #10457 this marks `~/.cargo/git` and `~/.cargo/registry` as not to be included in backups, and not subject to content indexing. These directories can be fairly large and frequently changed, and should only contain content that can be re-downloaded if necessary.

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

I did two manual tests:

1. Using the binary built from this tree, run `cargo update` in a source tree that has a git dependency, and observe that afterwards, there is a `CACHEDIR.TAG` in `~/.cargo/git`.
2. Similarly, run `cargo update` and observe that there's a `CACHEDIR.TAG` in `~/.cargo/registry`.

(I ran this on Linux. This code should also trigger OS-specific behavior on macOS and Windows that's the same as is currently applied to `target/`.)

I added some test assertions.
2022-04-27 08:55:00 +00:00