Skip to content

Commit

Permalink
Merge #254
Browse files Browse the repository at this point in the history
254:  Search for Xargo.toml in parent directories, including test r=RalfJung a=Nils-TUD

So far, xargo expected the Xargo.toml in the directory of the Cargo.toml. This patch searches for the Xargo.toml by walking up the directory hierarchy. This is useful if a workspace is used, leading, for example, to one Cargo.toml with the workspace and multiple Cargo.toml files for the members of the workspace. With this patch, it is no longer necessary to have one Xargo.toml for each Cargo.toml, but only one next to the workspace, for example.

Co-authored-by: Nils Asmussen <[email protected]>
  • Loading branch information
bors[bot] and Nils-TUD authored Sep 18, 2019
2 parents a880315 + d0dfcdc commit 2eabc76
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/xargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,10 @@ impl Toml {
}

pub fn toml(root: &Root) -> Result<Option<Toml>> {
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)
}
}
34 changes: 33 additions & 1 deletion tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
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<Self> {
const JSON: &'static str = r#"
{
"arch": "arm",
Expand All @@ -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", "-q", "--lib", "--vcs", "none", "--name", name])
Expand Down Expand Up @@ -374,6 +380,32 @@ fn target_dependencies() {
run!()
}

/// Test building a dependency specified as `target.{}.dependencies` in
/// ../Xargo.toml
#[cfg(feature = "dev")]
#[test]
fn target_dependencies_parentdir() {
fn run() -> Result<()> {
// need this exact target name to get the right gcc flags
const TARGET: &'static str = "riscv32i-unknown-none-elf";

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.riscv32i-unknown-none-elf.dependencies.alloc]
"#,
)?;
project.build(TARGET)?;
assert!(exists("core", TARGET)?);
assert!(exists("alloc", TARGET)?);

Ok(())
}

run!()
}

/// Test building a dependency specified as `dependencies` in Xargo.toml
#[cfg(feature = "dev")]
#[test]
Expand Down

0 comments on commit 2eabc76

Please sign in to comment.