From a5c36b2ab57851716464a4b951dd0702d45c9aa5 Mon Sep 17 00:00:00 2001 From: rzvxa Date: Tue, 30 Jul 2024 22:47:15 +0330 Subject: [PATCH] fix(ast_codegen): create output path if doesn't exist. --- tasks/ast_codegen/src/util.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tasks/ast_codegen/src/util.rs b/tasks/ast_codegen/src/util.rs index 615037ea997d6f..af0dc688f2a560 100644 --- a/tasks/ast_codegen/src/util.rs +++ b/tasks/ast_codegen/src/util.rs @@ -259,9 +259,13 @@ impl TokenStreamExt for TokenStream { } } -pub fn write_all_to>(data: &[u8], path: S) -> std::io::Result<()> { +pub fn write_all_to>(data: &[u8], path: S) -> std::io::Result<()> { use std::{fs, io::Write}; - let mut file = fs::File::create(path.as_ref())?; + let path = path.as_ref(); + if let Some(parent) = path.parent() { + fs::create_dir_all(parent)?; + } + let mut file = fs::File::create(path)?; file.write_all(data)?; Ok(()) }