114 Commits

Author SHA1 Message Date
Ed Page
539a48452a perf: Update toml 2025-07-08 11:55:41 -05:00
Ed Page
4ac865d3d7
Rework cargo-test-support & testsuite to use CARGO_BIN_EXE_* for Cargo (#15692)
### What does this PR try to resolve?

This PR reworks `cargo-test-support` and `testsuite` to use Snapbox's
[`cargo_bin!()`](https://docs.rs/snapbox/latest/snapbox/cmd/macro.cargo_bin.html)
instead of
[`cargo_bin()`](https://docs.rs/snapbox/latest/snapbox/cmd/fn.cargo_bin.html)
which makes assumptions about the structure of Cargo's build directory.
`cargo_bin!()` uses `CARGO_BIN_EXE_*` for locating the `cargo` binary
which should be more resilient to directory/layout changes.

Linking a relevant Zulip discussion
[here](https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/cargo_bin_exe.20and.20tests/with/513638220)[#t-cargo
> cargo_bin_exe and
tests](https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/cargo_bin_exe.20and.20tests/with/513638220)

As shown in that link, we could make these variables available at
runtime and not need to do this. However, `cargo-test-support`, as an
API, is a bit weird in that it is baking in support for one specific
binary. This can be confusing for callers and makes it more annoying for
callers provide their own `fn cargo`, e.g. see crate-ci/cargo-fixit#7

### Implementation Notes

`cargo_bin!()` only works when being called from the `testsuite` as it's
only set when executing integration tests and `cargo-test-support` is a
regular crate.
To make this change, I introduced an extension trait `CargoProjectExt`
in `testsuite` for running `.cargo()` and implemented it on `Project`.

In `cargo-test-support` other functionality relies on `.cargo()` so
these also needed to be moved to `testsuite`
*
[`src/tools.rs`](https://github.com/rust-lang/cargo/blob/master/crates/cargo-test-support/src/tools.rs)
* Parts
[`src/cross_compile`](https://github.com/rust-lang/cargo/blob/master/crates/cargo-test-support/src/cross_compile.rs)
* I had to split this up unfortunately, as `disabled()` requires running
Cargo to check if we should disable cross compile tests.
* Other fns in `cross_compile` are used in `cargo-test-support` so
moving everything to `testsuite` would have ended up requiring moving
many things to test suite.

### How to test and review this PR?

I'd definitely recommend reviewing commit by commit.
There are a lot of diffs due to the nature of reorganizing things.
I did my best to split things things into smaller PRs but they still
contain a lot of `use` statement diffs.

r? @epage
2025-06-26 15:21:51 +00:00
motorailgun
8f4ae79cb5 fix: Expand error messages around path dependency on cargo package and cargo publish 2025-06-26 02:53:54 +00:00
Ross Sullivan
92d9a94d02
chore: Migrated testsuite to testsuite::prelude 2025-06-25 22:37:24 +09:00
Ed Page
355bc56244 fix(publish): Remove quotes around packages
These aren't there elsewhere
2025-06-04 19:54:27 -05:00
Eric Huss
b5394da406 Update annotate-snippets from 0.11.4 to 0.11.5
Changelog: https://github.com/rust-lang/annotate-snippets-rs/blob/master/CHANGELOG.md#0115---2024-12-09

Looks to have some minor rendering differences.
2025-02-09 12:46:36 -08:00
Ed Page
f6514977ef
feat: add cargo pkgid support for cargo-script (#14961)
### What does this PR try to resolve?

close https://github.com/rust-lang/cargo/issues/14831

In this PR, we added the `cargo pkgid` support for the cargo-script.

For the package itself:

```console
cargo pkgid --manifest-path foo.rs
path+file:///my-project/foo.rs/foo#0.86.0
```

For its dependence:

```console
cargo pkgid --manifest-path foo.rs -p sqlx
registry+https://github.com/rust-lang/crates.io-index#sqlx@0.7.4
```

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

I have updated the unit tests and also added more test cases for it.

### Additional information

None
2025-02-04 19:52:07 +00:00
Rustin170506
d4c1eeeaa0 refactor: use manifest path as the key
Signed-off-by: Rustin170506 <techregister@pm.me>

fix
2025-01-20 21:53:13 +08:00
Ed Page
9bea071ff5 fix(login): Deprecate CLI token
This came up in #13623 to avoid putting tokens into shell history.
2025-01-13 10:40:13 -06:00
Weihang Lo
5dfdd59009
feat: make lockfile v4 the default
This commit makes lockfile version 4 the default version when Cargo
tries to write to a lockfile.

The lockfile version 4 has been stabilized since 1.78.0,
and will become default in 1.83.0.
the length of transition period is pretty similar as before.

One caveat is that in other output from Cargo,
e.g., `cargo metatada`, status messages,
`SourceID` will display in the v4 URL encoded format.
This shouldn't affect the majority of Rust users,
as `SourceId` representation should be opaque to them,
unless comparing `SourceId` across different version of toolchains.
2024-09-24 20:43:02 -04:00
Ed Page
d2ec764995 fix(resolve): Dont show locking workspace members
This is for `cargo generate-lockfile` and when syncing the lockfile with
the manifest.
We still show it for `cargo update` because of `cargo update
--workspace`.

We hacked around this previously by filtering out the `num_pkgs==1` case
for single packages but this didn't help with workspaces.
2024-08-22 16:57:06 -05:00
Ed Page
bb5488c9a0 tests: Update for snapbox deprecations 2024-07-24 10:42:50 -05:00
Ed Page
5b9799c6f4 refactor: Migrate from extern crate to test-support prelude
We now include the prelude in so many places, this simplifies how we can
present how `cargo-test-support` works.

Yes, this included some `use` clean ups but its already painful enough
walking through every test file, I didn't want to do it twice.
2024-07-12 15:57:00 -05:00
Ed Page
fd8a91d185 fix(test): Un-redact Packaged files
This is a partial revert of ##14121
(e11d1722bb6e1e58c91adb1964993c74b45f4293)

Our focus for redacting (auto or with globs) includes
- run-specific information (timing, hashes, platform-specific wording)
- rustc-specific information

(We tend to use globs for rustc-specific information because there might
be some very specific times we need to care about some of the details)

However, "Packaged files" does not fit into any of that and, for now, we
are erring on the side of redacting less, rather than more, with the
move to snapbox.
As we see how it works out and what the underlying requirements are, we
can revisit this.
2024-06-21 11:05:41 -04:00
d1t2
e11d1722bb
test: Auto-redact file number 2024-06-19 20:00:56 +08:00
Joe Neeman
c0287bec8d Change verification order during packaging.
Once we support packaging workspaces with dependencies, dependency
packages need to be built before anything is verified. In addition to a
little refactoring, this commit reorders the console messages so that
package metadata (archive size, etc.) is reported before verification
results.

Co-Authored-By: Tor Hovland <55164+torhovland@users.noreply.github.com>
2024-06-14 15:15:03 -05:00
Ed Page
e589ed7f59 test: Resolve alt_registry deprecations 2024-06-10 10:20:52 -05:00
Ed Page
dc5ac62cab fix(test): Deprecate non-snapbox assertions
While this is noisy and hides other deprecations, I figured deprecations would
make it easier for people to discover what tasks remain and allow us to
divide and conquer this work rather than doing a heroic PR.
In theory, this will be short lived and we'll go back to seeing
deprecations in our tests.
2024-06-10 10:20:52 -05:00
Ed Page
3054936cab refactor: Port from assert_matches_exact to assert_e2e
This leaves off `validate_crate_contents` as that would be an effort on
its own
2024-05-29 14:08:10 -05:00
Josh Stone
6dda4e006b Fix 2 tests for offline execution
In `alt_registry::warn_for_unused_fields`, the second part of the test
runs on `--registry crates-io`, so it needs a local replacement url.

In `install::install_global_cargo_config`, it was adding to the "config"
file, but the `pkg` before it configured the dummy registry replacement
in "config.toml". So that replacement wasn't actually used, and if you
ran tests online it was trying to install `bar v0.1.1` from the real
registry! The filename is now fixed, and the test double-checks that
we're only trying to install the local `bar v0.0.1`.
2024-04-22 16:19:17 -07:00
Ed Page
1876326b6b feat(resolve): Tell the user the style of resovle done
This is to help with #9930

Example changes:
```diff
-[LOCKING] 4 packages
+[LOCKING] 4 packages to latest version
-[LOCKING] 2 packages
+[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions
-[LOCKING] 2 packages
+[LOCKING] 2 packages to earliest versions
```

Benefits
- The package count is of "added" packages and this makes that more
  logically clear
- This gives users transparency into what is happening, especially with
  - what rust-version is use
  - the transition to this feature in the new edition
  - whether the planned config was applied or not (as I don't want it to
    require an MSRV bump)
- Will make it easier in tests to show what changed
- Provides more motiviation to show this message in `cargo update` and
  `cargo install` (that will be explored in a follow up PR)

This does come at the cost of more verbose output but hopefully not too
verbose.  This is why I left off other factors, like avoid-dev-deps.
2024-04-13 20:39:59 -05:00
Josh Stone
a70f23c50b test: don't compress test registry crates
They are still nominally gzipped, but using `Compression::none()` makes
them consistent even across zlib and zlib-ng, and this fixes checksum
differences in the testsuite. There is a one-time update of all those
checksums to catch up with this change though.
2024-04-11 14:58:42 -07:00
Ed Page
4ab2797f36 feat(lock): Print lockfile changes on all commands 2024-03-12 13:39:56 -05:00
Ed Page
14646e6af6 test: Make edition explicit on packages 2024-02-22 11:37:03 -06:00
Ed Page
e7e8d8748a fix(compiler): Clarify we're showing a profile name 2024-02-08 14:01:39 -06:00
Ed Page
69eb49194b fix: Switch more notes/warnings to lowercase
See https://doc.crates.io/contrib/implementation/console.html#style

By fixing existing cases, we make it more likely people will copy a case
they should.

I left out multi-sentance cases because I was unsure how to handle those

r? @weighanglo
2024-02-06 19:52:12 -06:00
Ed Page
675224b3a0 test(config): Shift to config.toml 2024-01-26 13:40:46 -06:00
bors
77f2da7b92 Auto merge of #12914 - epage:metadata, r=weihanglo
fix(metadata): Stabilize id format as PackageIDSpec

### What does this PR try to resolve?

For tools integrating with cargo, `cargo metadata` is the primary interface.  Limitations include:
-  There isn't an unambiguous way to map a package entry from `cargo metadata`  to a parameter to pass to other `cargo` commands.  An `id` field exists but it is documented as an opaque string, useful only for comparisons with other `id`s within the document.
- There isn't an unambiguous way of taking user parameters (`--package`) and mapping them to `cargo metadata` entries.  `cargo pkgid` could help but it returns a `PackageIdSpec` which doesn't exist within the `cargo metadata` output.

This attempts to solve these problems by switching the `id` field from `PackageId` to `PackageIdSpec` which is a [publicly documented format](https://doc.rust-lang.org/cargo/reference/pkgid-spec.html), can be generated by `cargo pkgid`, and is accepted by most commands via the `--package` flag.

As the `"id"` field is documented as opaque, this technically isn't a breaking change though people could be parsing it.

For `cargo_metadata` they do [use a new type that documents it as opaque but publicly expose the inner `String`](https://docs.rs/cargo_metadata/latest/cargo_metadata/struct.PackageId.html).  The `String` wasn't publicly exposed due to a request by users but instead their `PackageId` type replaced using `String`s in the API in oli-obk/cargo_metadata#59 with no indication given as to why the `String` was still exposed.  However, you'll note that before that PR, they had `WorkspaceMember` that parsed `PackageId`.  This was introduced in oli-obk/cargo_metadata#26 without a motivation given.

**Note that `PackageIdSpec` has multiple representation that might uniquely identify a package and we can return any one of them.**

Fixes #7267

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

### Additional information

cc `@oli-obk`
2024-01-15 15:45:36 +00:00
Scott Schafer
0d62ae2fc3
feat: Add rustc style errors for manifest parsing 2023-12-15 13:30:10 -07:00
Ed Page
db2e314077 fix: Improve registry name errors?
Because of workspace inheritance, the errors aren't the greatest
2023-12-13 11:37:08 -06:00
Ed Page
1791353689 fix!: Disallow empty registry names
This was allowed when switching from `toml` v0.5 to `toml_edit` which
started allowing empty keys when parsing TOML.
This mirrors the change
we made for disallowing empty feature names in #12928.
2023-12-13 10:38:37 -06:00
Ed Page
7200646a97 test: Demonstrate existing empty name errors 2023-12-13 10:38:34 -06:00
Ed Page
594c96ad51 refactor(metadata): Switch opaque ID from PackageID to PackageIDSpec 2023-12-06 08:58:56 -06:00
Weihang Lo
e57ce13da8
refactor: --registry always conflicts with --index
Move the validation upfront to clap
2023-09-15 22:33:27 +08:00
Arlo Siemsen
65ec65fe1e Fix printing multiple warning messages for unused fields in [registries] table 2023-08-02 18:20:46 -05:00
charles-r-earp
f43e6d947f Added workspace_default_members to more tests. 2023-05-03 12:44:08 -07: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
Arlo Siemsen
a1cba8fe49 Fix Cargo warning about unused sparse configuration key
When doing a credential lookup, Cargo deserializes the registry configuration and detects the
registries.crates-io.protocol key as unused and issues a warning.

This fixes the issue by adding the field to the struct
2023-04-03 11:27:11 -05:00
Eric Huss
3c295cf5ec Update tests for publish text changes 2023-03-15 08:50:11 -07:00
hi-rustin
814ded6ae9 Check publish_to_alt_registry publish content 2023-03-04 09:11:37 +08:00
hi-rustin
0b06a456f2 Make blocking tests non blocking 2023-02-23 09:11:52 +08:00
hi-rustin
a8233d4df5 Support store public request body in the HTTP mock server 2023-02-23 09:11:52 +08:00
hi-rustin
04d592c7ad Make some blocking tests non-blocking by using API server 2023-02-23 09:11:52 +08:00
Scott Schafer
1873c33482 chore: update alt_registry test to use check 2023-02-15 15:28:48 -06:00
Arlo Siemsen
7dc5506756 Stabilize sparse-registry 2023-01-05 11:04:52 -06:00
Weihang Lo
3d862d8d8b
by default saves credentials to .cargo/credentials.toml 2023-01-04 16:25:52 +00:00
Arlo Siemsen
9827412fee Implement RFC 3139: alternative registry authentication support 2022-11-16 14:36:19 -06:00
Arlo Siemsen
24bf873c83 Fix cargo install --index when used with registry.default 2022-11-15 11:28:29 -06:00
Arlo Siemsen
49fb8f3d88 Fix publishing with a dependency on a sparse registry 2022-10-20 17:21:32 -05:00
Arlo Siemsen
dd5134c7a5 Implement RFC 3289: source replacement ambiguity 2022-10-07 22:30:59 -05:00