123 Commits

Author SHA1 Message Date
Scott Schafer
d36c326926
chore(deps): update rust crate annotate-snippets to 0.12.1 2025-09-02 15:43:38 -06:00
Ed Page
db6891f244 fix(cli): Show the bad manifest path
In most cases, this will just be what you passed on the command line.
Even when its not, that likely represents a programmer error.

I mostly did this to help see what was the cause of a test failure.
2025-08-29 15:42:44 -05:00
Ross Sullivan
a24ae6fd58
feat(build-dir): Stabilize build-dir 2025-08-15 11:00:01 +09:00
Ross Sullivan
92d9a94d02
chore: Migrated testsuite to testsuite::prelude 2025-06-25 22:37:24 +09:00
Ross Sullivan
54e5369584
feat(build-dir): Added build-directory to cargo metadata output 2025-04-02 21:38:35 +09:00
Ross Sullivan
155aaae22e
test(build-dir): Added build_directory field to cargo metadata output 2025-04-02 21:36:05 +09:00
Alex Crichton
70dc4d8331 Don't use $CARGO_BUILD_TARGET in cargo metadata
This commit fixes a (five year old!) regression in `cargo metadata`
where if `--filter-platform` isn't explicitly specified it will
accidentally read `$CARGO_BUILD_TARGET` (or `build.target`
configuration) and use that as the default `--filter-platform`. The
reason for this is that the calculation for targets changed in #8167
and while the shared function makes sense for other commands such as
`cargo build` the targets have a different meaning in `cargo metadata`
so a slightly different set of functionality is desired.

This commit fixes the issue by introducing a new constructor for the
list of `CompileKind` variants where the fallback of "if nothing is
specified" is explicitly chosen.
2025-03-06 09:00:00 -08:00
Alex Crichton
2da492b8e5 Add a test showing that cargo metadata differs with CARGO_BUILD_TARGET
This'll change in the next commit.
2025-03-06 09:00:00 -08:00
Alex Crichton
895892e0a8 Strip trailing whitespace in tests/testsuite/metadata.rs 2025-03-06 09:00:00 -08:00
Ed Page
f80fc018a6 test: Ensure we don't rely on unit return values
This will allow changing `Execs::run` return type
2024-11-18 20:52:53 -06:00
Ed Page
f92e54faf9 test: Migrate remaining metadata with_json tests to snapbox 2024-10-03 21:15:10 -05:00
Ed Page
a6cf1be655 test: Switch from allow to expect deprecated
This caught a couple of lingering items.
2024-09-23 20:44:06 -05:00
Ethan Brierley
fe9600675e
feat: include public/private dependency status in cargo metadata output 2024-09-07 07:28:28 +01:00
Ethan Brierley
6829bf7ae0
test: public dependencies don't show up in cargo-metadata 2024-09-07 07:28:28 +01: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
b0e515aa61 fix(test): Move 'cargo_home' from 'install' to 'paths'
This is used outside of `cargo install` contexts and this makes it more
discoverable for those use cases.
2024-07-19 10:50:42 -05:00
Ed Page
0ccafcace9 fix(toml): Improve error on missing package and workspace
That the error was confused was brought up in #13904
2024-07-17 15:52:37 -05:00
eth3lbert
692f0ffb09
test: migrate metadata to snapbox 2024-07-06 07:02:58 +08: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
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
Ed Page
b930f7ad1b test(metadata): Show behavior with TOML-specific types
The goal is to know if/when these change so we can have a conversation
about what to do.
2024-04-04 16:37:39 -05:00
Ed Page
4ab2797f36 feat(lock): Print lockfile changes on all commands 2024-03-12 13:39:56 -05:00
bors
69726309bf Auto merge of #12783 - dvdhrm:pr/libname2, r=ehuss
cargo: prevent dashes in lib.name

The TOML parser of Cargo currently refuses `lib.name` entries that contain dashes. Unfortunately, it uses the package-name as default if no explicit `lib.name` entry is specified. This package-name, however, can contain dashes.

Cargo documentation states that the package name is converted first, yet this was never implemented by the code-base.

Fix this inconsistency and convert the package name to a suitable crate-name first.

