Commit graph

2893 commits

Author SHA1 Message Date
Scott Schafer 8fadfe7f33 test(registry): Allow custom_responders to call normal responders 2022-10-13 08:40:26 -05: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
Arlo Siemsen d51ed05324 Fix deadlock when build scripts are waiting for input on stdin 2022-10-12 11:46:51 -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
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
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
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 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
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
Ed Page dd6228ebdb test(test): Verify escaping behavior 2022-10-07 10:08:26 -05:00
Cassaundra Smith 805f424535
Add tests for cargo remove 2022-10-06 13:05:42 -07:00
Arlo Siemsen 931d8cbf99 Fix sparse registry lockfile urls containing 'registry+sparse+' 2022-10-05 11:08:00 -05:00
Eric Huss fc1f5a43fb Provide a better error message when mixing dep: with / 2022-10-02 18:03:01 -07:00
hi-rustin ff575b290f Also check the token argument
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-09-29 17:01:12 +08:00
hi-rustin b3da66f65b Add tests
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-09-29 17:01:12 +08:00
Ed Page 96948f7a24 refactor(cli): Upgrade to clap v4 2022-09-28 13:32:14 -05:00
bors 928561a0c5 Auto merge of #11135 - Muscraft:remove-ref-to-project, r=weihanglo
Reduce references to `[project]` within cargo

