Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for Xargo.toml in parent directories, including test #254

Merged
merged 2 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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> {
Nils-TUD marked this conversation as resolved.
Show resolved Hide resolved
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", "--lib", "--vcs", "none", "--name", name])
Expand Down Expand Up @@ -343,16 +349,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