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 19, 2019
2 parents a880315 + a5f8503 commit 08bf79c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 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)
}
}
15 changes: 11 additions & 4 deletions 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 @@ -350,16 +356,17 @@ fn simple() {
}

/// Test building a dependency specified as `target.{}.dependencies` in
/// Xargo.toml
/// ../Xargo.toml
#[cfg(feature = "dev")]
#[test]
fn target_dependencies() {
fn run() -> Result<()> {
// 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]
"#,
Expand Down

0 comments on commit 08bf79c

Please sign in to comment.