From 570d51c3ea863530470318335baacf6c1f6aa32c Mon Sep 17 00:00:00 2001 From: messense Date: Fri, 21 Jan 2022 21:48:30 +0800 Subject: [PATCH] Fail the build if Cargo.toml is placed outside of the directory containing pyproject.toml --- src/build_options.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/build_options.rs b/src/build_options.rs index 59d246480..565e7bbcd 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -113,10 +113,20 @@ impl BuildOptions { return Ok(path.clone()); } // check `manifest-path` option in pyproject.toml - let current_dir = env::current_dir().context("Failed to detect current directory ಠ_ಠ")?; + let current_dir = env::current_dir() + .context("Failed to detect current directory ಠ_ಠ")? + .canonicalize()?; let pyproject = PyProjectToml::new(¤t_dir).context("pyproject.toml is invalid")?; if let Some(path) = pyproject.manifest_path() { println!("🔗 Found cargo manifest path in pyproject.toml"); + // pyproject.toml must be placed at top directory + let manifest_dir = path + .parent() + .context("missing parent directory")? + .canonicalize()?; + if !manifest_dir.starts_with(¤t_dir) { + bail!("Cargo.toml can not be placed outside of the directory containing pyproject.toml"); + } return Ok(path.to_path_buf()); } // check Cargo.toml in current directory