There was an issue (#11129) with `[project]` being put in the docs but nothing else stating what `[project]` is. This was an oversight by me when writing the docs as `[project]` is still supported in cargo. [Back in 2014](86b2a2a432) `[project]` was [renamed to `[package]`](https://github.com/rust-lang/cargo/issues/3388#issuecomment-266504735), since then it has kinda sat as something that exists and is supported but not really. I brought this up in a [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/removal.20of.20.60.5Bproject.5D.60), and it was suggested that we could show a warning when `[project]` is used in a manifest of a _top-level_ crate.

To go slightly further than this I tried to change as many references from `[project]` to `[package]` as possible. This should hopefully help with confusion between `[project]` and `[package]` in the future.

This PR also includes a cherry-picked commit from #11131 as it was having issues with bors and fits well with the changes that are being made in this PR.

This should ideally be reviewed commit by commit
2022-09-27 09:26:27 +00:00
bors f6de921a5d Auto merge of #11114 - matklad:build-falgs, r=ehuss
Iteratively construct target cfg

When setting target features via rustflags via `[build]` config key, cargo correctly propagates them to rustc (via -C flag) and to build.rs (via CARGO_CFG_TARGET_FEATURE env var).

However, if `[target.cfg]` is used instead, build.rs doesn't get the flags (rustc still gets them though).

This changes it so that cargo will call `rustc` up to two times to collect the `cfg` values, updating which flags to use on the second call based on the cfg discovered in the first call.

Closes #6858.
2022-09-27 01:08:14 +00:00
Scott Schafer 8625d7274a fix(cargo): Add a warning on [project] table being used in a manifest 2022-09-26 10:32:48 -06:00
Scott Schafer cabee4f511 fix(cargo): Add a warning on package and project in the same Cargo.toml 2022-09-26 10:32:07 -06:00
Scott Schafer ab18bd40d5 refactor(testsuite): Replace [project] with [package] 2022-09-26 09:51:16 -06:00
Aleksey Kladov c333b0a7be when learning target information, run a little fixedpoint iteration loop 2022-09-26 13:22:43 +01:00
jiangying 260620e755
Update test.rs 2022-09-26 15:28:16 +08:00
bors 902bb0c2fc Auto merge of #11111 - Muscraft:http-publish-not-noop, r=ehuss
Http publish not noop

Currently the `cargo-test-support` `HttpServer` is noop on publish. This was causing issues with #11062 as there is [not function registry to pull from](https://github.com/rust-lang/cargo/pull/11062#issuecomment-1241220565). [A suggested fix](https://github.com/rust-lang/cargo/pull/11062#issuecomment-1241349110) to this was to have the test `HttpServer` act like a real registry and write to the filesystem. This would allow for tests to be run over the HTTP API and not fail since there was nothing to pull from.

This PR implements that suggestion by adding a body field to `Request`, and when hitting the publish endpoint it will try and write the `.crate` and manifest information to the filesystem.
2022-09-23 00:08:26 +00:00
bors 9230e4839d Auto merge of #11113 - rdimartino:maybeworkspace-deserialize, r=epage
Improve errors for TOML fields that support workspace inheritance

Fixes #10997

This also addresses the issue with `MaybeWorkspace<VecStringOrBool>` mentioned in #10942:

```
Caused by:
  invalid type: string "foo", expected a boolean or vector of strings for key `package.publish`
```

I removed the `maybe_workspace_vec_string` deserializer in 7a50c0c718 because the error message from the inner `Vec<String>` is now surfaced, but I can revert that if it's preferable to keep those changes.

I tried to base the `deserialize` implementation off of the derived impl for an untagged enum from `cargo expand`. This approach [ultimately led me](https://github.com/serde-rs/serde/blob/v1.0.144/serde/src/private/de.rs#L218) to adding the `serde-value` dependency.
2022-09-22 20:10:33 +00:00
Scott Schafer 251a2c7915 cargo-test-support: Make publish http api write to file system 2022-09-22 10:00:49 -06:00
Weihang Lo ef7a4ef062
Dont swallow errors when checking existence of a config key 2022-09-22 10:52:39 +01:00
Weihang Lo 2c6647df80
test(alias): with malformed config no proper error emitted
This demonstrate the old behaviour that no proper error is emitted if
there is a parse error during configuration parsing.
2022-09-22 10:46:32 +01:00
bors 23ab870c50 Auto merge of #11106 - x-hgg-x:issue-7992, r=epage
Add support for relative git submodule paths

Fixes #7992.

This is a continuation of #9592, tested on Linux and Windows.

> Git allows submodules to have relative URLs, but cargo does not handle this correctly, and simply fails to update submodules as described in issue https://github.com/rust-lang/cargo/issues/7992. This PR fixes that by passing in the parent git repo url to update_submodules.

The previous PR wasn't compatible on Windows, since it used [`std::path::Path`](https://doc.rust-lang.org/std/path/struct.Path.html) for merging the parent and relative submodule urls.

This PR uses [`url::Url`](https://docs.rs/url/latest/url/struct.Url.html) instead, which has the same behavior on all platforms. It also refers to the [git documentation](https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-add-bltbranchgt-f--force--nameltnamegt--referenceltrepositorygt--depthltdepthgt--ltrepositorygtltpathgt) for the definition of a relative git submodule path.
2022-09-21 18:09:09 +00:00
bors bee9c896c0 Auto merge of #11098 - Emilgardis:early-fail, r=epage
make unknown features on `cargo add` more discoverable

When adding an unknown feature via `cargo add -F krate/feat`, it can be easy to miss the fact that the change failed.

This fixes that by showing the following output on fail

<img width="474" alt="image" src="https://user-images.githubusercontent.com/1502855/191100141-3603cc9a-d4b6-4d6a-bbc6-41b34144b3f0.png">
2022-09-21 17:25:19 +00:00
bors a74a8d0456 Auto merge of #11122 - weihanglo:issue-11101, r=epage
Unlink old final artifacts before compilation
2022-09-21 16:43:29 +00:00
Weihang Lo bf1523b663
test: renamed uplifted artifact remains unmodified after rebuild 2022-09-21 16:02:42 +01:00
x-hgg-x 942f7f9c59 Add support for relative git submodule paths 2022-09-21 13:08:41 +02:00
Emil Gardström 1cc21b65d1
make unknown features on cargo add more discoverable 2022-09-21 08:07:16 +02:00
Ed Page 8f8a79a5a4 fix(cli): Error trailing args rather than ignore
This warning has been in for a sufficient time, requires a hack from
clap to avoid all argument ID validation, and allows users to run the
wrong command (imagine `cargo -- publish --dry-run`).

See also https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Cargo.20ignoring.20arguments.20with.20.60cargo.20--.20check.20--ignored.60
2022-09-20 16:54:01 -05:00
Robert DiMartino 7b16e59896 Add metadata test for invalid publish field 2022-09-20 09:34:58 -04:00
Aleksey Kladov 1a07767587 add failing test for CARGO_CFG_TARGET_FEATURE
When setting target features via rustflags via `[build]` config key,
cargo correctly propagates them to rustc (via -C flag) and to build.rs
(via CARGO_CFG_TARGET_FEATURE env var).

However, if `[target.cfg]` is used instead, build.rs doesn't get the
flags (rustc still gets them though).
2022-09-20 10:56:56 +01:00