Skip to content

Commit

Permalink
Auto merge of #13178 - epage:schemas, r=weihanglo
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Dec 18, 2023
2 parents 9c1316f + 633929d commit 881d790
Show file tree
Hide file tree
Showing 45 changed files with 177 additions and 134 deletions.
18 changes: 16 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cargo-platform = { path = "crates/cargo-platform", version = "0.1.4" }
cargo-test-macro = { path = "crates/cargo-test-macro" }
cargo-test-support = { path = "crates/cargo-test-support" }
cargo-util = { version = "0.2.6", path = "crates/cargo-util" }
cargo-util-schemas = { version = "0.1.0", path = "crates/cargo-util-schemas" }
cargo_metadata = "0.18.1"
clap = "4.4.10"
color-print = "0.3.5"
Expand Down Expand Up @@ -144,6 +145,7 @@ base64.workspace = true
bytesize.workspace = true
cargo-credential.workspace = true
cargo-platform.workspace = true
cargo-util-schemas.workspace = true
cargo-util.workspace = true
clap = { workspace = true, features = ["wrap_help"] }
color-print.workspace = true
Expand Down Expand Up @@ -183,7 +185,6 @@ rustfix.workspace = true
semver.workspace = true
serde = { workspace = true, features = ["derive"] }
serde-untagged.workspace = true
serde-value.workspace = true
serde_ignored.workspace = true
serde_json = { workspace = true, features = ["raw_value"] }
sha1.workspace = true
Expand All @@ -199,7 +200,6 @@ tracing.workspace = true
tracing-subscriber.workspace = true
unicase.workspace = true
unicode-width.workspace = true
unicode-xid.workspace = true
url.workspace = true
walkdir.workspace = true

Expand Down
22 changes: 22 additions & 0 deletions crates/cargo-util-schemas/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "cargo-util-schemas"
version = "0.1.0"
rust-version.workspace = true
edition.workspace = true
license.workspace = true
homepage = "https://github.com/rust-lang/cargo"
repository = "https://github.com/rust-lang/cargo"
description = "Deserialization schemas for Cargo"

[dependencies]
anyhow.workspace = true
semver.workspace = true
serde = { workspace = true, features = ["derive"] }
serde-untagged.workspace = true
serde-value.workspace = true
toml.workspace = true
unicode-xid.workspace = true
url.workspace = true

[lints]
workspace = true
1 change: 1 addition & 0 deletions crates/cargo-util-schemas/LICENSE-APACHE
1 change: 1 addition & 0 deletions crates/cargo-util-schemas/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod package_id_spec;
mod partial_version;
mod source_kind;

pub use package_id_spec::PackageIdSpec;
pub use partial_version::PartialVersion;
pub use source_kind::GitReference;
pub use source_kind::SourceKind;
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use semver::Version;
use serde::{de, ser};
use url::Url;

use crate::util_schemas::core::GitReference;
use crate::util_schemas::core::SourceKind;
use crate::util_schemas::manifest::PackageName;
use crate::util_semver::PartialVersion;
use crate::core::GitReference;
use crate::core::PartialVersion;
use crate::core::SourceKind;
use crate::manifest::PackageName;

