Skip to content

Commit

Permalink
refactor(schemas): Pull out mod for proposed schemas package
Browse files Browse the repository at this point in the history
Originally for #12801 we talked about a `cargo-util-manifest-schema` package
- `util` in the name to not clash with plugins
- manifest specific to keep the scope down

The problem is we have types that aren't manifest specific, like
- `PartialVersion` (currently slated for `cargo-util-semverext`)
- `RustVersion`
- `PackageIdSpec`
- `SourceKind` (soon)

Things get messy if we try to break things down into common packages.
Instead, I think it'd be useful to have a schemas package that has mods
for each type of schema, re-exporting what is needed.

Normally, componentizing your package by the layer in the stack is a
recipe for pain.
I don't think that'll apply here because these are meant to be so low
level.

The other big concern could be compile times.  My hope is it won't be
too bad.

So this moves the `util/toml` types into the module and we can add more
in the future.
  • Loading branch information
epage committed Dec 1, 2023
1 parent bbd2dcd commit 23054a4
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 129 deletions.
2 changes: 1 addition & 1 deletion src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use cargo::util::network::http::http_handle;
use cargo::util::network::http::needs_custom_http_transport;
use cargo::util::toml::schema::StringOrVec;
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 std::collections::BTreeMap;
use std::env;
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 @@ -93,9 +93,9 @@ use crate::core::{Feature, PackageId, Target, Verbosity};
use crate::util::errors::{CargoResult, VerboseError};
use crate::util::interning::InternedString;
use crate::util::machine_message::{self, Message};
use crate::util::toml::schema::TomlDebugInfo;
use crate::util::toml::schema::TomlTrimPaths;
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 rustfix::diagnostics::Applicability;

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use crate::core::{Dependency, PackageId, PackageIdSpec, SourceId, Summary};
use crate::core::{Edition, Feature, Features, WorkspaceConfig};
use crate::util::errors::*;
use crate::util::interning::InternedString;
use crate::util::toml::schema::{TomlManifest, TomlProfiles};
use crate::util::{short_hash, Config, Filesystem, RustVersion};
use crate::util_schemas::manifest::{TomlManifest, TomlProfiles};

pub enum EitherManifest {
Real(Manifest),
Expand Down
10 changes: 5 additions & 5 deletions src/cargo/core/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ use crate::core::resolver::features::FeaturesFor;
use crate::core::Feature;
use crate::core::{PackageId, PackageIdSpec, Resolve, Shell, Target, Workspace};
use crate::util::interning::InternedString;
use crate::util::toml::schema::TomlTrimPaths;
use crate::util::toml::schema::TomlTrimPathsValue;
use crate::util::toml::schema::{
ProfilePackageSpec, StringOrBool, TomlDebugInfo, TomlProfile, TomlProfiles,
};
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::{
ProfilePackageSpec, StringOrBool, TomlDebugInfo, TomlProfile, TomlProfiles,
};
use anyhow::{bail, Context as _};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::hash::Hash;
Expand Down
5 changes: 2 additions & 3 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ use crate::sources::{PathSource, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
use crate::util::edit_distance;
use crate::util::errors::{CargoResult, ManifestError};
use crate::util::interning::InternedString;
use crate::util::toml::{
read_manifest, schema::TomlDependency, schema::TomlProfiles, InheritableFields,
};
use crate::util::toml::{read_manifest, InheritableFields};
use crate::util::RustVersion;
use crate::util::{config::ConfigRelativePath, Config, Filesystem, IntoUrl};
use crate::util_schemas::manifest::{TomlDependency, TomlProfiles};
use cargo_util::paths;
use cargo_util::paths::normalize_path;
use pathdiff::diff_paths;
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
//! Files that interact with cargo include
//!
//! - Package
//! - `Cargo.toml`: User-written project manifest, loaded with [`util::toml::schema::TomlManifest`] and then
//! - `Cargo.toml`: User-written project manifest, loaded with [`util_schemas::manifest::TomlManifest`] 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,6 +152,7 @@ pub mod core;
pub mod ops;
pub mod sources;
pub mod util;
pub mod util_schemas;
pub mod util_semver;
mod version;

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use crate::util::important_paths::find_root_manifest_for_wd;
use crate::util::interning::InternedString;
use crate::util::is_rustup;
use crate::util::restricted_names;
use crate::util::toml::schema::StringOrVec;
use crate::util::{
print_available_benches, print_available_binaries, print_available_examples,
print_available_packages, print_available_tests,
};
use crate::util_schemas::manifest::StringOrVec;
use crate::CargoResult;
use anyhow::bail;
use cargo_util::paths;
Expand Down
Loading

0 comments on commit 23054a4

Please sign in to comment.