Repository navigation
feat(builtin-deps): Add SourceKind::Builtin
#17513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,8 @@ pub enum SourceKind { | |
| LocalRegistry, | ||
| /// A directory-based registry. | ||
| Directory, | ||
| /// Package sources distributed with the rust toolchain | ||
| Builtin, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existing comment regarding updating package_id_spec: #16675 (comment) I'll leave that for a future PR.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. I would expect it being an immediate follow-up though as it is also related to how we encode this in lockfile, in |
||
| } | ||
|
|
||
| // The hash here is important for what folder packages get downloaded into. | ||
|
|
@@ -40,6 +42,7 @@ impl SourceKind { | |
| SourceKind::SparseRegistry => None, | ||
| SourceKind::LocalRegistry => Some("local-registry"), | ||
| SourceKind::Directory => Some("directory"), | ||
| SourceKind::Builtin => Some("builtin"), | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -71,6 +74,10 @@ impl Ord for SourceKind { | |
| (_, SourceKind::Directory) => Ordering::Greater, | ||
|
|
||
| (SourceKind::Git(a), SourceKind::Git(b)) => a.cmp(b), | ||
| (SourceKind::Git(_), _) => Ordering::Less, | ||
| (_, SourceKind::Git(_)) => Ordering::Greater, | ||
|
|
||
| (SourceKind::Builtin, SourceKind::Builtin) => Ordering::Equal, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,6 +176,7 @@ impl SourceId { | |
| let url = url.into_url()?; | ||
| SourceId::new(SourceKind::Path, url, None) | ||
| } | ||
| "builtin" => SourceId::for_builtin(), | ||
| kind => Err(anyhow::format_err!("unsupported source protocol: {}", kind)), | ||
| } | ||
| } | ||
|
|
@@ -204,6 +205,12 @@ impl SourceId { | |
| SourceId::new(SourceKind::Path, url, None) | ||
| } | ||
|
|
||
| /// Creates a `SourceId` for the builtin packages in the configured toolchain. | ||
| pub fn for_builtin() -> CargoResult<SourceId> { | ||
| let url = "builtin://".into_url()?; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is probably good to move on. Just note that this affects other serialized output (lockfile and cargo metadata and probably others) and we might want to revisit this. For example,
|
||
| SourceId::new(SourceKind::Builtin, url, None) | ||
| } | ||
|
|
||
| /// Creates a `SourceId` from a filesystem path. | ||
| /// | ||
| /// `path`: an absolute path. | ||
|
|
@@ -404,6 +411,7 @@ impl SourceId { | |
| } | ||
| Ok(Box::new(PathSource::new(&path, self, gctx))) | ||
| } | ||
| SourceKind::Builtin => todo!("builtin source"), | ||
| SourceKind::Registry | SourceKind::SparseRegistry => { | ||
| Ok(Box::new(RegistrySource::remote(self, gctx)?)) | ||
| } | ||
|
|
@@ -664,6 +672,7 @@ impl fmt::Display for SourceId { | |
| Ok(()) | ||
| } | ||
| SourceKind::Path => write!(f, "{}", url_display(&self.inner.url)), | ||
| SourceKind::Builtin => write!(f, "builtin {}", url_display(&self.inner.url)), | ||
| SourceKind::Registry | SourceKind::SparseRegistry => { | ||
| write!(f, "registry `{}`", self.display_registry_name()) | ||
| } | ||
|
|
@@ -846,6 +855,10 @@ mod tests { | |
| assert_data_eq!(gen_hash(source_id), str!["473480029881867801"].raw()); | ||
| assert_data_eq!(short_hash(&source_id), str!["199e591d94239206"].raw()); | ||
|
|
||
| let source_id = SourceId::for_builtin().unwrap(); | ||
| assert_data_eq!(gen_hash(source_id), str!["8471877086995577839"].raw()); | ||
| assert_data_eq!(short_hash(&source_id), str!["ef7b241f53279275"].raw()); | ||
|
|
||
| let path = &ws_root.join("crate"); | ||
| let source_id = SourceId::for_local_registry(path).unwrap(); | ||
| #[cfg(not(windows))] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.