mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Assume README.md if readme=true
This commit is contained in:
parent
77c52c2b4f
commit
b0a3cc6b7a
@ -1199,11 +1199,18 @@ impl TomlManifest {
|
||||
project.namespaced_features.unwrap_or(false),
|
||||
)?;
|
||||
|
||||
let readme = readme_for_project(package_root, project);
|
||||
if let Some(ref r) = readme {
|
||||
if !package_root.join(r).is_file() {
|
||||
bail!("readme file with name '{}' was not found", r);
|
||||
}
|
||||
};
|
||||
|
||||
let metadata = ManifestMetadata {
|
||||
description: project.description.clone(),
|
||||
homepage: project.homepage.clone(),
|
||||
documentation: project.documentation.clone(),
|
||||
readme: readme_for_project(package_root, project),
|
||||
readme,
|
||||
authors: project.authors.clone().unwrap_or_default(),
|
||||
license: project.license.clone(),
|
||||
license_file: project.license_file.clone(),
|
||||
@ -1520,7 +1527,7 @@ fn readme_for_project(package_root: &Path, project: &TomlProject) -> Option<Stri
|
||||
None => default_readme_from_package_root(package_root),
|
||||
Some(value) => match value {
|
||||
StringOrBool::Bool(false) => None,
|
||||
StringOrBool::Bool(true) => default_readme_from_package_root(package_root),
|
||||
StringOrBool::Bool(true) => Some("README.md".to_string()),
|
||||
StringOrBool::String(v) => Some(v.clone()),
|
||||
},
|
||||
}
|
||||
|
@ -168,7 +168,8 @@ readme = "README.md"
|
||||
If no value is specified for this field, and a file named `README.md`,
|
||||
`README.txt` or `README` exists in the package root, then the name of that
|
||||
file will be used. You can suppress this behavior by setting this field to
|
||||
`false`.
|
||||
`false`. If the field is set to `true`, a default value of `README.md` will
|
||||
be assumed.
|
||||
|
||||
#### The `homepage` field
|
||||
|
||||
|
@ -185,16 +185,29 @@ fn cargo_read_manifest_suppress_default_readme() {
|
||||
.run();
|
||||
}
|
||||
|
||||
// If a file named README.txt exists, and `readme = true`, the value `README.txt` should be defaulted in.
|
||||
// If a file named README.md exists, and `readme = true`, the value `README.md` should be defaulted in.
|
||||
#[cargo_test]
|
||||
fn cargo_read_manifest_defaults_readme_if_true() {
|
||||
let p = project()
|
||||
.file("Cargo.toml", &basic_bin_manifest_with_readme("foo", "true"))
|
||||
.file("README.md", "Sample project")
|
||||
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
||||
.build();
|
||||
|
||||
p.cargo("read-manifest")
|
||||
.with_json(&manifest_output(&format!(r#""{}""#, "README.md")))
|
||||
.run();
|
||||
}
|
||||
|
||||
// If a file named README.md does not exist, and `readme = true`, it should panic.
|
||||
#[cargo_test]
|
||||
#[should_panic]
|
||||
fn cargo_read_manifest_panics_if_default_readme_not_found() {
|
||||
let p = project()
|
||||
.file("Cargo.toml", &basic_bin_manifest_with_readme("foo", "true"))
|
||||
.file("README.txt", "Sample project")
|
||||
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
||||
.build();
|
||||
|
||||
p.cargo("read-manifest")
|
||||
.with_json(&manifest_output(&format!(r#""{}""#, "README.txt")))
|
||||
.run();
|
||||
p.cargo("read-manifest").run();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user