File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -221,19 +221,23 @@ pub struct RulesIR {
221221}
222222
223223impl RulesIR {
224- pub fn write_ir ( & self ) {
225- let crate_root = self . crate_root . canonicalize ( ) . unwrap ( ) ;
224+ pub fn write_ir ( & self , out_dir : & Path ) {
226225 for ( rule_path, file_ir) in & self . all_ir {
227226 let rule_path = Path :: new ( rule_path) ;
228- let file_name = rule_path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
229- let json_name = file_name. replace ( "tgt_" , "ir_" ) . replace ( ".rs" , ".json" ) ;
230- let json_path = rule_path. parent ( ) . unwrap ( ) . join ( json_name) ;
231-
227+ let rule_name = rule_path. parent ( ) . unwrap ( ) . file_name ( ) . unwrap ( ) ;
228+ let json_name = rule_path
229+ . file_name ( )
230+ . unwrap ( )
231+ . to_str ( )
232+ . unwrap ( )
233+ . replace ( "tgt_" , "ir_" )
234+ . replace ( ".rs" , ".json" ) ;
235+ let json_path = out_dir. join ( rule_name) . join ( json_name) ;
236+
237+ std:: fs:: create_dir_all ( json_path. parent ( ) . unwrap ( ) ) . unwrap ( ) ;
232238 let json = serde_json:: to_string_pretty ( file_ir) . unwrap ( ) ;
233239 std:: fs:: write ( & json_path, format ! ( "{json}\n " ) ) . unwrap ( ) ;
234-
235- let json_rel = json_path. strip_prefix ( & crate_root) . unwrap_or ( & json_path) ;
236- println ! ( "{}" , json_rel. display( ) ) ;
240+ println ! ( "{}" , json_path. display( ) ) ;
237241 }
238242 }
239243}
Original file line number Diff line number Diff line change @@ -17,8 +17,11 @@ use semantic::SemanticAnalysis;
1717use syntactic:: SyntacticAnalysis ;
1818
1919fn main ( ) {
20+ let out_dir = std:: env:: args ( )
21+ . nth ( 1 )
22+ . expect ( "usage: rule-preprocessor <out-dir>" ) ;
2023 SemanticAnalysis :: run ( SyntacticAnalysis :: run (
2124 & std:: fs:: canonicalize ( "../rules" ) . unwrap ( ) ,
2225 ) )
23- . write_ir ( ) ;
26+ . write_ir ( & std :: path :: PathBuf :: from ( out_dir ) ) ;
2427}
You can’t perform that action at this time.
0 commit comments