Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a JSON output mode to cargo package. #14262

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LawnGnome
Copy link

In multi-crate workspaces, it can be ambiguous where files are sourced from when building packages. This extends the existing --list command line flag to optionally emit JSON when called as -l=json or --list=json. Existing behaviour is unaffected.

The JSON format is slightly different to that proposed in #11666: it exposes the distinction within cargo::ops::cargo_package itself around whether an archive file is generated or sourced from the disk. A new crate created with cargo new --lib foo generates this output:

{
  ".cargo_vcs_info.json": {
    "Generated": {
      "VcsInfo": {
        "git": {
          "sha1": "af0bf5917934ec4684cd23763f90c16242d7c5ce"
        },
        "path_in_vcs": ""
      }
    }
  },
  ".gitignore": {
    "OnDisk": "/tmp/foo/.gitignore"
  },
  "Cargo.toml": {
    "Generated": "Manifest"
  },
  "Cargo.toml.orig": {
    "OnDisk": "/tmp/foo/Cargo.toml"
  },
  "src/lib.rs": {
    "OnDisk": "/tmp/foo/src/lib.rs"
  }
}

I'm open minded as to whether the VcsInfo should actually be included, but it feels like there's little harm in doing so.

Fixes #11666, and is at least extremely relevant to #13953.

In multi-crate workspaces, it can be ambiguous where files are sourced
from when building packages. This extends the existing `--list` command
line flag to optionally emit JSON when called as `-l=json` or
`--list=json`. Existing behaviour is unaffected.

The JSON format is slightly different to that proposed in rust-lang#11666: it
exposes the distinction within `cargo::ops::cargo_package` itself around
whether an archive file is generated or sourced from the disk. A new
crate created with `cargo new --lib foo` generates this output:

```json
{
  ".cargo_vcs_info.json": {
    "Generated": {
      "VcsInfo": {
        "git": {
          "sha1": "af0bf5917934ec4684cd23763f90c16242d7c5ce"
        },
        "path_in_vcs": ""
      }
    }
  },
  ".gitignore": {
    "OnDisk": "/tmp/foo/.gitignore"
  },
  "Cargo.toml": {
    "Generated": "Manifest"
  },
  "Cargo.toml.orig": {
    "OnDisk": "/tmp/foo/Cargo.toml"
  },
  "src/lib.rs": {
    "OnDisk": "/tmp/foo/src/lib.rs"
  }
}
```

I'm open minded as to whether the `VcsInfo` should actually be included,
but it feels like there's little harm in doing so.

Fixes rust-lang#11666, and is at least extremely relevant to rust-lang#13953.
@rustbot
Copy link
Collaborator

rustbot commented Jul 17, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @weihanglo (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. A-cli-help Area: built-in command-line help A-documenting-cargo-itself Area: Cargo's documentation A-interacts-with-crates.io Area: interaction with registries Command-package Command-publish S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 17, 2024
@epage
Copy link
Contributor

epage commented Jul 18, 2024

FYI I'm moving this to Draft as this has not been accepted or needs-mentor yet.

We generally reserve PRs for discussing the implementation and leaving problem, requirements, and solution discussions to the issues. I'd recommend furthering the discussion on the Issue.

@epage epage marked this pull request as draft July 18, 2024 00:03
@bors
Copy link
Contributor

bors commented Jul 26, 2024

☔ The latest upstream changes (presumably #13947) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: Command-line interface, option parsing, etc. A-cli-help Area: built-in command-line help A-documenting-cargo-itself Area: Cargo's documentation A-interacts-with-crates.io Area: interaction with registries Command-package Command-publish S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a json output format of cargo package --list
5 participants