Skip to content

Commit

Permalink
fix creation of output directories
Browse files Browse the repository at this point in the history
  • Loading branch information
David Renshaw committed Mar 18, 2017
1 parent 44cf382 commit c692b5a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1765,13 +1765,13 @@ pub fn main<T>(mut inp: T, out_dir: &::std::path::Path) -> ::capnp::Result<()>
let id = requested_file.get_id();
let mut filepath = out_dir.to_path_buf();
let requested = ::std::path::PathBuf::from(try!(requested_file.get_filename()));
if let Some(parent) = requested.parent() {
filepath.push(requested);
if let Some(parent) = filepath.parent() {
try!(::std::fs::create_dir_all(parent));
filepath.push(parent);
}

let root_name = try!(path_to_stem_string(requested)).replace("-", "_");
filepath.push(&format!("{}_capnp.rs", root_name));
let root_name = try!(path_to_stem_string(&filepath)).replace("-", "_");
filepath.set_file_name(&format!("{}_capnp.rs", root_name));

let lines = Branch(vec!(
Line("// Generated by the capnpc-rust plugin to the Cap'n Proto schema compiler.".to_string()),
Expand Down
3 changes: 3 additions & 0 deletions test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ extern crate capnpc;
fn main() {
capnpc::CompilerCommand::new()
.file("test.capnp")
.file("schema/test-in-dir.capnp")
.file("schema-with-src-prefix/test-in-src-prefix-dir.capnp")
.src_prefix("schema-with-src-prefix")
.run()
.expect("compiling schema");
}
3 changes: 3 additions & 0 deletions test/schema-with-src-prefix/test-in-src-prefix-dir.capnp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@0x9bbc59b4f632f2e3;

struct Bar {}
3 changes: 3 additions & 0 deletions test/schema/test-in-dir.capnp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@0x997ccd7814c156ca;

struct Foo {}
11 changes: 10 additions & 1 deletion test/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@
extern crate capnp;

pub mod test_capnp {
include!(concat!(env!("OUT_DIR"), "/test_capnp.rs"));
include!(concat!(env!("OUT_DIR"), "/test_capnp.rs"));
}

pub mod test_in_dir_capnp {
include!(concat!(env!("OUT_DIR"), "/schema/test_in_dir_capnp.rs"));
}

pub mod test_in_src_prefix_dir_capnp {
// The src_prefix gets stripped away, so the generated code ends up directly in OUT_DIR.
include!(concat!(env!("OUT_DIR"), "/test_in_src_prefix_dir_capnp.rs"));
}

#[cfg(test)]
Expand Down

0 comments on commit c692b5a

Please sign in to comment.