Skip to content

Commit

Permalink
refactor(schemas): Pull out cargo-util-schemas crate
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Dec 15, 2023
1 parent a1cc5ca commit b57ba88
Show file tree
Hide file tree
Showing 38 changed files with 100 additions and 54 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
File renamed without changes.
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::PartialVersion;
use crate::util_schemas::core::SourceKind;
use crate::util_schemas::manifest::PackageName;
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
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::core::PartialVersion;
use crate::util_schemas::restricted_names;
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/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: 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
6 changes: 4 additions & 2 deletions src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
//! - [`cargo-util`](https://crates.io/crates/cargo-util)
//! ([nightly docs](https://doc.rust-lang.org/nightly/nightly-rustc/cargo_util)):
//! This contains general utility code that is shared between cargo and the testsuite
//! - [`cargo-util-schemas`](https://crates.io/crates/cargo-util-schemas)
//! ([nightly docs](https://doc.rust-lang.org/nightly/nightly-rustc/cargo_util-schemas)):
//! This contains the serde schemas for cargo
//! - [`crates-io`](https://crates.io/crates/crates-io)
//! ([nightly docs](https://doc.rust-lang.org/nightly/nightly-rustc/crates_io)):
//! This contains code for accessing the crates.io API.
Expand Down Expand Up @@ -98,7 +101,7 @@
//! Files that interact with cargo include
//!
//! - Package
//! - `Cargo.toml`: User-written project manifest, loaded with [`util_schemas::manifest::TomlManifest`] and then
//! - `Cargo.toml`: User-written project manifest, loaded with [`util::toml::read_manifest`] and then
//! translated to [`core::manifest::Manifest`] which maybe stored in a [`core::Package`].
//! - This is editable with [`util::toml_mut::manifest::LocalManifest`]
//! - `Cargo.lock`: Generally loaded with [`ops::resolve_ws`] or a variant of it into a [`core::resolver::Resolve`]
Expand Down Expand Up @@ -152,7 +155,6 @@ pub mod core;
pub mod ops;
pub mod sources;
pub mod util;
pub mod util_schemas;
mod version;

pub fn exit_with_error(err: CliError, shell: &mut Shell) -> ! {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_add/crate_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use anyhow::Context as _;

use super::Dependency;
use crate::util::toml_mut::dependency::RegistrySource;
use crate::util_schemas::manifest::PackageName;
use crate::CargoResult;
use cargo_util_schemas::manifest::PackageName;

/// User-specified crate
///
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::str::FromStr;

use anyhow::Context as _;
use cargo_util::paths;
use cargo_util_schemas::manifest::RustVersion;
use indexmap::IndexSet;
use itertools::Itertools;
use toml_edit::Item as TomlItem;
Expand All @@ -35,7 +36,6 @@ use crate::util::toml_mut::dependency::WorkspaceSource;
use crate::util::toml_mut::is_sorted;
use crate::util::toml_mut::manifest::DepTable;
use crate::util::toml_mut::manifest::LocalManifest;
use crate::util_schemas::manifest::RustVersion;
use crate::CargoResult;
use crate::Config;
use crate_spec::CrateSpec;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::util::important_paths::find_root_manifest_for_wd;
use crate::util::toml_mut::is_sorted;
use crate::util::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
use crate::util::{restricted_names, Config};
use crate::util_schemas::manifest::PackageName;
use anyhow::{anyhow, Context};
use cargo_util::paths::{self, write_atomic};
use cargo_util_schemas::manifest::PackageName;
use serde::de;
use serde::Deserialize;
use std::collections::BTreeMap;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ use crate::sources::PathSource;
use crate::util::cache_lock::CacheLockMode;
use crate::util::errors::CargoResult;
use crate::util::{profile, CanonicalUrl};
use crate::util_schemas::manifest::RustVersion;
use anyhow::Context as _;
use cargo_util_schemas::manifest::RustVersion;
use std::collections::{HashMap, HashSet};
use tracing::{debug, trace};

Expand Down
Loading

0 comments on commit b57ba88

Please sign in to comment.