-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Use JSON for cargo metadata parsing #9373
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -227,10 +227,9 @@ def cargo_crate_name(cargo_dir, manifest_path, results) | |||||||||||||||||||||||||||
| raise Gem::InstallError, "cargo metadata failed#{exit_reason}" | ||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # cargo metadata output is specified as json, but with the | ||||||||||||||||||||||||||||
| # --format-version 1 option the output is compatible with YAML, so we can | ||||||||||||||||||||||||||||
| # avoid the json dependency | ||||||||||||||||||||||||||||
| metadata = Gem::SafeYAML.safe_load(output) | ||||||||||||||||||||||||||||
| # cargo metadata output is specified as json | ||||||||||||||||||||||||||||
| require "json" | ||||||||||||||||||||||||||||
| metadata = JSON.parse(output) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| metadata = JSON.parse(output) | |
| metadata = | |
| begin | |
| JSON.parse(output) | |
| rescue JSON::ParserError => error | |
| if Gem.configuration.really_verbose | |
| puts output | |
| else | |
| results << output | |
| end | |
| raise Gem::InstallError, "cargo metadata produced invalid JSON: #{error.message}" | |
| end |
Copilot
AI
Mar 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open3.capture2e merges stdout+stderr, but cargo metadata writes JSON to stdout and can emit warnings/diagnostics to stderr even on success. With the new JSON.parse(output), any stderr content will make the string invalid JSON and break installs. Capture stdout separately (e.g., Open3.capture3 or capture2 with stderr captured independently) and parse only stdout; keep stderr for really_verbose/results output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that cargo metadata is parsed as JSON, the earlier
Gem.load_yamlin this method is unused and forces the YAML engine to be loaded during Rust extension installs. Please remove that call to avoid an unnecessary dependency/load cost (and to align with the goal of moving away from Psych).