11use clap:: Args ;
2+ use codeql_extractor:: file_paths:: PathTransformer ;
23use lazy_static:: lazy_static;
34use rayon:: prelude:: * ;
45use serde_json;
@@ -81,6 +82,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
8182 let file_list = fs:: File :: open ( file_paths:: path_from_string ( & options. file_list ) ) ?;
8283
8384 let overlay_changed_files: Option < HashSet < PathBuf > > = get_overlay_changed_files ( ) ;
85+ let path_transformer = file_paths:: load_path_transformer ( ) ?;
8486
8587 let language: Language = tree_sitter_ruby:: LANGUAGE . into ( ) ;
8688 let erb: Language = tree_sitter_embedded_template:: LANGUAGE . into ( ) ;
@@ -105,7 +107,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
105107 }
106108 _ => { } ,
107109 }
108- let src_archive_file = file_paths:: path_for ( & src_archive_dir, & path, "" ) ;
110+ let src_archive_file = file_paths:: path_for ( & src_archive_dir, & path, "" , path_transformer . as_ref ( ) ) ;
109111 let mut source = std:: fs:: read ( & path) ?;
110112 let mut needs_conversion = false ;
111113 let code_ranges;
@@ -118,6 +120,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
118120 & erb_schema,
119121 & mut diagnostics_writer,
120122 & mut trap_writer,
123+ path_transformer. as_ref ( ) ,
121124 & path,
122125 & source,
123126 & [ ] ,
@@ -162,7 +165,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
162165 "character-decoding-error" ,
163166 "Character decoding error" ,
164167 )
165- . file ( & file_paths:: normalize_path ( & path) )
168+ . file ( & file_paths:: normalize_and_transform_path ( & path, path_transformer . as_ref ( ) ) )
166169 . message (
167170 "Could not decode the file contents as {}: {}. The contents of the file must match the character encoding specified in the {} {}." ,
168171 & [
@@ -182,7 +185,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
182185 diagnostics_writer. write (
183186 diagnostics_writer
184187 . new_entry ( "unknown-character-encoding" , "Could not process some files due to an unknown character encoding" )
185- . file ( & file_paths:: normalize_path ( & path) )
188+ . file ( & file_paths:: normalize_and_transform_path ( & path, path_transformer . as_ref ( ) ) )
186189 . message (
187190 "Unknown character encoding {} in {} {}." ,
188191 & [
@@ -205,6 +208,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
205208 & schema,
206209 & mut diagnostics_writer,
207210 & mut trap_writer,
211+ path_transformer. as_ref ( ) ,
208212 & path,
209213 & source,
210214 & code_ranges,
@@ -215,14 +219,20 @@ pub fn run(options: Options) -> std::io::Result<()> {
215219 } else {
216220 std:: fs:: copy ( & path, & src_archive_file) ?;
217221 }
218- write_trap ( & trap_dir, path, & trap_writer, trap_compression)
222+ write_trap ( & trap_dir, path, & trap_writer, trap_compression, path_transformer . as_ref ( ) )
219223 } )
220224 . expect ( "failed to extract files" ) ;
221225
222226 let path = PathBuf :: from ( "extras" ) ;
223227 let mut trap_writer = trap:: Writer :: new ( ) ;
224228 extractor:: populate_empty_location ( & mut trap_writer) ;
225- let res = write_trap ( & trap_dir, path, & trap_writer, trap_compression) ;
229+ let res = write_trap (
230+ & trap_dir,
231+ path,
232+ & trap_writer,
233+ trap_compression,
234+ path_transformer. as_ref ( ) ,
235+ ) ;
226236 if let Ok ( output_path) = std:: env:: var ( "CODEQL_EXTRACTOR_RUBY_OVERLAY_BASE_METADATA_OUT" ) {
227237 // We're extracting an overlay base. For now, we don't have any metadata we need to store
228238 // that would get read when extracting the overlay, but the CLI expects us to write
@@ -254,8 +264,14 @@ fn write_trap(
254264 path : PathBuf ,
255265 trap_writer : & trap:: Writer ,
256266 trap_compression : trap:: Compression ,
267+ path_transformer : Option < & PathTransformer > ,
257268) -> std:: io:: Result < ( ) > {
258- let trap_file = file_paths:: path_for ( trap_dir, & path, trap_compression. extension ( ) ) ;
269+ let trap_file = file_paths:: path_for (
270+ trap_dir,
271+ & path,
272+ trap_compression. extension ( ) ,
273+ path_transformer,
274+ ) ;
259275 std:: fs:: create_dir_all ( trap_file. parent ( ) . unwrap ( ) ) ?;
260276 trap_writer. write_to_file ( & trap_file, trap_compression)
261277}
0 commit comments