/// Some or all of the data required to identify a package:
///
Expand Down Expand Up @@ -59,7 +59,7 @@ impl PackageIdSpec {
/// Some examples of valid strings
///
/// ```
/// use cargo::core::PackageIdSpec;
/// use cargo_util_schemas::core::PackageIdSpec;
///
/// let specs = vec![
/// "https://crates.io/foo",
Expand Down Expand Up @@ -280,7 +280,7 @@ impl<'de> de::Deserialize<'de> for PackageIdSpec {
#[cfg(test)]
mod tests {
use super::PackageIdSpec;
use crate::util_schemas::core::{GitReference, SourceKind};
use crate::core::{GitReference, SourceKind};
use url::Url;

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
use std::fmt::{self, Display};

use semver::{Comparator, Op, Version, VersionReq};
use semver::{Comparator, Version, VersionReq};
use serde_untagged::UntaggedEnumVisitor;

pub trait VersionExt {
fn is_prerelease(&self) -> bool;

fn to_exact_req(&self) -> VersionReq;
}

impl VersionExt for Version {
fn is_prerelease(&self) -> bool {
!self.pre.is_empty()
}

fn to_exact_req(&self) -> VersionReq {
VersionReq {
comparators: vec![Comparator {
op: Op::Exact,
major: self.major,
minor: Some(self.minor),
patch: Some(self.patch),
pre: self.pre.clone(),
}],
}
}
}

#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug)]
pub struct PartialVersion {
pub major: u64,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use serde::ser;
use serde::{Deserialize, Serialize};
use serde_untagged::UntaggedEnumVisitor;

use crate::util_schemas::core::PackageIdSpec;
use crate::util_schemas::restricted_names;
use crate::util_semver::PartialVersion;
use crate::core::PackageIdSpec;
use crate::core::PartialVersion;
use crate::restricted_names;

/// This type is used to deserialize `Cargo.toml` files.
#[derive(Debug, Deserialize, Serialize)]
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions crates/resolver-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ publish = false

[dependencies]
cargo.workspace = true
cargo-util-schemas.workspace = true
cargo-util.workspace = true
proptest.workspace = true
varisat.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/resolver-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use cargo::core::{GitReference, SourceId};
use cargo::sources::source::QueryKind;
use cargo::sources::IndexSummary;
use cargo::util::{CargoResult, Config, IntoUrl};
use cargo::util_schemas::manifest::RustVersion;
use cargo_util_schemas::manifest::RustVersion;

use proptest::collection::{btree_map, vec};
use proptest::prelude::*;
Expand Down
2 changes: 2 additions & 0 deletions crates/xtask-bump-check/src/xtask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ fn bump_check(args: &clap::ArgMatches, config: &cargo::util::Config) -> CargoRes
let mut cmd = ProcessBuilder::new("cargo");
cmd.arg("semver-checks")
.arg("check-release")
.args(&["--exclude", "cargo-util-schemas"]) // FIXME: Remove once 1.76 is stable
.arg("--workspace");
config.shell().status("Running", &cmd)?;
cmd.exec()?;
Expand All @@ -177,6 +178,7 @@ fn bump_check(args: &clap::ArgMatches, config: &cargo::util::Config) -> CargoRes
cmd.arg("semver-checks")
.arg("--workspace")
.args(&["--exclude", "rustfix"]) // FIXME: Remove once 1.76 is stable
.args(&["--exclude", "cargo-util-schemas"]) // FIXME: Remove once 1.76 is stable
.arg("--baseline-rev")
.arg(referenced_commit.id().to_string());
for krate in crates_not_check_against_channels {
Expand Down
1 change: 1 addition & 0 deletions publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'crates/cargo-platform',
'crates/cargo-util',
'crates/crates-io',
'crates/cargo-util-schemas',
'.',
]

Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use anyhow::format_err;
use cargo::core::{GitReference, SourceId, Workspace};
use cargo::ops;
use cargo::util::IntoUrl;
use cargo::util_semver::VersionExt;
use cargo::util::VersionExt;
use cargo::CargoResult;
use itertools::Itertools;
use semver::VersionReq;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use cargo::util::network::http::http_handle;
use cargo::util::network::http::needs_custom_http_transport;
use cargo::util::CliError;
use cargo::util::{self, closest_msg, command_prelude, CargoResult, CliResult, Config};
use cargo::util_schemas::manifest::StringOrVec;
use cargo_util::{ProcessBuilder, ProcessError};
use cargo_util_schemas::manifest::StringOrVec;
use std::collections::BTreeMap;
use std::env;
use std::ffi::OsStr;
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ use crate::util::errors::{CargoResult, VerboseError};
use crate::util::interning::InternedString;
use crate::util::machine_message::{self, Message};
use crate::util::{add_path_args, internal, iter_join_onto, profile};
use crate::util_schemas::manifest::TomlDebugInfo;
use crate::util_schemas::manifest::TomlTrimPaths;
use cargo_util::{paths, ProcessBuilder, ProcessError};
use cargo_util_schemas::manifest::TomlDebugInfo;
use cargo_util_schemas::manifest::TomlTrimPaths;
use rustfix::diagnostics::Applicability;

const RUSTDOC_CRATE_VERSION_FLAG: &str = "--crate-version";
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::rc::Rc;
use std::sync::Arc;

use anyhow::Context as _;
use cargo_util_schemas::manifest::RustVersion;
use cargo_util_schemas::manifest::{TomlManifest, TomlProfiles};
use semver::Version;
use serde::ser;
use serde::Serialize;
Expand All @@ -19,8 +21,6 @@ use crate::core::{Edition, Feature, Features, WorkspaceConfig};
use crate::util::errors::*;
use crate::util::interning::InternedString;
use crate::util::{short_hash, Config, Filesystem};
use crate::util_schemas::manifest::RustVersion;
use crate::util_schemas::manifest::{TomlManifest, TomlProfiles};

pub enum EitherManifest {
Real(Manifest),
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use self::workspace::{
find_workspace_root, resolve_relative_path, MaybePackage, Workspace, WorkspaceConfig,
WorkspaceRootConfig,
};
pub use crate::util_schemas::core::{GitReference, PackageIdSpec, SourceKind};
pub use cargo_util_schemas::core::{GitReference, PackageIdSpec, SourceKind};

pub mod compiler;
pub mod dependency;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::time::{Duration, Instant};

use anyhow::Context;
use bytesize::ByteSize;
use cargo_util_schemas::manifest::RustVersion;
use curl::easy::Easy;
use curl::multi::{EasyHandle, Multi};
use lazycell::LazyCell;
Expand All @@ -33,7 +34,6 @@ use crate::util::network::retry::{Retry, RetryResult};
use crate::util::network::sleep::SleepTracker;
use crate::util::toml::prepare_for_publish;
use crate::util::{self, internal, Config, Progress, ProgressStyle};
use crate::util_schemas::manifest::RustVersion;

pub const MANIFEST_PREAMBLE: &str = "\
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
Expand Down
8 changes: 4 additions & 4 deletions src/cargo/core/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ use crate::core::{
use crate::util::interning::InternedString;
use crate::util::toml::validate_profile;
use crate::util::{closest_msg, config, CargoResult, Config};
use crate::util_schemas::manifest::TomlTrimPaths;
use crate::util_schemas::manifest::TomlTrimPathsValue;
use crate::util_schemas::manifest::{
use anyhow::{bail, Context as _};
use cargo_util_schemas::manifest::TomlTrimPaths;
use cargo_util_schemas::manifest::TomlTrimPathsValue;
use cargo_util_schemas::manifest::{
ProfilePackageSpec, StringOrBool, TomlDebugInfo, TomlProfile, TomlProfiles,
};
use anyhow::{bail, Context as _};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::hash::Hash;
use std::{cmp, fmt, hash};
Expand Down
3 changes: 1 addition & 2 deletions src/cargo/core/resolver/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use std::task::Poll;
use crate::core::{Dependency, PackageId, Registry, Summary};
use crate::sources::source::QueryKind;
use crate::util::edit_distance::edit_distance;
use crate::util::{Config, OptVersionReq};
use crate::util_semver::VersionExt;
use crate::util::{Config, OptVersionReq, VersionExt};
use anyhow::Error;

use super::context::Context;
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/core/resolver/version_prefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};

use cargo_util_schemas::manifest::RustVersion;

use crate::core::{Dependency, PackageId, Summary};
use crate::util::interning::InternedString;
use crate::util_schemas::manifest::RustVersion;

/// A collection of preferences for particular package versions.
///
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/summary.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::core::{Dependency, PackageId, SourceId};
use crate::util::interning::InternedString;
use crate::util::CargoResult;
use crate::util_schemas::manifest::FeatureName;
use crate::util_schemas::manifest::RustVersion;
use anyhow::bail;
use cargo_util_schemas::manifest::FeatureName;
use cargo_util_schemas::manifest::RustVersion;
use semver::Version;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::fmt;
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use crate::util::errors::{CargoResult, ManifestError};
use crate::util::interning::InternedString;
use crate::util::toml::{read_manifest, InheritableFields};
use crate::util::{config::ConfigRelativePath, Config, Filesystem, IntoUrl};
use crate::util_schemas::manifest::RustVersion;
use crate::util_schemas::manifest::{TomlDependency, TomlProfiles};
use cargo_util::paths;
use cargo_util::paths::normalize_path;
use cargo_util_schemas::manifest::RustVersion;
use cargo_util_schemas::manifest::{TomlDependency, TomlProfiles};
use pathdiff::diff_paths;

/// The core abstraction in Cargo for working with a workspace of crates.
Expand Down
Loading

0 comments on commit 881d790

Please sign in to comment.