Commit graph

172 commits

Author SHA1 Message Date
Matheus Cardoso ecf05e4ff1
cargo install: suggest --git when package name is url 2023-08-27 23:04:21 -03:00
Ed Page 937932520b refactor(install): Move version parsing to the CLI 2023-08-23 16:22:31 -05:00
Ed Page 28b7c846af refactor(install): Shift crate argument parsing to clap 2023-08-23 15:25:05 -05:00
Weihang Lo b9e70ec0a2
test: relax assertions of panic handler message format 2023-07-29 17:12:46 +01:00
MarcusGrass 03675ef6a4
Add additional info on a new line 2023-06-05 11:27:31 +02:00
MarcusGrass 073a32b61f
Add message on reusing previous temporary path on failed cargo installs 2023-06-04 18:31:06 +02:00
Danil Hendra Suryawan 58b7bce63e feat(cli): emit error when install is given a toolchain name instead of crate name 2023-06-03 20:51:14 +07:00
Weihang Lo 7fb35c9c4e
test(install): correct the term workspace -> local packagd 2023-05-03 01:04:18 +01:00
Ted Kaminski 79bb2d7143 Update pkg-spec comment, and add 2 more test cases 2023-05-01 17:23:17 -05:00
Ted Kaminski 31d679e81a Build by PackageIdSpec, not name, to avoid ambiguity 2023-05-01 17:23:17 -05:00
Dom Slee 3363931f7f redundant escapes 2023-03-13 18:57:26 +11:00
Dom Slee ea27499a2e review comments 2023-03-13 17:54:45 +11:00
Dom Slee dc449bce6d cargo clippy + fmt 2023-03-12 23:52:45 +11:00
Dom Slee a668956dd7 improve error message and add related tests 2023-03-12 23:52:06 +11:00
Adrián Ortiz db457d950f Fixing issue https://github.com/rust-lang/cargo/issues/10834:
- Adding display of which target failed to compile
- Consistent messages for warnings/errors.
- Fixing assertions on related tests.
2023-03-07 06:45:26 +01:00
Eric Huss ab726e7e7f Fix test for Windows 2023-02-25 18:07:49 -08:00
Arlo Siemsen 16ad1f2945 Fix Cargo removing the sparse+ prefix from sparse URLs in .crates.toml 2023-02-25 18:07:46 -08:00
Eric Huss 736fb2f62a Fix warning with tempfile 2023-02-25 15:35:12 -08:00
bors 0625b29d84 Auto merge of #11410 - TrAyZeN:master, r=epage
Suggest cargo add when installing library crate

### What does this PR try to resolve?

When using `cargo install` instead of `cargo use` the error message is the following:
```
error: there is nothing to install in `foo v0.0.1`, because it has no binaries
`cargo install` is only for installing programs, and can't be used with libraries.
To use a library crate, add it as a dependency in a Cargo project instead.
```
It would be good to suggest to the user to use `cargo add`.

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

The `no_binaries` test from `tests/testsuite/install.rs` covers that case.
2023-02-23 18:44:31 +00:00
TrAyZeN 98edd706ad Suggest cargo add when installing library crate 2023-02-18 17:39:11 +01:00
Ed Page 6007f05a85 chore: Update to toml v0.6, toml_edit v0.18
`toml` replaces `toml_edit::easy`, using `toml_edit` as its parser.
2023-01-19 15:26:28 -06:00
bors 6c095cce88 Auto merge of #11558 - Muscraft:stabilize-cargo-fix-message, r=epage
feat: stabilize auto fix note

A note that some warnings could be fixed by running a `cargo fix` command was added in #10989 and made to work with `clippy` in #11399. It has only been turned on for `nightly` builds so far; this PR would make it show on `stable`.

