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

Add parent directory creation to write_to_file function #2584

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindgen-integration/build.rs
Expand Up @@ -168,7 +168,7 @@ fn setup_macro_test() {
let macros = Arc::new(RwLock::new(HashSet::new()));

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let out_rust_file = out_path.join("test.rs");
let out_rust_file = out_path.join("test/test.rs");
let out_rust_file_relative = out_rust_file
.strip_prefix(std::env::current_dir().unwrap().parent().unwrap())
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion bindgen-integration/src/lib.rs
@@ -1,7 +1,7 @@
#![allow(warnings)]

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

mod extern_bindings {
Expand Down
4 changes: 4 additions & 0 deletions bindgen/lib.rs
Expand Up @@ -900,6 +900,10 @@ impl Bindings {

/// Write these bindings as source text to a file.
pub fn write_to_file<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
if let Some(parent_dir) = path.as_ref().parent() {
std::fs::create_dir_all(parent_dir)?;
}

let file = OpenOptions::new()
.write(true)
.truncate(true)
Expand Down