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

Also emit source information for paths #8988

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/cargo/core/source/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::util::{CanonicalUrl, CargoResult, Config, IntoUrl};
use log::trace;
use serde::de;
use serde::ser;
use std::cell::Cell;
use std::cmp::{self, Ordering};
use std::collections::HashSet;
use std::fmt::{self, Formatter};
Expand Down Expand Up @@ -437,12 +438,30 @@ impl Ord for SourceId {
}
}

thread_local! {
static SERIALIZE_STRIP_PATHS: Cell<bool> = Cell::new(false);
}

#[must_use]
#[allow(dead_code)]
pub fn disable_path_serialization() -> impl Drop {
// Ensure that we reset the setting eventually.
struct DropGuard;
impl Drop for DropGuard {
fn drop(&mut self) {
SERIALIZE_STRIP_PATHS.with(|ssp| ssp.set(false));
}
}
SERIALIZE_STRIP_PATHS.with(|ssp| ssp.set(true));
DropGuard
}

impl ser::Serialize for SourceId {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
{
if self.is_path() {
if self.is_path() && SERIALIZE_STRIP_PATHS.with(|ssp| ssp.get()) {
None::<String>.serialize(s)
} else {
s.collect_str(&self.as_url())
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ fn alt_reg_metadata() {
"license": null,
"license_file": null,
"description": null,
"source": null,
"source": "path+file://[..]/foo",
"dependencies": [
{
"name": "altdep",
Expand Down Expand Up @@ -936,7 +936,7 @@ fn alt_reg_metadata() {
"license": null,
"license_file": null,
"description": null,
"source": null,
"source": "path+file://[..]/foo",
"dependencies": [
{
"name": "altdep",
Expand Down Expand Up @@ -1141,7 +1141,7 @@ fn unknown_registry() {
"license": null,
"license_file": null,
"description": null,
"source": null,
"source": "path+file://[..]/foo",
"dependencies": [
{
"name": "bar",
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/features_namespaced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ fn json_exposed() {
"description": null,
"homepage": null,
"documentation": null,
"source": null,
"source": "path+file://[..]/foo",
"dependencies": "{...}",
"targets": "{...}",
"features": {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3106,7 +3106,7 @@ fn metadata_master_consistency() {
"license": null,
"license_file": null,
"description": null,
"source": null,
"source": "path+file://[..]/foo",
"dependencies": [
{
"name": "bar",
Expand Down
42 changes: 21 additions & 21 deletions tests/testsuite/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn cargo_metadata_simple() {
"version": "0.5.0",
"id": "foo[..]",
"keywords": [],
"source": null,
"source": "path+file://[..]/foo",
"dependencies": [],
"edition": "2015",
"license": null,
Expand Down Expand Up @@ -125,7 +125,7 @@ crate-type = ["lib", "staticlib"]
"version": "0.5.0",
"id": "foo[..]",
"keywords": [],
"source": null,
"source": "path+file://[..]/foo",
"dependencies": [],
"edition": "2015",
"license": null,
Expand Down Expand Up @@ -212,7 +212,7 @@ optional_feat = []
"version": "0.5.0",
"id": "foo[..]",
"keywords": [],
"source": null,
"source": "path+file://[..]/foo",
"dependencies": [],
"edition": "2015",
"license": null,
Expand Down Expand Up @@ -440,7 +440,7 @@ fn cargo_metadata_with_deps_and_version() {
"repository": null,
"homepage": null,
"documentation": null,
"source": null,
"source": "path+file://[..]/foo",
"targets": [
{
"crate_types": [
Expand Down Expand Up @@ -616,7 +616,7 @@ name = "ex"
"links": null,
"description": null,
"edition": "2015",
"source": null,
"source": "path+file://[..]/foo",
"dependencies": [],
"targets": [
{
Expand Down Expand Up @@ -709,7 +709,7 @@ crate-type = ["rlib", "dylib"]
"links": null,
"description": null,
"edition": "2015",
"source": null,
"source": "path+file://[..]/foo",
"dependencies": [],
"targets": [
{
Expand Down Expand Up @@ -804,7 +804,7 @@ fn workspace_metadata() {
"homepage": null,
"documentation": null,
"keywords": [],
"source": null,
"source": "path+file://[..]/bar",
"dependencies": [],
"license": null,
"license_file": null,
Expand Down Expand Up @@ -841,7 +841,7 @@ fn workspace_metadata() {
"version": "0.5.0",
"id": "baz[..]",
"keywords": [],
"source": null,
"source": "path+file://[..]/baz",
"dependencies": [],
"license": null,
"license_file": null,
Expand Down Expand Up @@ -933,7 +933,7 @@ fn workspace_metadata_no_deps() {
"version": "0.5.0",
"id": "bar[..]",
"keywords": [],
"source": null,
"source": "path+file://[..]/bar",
"dependencies": [],
"license": null,
"license_file": null,
Expand Down Expand Up @@ -970,7 +970,7 @@ fn workspace_metadata_no_deps() {
"version": "0.5.0",
"id": "baz[..]",
"keywords": [],
"source": null,
"source": "path+file://[..]/baz",
"dependencies": [],
"license": null,
"license_file": null,
Expand Down Expand Up @@ -1032,7 +1032,7 @@ const MANIFEST_OUTPUT: &str = r#"
"name":"foo",
"version":"0.5.0",
"id":"foo[..]0.5.0[..](path+file://[..]/foo)",
"source":null,
"source":"path+file://[..]/foo",
"dependencies":[],
"keywords": [],
"license": null,
Expand Down Expand Up @@ -1222,7 +1222,7 @@ fn package_metadata() {
"version": "0.1.0",
"id": "foo[..]",
"keywords": ["database"],
"source": null,
"source": "path+file://[..]/foo",
"dependencies": [],
"edition": "2015",
"license": null,
Expand Down Expand Up @@ -1299,7 +1299,7 @@ fn package_publish() {
"version": "0.1.0",
"id": "foo[..]",
"keywords": ["database"],
"source": null,
"source": "path+file://[..]/foo",
"dependencies": [],
"edition": "2015",
"license": null,
Expand Down Expand Up @@ -1382,7 +1382,7 @@ fn cargo_metadata_path_to_cargo_toml_project() {
"repository": null,
"homepage": null,
"documentation": null,
"source": null,
"source": "path+file://[..]/bar-0.5.0",
"targets": [
{
"crate_types": [
Expand Down Expand Up @@ -1468,7 +1468,7 @@ fn package_edition_2018() {
"repository": null,
"homepage": null,
"documentation": null,
"source": null,
"source": "path+file://[..]/foo",
"targets": [
{
"crate_types": [
Expand Down Expand Up @@ -1558,7 +1558,7 @@ fn target_edition_2018() {
"repository": null,
"homepage": null,
"documentation": null,
"source": null,
"source": "path+file://[..]/foo",
"targets": [
{
"crate_types": [
Expand Down Expand Up @@ -1766,7 +1766,7 @@ fn rename_dependency() {
"repository": null,
"homepage": null,
"documentation": null,
"source": null,
"source": "path+file://[..]/foo",
"targets": [
{
"crate_types": [
Expand Down Expand Up @@ -1886,7 +1886,7 @@ fn metadata_links() {
"repository": null,
"homepage": null,
"documentation": null,
"source": null,
"source": "path+file://[..]/foo",
"targets": [
{
"crate_types": [
Expand Down Expand Up @@ -1974,11 +1974,11 @@ fn deps_with_bin_only() {
"license": null,
"license_file": null,
"description": null,
"source": null,
"source": "path+file://[..]/foo",
"dependencies": [
{
"name": "bdep",
"source": null,
"source": "path+file://[..]/bdep",
"req": "*",
"kind": null,
"rename": null,
Expand Down Expand Up @@ -2258,7 +2258,7 @@ fn filter_platform() {
"license": null,
"license_file": null,
"description": null,
"source": null,
"source": "path+file://[..]/foo",
"dependencies": [
{
"name": "normal-dep",
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/read_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn manifest_output(readme_value: &str) -> String {
"links": null,
"description": null,
"edition": "2015",
"source":null,
"source": "path+file://[..]/foo",
"dependencies":[],
"targets":[{{
"kind":["bin"],
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ fn update_precise_first_run() {
"name": "bar",
"readme": null,
"repository": null,
"source": null,
"source": "path+file://[..]/foo",
"targets": [
{
"crate_types": [
Expand Down