mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Auto merge of #9607 - hi-rustin:rustin-patch-cargo-toml, r=ehuss
Detect incorrectly named cargo.toml close https://github.com/rust-lang/cargo/issues/9541
This commit is contained in:
commit
9233aa06c8
@ -211,6 +211,13 @@ fn install_one(
|
|||||||
specify an alternate source",
|
specify an alternate source",
|
||||||
src.path().display()
|
src.path().display()
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
if src.path().join("cargo.toml").exists() {
|
||||||
|
bail!(
|
||||||
|
"`{}` does not contain a Cargo.toml file, but found cargo.toml please try to rename it to Cargo.toml. \
|
||||||
|
--path must point to a directory containing a Cargo.toml file.",
|
||||||
|
src.path().display()
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
bail!(
|
bail!(
|
||||||
"`{}` does not contain a Cargo.toml file. \
|
"`{}` does not contain a Cargo.toml file. \
|
||||||
@ -219,6 +226,7 @@ fn install_one(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
select_pkg(
|
select_pkg(
|
||||||
&mut src,
|
&mut src,
|
||||||
dep,
|
dep,
|
||||||
|
@ -88,10 +88,19 @@ pub fn read_packages(
|
|||||||
if all_packages.is_empty() {
|
if all_packages.is_empty() {
|
||||||
match errors.pop() {
|
match errors.pop() {
|
||||||
Some(err) => Err(err),
|
Some(err) => Err(err),
|
||||||
None => Err(anyhow::format_err!(
|
None => {
|
||||||
|
if find_project_manifest_exact(path, "cargo.toml").is_ok() {
|
||||||
|
Err(anyhow::format_err!(
|
||||||
|
"Could not find Cargo.toml in `{}`, but found cargo.toml please try to rename it to Cargo.toml",
|
||||||
|
path.display()
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
Err(anyhow::format_err!(
|
||||||
"Could not find Cargo.toml in `{}`",
|
"Could not find Cargo.toml in `{}`",
|
||||||
path.display()
|
path.display()
|
||||||
)),
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(all_packages.into_iter().map(|(_, v)| v).collect())
|
Ok(all_packages.into_iter().map(|(_, v)| v).collect())
|
||||||
|
@ -4,19 +4,33 @@ use std::path::{Path, PathBuf};
|
|||||||
|
|
||||||
/// Finds the root `Cargo.toml`.
|
/// Finds the root `Cargo.toml`.
|
||||||
pub fn find_root_manifest_for_wd(cwd: &Path) -> CargoResult<PathBuf> {
|
pub fn find_root_manifest_for_wd(cwd: &Path) -> CargoResult<PathBuf> {
|
||||||
let file = "Cargo.toml";
|
let valid_cargo_toml_file_name = "Cargo.toml";
|
||||||
|
let invalid_cargo_toml_file_name = "cargo.toml";
|
||||||
|
let mut invalid_cargo_toml_path_exists = false;
|
||||||
|
|
||||||
for current in paths::ancestors(cwd, None) {
|
for current in paths::ancestors(cwd, None) {
|
||||||
let manifest = current.join(file);
|
let manifest = current.join(valid_cargo_toml_file_name);
|
||||||
if manifest.exists() {
|
if manifest.exists() {
|
||||||
return Ok(manifest);
|
return Ok(manifest);
|
||||||
}
|
}
|
||||||
|
if current.join(invalid_cargo_toml_file_name).exists() {
|
||||||
|
invalid_cargo_toml_path_exists = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if invalid_cargo_toml_path_exists {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"could not find `{}` in `{}` or any parent directory",
|
"could not find `{}` in `{}` or any parent directory, but found cargo.toml please try to rename it to Cargo.toml",
|
||||||
file,
|
valid_cargo_toml_file_name,
|
||||||
cwd.display()
|
cwd.display()
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
anyhow::bail!(
|
||||||
|
"could not find `{}` in `{}` or any parent directory",
|
||||||
|
valid_cargo_toml_file_name,
|
||||||
|
cwd.display()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the path to the `file` in `pwd`, if it exists.
|
/// Returns the path to the `file` in `pwd`, if it exists.
|
||||||
|
@ -561,6 +561,24 @@ fn cargo_compile_without_manifest() {
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn cargo_compile_with_lowercase_cargo_toml() {
|
||||||
|
let p = project()
|
||||||
|
.no_manifest()
|
||||||
|
.file("cargo.toml", &basic_manifest("foo", "0.1.0"))
|
||||||
|
.file("src/lib.rs", &main_file(r#""i am foo""#, &[]))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
p.cargo("build")
|
||||||
|
.with_status(101)
|
||||||
|
.with_stderr(
|
||||||
|
"[ERROR] could not find `Cargo.toml` in `[..]` or any parent directory, \
|
||||||
|
but found cargo.toml please try to rename it to Cargo.toml",
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
fn cargo_compile_with_invalid_code() {
|
fn cargo_compile_with_invalid_code() {
|
||||||
let p = project()
|
let p = project()
|
||||||
|
@ -399,6 +399,23 @@ fn install_target_dir() {
|
|||||||
assert!(path.exists());
|
assert!(path.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn install_path_with_lowercase_cargo_toml() {
|
||||||
|
let toml = paths::root().join("cargo.toml");
|
||||||
|
fs::write(toml, "").unwrap();
|
||||||
|
|
||||||
|
cargo_process("install --path .")
|
||||||
|
.with_status(101)
|
||||||
|
.with_stderr(
|
||||||
|
"\
|
||||||
|
[ERROR] `[CWD]` does not contain a Cargo.toml file, \
|
||||||
|
but found cargo.toml please try to rename it to Cargo.toml. --path must point to a directory containing a Cargo.toml file.
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
fn multiple_crates_error() {
|
fn multiple_crates_error() {
|
||||||
let p = git::repo(&paths::root().join("foo"))
|
let p = git::repo(&paths::root().join("foo"))
|
||||||
@ -760,6 +777,26 @@ fn git_repo() {
|
|||||||
assert_has_installed_exe(cargo_home(), "foo");
|
assert_has_installed_exe(cargo_home(), "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn git_repo_with_lowercase_cargo_toml() {
|
||||||
|
let p = git::repo(&paths::root().join("foo"))
|
||||||
|
.file("cargo.toml", &basic_manifest("foo", "0.1.0"))
|
||||||
|
.file("src/main.rs", "fn main() {}")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
cargo_process("install --git")
|
||||||
|
.arg(p.url().to_string())
|
||||||
|
.with_status(101)
|
||||||
|
.with_stderr(
|
||||||
|
"\
|
||||||
|
[UPDATING] git repository [..]
|
||||||
|
[ERROR] Could not find Cargo.toml in `[..]`, but found cargo.toml please try to rename it to Cargo.toml
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
fn list() {
|
fn list() {
|
||||||
pkg("foo", "0.0.1");
|
pkg("foo", "0.0.1");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user