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 11, 2019
2 parents a6d1969 + 26494e7 commit 26009a8
Show file tree
Hide file tree
Showing 2 changed files with 35 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)
}
}
32 changes: 31 additions & 1 deletion tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ struct Project {

impl Project {
fn new(name: &'static str) -> Result<Self> {
Self::new_in(std::env::temp_dir(), name)
}

fn new_in(dir: PathBuf, name: &'static str) -> Result<Self> {
const JSON: &'static str = r#"
{
"arch": "arm",
Expand All @@ -186,7 +190,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])
Expand Down Expand Up @@ -367,6 +371,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 = "thumbv7m-parent-eabi";

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-parent-eabi.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 26009a8

Please sign in to comment.