Skip to content

Commit 881d790

Browse files
committed
Auto merge of #13178 - epage:schemas, r=weihanglo
refactor(schemas): Pull out as `cargo-util-schemas` ### What does this PR try to resolve? Fixes #12801 ### How should we test and review this PR? See the individual commits for further justifications on the changes ### Additional information
2 parents 9c1316f + 633929d commit 881d790

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+177
-134
lines changed

Cargo.lock

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ cargo-platform = { path = "crates/cargo-platform", version = "0.1.4" }
3030
cargo-test-macro = { path = "crates/cargo-test-macro" }
3131
cargo-test-support = { path = "crates/cargo-test-support" }
3232
cargo-util = { version = "0.2.6", path = "crates/cargo-util" }
33+
cargo-util-schemas = { version = "0.1.0", path = "crates/cargo-util-schemas" }
3334
cargo_metadata = "0.18.1"
3435
clap = "4.4.10"
3536
color-print = "0.3.5"
@@ -144,6 +145,7 @@ base64.workspace = true
144145
bytesize.workspace = true
145146
cargo-credential.workspace = true
146147
cargo-platform.workspace = true
148+
cargo-util-schemas.workspace = true
147149
cargo-util.workspace = true
148150
clap = { workspace = true, features = ["wrap_help"] }
149151
color-print.workspace = true
@@ -183,7 +185,6 @@ rustfix.workspace = true
183185
semver.workspace = true
184186
serde = { workspace = true, features = ["derive"] }
185187
serde-untagged.workspace = true
186-
serde-value.workspace = true
187188
serde_ignored.workspace = true
188189
serde_json = { workspace = true, features = ["raw_value"] }
189190
sha1.workspace = true
@@ -199,7 +200,6 @@ tracing.workspace = true
199200
tracing-subscriber.workspace = true
200201
unicase.workspace = true
201202
unicode-width.workspace = true
202-
unicode-xid.workspace = true
203203
url.workspace = true
204204
walkdir.workspace = true
205205

crates/cargo-util-schemas/Cargo.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "cargo-util-schemas"
3+
version = "0.1.0"
4+
rust-version.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
homepage = "https://github.com/rust-lang/cargo"
8+
repository = "https://github.com/rust-lang/cargo"
9+
description = "Deserialization schemas for Cargo"
10+
11+
[dependencies]
12+
anyhow.workspace = true
13+
semver.workspace = true
14+
serde = { workspace = true, features = ["derive"] }
15+
serde-untagged.workspace = true
16+
serde-value.workspace = true
17+
toml.workspace = true
18+
unicode-xid.workspace = true
19+
url.workspace = true
20+
21+
[lints]
22+
workspace = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE-APACHE

crates/cargo-util-schemas/LICENSE-MIT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE-MIT
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
mod package_id_spec;
2+
mod partial_version;
23
mod source_kind;
34

45
pub use package_id_spec::PackageIdSpec;
6+
pub use partial_version::PartialVersion;
57
pub use source_kind::GitReference;
68
pub use source_kind::SourceKind;

src/cargo/util_schemas/core/package_id_spec.rs renamed to crates/cargo-util-schemas/src/core/package_id_spec.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use semver::Version;
66
use serde::{de, ser};
77
use url::Url;
88

9-
use crate::util_schemas::core::GitReference;
10-
use crate::util_schemas::core::SourceKind;
11-
use crate::util_schemas::manifest::PackageName;
12-
use crate::util_semver::PartialVersion;
9+
use crate::core::GitReference;
10+
use crate::core::PartialVersion;
11+
use crate::core::SourceKind;
12+
use crate::manifest::PackageName;
1313

1414
/// Some or all of the data required to identify a package:
1515
///
@@ -59,7 +59,7 @@ impl PackageIdSpec {
5959
/// Some examples of valid strings
6060
///
6161
/// ```
62-
/// use cargo::core::PackageIdSpec;
62+
/// use cargo_util_schemas::core::PackageIdSpec;
6363
///
6464
/// let specs = vec![
6565
/// "https://crates.io/foo",
@@ -280,7 +280,7 @@ impl<'de> de::Deserialize<'de> for PackageIdSpec {
280280
#[cfg(test)]
281281
mod tests {
282282
use super::PackageIdSpec;
283-
use crate::util_schemas::core::{GitReference, SourceKind};
283+
use crate::core::{GitReference, SourceKind};
284284
use url::Url;
285285

286286
#[test]

src/cargo/util_semver.rs renamed to crates/cargo-util-schemas/src/core/partial_version.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,8 @@
11
use std::fmt::{self, Display};
22

3-
use semver::{Comparator, Op, Version, VersionReq};
3+
use semver::{Comparator, Version, VersionReq};
44
use serde_untagged::UntaggedEnumVisitor;
55

6-
pub trait VersionExt {
7-
fn is_prerelease(&self) -> bool;
8-
9-
fn to_exact_req(&self) -> VersionReq;
10-
}
11-
12-
impl VersionExt for Version {
13-
fn is_prerelease(&self) -> bool {
14-
!self.pre.is_empty()
15-
}
16-
17-
fn to_exact_req(&self) -> VersionReq {
18-
VersionReq {
19-
comparators: vec![Comparator {
20-
op: Op::Exact,
21-
major: self.major,
22-
minor: Some(self.minor),
23-
patch: Some(self.patch),
24-
pre: self.pre.clone(),
25-
}],
26-
}
27-
}
28-
}
29-
306
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug)]
317
pub struct PartialVersion {
328
pub major: u64,
File renamed without changes.

0 commit comments

Comments
 (0)