Commit graph

12841 commits

Author SHA1 Message Date
Ed Page 5f30808d00 chore: Update tests for latest clap 2022-10-13 15:16:38 -05:00
bors b592ba4d97 Auto merge of #11230 - epage:unstable2, r=weihanglo
feat(publish): Support 'publish.timeout' config behind '-Zpublish-timeout'

Originally, crates.io would block on publish requests until the publish
was complete, giving `cargo publish` this behavior by extension.  When
crates.io switched to asynchronous publishing, this intermittently broke
people's workflows when publishing multiple crates.  I say interittent
because it usually works until it doesn't and it is unclear why to the
end user because it will be published by the time they check.  In the
end, callers tend to either put in timeouts (and pray), poll the
server's API, or use `crates-index` crate to poll the index.

This isn't sufficient because
- For any new interested party, this is a pit of failure they'll fall
  into
- crates-index has re-implemented index support incorrectly in the past,
  currently doesn't handle auth, doesn't support `git-cli`, etc.
- None of these previous options work if we were to implement
  workspace-publish support (https://github.com/rust-lang/cargo/issues/1169)
- The new sparse registry might increase the publish times, making the
  delay easier to hit manually
- The new sparse registry goes through CDNs so checking the server's API
  might not be sufficient
- Once the sparse registry is available, crates-index users will find
  out when the package is ready in git but it might not be ready through
  the sparse registry because of CDNs

This introduces unstable support for blocking by setting
`publish.timeout` to non-zero value.

A step towards #9507
2022-10-13 16:21:09 +00:00
bors 0b61503914 Auto merge of #11231 - hi-rustin:rustin-patch-build-doc, r=epage
Add missing edition

### What does this PR try to resolve?

When I read this doc, I found that we are missing the edition key in this manifest. I think we should add it because `cargo new` always does this.
2022-10-13 15:37:33 +00:00
hi-rustin fa815f345c Add missing edition
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-10-13 23:14:31 +08:00
Ed Page 04d836fa71 feat(publish): Support 'publish.timeout' config behind '-Zpublish-timeout'
Originally, crates.io would block on publish requests until the publish
was complete, giving `cargo publish` this behavior by extension.  When
crates.io switched to asynchronous publishing, this intermittently broke
people's workflows when publishing multiple crates.  I say interittent
because it usually works until it doesn't and it is unclear why to the
end user because it will be published by the time they check.  In the
end, callers tend to either put in timeouts (and pray), poll the
server's API, or use `crates-index` crate to poll the index.

This isn't sufficient because
- For any new interested party, this is a pit of failure they'll fall
  into
- crates-index has re-implemented index support incorrectly in the past,
  currently doesn't handle auth, doesn't support `git-cli`, etc.
- None of these previous options work if we were to implement
  workspace-publish support (#1169)
- The new sparse registry might increase the publish times, making the
  delay easier to hit manually
- The new sparse registry goes through CDNs so checking the server's API
  might not be sufficient
- Once the sparse registry is available, crates-index users will find
  out when the package is ready in git but it might not be ready through
  the sparse registry because of CDNs

This introduces unstable support for blocking by setting
`publish.timeout` to non-zero value.

A step towards #9507
2022-10-13 08:53:36 -05:00
Scott Schafer 66b62d2745 test(publish): Demonstrate the impact of non-blocking publish 2022-10-13 08:40:26 -05:00
Scott Schafer 8fadfe7f33 test(registry): Allow custom_responders to call normal responders 2022-10-13 08:40:26 -05:00
bors 9bdc926508 Auto merge of #11219 - weihanglo:doc/profiles, r=ehuss
doc(profiles): add module level doc
2022-10-12 22:48:04 +00:00
bors 823d917df0 Auto merge of #11216 - epage:registry, r=ehuss
refactor(publish): Clarify which SourceId is being used

Ran into confusion on this when updating #11062 to be on top of #10907. This now threads both types of sources through which comments explaining each so callers will always have to explicitly acknowledge which they are dealing with.
2022-10-12 21:47:33 +00:00
bors 5788d76d68 Auto merge of #11209 - arlosi:sparse-kind, r=ehuss
Add new SourceKind::SparseRegistry to differentiate sparse registries

Refactor sparse registry to have its own `SourceKind`.
Follow up from https://github.com/rust-lang/cargo/pull/11177#issuecomment-1272395571

r? `@ehuss`
2022-10-12 21:03:19 +00:00
bors 642a0e625d Auto merge of #11205 - arlosi:build-deadlock, r=ehuss
Fix deadlock when build scripts are waiting for input on stdin

### What does this PR try to resolve?

#10738 introduced a regression where build scripts did not close stdin, causing deadlocks for build scripts waiting for stdin.

Fixes #11196 by not piping `stdin` unless requested by the `ProcessBuilder`.

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

Run a build script that reads from stdin and check that it no longer hangs. See the POC in the linked issue. The included test hangs without the fix.

r? `@ehuss`
2022-10-12 20:18:44 +00:00
bors 953a63013e Auto merge of #11184 - weihanglo:features2-refactor, r=ehuss
refactor: New variant `FeaturesFor::ArtifactDep`
2022-10-12 19:35:06 +00:00
Weihang Lo 74d7fe395a
doc(profiles): add module level doc 2022-10-12 19:10:41 +01:00
Arlo Siemsen d51ed05324 Fix deadlock when build scripts are waiting for input on stdin 2022-10-12 11:46:51 -05:00
bors 35162068fb Auto merge of #11221 - arlosi:fixci, r=weihanglo
Fix rustdoc warning about unclosed HTML tag

nightly rustdoc is warning about `<name>` being an unclosed HTML tag. Fix by using backticks instead of single quotes.
2022-10-12 15:14:38 +00:00
Arlo Siemsen c99e9732f9 Use backticks instead of single quotes to fix rustdoc CI 2022-10-12 10:07:15 -05:00
Ed Page c9f984a9b4 refactor(publish): Clarify which SourceId is being used
Ran into confusion on this when updating #11062 to be on top of #10907.
This now threads both types of sources through which comments explaining
each so callers will always have to explicitly acknowledge which they
are dealing with.
2022-10-12 09:57:29 -05:00
bors 83a1f66d11 Auto merge of #11210 - epage:publish, r=weihanglo
refactor(tests): Prepare for wait-for-publish test changes

In #11062, we are updating `cargo publish` to wait until a package is published.   The problem is a lot of our tests will block until the timeout.  In finding the tests to update, I was originally relying on test failures from the extra output when timing out.  The problem is not all tests verify the test output so they don't fail.

This tries to update the tests to make the introduction of a timeout more obvious.
- Adding `with_stderr` where it wasn't before
- Moving away from `with_stderr_contains` for publish tests

To help with that, I made the predicates on cargo commands more consistent.

I also moved descriptions of tests to be outside of the test so I can more easily document the `registry::init` calls with what we are doing.
2022-10-11 22:59:06 +00:00
bors 8e740bb6c8 Auto merge of #11215 - arlosi:sparse-cfg, r=weihanglo
Add configuration option for controlling crates.io protocol

### What does this PR try to resolve?

Currently, if `-Z sparse-registry` is passed, then Cargo will access crates.io using the sparse protocol. Since we want to stabilize this feature soon, we need a stable way to control which protocol is used.

This adds a config option `registries.crates-io.protocol` that can be set to either `sparse` or `git`. If the option is unset, it will be `sparse` if `-Z sparse-registry` is enabled, otherwise it will be `git`.

This PR does not stabilize `sparse-registry`. Using `registries.crates-io.protocol` without `-Z sparse-registry` will result in an error.

The next steps after PR are to:
* stabilize `sparse-registry`
* make `sparse` the default protocol

### Additional information
The config option is based on the discussion in this note: https://hackmd.io/`@rust-cargo-team/B13O52Zko`
2022-10-11 22:01:32 +00:00
Arlo Siemsen d77aef5ba4 Add configuration option for controlling crates.io protocol
`registries.crates-io.protocol` can be set to either `sparse` or `git`.
The default is `git` unless `-Z sparse-registry` is passed.
2022-10-11 14:44:09 -05:00
Arlo Siemsen 56f68168f3 Add new SourceKind::SparseRegistry to differentiate sparse registries 2022-10-11 09:26:59 -05:00
bors b8f30cb23c Auto merge of #11207 - weihanglo:doc-polish, r=epage
Add more doc comments for three modules
2022-10-10 19:16:06 +00:00
Weihang Lo 24fa52780b
doc(util/profile): polish 2022-10-10 20:01:38 +01:00
Weihang Lo b981b7e542
doc(cargo_compile): polish 2022-10-10 20:01:38 +01:00
bors fef785a14f Auto merge of #11208 - tshepang:patch-1, r=epage
docs: fix
2022-10-10 18:26:19 +00:00
Tshepang Mbambo daf6fd366c
docs: fix 2022-10-10 20:17:31 +02:00
Ed Page 08df53ba48 refactor(tests): Be explicit about publish stderr 2022-10-10 13:03:20 -05:00
Ed Page 5e5b5325be refactor(tests): Be more explicit about publish stderr
This will help find tests timing out due to #11062
2022-10-10 12:54:32 -05:00
Weihang Lo 92007a5897
doc(unit_dependencies): polish 2022-10-10 18:52:44 +01:00
Ed Page 5e1a647924 refactor(tests): Consistent predicate ordering 2022-10-10 12:50:54 -05:00
Ed Page af82aa0b68 refactor(tests): Remove redundant with_status(0) 2022-10-10 12:45:46 -05:00
Ed Page 0846b8eba4 refactor(tests): Document case outside the test, rather than in
This will make it easier to document some of the lines of code
2022-10-10 12:42:53 -05:00
bors e691e18ef8 Auto merge of #11204 - cassaundra:remove-completions, r=weihanglo
Add completions for `cargo remove`

### What does this PR try to resolve?

This PR continues the deferred work of #11099 by adding bash and zsh completions for the cargo remove subcommand.

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

There doesn't seem to be much in the way of testing for these completions automatically, so I would suggest verifying that they work in practice and sufficiently cover the subcommand's surface area.

### Additional Information

I will also soon post a PR for cargo remove's documentation.
2022-10-10 07:53:39 +00:00
Cassaundra Smith 3b6d2c4c8c
Add completions for cargo remove 2022-10-09 16:14:07 -07:00
bors 0c29d43b9a Auto merge of #11077 - weihanglo:issue-10992, r=ehuss
Config file loaded via CLI takes priority over env vars

### What does this PR try to resolve?

Fixes #10992

Behaviour changes: After this commit, config files loaded via CLI take
priority over env vars. Config files loaded via [`config-include`]
feature also get a higher priority over env vars, if the initial config
file is being loaded via CLI.

Cargo knows why it loads a specific config file with `WhyLoad` enum,
and store in the field of `Definition::Cli(…)`. With this additional data,
config files loaded via `--config <path>` get a `Definition::Cli(Some(…))`.
In contrast, `--config <value>` with ordinary values become `Definition::Cli(None)`.

The error message of the `Definition::Cli(Some(…))` is identical to
`Definition::Path(…)`, so we won't lose any path information to debug.

[`config-include`]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#config-include

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

Reviewing commit by commit is probably fine. The first two commits adding tests to `config-cli` and `config-include`, which exercises the expected behaviour we are going to fix in the next commits.

To check the precedence, set up a project with an extra config file, such as

```
# Expect to have a target-dir named `foo`
CARGO_BUILD_TARGET_DIR='env' cargo c --config 'build.target-dir = "cli"' --config .cargo/foo.toml

# Inside .cargo/foo.toml
[build]
target-dir = "foo"
```

### Additional information

This is a bit hacky IMO. I don't like leaking the path info to `Definition::Cli`. However, it is really tricky to provide information for deserialization before values get merged.
2022-10-09 15:24:20 +00:00
Weihang Lo e0502e4e78
test(config-include): fix typo
Co-authored-by: Jon Gjengset <jon@thesquareplanet.com>
2022-10-09 16:14:20 +08:00
bors 25c5ced766 Auto merge of #11197 - weihanglo:enum-default, r=epage
Use `#[default]` when possible

Just realize that we can derive `Default` for some enums with `#[default]` attribute. This makes default value closer to enum definition.

Ref: https://doc.rust-lang.org/std/default/trait.Default.html#enums
2022-10-09 00:42:02 +00:00
Weihang Lo 8fbc8459d5
Use #[default] when possible
Make the default value closer to enum definition.
2022-10-09 00:30:14 +01:00
Weihang Lo 303d8c3688
wording: if -> when 2022-10-08 08:49:32 +01:00
Weihang Lo cc204e8744
refactor(features2): new variant FeaturesFor::ArtifactDep
As the existence of `FeaturesFor` is acting as a key that discriminate
activated features for the same package with different circumstances.
Artifact dependencies deserve its own variant and it makes things clear to me.

- `NormalOrDevOrArtifactTarget(None)` ->  `NormalOrDev`
- `NormalOrDevOrArtifactTarget(Some(Target))` -> `ArtifactDep(Target)`
2022-10-08 08:39:42 +01:00
bors d9b05a149c Auto merge of #10907 - arlosi:sr2, r=ehuss
Implement RFC 3289: source replacement ambiguity

### Implements [RFC 3289](https://github.com/rust-lang/rfcs/pull/3289)
* When the crates-io source is replaced, the user needs to specify `--registry <NAME>` when running an API operation to disambiguate which registry to use. Otherwise, cargo will issue a new error.
* In source replacement, the `replace-with` key can reference the name of an alt registry in the `[registries]` table.
* Publishing to source-replaced crates.io is no longer permitted using the crates.io token (`registry.token`). We have had a deprecation warning in place since #7973 (1.45.0).

### Testing
* Tests that interacting with crates.io use the new `replace_crates_io` function, which internally sets an environment variable to change the URL of crates.io.

Changes are insta-stable.

cc #10894
r? `@Eh2406`
2022-10-08 03:50:40 +00:00
Arlo Siemsen dd5134c7a5 Implement RFC 3289: source replacement ambiguity 2022-10-07 22:30:59 -05:00
bors 8743325fe0 Auto merge of #11193 - cassaundra:wrong-cargo-test, r=ehuss
Use correct version of cargo in test

Fix `cargo_remove::offline` test using wrong version of cargo in test, the local version and calling instance of cargo instead of the one being tested.

Issue discovered in #10907 after merge of  #11099.
2022-10-08 00:47:04 +00:00
Cassaundra Smith 40a387c4bd
Use correct version of cargo in test 2022-10-07 17:03:29 -07:00
bors 882c5dd830 Auto merge of #11145 - hi-rustin:rustin-patch-login, r=weihanglo
Check empty input for login

### What does this PR try to resolve?

close https://github.com/rust-lang/cargo/issues/11144
Check empty input for login.

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

- unit test
- cargo login and enter
2022-10-07 20:37:58 +00:00
bors d1a2592265 Auto merge of #11069 - arlosi:retry, r=Eh2406
Add retry support to sparse registries

Sparse (HTTP) registries currently do not respect Cargo's retry policy for http requests.

This change makes sparse registries use the same retry system as package downloads.
2022-10-07 19:56:05 +00:00
bors 3cdf1ab25d Auto merge of #11190 - epage:test, r=weihanglo
fix(test): Distinguish 'testname' from escaped arguments

When working on clap v4, it appeared that `last` and `trailing_var_arg`
are mutually exclusive, so I called that out in the debug asserts in
#4187.  Unfortunately, I didn't document my research on this
as my focus was elsewhere.

When updating cargo to use clap v4 in #11159, I found `last` and
`trailing_var_arg` were used together.  I figured this was what I was
trying to catch with above and I went off of my intuitive sense of these
commands and assumed `trailing_var_arg` was intended, not knowing about
the `testname` positional that is mostly just a forward to `libtest`,
there for documentation purposes, except for a small optimization.

So it looks like we just need the `last` call and not the
`trailing_var_arg` call.

This restores us to behavior from 531ce1321d which is what I originally
wrote the tests against.

It looks like #11159 was merged after the last beta branch was made, so we shouldn't
need to cherry-pick this into any other release.

For reviewing this, I made the test updates in the first commit, showing the wrong behavior.  The following commit fixes the behavior and updates the tests to expected behavior.

Fixes #11191
2022-10-07 17:34:03 +00:00
Arlo Siemsen dcc512b317 Add retry support to sparse registries 2022-10-07 12:00:24 -05:00
Ed Page 3dd8413f77 fix(test): Distinguish 'testname' from escaped arguments
When working on clap v4, it appeared that `last` and `trailing_var_arg`
are mutually exclusive, so I called that out in the debug asserts in
clap-rs/clap#4187.  Unfortunately, I didn't document my research on this
as my focus was elsewhere.

When updating cargo to use clap v4 in #11159, I found `last` and
`trailing_var_arg` were used together.  I figured this was what I was
trying to catch with above and I went off of my intuitive sense of these
commands and assumed `trailing_var_arg` was intended, not knowing about
the `testname` positional that is mostly just a forward to `libtest`,
there for documentation purposes, except for a small optimization.

So it looks like we just need the `last` call and not the
`trailing_var_arg` call.

This restores us to behavior from 531ce1321 which is what I originally
wrote the tests against.
2022-10-07 10:23:55 -05:00
bors aff3bb8083 Auto merge of #11177 - arlosi:sparse-lockfile, r=weihanglo
Fix sparse registry lockfile urls containing 'registry+sparse+'

The `Cargo.lock` file for alternative sparse registries incorrectly lists the url as `registry+sparse+` rather than `sparse+`.

Fixes #10963
2022-10-07 15:22:39 +00:00