This fixes #12780. It is an alternative to #12640.
2024-03-16 20:50:35 +00: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
594c96ad51 refactor(metadata): Switch opaque ID from PackageID to PackageIDSpec 2023-12-06 08:58:56 -06:00
David Rheinsberg
3ca04e261e cargo: prevent dashes in lib.name
The TOML parser of Cargo currently refuses `lib.name` entries that
contain dashes. Unfortunately, it uses the package-name as default if no
explicit `lib.name` entry is specified. This package-name, however, can
contain dashes.

Cargo documentation states that the package name is converted first, yet
this was never implemented by the code-base.

Fix this inconsistency and convert the package name to a suitable
crate-name first.
2023-10-17 13:48:41 +02:00
Ed Page
bfb5d1db0e fix(toml): Default package.publish based on presence of package.version
Before the default was hardcoded to `true`.  The problem was that means
that to remove the `package.version` boilerplate, you had to add
`package.publish = false` boilerplate.

To make the errors easier to understand in this situation, I err on the
side of encouraging people to put `publish = true` in their manifests.

By making this change, we also unblock "cargo script" /
`Cargo.toml` unifying the handling of `package.publish`.
2023-10-11 13:17:03 -05:00
Ed Page
1923b5b862 feat(toml): Allow versionless packages
This defaults the version to `0.0.0` for most of cargo.

It is an error to lack a version and have a package publishable.
That means you have to add `publish = false`.
2023-10-11 13:13:44 -05:00
Ed Page
5c9a126911 test(toml): Verify existing version-less behavior 2023-10-06 12:21:07 -05:00
Ed Page
53dcd2f454 fix(manifest): Provide more context on sematic errors 2023-08-24 16:27:53 -05: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
Scott Schafer
a32af2fff1 fix(toml): Provide a way to show unused manifest keys for workspace inheritance 2023-03-01 13:43:57 -06:00
Ed Page
6007f05a85 chore: Update to toml v0.6, toml_edit v0.18
`toml` replaces `toml_edit::easy`, using `toml_edit` as its parser.
2023-01-19 15:26:28 -06:00
Weihang Lo
d02e36cea1
Only output field extern_name when using -Zbindeps 2023-01-16 14:12:32 +00:00
Weihang Lo
690e6a4128
cargo-metadata: error out if same dep with differnt names
Previous, `cargo metadata` allows a dependency with different renamed
co-exist. However, its `resolve.nodes.deps` will miss that dependency,
which is wrong. After this commit, `cargo metadata starts erroring out
for that situation.
2023-01-16 14:12:32 +00:00
Weihang Lo
272193aa29
cargo-metadata: error out when encountering invalid artifact kind syntax
This refactor reuse the logic of
`core::compiler::unit_dependencies::match_artifacts_kind_with_targets`
to emit error if there is any syntax error in `ArtifactKind`.

It also put `match_artifacts_kind_with_targets` to a better place `core::compiler::artifact`.
2023-01-16 14:12:13 +00:00
Weihang Lo
e5ec492b6f
cargo-metadata: support -Zbindeps info 2023-01-16 14:12:13 +00:00
Weihang Lo
c51c6bb6ac
chore: reflect to clap updates 2023-01-14 09:23:39 +00:00
Ed Page
5f30808d00 chore: Update tests for latest clap 2022-10-13 15:16:38 -05:00
Ed Page
96948f7a24 refactor(cli): Upgrade to clap v4 2022-09-28 13:32:14 -05:00
Scott Schafer
ab18bd40d5 refactor(testsuite): Replace [project] with [package] 2022-09-26 09:51:16 -06:00
Robert DiMartino
7b16e59896 Add metadata test for invalid publish field 2022-09-20 09:34:58 -04:00
Robert DiMartino
7a50c0c718 Remove maybe_workspace_vec_string specific deserializer 2022-09-19 23:45:51 -04:00
Robert DiMartino
06c31de972 Improve errors for TOML fields that support workspace inheritance 2022-09-19 23:41:20 -04:00
Ky Phan
8f1a75d584 Add unit test for invalid authors, refactor name 2022-08-08 22:05:43 +07:00
Scott Schafer
c239e407e7 add a reason to masquerade_as_nightly_cargo so it is searchable 2022-07-15 21:32:23 -05:00