Commit graph

5437 commits

Author SHA1 Message Date
Eric Huss 1df0f1d734 Add allow(internal_features) 2023-08-05 12:11:07 -07:00
Weihang Lo c60c06585c
fix: clear cache for old .cargo-ok format
In 1.71, `.cargo-ok` changed to contain a JSON `{ v: 1 }` to indicate
the version of it. A failure of parsing will result in a heavy-hammer
approach that unpacks the `.crate` file again. This is in response to a
security issue that the unpacking didn't respect umask on Unix systems.
2023-08-03 13:42:54 +01:00
Weihang Lo 4fafa69a4d
fix: respect umask when unpacking .crate files
Without this, an attacker can leverage globally writable files buried
in the `.crate` file. After a user downloaded and unpacked the file,
the attacker can then write malicous code to the downloaded sources.
2023-08-03 13:41:08 +01:00
Weihang Lo 789a2fb4bf
test: verify permissions bits are preserved when unpacking
This is not secure and will be fixed in the next commit.
2023-08-03 13:39:48 +01:00
Arlo Siemsen 65ec65fe1e Fix printing multiple warning messages for unused fields in [registries] table 2023-08-02 18:20:46 -05:00
bors 6dc1deaddf Auto merge of #12429 - Nilstrieb:we-love-internal-features, r=weihanglo
`#[allow(internal_features)]` in RUSTC_BOOTSTRAP test

