Skip to content

schemas: using enumerated ResolveVersion #75

@secona

Description

@secona

Problem

For lockfile versions, the schemas currently use Option<u32>. The problem with this is that it may become ambiguous when the version is null. Unsure if we should use ResolveVersion directly or define our own.

pub enum LockDependenciesOut {
Lockfile {
version: Option<u32>,
},

In #69, I noticed that resolve_with_previous can output a resolve with version ResolveVersion::V2. However, since ResolveVersion serializes V2 into a None, this results in a null version in the output messages.

I also noticed that using read-lockfile to read old Cargo.lock versions outputs a null as the version. I think this is fine, but what do we think of actually detecting versions to prevent null in the output messages?

#[cargo_test]
fn old_lockfile() {
let cksum = Package::new("a", "0.1.0").publish();
let p = project()
.file("src/lib.rs", "")
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
[dependencies]
a = "0.1.0"
"#,
)
.file(
"Cargo.lock",
&format!(
r#"
[root]
name = "foo"
version = "0.0.1"
dependencies = [
"bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "a"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum a 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "{cksum}"
"#,
),
)
.build();
p.cargo_plumbing("plumbing read-lockfile")
.arg("--lockfile-path")
.arg(p.root().join("Cargo.lock"))
.with_status(0)
.with_stdout_data(
str![[r#"
[
{
"reason": "lockfile",
"version": null
},
{
"reason": "locked-package",
"id": "registry+https://github.com/rust-lang/crates.io-index#[email protected]"
},
{
"reason": "locked-package",
"id": "[email protected]",
"dependencies": [
"registry+https://github.com/rust-lang/crates.io-index#[email protected]"
]
},
{
"reason": "metadata",
"checksum a 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)": "3436ae58a84bb2033accec0cb50c6611f312249899579714793e0d0509470cd9"
}
]
"#]]
.is_json()
.against_jsonlines(),
)
.run();
}

Tasks

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-schemaC-enhancementCategory: Raise on the bar on expectations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions