Skip to content

Commit a1449ee

Browse files
committed
Auto merge of #13128 - epage:schema, r=weihanglo
refactor: Pull PackageIdSpec into schema ### What does this PR try to resolve? This removes one of the remaining ties `util_schemas` has on the rest of cargo as part of #12801. ### How should we test and review this PR? This is broken up into small commits ### Additional information
2 parents 72b3eb5 + d1b1cb1 commit a1449ee

23 files changed

+891
-821
lines changed

src/bin/cargo/commands/remove.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use cargo::core::dependency::DepKind;
22
use cargo::core::PackageIdSpec;
3+
use cargo::core::PackageIdSpecQuery;
34
use cargo::core::Resolve;
45
use cargo::core::Workspace;
56
use cargo::ops::cargo_remove::remove;

src/cargo/core/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ pub use self::manifest::{EitherManifest, VirtualManifest};
44
pub use self::manifest::{Manifest, Target, TargetKind};
55
pub use self::package::{Package, PackageSet};
66
pub use self::package_id::PackageId;
7-
pub use self::package_id_spec::PackageIdSpec;
7+
pub use self::package_id_spec::PackageIdSpecQuery;
88
pub use self::registry::Registry;
99
pub use self::resolver::{Resolve, ResolveVersion};
1010
pub use self::shell::{Shell, Verbosity};
11-
pub use self::source_id::{GitReference, SourceId, SourceKind};
11+
pub use self::source_id::SourceId;
1212
pub use self::summary::{FeatureMap, FeatureValue, Summary};
1313
pub use self::workspace::{
1414
find_workspace_root, resolve_relative_path, MaybePackage, Workspace, WorkspaceConfig,
1515
WorkspaceRootConfig,
1616
};
17+
pub use crate::util_schemas::core::{GitReference, PackageIdSpec, SourceKind};
1718

1819
pub mod compiler;
1920
pub mod dependency;

src/cargo/core/package_id.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::sync::OnceLock;
1010
use serde::de;
1111
use serde::ser;
1212

13+
use crate::core::PackageIdSpec;
1314
use crate::core::SourceId;
1415
use crate::util::interning::InternedString;
1516
use crate::util::CargoResult;
@@ -186,6 +187,15 @@ impl PackageId {
186187
pub fn tarball_name(&self) -> String {
187188
format!("{}-{}.crate", self.name(), self.version())
188189
}
190+
191+
/// Convert a `PackageId` to a `PackageIdSpec`, which will have both the `PartialVersion` and `Url`
192+
/// fields filled in.
193+
pub fn to_spec(&self) -> PackageIdSpec {
194+
PackageIdSpec::new(String::from(self.name().as_str()))
195+
.with_version(self.version().clone().into())
196+
.with_url(self.source_id().url().clone())
197+
.with_kind(self.source_id().kind().clone())
198+
}
189199
}
190200

191201
pub struct PackageIdStableHash<'a>(PackageId, &'a Path);

0 commit comments

Comments
 (0)