Skip to content

Commit b0a3cc6

Browse files
committed
Assume README.md if readme=true
1 parent 77c52c2 commit b0a3cc6

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,11 +1199,18 @@ impl TomlManifest {
11991199
project.namespaced_features.unwrap_or(false),
12001200
)?;
12011201

1202+
let readme = readme_for_project(package_root, project);
1203+
if let Some(ref r) = readme {
1204+
if !package_root.join(r).is_file() {
1205+
bail!("readme file with name '{}' was not found", r);
1206+
}
1207+
};
1208+
12021209
let metadata = ManifestMetadata {
12031210
description: project.description.clone(),
12041211
homepage: project.homepage.clone(),
12051212
documentation: project.documentation.clone(),
1206-
readme: readme_for_project(package_root, project),
1213+
readme,
12071214
authors: project.authors.clone().unwrap_or_default(),
12081215
license: project.license.clone(),
12091216
license_file: project.license_file.clone(),
@@ -1520,7 +1527,7 @@ fn readme_for_project(package_root: &Path, project: &TomlProject) -> Option<Stri
15201527
None => default_readme_from_package_root(package_root),
15211528
Some(value) => match value {
15221529
StringOrBool::Bool(false) => None,
1523-
StringOrBool::Bool(true) => default_readme_from_package_root(package_root),
1530+
StringOrBool::Bool(true) => Some("README.md".to_string()),
15241531
StringOrBool::String(v) => Some(v.clone()),
15251532
},
15261533
}

src/doc/src/reference/manifest.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ readme = "README.md"
168168
If no value is specified for this field, and a file named `README.md`,
169169
`README.txt` or `README` exists in the package root, then the name of that
170170
file will be used. You can suppress this behavior by setting this field to
171-
`false`.
171+
`false`. If the field is set to `true`, a default value of `README.md` will
172+
be assumed.
172173

173174
#### The `homepage` field
174175

tests/testsuite/read_manifest.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,29 @@ fn cargo_read_manifest_suppress_default_readme() {
185185
.run();
186186
}
187187

188-
// If a file named README.txt exists, and `readme = true`, the value `README.txt` should be defaulted in.
188+
// If a file named README.md exists, and `readme = true`, the value `README.md` should be defaulted in.
189189
#[cargo_test]
190190
fn cargo_read_manifest_defaults_readme_if_true() {
191191
let p = project()
192192
.file("Cargo.toml", &basic_bin_manifest_with_readme("foo", "true"))
193-
.file("README.txt", "Sample project")
193+
.file("README.md", "Sample project")
194194
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
195195
.build();
196196

197197
p.cargo("read-manifest")
198-
.with_json(&manifest_output(&format!(r#""{}""#, "README.txt")))
198+
.with_json(&manifest_output(&format!(r#""{}""#, "README.md")))
199199
.run();
200200
}
201+
202+
// If a file named README.md does not exist, and `readme = true`, it should panic.
203+
#[cargo_test]
204+
#[should_panic]
205+
fn cargo_read_manifest_panics_if_default_readme_not_found() {
206+
let p = project()
207+
.file("Cargo.toml", &basic_bin_manifest_with_readme("foo", "true"))
208+
.file("README.txt", "Sample project")
209+
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
210+
.build();
211+
212+
p.cargo("read-manifest").run();
213+
}

0 commit comments

Comments
 (0)