-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Elaborate registry names to index URLs when publishing #4957
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,25 +178,26 @@ impl<'de> de::Deserialize<'de> for TomlDependency { | |
} | ||
|
||
#[derive(Deserialize, Serialize, Clone, Debug, Default)] | ||
#[serde(rename_all = "kebab-case")] | ||
pub struct DetailedTomlDependency { | ||
version: Option<String>, | ||
registry: Option<String>, | ||
registry_index: Option<String>, | ||
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. Could this use |
||
path: Option<String>, | ||
git: Option<String>, | ||
branch: Option<String>, | ||
tag: Option<String>, | ||
rev: Option<String>, | ||
features: Option<Vec<String>>, | ||
optional: Option<bool>, | ||
#[serde(rename = "default-features")] | ||
default_features: Option<bool>, | ||
#[serde(rename = "default_features")] | ||
default_features2: Option<bool>, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
#[serde(rename_all = "kebab-case")] | ||
pub struct TomlManifest { | ||
#[serde(rename = "cargo-features")] | ||
cargo_features: Option<Vec<String>>, | ||
package: Option<Box<TomlProject>>, | ||
project: Option<Box<TomlProject>>, | ||
|
@@ -207,11 +208,9 @@ pub struct TomlManifest { | |
test: Option<Vec<TomlTestTarget>>, | ||
bench: Option<Vec<TomlTestTarget>>, | ||
dependencies: Option<BTreeMap<String, TomlDependency>>, | ||
#[serde(rename = "dev-dependencies")] | ||
dev_dependencies: Option<BTreeMap<String, TomlDependency>>, | ||
#[serde(rename = "dev_dependencies")] | ||
dev_dependencies2: Option<BTreeMap<String, TomlDependency>>, | ||
#[serde(rename = "build-dependencies")] | ||
build_dependencies: Option<BTreeMap<String, TomlDependency>>, | ||
#[serde(rename = "build_dependencies")] | ||
build_dependencies2: Option<BTreeMap<String, TomlDependency>>, | ||
|
@@ -471,13 +470,13 @@ struct Context<'a, 'b> { | |
} | ||
|
||
impl TomlManifest { | ||
pub fn prepare_for_publish(&self) -> TomlManifest { | ||
pub fn prepare_for_publish(&self, config: &Config) -> CargoResult<TomlManifest> { | ||
let mut package = self.package.as_ref() | ||
.or_else(|| self.project.as_ref()) | ||
.unwrap() | ||
.clone(); | ||
package.workspace = None; | ||
return TomlManifest { | ||
return Ok(TomlManifest { | ||
package: Some(package), | ||
project: None, | ||
profile: self.profile.clone(), | ||
|
@@ -486,56 +485,68 @@ impl TomlManifest { | |
example: self.example.clone(), | ||
test: self.test.clone(), | ||
bench: self.bench.clone(), | ||
dependencies: map_deps(self.dependencies.as_ref()), | ||
dev_dependencies: map_deps(self.dev_dependencies.as_ref() | ||
.or_else(|| self.dev_dependencies2.as_ref())), | ||
dependencies: map_deps(config, self.dependencies.as_ref())?, | ||
dev_dependencies: map_deps(config, self.dev_dependencies.as_ref() | ||
.or_else(|| self.dev_dependencies2.as_ref()))?, | ||
dev_dependencies2: None, | ||
build_dependencies: map_deps(self.build_dependencies.as_ref() | ||
.or_else(|| self.build_dependencies2.as_ref())), | ||
build_dependencies: map_deps(config, self.build_dependencies.as_ref() | ||
.or_else(|| self.build_dependencies2.as_ref()))?, | ||
build_dependencies2: None, | ||
features: self.features.clone(), | ||
target: self.target.as_ref().map(|target_map| { | ||
target: match self.target.as_ref().map(|target_map| { | ||
target_map.iter().map(|(k, v)| { | ||
(k.clone(), TomlPlatform { | ||
dependencies: map_deps(v.dependencies.as_ref()), | ||
dev_dependencies: map_deps(v.dev_dependencies.as_ref() | ||
.or_else(|| v.dev_dependencies2.as_ref())), | ||
Ok((k.clone(), TomlPlatform { | ||
dependencies: map_deps(config, v.dependencies.as_ref())?, | ||
dev_dependencies: map_deps(config, v.dev_dependencies.as_ref() | ||
.or_else(|| v.dev_dependencies2.as_ref()))?, | ||
dev_dependencies2: None, | ||
build_dependencies: map_deps(v.build_dependencies.as_ref() | ||
.or_else(|| v.build_dependencies2.as_ref())), | ||
build_dependencies: map_deps(config, v.build_dependencies.as_ref() | ||
.or_else(|| v.build_dependencies2.as_ref()))?, | ||
build_dependencies2: None, | ||
}) | ||
})) | ||
}).collect() | ||
}), | ||
}) { | ||
Some(Ok(v)) => Some(v), | ||
Some(Err(e)) => return Err(e), | ||
None => None, | ||
}, | ||
replace: None, | ||
patch: None, | ||
workspace: None, | ||
badges: self.badges.clone(), | ||
cargo_features: self.cargo_features.clone(), | ||
}; | ||
}); | ||
|
||
fn map_deps(deps: Option<&BTreeMap<String, TomlDependency>>) | ||
-> Option<BTreeMap<String, TomlDependency>> | ||
fn map_deps(config: &Config, deps: Option<&BTreeMap<String, TomlDependency>>) | ||
-> CargoResult<Option<BTreeMap<String, TomlDependency>>> | ||
{ | ||
let deps = match deps { | ||
Some(deps) => deps, | ||
None => return None | ||
None => return Ok(None), | ||
}; | ||
Some(deps.iter().map(|(k, v)| (k.clone(), map_dependency(v))).collect()) | ||
let deps = deps.iter() | ||
.map(|(k, v)| Ok((k.clone(), map_dependency(config, v)?))) | ||
.collect::<CargoResult<BTreeMap<_, _>>>()?; | ||
Ok(Some(deps)) | ||
} | ||
|
||
fn map_dependency(dep: &TomlDependency) -> TomlDependency { | ||
fn map_dependency(config: &Config, dep: &TomlDependency) -> CargoResult<TomlDependency> { | ||
match *dep { | ||
TomlDependency::Detailed(ref d) => { | ||
let mut d = d.clone(); | ||
d.path.take(); // path dependencies become crates.io deps | ||
TomlDependency::Detailed(d) | ||
// registry specifications are elaborated to the index URL | ||
if let Some(registry) = d.registry.take() { | ||
let src = SourceId::alt_registry(config, ®istry)?; | ||
d.registry_index = Some(src.url().to_string()); | ||
} | ||
Ok(TomlDependency::Detailed(d)) | ||
} | ||
TomlDependency::Simple(ref s) => { | ||
TomlDependency::Detailed(DetailedTomlDependency { | ||
Ok(TomlDependency::Detailed(DetailedTomlDependency { | ||
version: Some(s.clone()), | ||
..Default::default() | ||
}) | ||
})) | ||
} | ||
} | ||
} | ||
|
@@ -933,10 +944,18 @@ impl TomlDependency { | |
None => SourceId::crates_io(cx.config)? | ||
}; | ||
|
||
let new_source_id = match (details.git.as_ref(), details.path.as_ref(), details.registry.as_ref()) { | ||
(Some(_), _, Some(_)) => bail!("dependency ({}) specification is ambiguous. \ | ||
let new_source_id = match ( | ||
details.git.as_ref(), | ||
details.path.as_ref(), | ||
details.registry.as_ref(), | ||
details.registry_index.as_ref(), | ||
) { | ||
(Some(_), _, Some(_), _) | | ||
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. One day we will make this better. It is not this day. |
||
(Some(_), _, _, Some(_))=> bail!("dependency ({}) specification is ambiguous. \ | ||
Only one of `git` or `registry` is allowed.", name), | ||
(Some(git), maybe_path, _) => { | ||
(_, _, Some(_), Some(_)) => bail!("dependency ({}) specification is ambiguous. \ | ||
Only one of `registry` or `registry-index` is allowed.", name), | ||
(Some(git), maybe_path, _, _) => { | ||
if maybe_path.is_some() { | ||
let msg = format!("dependency ({}) specification is ambiguous. \ | ||
Only one of `git` or `path` is allowed. \ | ||
|
@@ -963,7 +982,7 @@ impl TomlDependency { | |
let loc = git.to_url()?; | ||
SourceId::for_git(&loc, reference)? | ||
}, | ||
(None, Some(path), _) => { | ||
(None, Some(path), _, _) => { | ||
cx.nested_paths.push(PathBuf::from(path)); | ||
// If the source id for the package we're parsing is a path | ||
// source, then we normalize the path here to get rid of | ||
|
@@ -981,8 +1000,12 @@ impl TomlDependency { | |
cx.source_id.clone() | ||
} | ||
}, | ||
(None, None, Some(registry)) => SourceId::alt_registry(cx.config, registry)?, | ||
(None, None, None) => SourceId::crates_io(cx.config)?, | ||
(None, None, Some(registry), None) => SourceId::alt_registry(cx.config, registry)?, | ||
(None, None, None, Some(registry_index)) => { | ||
let url = registry_index.to_url()?; | ||
SourceId::for_registry(&url)? | ||
} | ||
(None, None, None, None) => SourceId::crates_io(cx.config)?, | ||
}; | ||
|
||
let version = details.version.as_ref().map(|v| &v[..]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah unfortuantely I don't think we can do this as it breaks manifests that use
default_features = false
, for example.When we first moved to serde we ran into that (as the old rustc-serialize toml-rs accepted both) and that's why there's two entries below :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
#[serde(rename = "default_features")]
down on default_features2 will handle that: https://play.rust-lang.org/?gist=db44b7c463a8b4ac43c0b67e2b36e5d0&version=stableThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! I missed that, nice!