Skip to content

Commit

Permalink
refactor(schemas): Pull out cargo-util-schemas crate
Browse files Browse the repository at this point in the history
Fixes #12801
  • Loading branch information
epage committed Dec 15, 2023
1 parent ba3b592 commit d06dd39
Show file tree
Hide file tree
Showing 32 changed files with 88 additions and 47 deletions.
17 changes: 15 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
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.
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
2 changes: 1 addition & 1 deletion src/cargo/sources/registry/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ use crate::util::cache_lock::CacheLockMode;
use crate::util::interning::InternedString;
use crate::util::IntoUrl;
use crate::util::{internal, CargoResult, Config, Filesystem, OptVersionReq};
use crate::util_schemas::manifest::RustVersion;
use anyhow::bail;
use cargo_util::{paths, registry::make_dep_path};
use cargo_util_schemas::manifest::RustVersion;
use semver::Version;
use serde::Deserialize;
use std::borrow::Cow;
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use crate::util::{
print_available_benches, print_available_binaries, print_available_examples,
print_available_packages, print_available_tests,
};
use crate::util_schemas::manifest::ProfileName;
use crate::util_schemas::manifest::RegistryName;
use crate::util_schemas::manifest::StringOrVec;
use crate::CargoResult;
use anyhow::bail;
use cargo_util::paths;
use cargo_util_schemas::manifest::ProfileName;
use cargo_util_schemas::manifest::RegistryName;
use cargo_util_schemas::manifest::StringOrVec;
use clap::builder::UnknownArgumentValueParser;
use std::ffi::{OsStr, OsString};
use std::path::Path;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ use crate::util::network::http::http_handle;
use crate::util::try_canonicalize;
use crate::util::{internal, CanonicalUrl};
use crate::util::{Filesystem, IntoUrl, IntoUrlWithBase, Rustc};
use crate::util_schemas::manifest::RegistryName;
use anyhow::{anyhow, bail, format_err, Context as _};
use cargo_credential::Secret;
use cargo_util::paths;
use cargo_util_schemas::manifest::RegistryName;
use curl::easy::Easy;
use lazycell::LazyCell;
use serde::de::IntoDeserializer as _;
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/util/toml/embedded.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use anyhow::Context as _;

use cargo_util_schemas::manifest::PackageName;

use crate::util::restricted_names;
use crate::util_schemas::manifest::PackageName;
use crate::CargoResult;
use crate::Config;

Expand Down
4 changes: 2 additions & 2 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::str::{self, FromStr};
use anyhow::{anyhow, bail, Context as _};
use cargo_platform::Platform;
use cargo_util::paths;
use cargo_util_schemas::manifest;
use cargo_util_schemas::manifest::RustVersion;
use itertools::Itertools;
use lazycell::LazyCell;
use tracing::{debug, trace};
Expand All @@ -24,8 +26,6 @@ use crate::sources::{CRATES_IO_INDEX, CRATES_IO_REGISTRY};
use crate::util::errors::{CargoResult, ManifestError};
use crate::util::interning::InternedString;
use crate::util::{self, config::ConfigRelativePath, Config, IntoUrl, OptVersionReq};
use crate::util_schemas::manifest;
use crate::util_schemas::manifest::RustVersion;

mod embedded;
mod targets;
Expand Down
Loading

0 comments on commit d06dd39

Please sign in to comment.