The original motivation for making this note `nightly` only, was to [allow for iteration](https://github.com/rust-lang/cargo/issues/10976#issuecomment-1289297978) on the message output. There has yet to be any feedback on the message format in the time that it has been on `nightly`. This was brought up in a recent cargo team meeting and it was thought that we should move forward with showing this on `stable`.

close #10976
2023-01-22 00:50:42 +00:00
bors 23424fde2e Auto merge of #11067 - tedinski:install_workspace_root, r=weihanglo
Ignore `workspace.default-members` when running `cargo install` on root package of a non-virtual workspace

### What does this PR try to resolve?

* Fixes #11058

Two observable behaviors are fixed:

1. When running `cargo install` with `--path` or `--git` and specifically requesting the root package of a non-virtual workspace, `cargo install` will accidentally build `workspace.default-members` instead of the requested root package.
2. Further, if that `default-members` does not include the root package, it will install binaries from those other packages (the `default-members`) and claim they were the binaries from the root package! There is no way, actually, to install the root package binaries.

These two behaviors have the same root cause:

* `cargo install` effectively does `cargo build --release` in the requested package directory, but when this is the root of a non-virtual workspace, that builds `default-members` instead of the requested package.

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

I have included a test exhibiting this behavior. It currently fails in the manner indicated in the test, and passes with the changes included in this PR.

I'm not sure the solution in the PR is the _best_ solution, but the alternative I am able to come up with involves much more extensive changes to how `cargo install` works, to produce a distinct `CompileOptions` for every package built. I tried to keep the new workspace "API" `ignore_default_members()` as narrowly-scoped in its effect as possible.

### Additional information

The only way I could think this behavior change could impact someone is if they were somehow using `cargo install --path` (or `--git`) and wanting it to actually install the binaries from all of `default-members`. However, I don't believe that's possible, since if there are multiple packages with binaries, I believe cargo requires the packages to be specified. So someone would have to be additionally relying on specifying just the root package, but then wanting the binaries from more than just the root. I think this is probably an acceptable risk for merging!
2023-01-18 15:47:10 +00:00
Weihang Lo c51c6bb6ac
chore: reflect to clap updates 2023-01-14 09:23:39 +00:00
Ted Kaminski 7dc8be5414 Ignore workspace.default-members when running cargo install on root package of a non-virtual workspace 2023-01-13 00:12:06 +00:00
Scott Schafer 6131222ba2 feat: stabilize auto fix note 2023-01-10 13:52:29 -06:00
bors 79fe7573b0 Auto merge of #11401 - adam248:patch-1, r=ehuss
add newline char to `cargo install .` error message for easier reading.

I just noticed the `cargo install .` error message was not formatted very nicely.

Just added a newline char to make it cleaner.

Thanks
2022-11-25 13:34:10 +00:00
Adam Butler 1b7e256413 fixed typo causing broken cargo install . test case 2022-11-22 14:14:29 +09:30
Adam Butler db0d3f9de1
fixed cargo fmt error regarding unknown escape char. 2022-11-22 13:24:59 +09:30
Adam Butler c5836e97ba
fixed broken error made by newline char in cargo install . error message 2022-11-22 13:19:05 +09:30
Scott Schafer 8ff8eaa496 add a note that some warnings can be auto-fixed 2022-10-27 19:07:59 -05:00
Ed Page 96948f7a24 refactor(cli): Upgrade to clap v4 2022-09-28 13:32:14 -05:00
Scott Schafer c239e407e7 add a reason to masquerade_as_nightly_cargo so it is searchable 2022-07-15 21:32:23 -05:00
Arlo Siemsen 24dac452c5 Improve testing framework for http registries
Improve integration of the http server introduced by the http-registry feature.
Now the same HTTP server is used for serving downloads, the index, and
the API.

This makes it easier to write tests that deal with authentication and
http registries.
2022-06-10 16:51:35 -05: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
Scott Schafer cab6d30c1d fix typos found by the typos-cli crate 2022-05-10 16:47:28 -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
Ed Page 2313edd4b2 fix(yank): Use '--version' like install
During the design conversations on cargo-add, we noticed that
`cargo-install` has a public flag `--version` and an invisible alias
`--vers` while `cargo-yank` has a public flag `--vers`.  This switches
`cargo-yank` to publicly use `--version` and have an invisible alias
`--vers`, making them consistent.

Completions are a best guess.
2022-04-19 16:45:13 -05:00
David Tolnay b2b3bdeede
Consistently use crate::display_error on errors during drain 2022-02-17 13:59:06 -08:00
Ed Page 24defcbc14 fix(install): Keep v1 file formatting the same
Inspired by #10345, I looked for other cases where
`toml_edit::easy::to_string` is used (which outputs inline tables) to
see if we should switch to `to_string_pretty`.  The crates v1 file was
the only case I found.

As a side effect, we can no longer elide the empty `dev-dependencies`
table in published manifests.  This was the behavior before `toml_edit`,
so not much of a loss.
2022-01-31 10:42:05 -06:00
Weihang Lo 76301ebab9
Test: install bin with --path outside current workspace 2022-01-27 18:31:02 +08:00
Weihang Lo d323ad672c
Test: install with path outside current workspace
Make up this test case to reflect the current incorrect behavior.
2022-01-27 18:31:01 +08:00
Ed Page 320c279f43 Port cargo from toml-rs to toml_edit
Benefits:
- A TOML 1.0 compliant parser
- Unblock future work
  - Have `cargo init` add the current crate to the workspace, rather
    than error
  - #5586: Upstream `cargo-add`
2022-01-13 09:27:27 -06:00
hi-rustin 6351472a80 Add --message-format for install
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2021-11-21 12:16:50 +08:00
David Tolnay 05f6604660
Swap out some outdated repo urls in documentation 2021-08-31 13:33:02 -07:00
Nipunn Koorapati f9c2d04592 Factor into struct InstallablePackage 2021-08-19 09:57:53 -07:00
Weihang Lo 8c75e2ffa0
Update tests to use registry names 2021-07-22 00:50:30 +08:00
Joshua Nelson 9c7cc545d7 Combine rustc and cargo's diagnostic summaries
This works by introspecting rustc's error output, using the JSON format
to determine whether it's a warning or error, then skipping it
altogether if it's a summary of the diagnostics printed.

Before:

```
src/main.rs:1:10: warning: trait objects without an explicit `dyn` are deprecated
src/main.rs:1:1: error[E0601]: `main` function not found in crate `wrong`
src/main.rs:1:9: error[E0038]: the trait `Clone` cannot be made into an object
error: aborting due to 2 previous errors; 1 warning emitted
error: could not compile `wrong`

```

After:

```
$ cargo check --message-format short
src/main.rs:1:10: warning: trait objects without an explicit `dyn` are deprecated
src/main.rs:1:1: error[E0601]: `main` function not found in crate `wrong`
src/main.rs:1:9: error[E0038]: the trait `Clone` cannot be made into an object
error: could not compile `wrong` due to 2 previous errors; 1 warning emitted
```
2021-07-06 19:46:27 -04:00
hi-rustin b3a1d0ceba Only testing on linux 2021-06-22 15:36:32 +08:00
hi-rustin cb1a3f05f0 Detect incorrectly named cargo.toml for build 2021-06-22 15:31:28 +08:00