From fd8fe3502f16f0ac6ce0976b60b975536668cb44 Mon Sep 17 00:00:00 2001 From: Nils Asmussen Date: Thu, 9 Nov 2017 20:42:18 +0100 Subject: [PATCH 1/2] Search for Xargo.toml in parent directories. --- src/xargo.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/xargo.rs b/src/xargo.rs index 168b8c4..06b21bd 100644 --- a/src/xargo.rs +++ b/src/xargo.rs @@ -121,11 +121,10 @@ impl Toml { } pub fn toml(root: &Root) -> Result> { - let p = root.path().join("Xargo.toml"); - - if p.exists() { - util::parse(&p).map(|t| Some(Toml { table: t })) - } else { + if let Some(p) = util::search(root.path(), "Xargo.toml") { + util::parse(&p.join("Xargo.toml")).map(|t| Some(Toml { table: t })) + } + else { Ok(None) } } From a5f8503f3fd216a8bbf2fc96e35e3718ad01506e Mon Sep 17 00:00:00 2001 From: Nils Asmussen Date: Mon, 9 Sep 2019 13:36:35 +0200 Subject: [PATCH 2/2] Modified existing test to search Xargo.toml in parent directory. This commit does not add a new test, because a unique and existing target is required, which turned out to be challenging. --- tests/smoke.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/smoke.rs b/tests/smoke.rs index 71bc042..85a619b 100644 --- a/tests/smoke.rs +++ b/tests/smoke.rs @@ -171,7 +171,13 @@ struct Project { } impl Project { + /// Creates a new project with given name in a temporary directory. fn new(name: &'static str) -> Result { + Self::new_in(std::env::temp_dir(), name) + } + + /// Creates a new project with given name in a sub directory of `dir`. + fn new_in(dir: PathBuf, name: &'static str) -> Result { const JSON: &'static str = r#" { "arch": "arm", @@ -186,7 +192,7 @@ impl Project { } "#; - let td = TempDir::new("xargo").chain_err(|| "couldn't create a temporary directory")?; + let td = TempDir::new_in(dir, "xargo").chain_err(|| "couldn't create a temporary directory")?; xargo()? .args(&["init", "--lib", "--vcs", "none", "--name", name]) @@ -343,7 +349,7 @@ fn simple() { } /// Test building a dependency specified as `target.{}.dependencies` in -/// Xargo.toml +/// ../Xargo.toml #[cfg(feature = "dev")] #[test] fn target_dependencies() { @@ -351,8 +357,9 @@ fn target_dependencies() { // need this exact target name to get the right gcc flags const TARGET: &'static str = "thumbv7m-none-eabi"; - let project = Project::new(TARGET)?; - project.xargo_toml( + let td = TempDir::new("xargo").chain_err(|| "couldn't create a temporary directory")?; + let project = Project::new_in(td.path().to_path_buf(), TARGET)?; + write(&td.path().join("Xargo.toml"), false, r#" [target.thumbv7m-none-eabi.dependencies.alloc] "#,