This will be required in the future (where "the future" is rust-lang/rust#108955 which fails CI because of cargo here).

This does emit the unknown lints lint right now but that doesn't matter as it's just warn-by-default - internal_features is deny-by-default though, so it causes errors.
2023-08-02 00:23:54 +00:00
Nilstrieb b2720536b0 #[allow(internal_features)] in RUSTC_BOOTSTRAP test
This will be required in the future (where "the future" is my PR
which fails CI because of cargo here).
2023-08-01 18:18:29 +02:00
bors baebd2bfb6 Auto merge of #12428 - epage:update, r=weihanglo
fix(update): Tweak CLI behavior

### What does this PR try to resolve?

When looking at `cargo update` for #12425, I noticed that the two flags related to `--package` were not next to it or each other.  I figured grouping them like that would make things easier to browse.

When looking into that, I noticed that the two flags conflict and figured we'd provide a better error message if we did that through clap.

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

Looking per commit will help show the behavior changes.

### Additional information

I wanted to scope this to being simple, non-controversial, low effort, incremental improvements with this change so I did not look into the history of `--aggressive` not requiring  `--package` like `--precise` does and figure out if there is any consistency we can be working towards.
2023-08-01 15:20:25 +00:00
Ed Page 4fd0c3c46c fix(update): Group -p related flags 2023-07-31 21:21:02 -05:00
Ed Page 57762917fb fix(update): Perform error check in clap 2023-07-31 21:18:31 -05:00
Ed Page e290ed7a02 test(update): Add a --aggressive --precise error test 2023-07-31 21:16:54 -05:00
bors 29a6f2fab2 Auto merge of #12424 - arlosi:credential-thiserror, r=arlosi
Use thiserror for credential provider errors

### What does this PR try to resolve?
Errors from credential providers currently must a single string. This leads to a lot of `.map_err(|e|cargo_credential::Error::Other(e.to_string())`, which loses the `source()` of these errors.

This changes the `cargo_credential::Error` to use `thiserror` and adds a custom serialization for `std::error::Error` that preserves the source error chain across serialization / deserialization.

A unit test is added to verify serialization / deserialization.
2023-07-31 22:00:41 +00:00
Predrag Gruevski 2f59b20df6 Mention that cargo test --all-targets excludes doctests
Per my proposal here: https://github.com/rust-lang/cargo/issues/6669#issuecomment-1658593167

I tried to keep the edit minimalistic to match the surrounding style.

If the maintainers are amenable to it, I think it could also be useful to do one or more of:
- Offer concrete guidance on what to do to run actually-all tests (`--all-targets` then separately `--doc`).
- Link to the issue at: https://github.com/rust-lang/cargo/issues/6669
- Mention that `cargo test` without `--all-targets` runs doctests by default, which seems not immediately obvious.

I'd be happy to attempt to add any of the above that the maintainers feel would be a good fit here.
2023-07-31 20:09:24 +00:00
Arlo Siemsen a81d558941 Use thiserror for credential provider errors 2023-07-31 13:45:08 -05:00
bors 9fe58acfb7 Auto merge of #12411 - weihanglo:issue/12404, r=ehuss
fix: normalize relative git submodule urls with `ssh://`
2023-07-30 17:05:18 +00:00
Weihang Lo 8a4d04414e fix: normalize relative git submodule urls with ssh://
Git only assumes a submodule URL is a relative path if it starts with `./`
or `../` [^1]. To fetch the correct repo, we need to construct an aboslute
submodule URL.

At this moment it comes with some limitations:

* GitHub doesn't accept non-normalized URLs wth relative paths.
  (`ssh://git@github.com/rust-lang/cargo.git/relative/..` is invalid)
* `url` crate cannot parse SCP-like URLs.
  (`git@github.com:rust-lang/cargo.git` is not a valid WHATWG URL)

To overcome these, this patch always tries `Url::parse` first to normalize
the path. If it couldn't, append the relative path as the last resort and
pray the remote git service supports non-normalized URLs.

See also rust-lang/cargo#12404 and rust-lang/cargo#12295.

[^1]: <https://git-scm.com/docs/git-submodule>
2023-07-30 10:04:32 -07:00
Weihang Lo b59527901d
test: relax help text assertion
When running test in rust-lang/rust via `./x test src/tool/cargo`,
there is no rustup integrated.
2023-07-30 07:42:04 +01:00
bors 1680ab508e Auto merge of #12413 - weihanglo:tweak-panic-msg, r=ehuss
test: relax assertions of panic handler message format
2023-07-29 22:50:14 +00:00
Weihang Lo b9e70ec0a2
test: relax assertions of panic handler message format 2023-07-29 17:12:46 +01:00
hi-rustin 4bdeb53cb5 Bail out an error when using cargo:: in custom build script
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-07-27 23:00:52 +08:00
Ed Page cc6b6c9584 fix(package): Avoid multiple package list entries
To keep things simple, especially in getting a `Hash` implementation
correct, I'm leveraging `unicase` for case-insensitive
comparisons which is an existing dependency and I've been using for
years on other projects.

This also opens the door for us to add cross-platform compatibility
hazard warnings about multiple paths that would write to the same
location on a case insensitive file system.  I held off on that because
I assume we would want #12235 first.

This does mean we can't test the "no manifest" case anymore because the
one case (no pun intended) I knew of for hitting it is now gone.
2023-07-26 11:02:47 -05:00
Ed Page 9b14e39cd7 test(package): Verify mixed-case Cargo.toml 2023-07-26 10:10:21 -05:00
Ed Page 5101372312 test(cli): Track --help output
This makes it easier to evaluate the usability of PRs, like #11905
2023-07-24 17:12:20 -05:00
Ed Page 3166e5f614 fix(package): Warn when manifest is not more generally found
Being a bit cautious about not turning this into an error since this is
most likely because of case insensitive filesystems.
2023-07-24 16:49:38 -05:00
Ed Page f4c97b24a8 test(package): Verify the no-manifest case 2023-07-24 16:41:15 -05:00
Ed Page bbb6aff67a fix(package): Normalize cargo.toml to Cargo.toml for windows 2023-07-24 16:29:14 -05:00
Ed Page 5dd39df6f1 test(package): Verify cargo.toml behavior 2023-07-24 16:13:21 -05:00
bors 55281fd3ee Auto merge of #12398 - epage:cargo-config, r=weihanglo
refactor(test): Move cargo-config into a dir

This is split out of #11912 and is prep for adding more UI tests.

Generally our UI tests are in a directory named after the full cargo command (`cargo config`).  These tend to use `snapbox`.

Here we are tests for the `cargo config` command not written by `snapbox` in a `cargo_config.rs` file.  This conflicts with adding snapbox UI tests later in a `cargo_config/` folder.  Upon looking at this file, it appears to be UI tests, so I think it would make sense to move them into the `cargo_config/` folder.  Definitely wouldn't make sense to move them into `config.rs` since that is general config testing.
2023-07-24 20:14:19 +00:00
Ed Page f06911cb90 refactor(test): Move cargo-config into a dir
This is split out of #11912 and is prep for adding more UI tests.

Generally our UI tests are in a directory named after the full cargo
command (`cargo config`).  These tend to use `snapbox`.

Here we are tests for the `cargo config` command not written by
`snapbox` in a `cargo_config.rs` file.  This conflicts with adding
snapbox UI tests later in a `cargo_config/` folder.  Upon looking at this
file, it appears to be UI tests, so I think it would make sense to move
them into the `cargo_config/` folder.  Definitely wouldn't make sense to
move them into `config.rs` since that is general config testing.
2023-07-24 14:47:29 -05:00
Ed Page 79469f3019 refactor(tests): Name init ui tests more consistently
Currently, the UI tests are
- `cargo add`
- `cargo new`
- `cargo remove`
- `init`

One of these is not like the others. This change renames `init` to
`cargo_init` to suggest it is the UI tests for the `cargo init` command,
rather than `init` functionality.
2023-07-24 13:39:37 -05:00
bors 7c82ff2e06 Auto merge of #12280 - weihanglo:git-ref-ambiguity, r=ehuss
fix: encode URL params correctly for SourceId in Cargo.lock

We use [`form_urlencoded::byte_serialize`](https://docs.rs/form_urlencoded/1.2.0/form_urlencoded/fn.byte_serialize.html), which is re-exported by `url` crate. Tests are copied from <https://github.com/rust-lang/cargo/pull/11086>. Kudos to the original author!
2023-07-23 19:01:50 +00:00
Arlo Siemsen 6151a4152b Send all headers to cred provider 2023-07-21 17:30:01 -05:00
Arlo Siemsen 2b39792aef Credential provider implementation 2023-07-21 16:02:24 -05:00
bors b40be8bdcf Auto merge of #12310 - weihanglo:asymmetric-challenge, r=Eh2406
feat(crates-io): expose HTTP headers and Error type

### What does this PR try to resolve?

This is part of #11521.

[RFC 3231] mentions the authentication process could have an additional **challenge-response mechanism** to prevent potential replay attacks. The challenge usually comes from HTTP `www-authenticate` header as a opaque string. When a client gets a 401/403 response with such a challenge, it may attach the `challenge` to the payload and request again to anwser the challenge.

```
➡️ cargo  requests
⬅️ server responds with `www-authenticate` containing some opaque challenge string
➡️ cargo  automatically requests again without any user perception
⬅️ server responds ok
```

However, `crates-io` crate doesn't expose HTTP headers. There is no access to `www-authenticate` header.

This PR make it expose HTTP headers and the custom `Error` type, so `cargo` can access and do further on the authentication process.

[RFC 3231]: https://rust-lang.github.io/rfcs/3231-cargo-asymmetric-tokens.html#the-authentication-process
2023-07-20 22:19:10 +00:00
Charles Samborski 54ad4a01df fix(new): Don't ignore Cargo.lock for all package types
Following the default guidance to commit a lockfile, this updates
`cargo new` to do it by default.
2023-07-19 11:56:40 -05:00
bors fc6cf8c7f8 Auto merge of #12369 - jo1gi:readonly-cargo-home-subdirs, r=weihanglo
fix: only skip mtime check on `~/.cargo/{git,registry}`

Fixes #12090

Make cargo only skip mtime checks on `$CARGO_HOME/{git, registry}`.
2023-07-19 11:16:15 +00:00
Joakim Holm 839069f03f only skip mtime check on $CARGO_HOME/{git,registry}
Closes #12090

Commit

Fix formatting

Fix tests

Fix formatting

Fix formatting

Fix formatting
2023-07-19 12:38:56 +02:00
Weihang Lo 31b500c7c0
refactor(crates-io): use thiserror
Optionally use `thiserror` to reduce boilerplates but this part can
be dropped if we don't want.
2023-07-18 22:22:47 +01:00
bors 5a9f611178 Auto merge of #12359 - weihanglo:issue/12295, r=ehuss
fix(git): respect scp-like URL for nested submodules
2023-07-18 00:50:01 +00:00
Bart Massey b9bee5297e corrected unspecifiead to unspecified 2023-07-15 16:52:55 -07:00
Weihang Lo a7247babf6
fix(git): respect scp-like URL for nested submodules
`parent_remote_url` used to be `&str` before #12244. However, we changed
the type to `Url` and it started failing to parse scp-like URLs since
they are not compliant with WHATWG URL spec.

In this commit, we change it back to `&str` and construct the URL
manually. This should be safe since Cargo already checks if it is a
relative URL for that if branch.
2023-07-15 09:01:08 +01:00
bors 694a579566 Auto merge of #12349 - epage:sanitize, r=weihanglo
fix(embedded): Always generate valid package names

### What does this PR try to resolve?

The sanitization logic uses a placeholder for the first character that isn't valid in the first character position.  #12329 took the approach of always using `_` which has the problem of mixing separators if the user used `-` or we had other placeholders to insert.  Instead, this takes the approach of stripping the leading invalid characters and using a placeholder name if nothing is left.

Fixes #12330

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

Per-commit.  The first adds tests so the change in behavior can be observed over each additional commit.

### Additional information

I was also hoping to make the binary name not use placeholders by setting `bin.name` to `file_stem` but then I got
```
   Compiling s-h-w-c- v0.0.0 (/home/epage/src/personal/cargo/target/tmp/cit/t133/foo)
error: invalid character `'.'` in crate name: `s_h.w§c!`

error: invalid character `'§'` in crate name: `s_h.w§c!`

error: invalid character `'!'` in crate name: `s_h.w§c!`

error: could not compile `s-h-w-c-` (bin "s-h.w§c!") due to 3 previous errors
```
I decided to not get into what are or aren't valid characters according to rustc.
2023-07-11 22:28:29 +00:00
Ed Page 10fbb470bb fix(embedded): Error on unsupported commands
- `cargo pkgid` is unsupported because we can't (yet) generate valid
  pkgids for embedded manifests.  Adding support for this would be a
  step towards workspace support
- `cargo package` and `cargo publish` are being deferred.  These would
  be more important for `[lib]` support.  `cargo install` for `[[bin]]`s
  is a small case and As single-file packages are fairly restrictive, a
  `[[bin]]` is a lower priority.
2023-07-11 15:34:17 -05:00
Ed Page aaaa37f409 test(embedded): Add tests for unsupported commands 2023-07-11 15:26:28 -05:00
Ed Page 7d4e39c4f5 fix(embedded): Don't generate empty package names 2023-07-11 14:37:44 -05:00
Ed Page 87be661989 fix(embedded): Don't generate package names with invalid leading digit 2023-07-11 14:35:50 -05:00
Ed Page 09d6c79278 test(script): Verify existing leading number behavior 2023-07-11 14:27:36 -05:00
Ed Page 0e648c3ee4 fix(script): Be quiet on programmatic output
The goal is that we shouldn't interefere with end-user output when
"cargo script"s are used programmatically.  The only way to detect this
is when piping.  CI will also look like this.

My thought is that if someone does want to do `#!/usr/bin/env -S cargo -v`, it
should have a consistent meaning between local development
(`cargo run --manifest-path`) and "script mode" (`cargo`), so I
effectively added a new verbosity level in these cases.  To get normal
output in all cases, add a `-v` like the tests do.  Do `-vv` if you want
the normal `-v` mode.  If you want it always quiet, do `--quiet`.

I want to see the default verbosity for interactive "script mode" a bit
quieter to the point that all normal output cargo makes is cleared before
running the built binary.  I am holding off on that now as that could
tie into bigger conversations / refactors
(see https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Re-thinking.20cargo's.20output).
2023-06-22 19:27:00 -05:00
Ed Page 279077987b test(script): Verify verbosity 2023-06-22 19:27:00 -05:00
bors 2035d0d1b9 Auto merge of #12303 - epage:config, r=joshtriplett
fix(script): Process config relative to script, not CWD

### What does this PR try to resolve?

This is part of the work for #12207.

When you put in your path `foo.rs`:
```rust
#!/usr/bin/env cargo

fn main() {}
```

You expect it to build once and then repeatedly run the same version.  However, `.cargo/config.toml` doesn't work like that (normally).  It is an environment file, like `.env`, and is based on your current working directory.  So if you run `foo.rs` from within a random project, it might rebuild due to RUSTFLAGS in `.cargo/config.toml`.

I had some concern about whether this current behavior is right or not and [noted this in the Pre-RFC](https://github.com/epage/cargo-script-mvs/blob/main/0000-cargo-script.md#unresolved-questions).  This came up again while we were [discussing editions on zulip](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/cargo.20script.20and.20edition).  In looking further into this, it turns out we already have precedence for this with `cargo install --path <path>`.

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

The second commit has the fix, the docs, and a change to a test (from the first commit) to show that the fix actually changed behavior.
2023-06-22 21:47:34 +00:00
Ed Page 78334e868e fix(script): Process config relative to script, not CWD 2023-06-22 14:15:20 -05:00
Ed Page 9d85c891e8 test(script): Verify existing config behavior 2023-06-22 14:05:44 -05:00
Eric Huss 604c8f8122 -Znext-lockfile-bump: Don't suggest using -Z on stable 2023-06-22 11:55:42 -07:00
bors 05cd14ecf9 Auto merge of #12298 - weihanglo:config-include-toml, r=epage
Add `.toml` file extension restriction for `-Zconfig-include`
2023-06-21 21:48:29 +00:00
Weihang Lo 33b0a24082
test(config-include): assert config merged in DFS 2023-06-21 20:18:09 +01:00
Weihang Lo 3f82ec7093
feat: check if config-include file ends with .toml
This is to avoid possible name collisions. For example, a user
creates a file called `.cargo/cache`, and then in the future
cargo wants to create a directory called `.cargo/cache/`, that
would collide with what the user specified. Restricting to `.toml`
extensions would avoid that since we won’t make a directory named
with a `.toml` extension.
2023-06-21 20:18:08 +01:00
bors 4cebd130eb Auto merge of #12289 - epage:basic, r=weihanglo
fix: Allow embedded manifests in all commands

### What does this PR try to resolve?

This is a part of #12207.

One of the goals is for embedded manifests to be a first class citizen.  If you have a script, you should be able to run tests on it, for example.

This expands the error check from just `Cargo.toml` to also single-file packages so you can use it in `--manifest-path`.

This, however, does mean that these *can* be used in places that likely won't work yet, like `cargo publish`.

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

By commit.  We introduce tests for basic commands and then implement and refine the support for this.

### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.
2023-06-21 18:59:29 +00:00
bors 3de1cc462b Auto merge of #12281 - epage:toml, r=weihanglo
feat(cli): Support `cargo Cargo.toml`

### What does this PR try to resolve?

This is making the assumption that we want full unity between places accepting both single-file packages and `Cargo.toml` for #12207.   This has not been brought up before in any of the discussions (Internals, eRFC), so I can understand if there are concerns about this and we decide to hold off.

We might want to resolve symlinks before this so people can have a prettier name for these.

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

The test for this was added in a commit before the actual change, letting people see how the behavior changed.
2023-06-21 18:07:32 +00:00
Ed Page d8583f4a5e fix(cli): Improve error on manifest dir 2023-06-21 12:26:15 -05:00
Ed Page 85023c46e4 test(cli): Verify missing-manifest behavior 2023-06-21 11:46:36 -05:00
Ed Page af69746ba6 test(cli): Verify directory-manifest behaivor 2023-06-21 11:30:55 -05:00
Eric Huss 9835622853 Convert valid feature name warning to an error. 2023-06-20 12:39:27 -07:00
Ed Page b1394895ad fix(cli): Ensure we don't accidentally let embedded manifests on stable
There should be a later check when parsing but just in case, let's have
a check here as well.
2023-06-19 21:26:49 -05:00
Ed Page 4e49af4071 fix: Allow embedded manifests in all commands
I originally centralized the error reporting until I realized it likely
is intentionally not centralized so we report errors in terms of the
arguments the user provided.
2023-06-19 20:33:30 -05:00
Ed Page 98ed8abe6d test(embedded): Verify existing behavior on basic commands 2023-06-19 16:12:20 -05:00
Ed Page bb1f6f29bc fix(embedded): Don't pollute script dir with lockfile
This puts the lockfile back into a target directory in the users home,
like before #12268.

Another idea that came up was to move the workspace root to be in the
target directory (which would effectively be like pre-#12268) but I
think that is a bit hacky / misleading.

This does mean that the lockfile is buried away from the user and they
can't pass it along with their script.  In most cases I've dealt with,
this would be fine.  When the lockfile is needed, they will also most
likely have a workspace, so it shoud have a local lockfile in that case.
The inbetween case is something that needs further evaluation for
whether we should handle it and how.
2023-06-17 15:27:03 -05:00
Ed Page 53a63b2775 test(embedded): Verify existing lockfile behavior 2023-06-17 15:11:46 -05:00
bors 2cf2c32c1a Auto merge of #12221 - Swatinem:enable-doctest-in-workspace, r=weihanglo
Enable `doctest-in-workspace` by default

This stabilizes and enables the `-Z doctest-in-workspace` flag by default.

Also adds another testcase to make sure that the `include!()` and `file!()` macros interact well together.

fixes #9427
fixes https://github.com/rust-lang/rust/issues/46372
2023-06-17 20:37:43 +00:00
Arpad Borsos 18e290c0e4
Enable doctest-in-workspace by default
This stabilizes and enables the `-Z doctest-in-workspace` flag by default.

Also adds another testcase to make sure that the `include!()` and `file!()` macros interact well together.
2023-06-17 19:34:34 +02:00
bors e518f7c45e Auto merge of #12283 - epage:build, r=weihanglo
fix(embedded): Don't auto-discover build.rs files

With #12268, we moved the manifest root to be the scripts parent
directory, making it so auto-discovery might pick some things up.

We previously ensured `auto*` don't pick things up but missed `build.rs`
This is now addressed.
2023-06-17 17:06:00 +00:00
bors 81a73926b3 Auto merge of #12282 - epage:target, r=weihanglo
fix(embeded): Don't pollute the scripts dir with `target/`

### What does this PR try to resolve?

This PR is part of #12207.

This specific behavior was broken in #12268 when we stopped using an intermediate
`Cargo.toml` file.

Unlike pre-#12268,
- We are hashing the path, rather than the content, with the assumption
  that people change content more frequently than the path
- We are using a simpler hash than `blake3` in the hopes that we can get
  away with it

Unlike the Pre-RFC demo
- We are not forcing a single target dir for all scripts in the hopes
  that we get #5931

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

A new test was added specifically to show the target dir behavior, rather than overloading an existing test or making all tests sensitive to changes in this behavior.

### Additional information

In the future, we might want to resolve symlinks before we get to this point
2023-06-17 16:15:20 +00:00
Ed Page 3f93030614 fix(embedded): Don't auto-discover build.rs files
With #12268, we moved the manifest root to be the scripts parent
directory, making it so auto-discovery might pick some things up.

We previously ensured `auto*` don't pick things up but missed `build.rs`
This is now addressed.
2023-06-17 11:01:02 -05:00
Ed Page 4427cfe619 test(script): Verify existing build.rs behavior 2023-06-17 10:59:54 -05:00
Weihang Lo 65b292f7dc
test: encode URL params correctly for SourceId in Cargo.lock
This will happen in lockfile format v4.
2023-06-17 15:57:42 +01:00
Weihang Lo 5974123fda
test: v3 lockfile format doesn't respect url encode
These tests verify the existing buggy behavior.
2023-06-17 15:57:41 +01:00
Weihang Lo 03556056d4
feat: prepare for the next lockfile bump
The `-Znext-lockfile-bump` is added, so we can prepare for all
lockfile format changes and then stabilize then all at once.

`-Znext-lockfile-bump` is not intended for using outside our test
suite and development. Hence it's hidden.
2023-06-17 10:24:53 +01:00
Ed Page aca7b08405 fix(embedded): Keep target dir in cargo home
This was broken in #12268 when we stopped using an intermediate
`Cargo.toml` file.

Unlike pre-#12268,
- We are hashing the path, rather than the content, with the assumption
  that people change content more frequently than the path
- We are using a simpler hash than `blake3` in the hopes that we can get
  away with it

Unlike the Pre-RFC demo
- We are not forcing a single target dir for all scripts in the hopes
  that we get #5931
2023-06-16 21:37:55 -05:00
Ed Page 7f2eca409f feat(cli): Accept 'cargo Cargo.toml'
This wasn't in the original Pre-RFC but in terms of consistently
accepting manifests everything, I think this makes sense.
2023-06-16 21:12:22 -05:00
Ed Page ffb997fd2d test(cli): Verify you can't use Cargo.toml 2023-06-16 21:12:22 -05:00
Ed Page 5ed07925cc fix(embedded): Ensure we don't auto-discover any targets 2023-06-16 21:08:48 -05:00
Ed Page 575b9ac934 fix(embedded): Don't create an intermediate manifest
To parse the manifest, we have to write it out so our regular manifest
loading code could handle it.  This updates the manifest parsing code to
handle it.

This doesn't mean this will work everywhere in all cases though.  For
example, ephemeral workspaces parses a manifest from the SourceId and
these won't have valid SourceIds.

As a consequence, `Cargo.lock` and `CARGO_TARGET_DIR` are changing from being next to
the temp manifest to being next to the script.  This still isn't the
desired behavior but stepping stones.

This also exposes the fact that we didn't disable `autobins` like the
documentation says we should.
2023-06-16 21:08:47 -05:00
Ed Page 2c70983e8d test(embedded): Verify no autobin behavior is running 2023-06-16 21:06:01 -05:00
Ed Page b116864d79 fix(embedded): Be consistent with existing style when sanitizing 2023-06-15 19:09:28 -05:00
Ed Page 56b2812a85 fix(embedded): Don't append hash to bin names
Background: the hash existed for sharing a target directory.  That code isn't
implemented yet and a per-user build cache might remove the need for it,
so let's remove it for now and more carefully weigh adding it back in.

Immediate: This reduces the chance of hitting file length issues on Windows.

Generally: This is a bit hacky and for an official solution, we should
probably try to find a better way.  This could become more important as
single-file packages are allowed in workspaces.
2023-06-14 12:25:59 -05:00
Ed Page 33c9d8e2fd feat(cli): Pull in cargo-script-mvs core logic
This is no where near the implementation we want but I think we should
develop incrementally on top of what we already have.

See https://github.com/epage/cargo-script-mvs/tree/main
2023-06-09 22:03:18 -05:00
Ed Page 3c15d24960 fix(cli): Warn on stable for precedence changes
This will give us a window to collect feedback on if this affects
anyone.
2023-06-09 22:02:54 -05:00
Ed Page b2b4d9771f test(cli): Verify precedence over external subcommands 2023-06-09 13:16:12 -05:00
Ed Page 21736eda0c feat(cli): Interpret some subcommands as manifest-commands 2023-06-08 20:17:03 -05:00
bors 7a0b24b05f Auto merge of #12246 - epage:lint, r=weihanglo
chore: Migrate print-ban from test to clippy

This should be more resilient to false positives like in #12245 where a string contains `println`.

See also #12224
2023-06-09 13:39:06 +00:00
Ed Page 9df5e79dfb chore: Migrate print-ban from test to clippy
This should be more resilient to false positives like in #12245 where a
string contains `println`.
2023-06-09 08:11:49 -05:00
christian 56318e0b6c remove escapes and leading whitespace from string matches 2023-06-08 17:09:21 +00:00
christian 71b37f2fd1 add test case 2023-06-08 15:27:23 +00:00
Weihang Lo 51ebba2fc1
test: loose overly matches for git cli output
The output format should be stable I believe, but it turns out not.
This is how `git fetch` man page says [1]:

```
<flag> <summary> <from> -> <to> [<reason>]
```

In Git 2.41 they've changed the fetch output a bit [2].

I think let's just loose it to prevent future breakages.

[1]: https://git-scm.com/docs/git-fetch#_output
[2]: https://github.blog/2023-06-01-highlights-from-git-2-41/
2023-06-07 22:55:17 +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
bors b0fa79679e Auto merge of #12226 - danilhendrasr:feat/emit-error-on-toolchain-add-and-install, r=weihanglo
Emit error when users try to use a toolchain via the `add` or `install` command

Running `cargo install +nightly` or `cargo add +nightly` does not actually use the nightly toolchain, but the user won't know until the compilation fails. With this PR, an error is emitted if the `install` and `add` command is given a crate name
that starts with a `+` as we assume the user's intention was to use a certain toolchain instead of installing/adding a crate.

Example:
<img width="758" alt="image" src="https://github.com/rust-lang/cargo/assets/45989466/16e59436-32ee-49ee-9933-8b68b176c09d">

Fixes #10362
2023-06-03 14:19:48 +00: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
Danil Hendra Suryawan a9c47cc3ab feat(cli): emit error when add is given a toolchain name instead of a crate name 2023-06-03 20:50:24 +07:00
Charalampos Mitrodimas a777b82d5f Support "default" option for build.jobs
This commit adds support for passing the keyword "default"
to either the CLI "--jobs" argument on the "[build.jobs]"
section of ".cargo/config".

This is dony by:
  1. Changing the "jobs" config type to an enum that holds
     a String or an Integer(i.e. i32).
  2. Matching the enum & casting it to an integer

Signed-off-by: Charalampos Mitrodimas <charmitro@gmail.com>
2023-06-03 15:24:41 +03:00
Weihang Lo d4067e4881
fix: should assert against stderr instead
This was an overlook in #12205
2023-05-31 20:46:11 +01:00
Weihang Lo 64a1f204f3
refactor: only when -C debuginfo > 0 will spilt-debuginfo be passed
It was unnecessary to pass `spilt-debuginfo` if there is no debuginfo.
Tests are touched here only for matching rustflags invocation stderr
in the original test suite.
2023-05-31 20:43:57 +01:00
jyn e2eacc6414 Don't distinguish Debuginfo::None and Debuginfo::Explicit(None)
Previously, `Debuginfo::None` meant "don't pass -C debuginfo" and `Explicit(None)` meant
"-C debuginfo=0", which occasionally led to caching bugs where cargo would sometimes pass
`-C debuginfo=0` and sometimes not. There are no such bugs currently that we know of, but
representing them the same within cargo avoids the possibility of the bug popping up again in the
future.

I tested the `with_stderr_does_not_contain_tests` with this diff to ensure they did not pass:
```diff
diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs
index 55ec17182..c186dd00a 100644
--- a/src/cargo/core/compiler/mod.rs
+++ b/src/cargo/core/compiler/mod.rs
@@ -1073,9 +1073,7 @@ fn build_base_args(

     let debuginfo = debuginfo.into_inner();
     // Shorten the number of arguments if possible.
-    if debuginfo != TomlDebugInfo::None {
         cmd.arg("-C").arg(format!("debuginfo={}", debuginfo));
-    }

     cmd.args(unit.pkg.manifest().lint_rustflags());
     if !rustflags.is_empty() {
```
2023-05-30 17:06:50 -05:00
Eric Huss 16ac6fae11 Re-enable code_generation test on Windows 2023-05-29 12:01:02 -07:00
bors 8f49b5556b Auto merge of #12191 - epage:mut, r=weihanglo
fix(add): Reduce the chance we re-format the user's `[features]` table

### What does this PR try to resolve?

#11743 pointed out that we re-format the users `[features]` table when running `cargo add`  which was a bug introduced in #11099.

This reduces the chance people will run into this problem
- Reducing the scope of the `fmt` call
- Preserving formatting in a simple case

Actually removing the `fmt` case can make some common formatting cases more complex to do "right", so I'm punting on that for now.

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

Look at the individual commits as I show how each change improves the behavior of `cargo add`.
2023-05-27 10:33:39 +00:00
Ed Page 0da6997ccc test(add): Remove expensive test
This is a carry-over from cargo-edit where we had to worry about the UX
of all of the behavior while now we are just relying on built-in cargo
behavior and don't need to test it specifically for `cargo add`.

On my machine, this test takes 11s.
2023-05-26 19:24:13 -05:00
bors c412aa4fac Auto merge of #12189 - epage:add, r=weihanglo
refactor(tests): Reduce cargo-add setup load

This just gets rid of irrelevant packages in the registry.  Looking into which versions aren't needed would require a deeper pass, so I held off on that for now.

Before, the tests were in the 300-500ms range and now they take 100-300ms.

This did call to my attention that `unrelated` is misspelled as `unrelateed` but holding off on fixing that to reduce conflicts.
2023-05-26 22:15:09 +00:00
Ed Page dbf9134d57 fix(add): Preserve formatting 2023-05-26 16:49:59 -05:00
Ed Page 6d8f35f729 fix(add): Reduce the chance of breaking the user's formatting 2023-05-26 16:49:59 -05:00
Ed Page b903527f28 test(add): Show features table fmt bug 2023-05-26 16:49:14 -05:00
bors d08c587469 Auto merge of #10910 - Nemo157:lint-different-resolver-10112, r=epage
Warn when an edition 2021 crate is in a virtual workspace with default resolver

Edition 2021 updates the default resolver to version "2", but developers using virtual workspaces commonly don't get this update because the virtual workspace defaults to version "1". Warn when this situation occurs so those developers can explicitly configure their workspace and will be more likely to know that they will need to update it in the future.

Fixes #10112
2023-05-26 19:57:28 +00:00
Wim Looman 3dec6f234d
Remove unnecessary warning line 2023-05-26 20:27:34 +02:00
Wim Looman 49cc60b1aa
Add notes on how to configure the virtual workspace's resolver 2023-05-26 20:20:56 +02:00
Wim Looman 7067d0df58
Improve warning message grammar 2023-05-26 20:09:27 +02:00
Wim Looman c31877def5
Update cargo new workspace inheritance tests to specify resolver 2023-05-26 17:14:34 +02:00
Wim Looman 620f66fa92
Mention workspace root's manifest explicitly 2023-05-26 16:41:04 +02:00
Ed Page 29dc47fa9a refactor(tests): Reduce cargo-add setup load
This just gets rid of irrelevant packages in the registry.  Looking into
which versions aren't needed would require a deeper pass, so I held off
on that for now.

Before, the tests were in the 300-500ms range and now they take
100-300ms.

This did call to my attention that `unrelated` is misspelled as
`unrelateed` but holding off on fixing that to reduce conflicts.
2023-05-26 09:24:45 -05:00
Wim Looman 2e2b3c1f1e
Warn when an edition 2021 crate is in a virtual workspace with default resolver
Edition 2021 updates the default resolver to version "2", but developers
using virtual workspaces commonly don't get this update because the
virtual workspace defaults to version "1". Warn when this situation
occurs so those developers can explicitly configure their workspace and
will be more likely to know that they will need to update it in the
future.
2023-05-26 16:11:09 +02:00
bors b9b5a45e3c Auto merge of #12184 - epage:rm, r=weihanglo
refactor(tests): Reduce cargo-remove setup load

This reduces the number of packages published in tests.  This is an artifact of when I changed `cargo-edit` from relying on crates.io to test-generated published packages.  I took the fastest path to making that conversion and took the shortcut of creating everything for every test.  I had assumed the cost was low but `@Muscraft` noticed that this takes up a lot of space which we run out of on CI occasionally and I expect a lot of small files are slowing down windows.

This only updates `cargo-remove`.  I'll be doing a follow up for `cargo-add`.
2023-05-26 13:53:32 +00:00
Ed Page ad9a44ddde refactor(tests): Reduce cargo-remove setup load
Benefits
- Clarifies a tests needs
- Speeds up testing, especially on Windows
- Reduces disk space issues within CI
2023-05-25 13:43:16 -05:00
bors fc905782cf Auto merge of #12174 - hi-rustin:rustin-patch-lints, r=epage
Automatically inherit workspace lints when running cargo new/init
2023-05-24 13:46:51 +00:00
bors 092db788d1 Auto merge of #12022 - jyn514:debuginfo-tests, r=weihanglo
Test that the new `debuginfo` options match between cargo and rustc

As requested in https://github.com/rust-lang/cargo/pull/11958#issuecomment-1518684469.

r? `@ehuss`
2023-05-24 06:59:49 +00:00
jyn e319c2c039 Test that the new debuginfo options match between cargo and rustc 2023-05-23 22:00:17 -05:00
hi-rustin 6573701227 Add inherit_workspace_lints test
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-05-24 10:36:06 +08:00
cassaundra 30a445b9a4
Add tests for cargo add's rust-version behavior 2023-05-23 11:06:08 -07:00
bors feb9bcf630 Auto merge of #12168 - epage:lints2, r=weihanglo
fix(lints): Switch to -Zlints so stable projects can experiment

### What does this PR try to resolve?

In #12115, we explored how we can let stable projects
experiment with `[lints]` to provide feedback.  What we settled on is
switching from the `cargo-features` manifest key to the `-Z` flag as
`cargo-features` always requires nightly while `-Z` only requires it
when being passed in.  This means a project can have a `[lints]` table
and have CI / contributors run `cargo +nightly check -Zlints` when they
care about warnings.

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

Demonstrate how you test this change and guide reviewers through your PR.
With a smooth review process, a pull request usually gets reviewed quicker.

If you don't know how to write and run your tests, please read the guide:
https://doc.crates.io/contrib/tests

### Additional information

I considered reworking the code to show the user the errors they would encounter once the feature is stable but held off.  I wasn't quite sure what language to use and most likely a user would have something doing error reporting, like CI, so it should be fine.
2023-05-23 13:52:22 +00:00
hi-rustin 821725dcd1 Add a inherit test for init
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-05-23 10:36:48 +08:00
hi-rustin 5265b1d0ec Add tests for inherit_workspace_package_table
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-05-23 10:36:08 +08:00
bors e5e68c4093 Auto merge of #12148 - epage:lints, r=weihanglo
feat: `lints` feature

### What does this PR try to resolve?

Implement rust-lang/rfcs#3389 which shifts a subset of `.cargo/config.toml` functionality to `Cargo.toml` by adding a `[lints]` table.

This **should** cover all of the user-facing aspects of the RFC
- This doesn't reduce what flags we fingerprint
- This will fail if any lint name as `::` in it.  What to do in this case was in the RFC discussion but I couldn't find the thread to see what all was involved in that discussion
- This does not fail if a `[lints]` table is present or malformed unless nightly with the `lints` feature enabled
  - The idea is this will act like a `[lints]` table is present in an existing version of rust, ignore it
  - The intent is to not force an MSRV bump to use it.
  - When disabled, it will be a warning
  - When disabled, it will be stripped so we don't publish it

Tracking issue for this is #12115.

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

1. Look at this commit by commit to see it gradually build up
2. Look through the final set of test cases to make sure everything in the RFC is covered

I tried to write this in a way that will make it easy to strip out the special handling of this unstable feature, both in code and commit history

### Additional information

I'd love to bypass the need for `cargo-features = ["lints"]` so users today can test it on their existing projects but hesitated for now.  We can re-evaluate that later.

I broke out the `warn_for_feature` as an experiment towards us systemitizing this stabilization approach which we also used with #9732.  This works well when we can ignore the new information which isn't too often but sometimes happens.

This does involve a subtle change to `profile.rustflags` precedence but
its nightly and most likely people won't notice it?  The benefit is its
in a location more like the rest of the rustflags.
2023-05-22 19:54:39 +00:00
Ed Page 08fdd86d84 fix(lints): Switch to -Zlints so stable projects can experiment
In rust-lang/cargo#12115, we explored how we can let stable projects
experiment with `[lints]` to provide feedback.  What we settled on is
switching from the `cargo-features` manifest key to the `-Z` flag as
`cargo-features` always requires nightly while `-Z` only requires it
when being passed in.  This means a project can have a `[lints]` table
and have CI / contributors run `cargo +nightly check -Zlints` when they
care about warnings.
2023-05-22 13:45:20 -05:00
Ed Page 2c48b10ef0 test(lints): Remove unused cargo-features 2023-05-22 13:44:56 -05:00
Ed Page e4b01367a1 test(lints): Simplify failure tests 2023-05-22 10:14:35 -05:00
Ed Page be76a55358 test(lints): Verify precedence with build.rustflags 2023-05-22 10:06:57 -05:00
Ed Page 3cba0c1b52 test(lints): Verify dependency behavior 2023-05-22 09:59:23 -05:00
Ed Page 12bc06aaf2 test(lints): Clarify why verbose is used 2023-05-22 09:59:23 -05:00
Ed Page 66a9116f03 fix(lints): Put lints after profile.rustflags
This does involve a subtle change to `profile.rustflags` precedence but
its nightly and most likely people won't notice it?  The benefit is its
in a location more like the rest of the rustflags.
2023-05-22 09:58:42 -05:00
Ed Page e82fe885b5 test(lints): Verify precedence with profile.rustflags 2023-05-22 09:53:25 -05:00
Ed Page 1dfa101cd1 fix(lints): Tie into manifest warnings
This improves the messaging experience (sometimes showing manifest path)
and hiding the warning when not relevant).
2023-05-22 09:53:25 -05:00
Ed Page a8d7c8a58f fix(lints): Clean up warnings about lints feature 2023-05-22 09:53:25 -05:00
Ed Page 5072d9b789 fix(lints): Ignore lints table on stable 2023-05-22 09:53:25 -05:00
Ed Page 66038fad36 test(lints): Show bug with lints on stable 2023-05-22 09:53:25 -05:00
Ed Page a7555f976e fix(lints): Only warn when seeing lints on stable
This will make it easier for users to test this feature
2023-05-22 09:53:25 -05:00
Ed Page 4279d0d56c feat(lints): Pass lints to tools 2023-05-22 09:53:25 -05:00
Ed Page fad2ea5cfd feat(lints): Error check the lints table 2023-05-22 09:53:22 -05:00
Ed Page 8de25292fd feat(lints): Parse [lints] table on nightly 2023-05-22 09:52:03 -05:00
Weihang Lo 277e65bf4c
fix: pass -C debuginfo after weakening if explicitly set
The weakening of debuginfo for build script shouldn't turn debuginfo
to `DebugInfo::None`. That will result in not passing `-C debuginfo=0`
to rustc, leading to build artifact cache miss.
2023-05-22 00:37:08 +01:00
Eval EXEC e906797b91
Add test case for confilict README.md check
Signed-off-by: Eval EXEC <execvy@gmail.com>
2023-05-14 16:55:23 +08:00
Eric Huss a0f832f4e8 Fix dep/feat syntax with hidden implicit optional dependencies 2023-05-11 09:34:38 -07:00
Eric Huss 2dccb71acd Disallow RUSTUP_TOOLCHAIN in the [env] table. 2023-05-08 09:30:59 -07:00
Eric Huss 4ec06f4820 Disallow RUSTUP_HOME in the [env] table. 2023-05-07 10:01:43 -07:00
bors 27a41d6789 Auto merge of #12095 - ehuss:fix-token-redact, r=weihanglo
Fix redacting tokens in http debug.

Unfortunately it seems like #8222 didn't properly redact tokens when connecting to an http2 server. There were multiple problems:

* For some reason, curl changes the authorization header to be lowercase when using http2.
* Curl also logs the h2h3 lines separately with a different syntax.

This fixes it by checking for these additional cases.

This also adds a test, but it doesn't actually detect this problem because we don't have an http2 server handy. You can test this yourself by running `CARGO_LOG=trace CARGO_HTTP_DEBUG=true cargo publish --token a-unique-token --allow-dirty --no-verify`, and verifying the output does not contain the given token text.
2023-05-06 23:16:31 +00:00
Eric Huss a2ed96df6a Fix self_signed_should_fail for macOS. 2023-05-06 12:41:34 -07:00
Eric Huss d6c20cf109 Fix redacting tokens in http debug. 2023-05-06 12:41:06 -07:00
bors e2d14882a5 Auto merge of #12083 - Eh2406:names, r=weihanglo
do not try an exponential number of package names

re #11934, and as discussed in the cargo team meeting, this changes the strategy to "the original, all underscore, and all dashes".

I was excessively proud of the `hyphen_combination_num` based implementation when I came up with it. But it's always been a hack. I'm glad to be the one to remove it.
2023-05-05 17:18:08 +00:00
Jacob Finkelman d6021c9c34 do not try an exponential number of package names 2023-05-05 17:15:06 +00:00
Weihang Lo 3df35edca7
fix: hack around libsysroot instead of libtest 2023-05-05 14:48:37 +01:00
bors 2d693e20ea Auto merge of #11917 - ehuss:rustup-circumvent, r=weihanglo
Optimize usage under rustup.

Closes #10986

This optimizes cargo when running under rustup to circumvent the rustup proxies. The rustup proxies introduce overhead that can make a noticeable difference.

The solution here is to identify if cargo would normally run `rustc` from PATH, and the current `rustc` in PATH points to something that looks like a rustup proxy (by comparing it to the `rustup` binary which is a hard-link to the proxy). If it detects this situation, then it looks for a binary in `$RUSTUP_HOME/toolchains/$TOOLCHAIN/bin/$TOOL`. If it finds the direct toolchain executable, then it uses that instead.

## Considerations

There have been some past attempts in the past to address this, but it has been a tricky problem to solve. This change has some risk because cargo is attempting to guess what the user and rustup wants, and it may guess wrong. Here are some considerations and risks for this:

* Setting `RUSTC` (as in https://github.com/rust-lang/rustup/pull/2958) isn't an option. This makes the `RUSTC` setting "sticky" through invocations of different toolchains, such as a cargo subcommand or build script which does something like `cargo +nightly build`.

* Changing `PATH` isn't an option, due to issues like https://github.com/rust-lang/rustup/issues/3036 where cargo subcommands would be unable to execute proxies (so things like `+toolchain` shorthands don't work).

* Setting other environment variables in rustup (as in https://github.com/rust-lang/rustup/pull/3207 which adds `RUSTUP_TOOLCHAIN_DIR` the path to the toolchain dir) comes with various complications, as there is risk that the environment variables could get out of sync with one another (like with `RUSTUP_TOOLCHAIN`), causing tools to break or become confused.

  There was some consideration in that PR for adding protections by using an encoded environment variable that could be cross-checked, but I have concerns about the complexity of the solution.

  We may want to go with this solution in the long run, but I would like to try a short term solution in this PR first to see how it turns out.

* This won't work for a `rustup-toolchain.toml` override with a [`path`](https://rust-lang.github.io/rustup/overrides.html#path) setting. Cargo will use the slow path in that case. In theory it could try to detect this situation, which may be an exercise for the future.

* Some build-scripts, proc-macros, or custom cargo subcommands may be doing unusual things that interfere with the assumptions made in this PR. For example, a custom subcommand could call a `cargo` executable that is not managed by rustup. Proc-macros may be executing cargo or rustc, assuming it will reach some particular toolchain. It can be difficult to predict what unusual ways cargo and rustc are being used. This PR (and its tests) tries to make extra sure that it is resilient even in unusual circumstances.

* The "dev" fallback in rustup can introduce some complications for some solutions to this problem. If a rustup toolchain does not have cargo, such as with a developer "toolchain link", then rustup will automatically call either the nightly, beta, or stable cargo if they are available. This PR should work correctly, since rustup sets the correct `RUSTUP_TOOLCHAIN` environment variable for the *actual* toolchain, not the one where cargo was executed from.

* Special care should be considered for dynamic linking. `LD_LIBRARY_PATH` (linux), `DYLD_LIBRARY_PATH` (macos), and `PATH` (windows) need to be carefully set so that `rustc` can find its shared libraries. Directly executing `rustc` has some risk that it will load the wrong shared libraries. There are some mitigations for this. macOS and Linux use rpath, and Windows looks in the same directory as `rustc.exe`. Also, rustup configures the dyld environment variables from the outer cargo. Finally, cargo also configures these (particularly for the deprecated compiler plugins).

* This shouldn't impact installations that don't use rustup.

* I've done a variety of testing on the big three platforms, but certainly nowhere exhaustive.
    * One of many examples is making sure Clippy's development environment works correctly, which has special requirements for dynamic linking.

* There is risk about future rustup versions changing some assumptions made here. Some assumptions:
    * It assumes that if `RUSTUP_TOOLCHAIN` is set, then the proxy *always* runs exactly that toolchain and no other. If this changes, cargo could execute the wrong version. Currently `RUSTUP_TOOLCHAIN` is the highest priority [toolchain override](https://rust-lang.github.io/rustup/overrides.html) and is fundamental to how toolchain selection becomes "sticky", so I think it is unlikely to change.
    * It assumes rustup sets `RUSTUP_TOOLCHAIN` to a value that is exactly equal to the name of the toolchain in the `toolchains` directory. This works for user shorthands like `RUSTUP_TOOLCHAIN=nightly`, which gets converted to the full toolchain name. However, it does not work for `path` overrides (see above).
    * It assumes the `toolchains` directory layout is always `$RUSTUP_HOME/toolchains/$TOOLCHAIN`. If this changes, then I think the only consequence is that cargo will go back to the slow path.
    * It assumes downloading toolchains is not needed (since cargo running from the toolchain means it should already be downloaded).
    * It assumes there is no other environment setup needed (such as the dyld paths mentioned above).

  My hope is that if assumptions are no longer valid that the worst case is that cargo falls back to the slow path of running the proxy from PATH.

## Performance

This change won't affect the performance on Windows because rustup currently alters PATH to point to the toolchain directory. However, https://github.com/rust-lang/rustup/pull/3178 is attempting to remove that, so this PR will be required to avoid a performance penalty on Windows. That change is currently opt-in, and will likely take a long while to roll out since it won't be released until after the next release, and may be difficult to get sufficient testing.

I have done some rough performance testing on macOS, Windows, and Linux on a variety of different kinds of projects with different commands. The following attempts to summarize what I saw.

The timings are going to be heavily dependent on the system and the project. These are the values I get on my systems, but will likely be very different for everyone else.

The Windows tests were performed with a custom build of rustup with https://github.com/rust-lang/rustup/pull/3178 applied and enabled (stock rustup shows no change in performance as explained above).

The data is summarized in this spreadsheet: https://docs.google.com/spreadsheets/d/1zSvU1fQ0uSELxv3VqWmegGBhbLR-8_KUkyIzCIk21X0/edit?usp=sharing

`hello-world` has a particularly large impact of about 1.68 to 2.7x faster. However, a large portion of this overhead is related to running `rustc` at the start to discover its version and querying it for information. This is cached after the first run, so except for first-time builds, the effect isn't as noticeable. The "check with info" row is an benchmark that removes `target/debug/deps` but keeps the `.rustc_info.json` file.

Incremental builds are a bit more difficult to construct since it requires customizing the commands for each project. I only did an incremental test for cargo itself, running `touch src/cargo/lib.rs` and then `cargo check --lib`.

These measurements excluded the initial overhead of launching the rustup proxy to launch the initial cargo process. This was done just for simplicity, but it makes the test a little less characteristic of a typical usage, which will have some constant overhead for running the proxy.

These tests were done using [`hyperfine`](https://crates.io/crates/hyperfine) version 1.16.1. The macOS system was an M2 Max (12-thread). The Windows and Linux experiments were run on a AMD Ryzen Threadripper 2950X (32-thread). Rust 1.68.2 was used for testing. I can share the commands if people want to see them.
2023-05-04 23:51:38 +00:00
Eric Huss d4b0b494f1 Add an optimization when running under rustup. 2023-05-03 13:45:54 -07:00
Eric Huss 52317aa8f8 Add some tests for simulating behavior under rustup. 2023-05-03 13:45:54 -07:00
charles-r-earp 61df6bb418 Fixed test update::update_precise_first_run. 2023-05-03 13:08:51 -07:00
charles-r-earp f43e6d947f Added workspace_default_members to more tests. 2023-05-03 12:44:08 -07:00
charles-r-earp e421345d22 Added workspace_default_members to tests. 2023-05-03 12:44:08 -07:00
charles-r-earp 8c96a28ff7 Added workspace_default_members. 2023-05-03 12:44:08 -07:00
bors 2f06c80bd0 Auto merge of #11840 - Byron:shallow-support, r=weihanglo
support for shallow clones and fetches with `gitoxide`

This PR makes it possible to enable shallow clones and fetches for git dependencies and crate indices independently with the `-Zgitoxide=fetch,shallow_deps` and `-Zgitoxide=fetch,shallow_index` respectively.

### Tasks

* [x] setup the shallow option when fetching, differentiated by 'registry' and 'git-dependency'
* [x] validate registries are cloned shallowly *and* fetched shallowly
* [x] validate git-dependencies are cloned shallowly *and* fetched shallowly
* [x] a test to show what happens if a shallow index is opened with `git2` (*it can open it and fetch like normal, no issues*)
* [x] assure that `git2` can safely operate on a shallow clone - we unshallow it beforehand, both for registries and git dependencies
* [x] assure git-deps with revisions are handled correctly (they should just not be shallow, and they should unshallow themselves if they are)
* [x] make sure shallow index clones aren't seen by older cargo's
* [x] make sure shallow git dependency clones aren't seen by older cargo's
* [x] shallow.lock test and more test-suite runs with shallow clones enabled for everything
* [x] release new version of `gix` with full shallow support and use it here
* [x] check why `shallow` files remain after unshallowing. Should they not rather be deleted if empty? - Yes, `git` does so as well, implemented [with this commit](2cd5054b0a)
* ~~see if it can be avoided to ever unshallow an existing `-shallow` clone by using the right location from the start. If not, test that we can go `shallow->unshallow->shallow` without a hitch.~~ Cannot happen anymore as it can predict the final location perfectly.
* [x] `Cargo.lock` files don't prevent shallow clones
* [x] assure all other tests work with shallow cloning enabled (or fix the ones that don't with regression protection)
* [x] can the 'split-brain' issue be solved for good?

### Review Notes

* there is a chance of 'split brain' in git-dependencies  as the logic for determining whether the clone/fetch is shallow is repeated in two places. This isn't the case for registries though.

### Notes

* I am highlighting that this is the `gitoxide` version of shallow clones as the `git2` version [might soon be available](https://github.com/libgit2/libgit2/pull/6396) as well. Having that would be good as it would ensure interoperability remains intact.
* Maybe for when `git2` has been phased out, i.e. everything else is working, I think (unscientifically) there might be benefits  in using worktrees for checkouts. Admittedly I don't know the history of why they weren't used in the first place. Also: `gitoxide` doesn't yet support local clones and might not have to if worktrees were used instead.
2023-05-03 07:12:20 +00:00
Weihang Lo 7fb35c9c4e
test(install): correct the term workspace -> local packagd 2023-05-03 01:04:18 +01:00
Sebastian Thiel 3bd08d934b
Move helper functions to the bottom for consistency; fix name 2023-05-02 18:57:42 +02: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
Sebastian Thiel 2aaebcbcaa
Only fetch single object in shallow mode for compatibility 2023-04-29 14:29:11 +02:00
Sebastian Thiel d4b8fc68ab
Allow fetching a single object, shallow or not.
Doing so seems cleaner as there should be no logical difference between
shallow or not-shallow when fetching. We want a specific object, and should
get it with the refspec. `git` will assure we see all objects we need,
handling shallow-ness for us.

Note that one test needed adjustments due to the different mechanism used
when fetching local repositories, requiring more changes to properly 'break'
the submodule repo when `gitoxide` is used.
2023-04-29 12:21:45 +02:00
Sebastian Thiel 8b3508cad7
Move all tests for shallow fetching into their own module
Note that those which test both with and without shallow still go
into the shallow module.
2023-04-29 09:52:08 +02:00
bors a285008c8e Auto merge of #12044 - jrose-signal:cargo-tree-no-proc-macro, r=epage
cargo-tree: Handle -e no-proc-macro when building the graph

### What does this PR try to resolve?

Makes `-e no-proc-macro` more useful when combined with `-i` or `-d`. Fixes #12030.

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

The new and existing tests should cover this, I hope!

### Additional information

Pruning proc-macro crates during graph construction is closer to how the edge-based filters work (`[no-]build` etc.), so even though `no-proc-macro` isn't technically filtering on edges, it's following a well-established code path.
2023-04-27 21:04:25 +00:00
Jordan Rose a0576d1767 cargo-tree: Handle -e no-proc-macro when building the graph
This is closer to how the edge-based filters work ([no-]build etc.),
and results in a more useful behavior when combined with -i or -d.
2023-04-27 10:54:51 -07:00
Jordan Rose 747a5924a0 test: Add a test for cargo tree --duplicates with a proc-macro 2023-04-27 10:49:22 -07:00
Sebastian Thiel 2f45cb54fa
Assure that git-dependencies will get the correct storage, without ever unshallowing them.
This is an improvement over the previous version which would use unshallowing that effectively
makes a shallow repo *not* shallow.

Furthermore, we will now only fetch a single commit, each time we fetch, which should be faster
for the server as well as for the client.

We also make it possible to fetch individual commits that would be specified via Cargo.lock.
2023-04-27 18:49:59 +02:00
Sebastian Thiel 4b93f095c8
Various improvements to address the PR review.
https://github.com/rust-lang/cargo/pull/11840#pullrequestreview-1383844802
2023-04-27 14:19:01 +02:00
Sebastian Thiel 38d92dd9a8
place shallow git dependencies into a different directory.
That way, we avoid any danger with older cargo's not being able
to handle such a repository correctly.
2023-04-27 14:18:27 +02:00
Sebastian Thiel d4af571686
name the shallow registry differently
A couple of test expectations are adjusted accordingly.

Is this desirable behaviour? Unfortunately, there is no alternative
as adding shallow to an existing index most definitely breaks backwards
compatibility.
2023-04-27 14:18:26 +02:00
Sebastian Thiel c7ff94fce8
Enable shallow clones and fetches for registry and git dependencies.
The implementation hinges on passing information about the kind of clone
and fetch to the `fetch()` method, which then configures the fetch accordingly.

Note that it doesn't differentiate between initial clones and fetches as
the shallow-ness of the repository is maintained nonetheless.
2023-04-27 14:18:22 +02:00
cassaundra 5554889f88
Include rust-version in publish request
crates.io reads rust-version from the tarball directly, but we can include it in
the publish request for the sake of consistency for third-party registries.
2023-04-26 11:59:29 -07:00
Kyle Matsuda 90c7d3b9b8 update the publish_with_missing_readme test with new warning 2023-04-25 12:27:39 -06:00
Kyle Matsuda 27e95997ce failing tests on empty readme and license-path fields 2023-04-25 12:27:39 -06:00
Weihang Lo 00484fe00a
fix: apply [env] to target info discovery rustc 2023-04-24 20:30:44 +01:00
Weihang Lo e1c7ce8903
test: [env] isn't applied to target info discovery rustc 2023-04-24 20:28:20 +01:00
bors b5177c6d46 Auto merge of #12001 - hi-rustin:rustin-patch-dep-empty, r=weihanglo
Improve error message for empty dep
2023-04-24 09:20:41 +00:00
bors 77069b43f0 Auto merge of #11958 - jyn514:named-debuginfo, r=Muscraft
Allow named debuginfo options in Cargo.toml
2023-04-22 15:08:08 +00:00
bors 738c699342 Auto merge of #11997 - hi-rustin:rustin-patch-dep-message, r=weihanglo
Better error message when getting an empty dep table
2023-04-20 09:16:30 +00:00
hi-rustin af0cd9fc5a Improve error message for empty dep
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-04-20 09:32:24 +08:00
hi-rustin e0276cae19 Update error message to not start with capital letters
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-04-20 09:16:45 +08:00
jyn a982bccfe8 add more debuginfo tests 2023-04-19 20:01:04 -05:00
hi-rustin 4d401bd0b9 Add test for empty dep table error
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-04-20 08:49:30 +08:00
Eric Huss 6fa758e83c Fix flaky not_found_permutations test. 2023-04-14 08:01:34 -07:00
bors b0742b2145 Auto merge of #11882 - hi-rustin:rustin-patch-clippy-fix, r=weihanglo
Correct the bug report for `cargo clippy --fix`
2023-04-14 07:05:37 +00:00
hi-rustin 08169fd015 Add rustc_shim_for_cargo_fix and wrapped_clippy_driver to reuse code
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-04-14 11:23:41 +08:00
hi-rustin 47f6e2ddc9 Add broken_clippy_fixes_backed_out
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-04-14 10:46:53 +08:00
bors 84b7041fd2 Auto merge of #11950 - ehuss:stabilize-logout, r=epage
Stabilize `cargo logout`

This stabilizes the `cargo logout` command.

Closes #11910
Closes #11884
2023-04-13 20:08:40 +00:00
jyn 8a9db7a020 Address review comments
- Update the documentation and doc-comments
- Improve the error message for parsing Cargo.toml
2023-04-12 12:05:14 -05:00
Eric Huss a70c108961 Stabilize cargo logout 2023-04-12 09:56:43 -07:00
Eric Huss c00a633bd6 Don't display headers in spurious warning message.
The headers can significantly contribute to noise in the output,
drowning out the rest of the output. Most investigation will likely be
focused on the case where cargo completely fails to download, so this
only shows the full detail in the final error message.
2023-04-12 09:38:53 -07:00
Eric Huss 4702fa3ad3 Include the IP address in HTTP errors. 2023-04-12 09:38:53 -07:00
Eric Huss c7c9b8f32b Show some HTTP headers in error messages. 2023-04-12 09:38:52 -07:00