22// the corresponding warnings aren't helpful.
33#![ allow( dead_code, unused_imports) ]
44
5+ use core:: fmt:: Write ;
6+
57use std:: {
68 fs,
79 path:: { Path , PathBuf } ,
@@ -167,7 +169,7 @@ struct Input {
167169 ///
168170 /// If the subdirectory is omitted, we assume that the output goes
169171 /// to "wgsl".
170- subdirectory : Option < PathBuf > ,
172+ subdirectory : PathBuf ,
171173
172174 /// The input filename name, without a directory.
173175 file_name : PathBuf ,
@@ -190,9 +192,9 @@ impl Input {
190192 /// The `input` path is interpreted relative to the `BASE_DIR_IN`
191193 /// subdirectory of the directory given by the `CARGO_MANIFEST_DIR`
192194 /// environment variable.
193- fn new ( subdirectory : Option < & str > , name : & str , extension : & str ) -> Input {
195+ fn new ( subdirectory : & str , name : & str , extension : & str ) -> Input {
194196 Input {
195- subdirectory : subdirectory . map ( PathBuf :: from) ,
197+ subdirectory : PathBuf :: from ( subdirectory ) ,
196198 // Don't wipe out any extensions on `name`, as
197199 // `with_extension` would do.
198200 file_name : PathBuf :: from ( format ! ( "{name}.{extension}" ) ) ,
@@ -202,13 +204,11 @@ impl Input {
202204
203205 /// Return an iterator that produces an `Input` for each entry in `subdirectory`.
204206 fn files_in_dir (
205- subdirectory : Option < & ' static str > ,
207+ subdirectory : & ' static str ,
206208 file_extensions : & ' static [ & ' static str ] ,
207209 ) -> impl Iterator < Item = Input > + ' static {
208- let mut input_directory = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( BASE_DIR_IN ) ;
209- if let Some ( ref subdirectory) = subdirectory {
210- input_directory. push ( subdirectory) ;
211- }
210+ let input_directory = Path :: new ( CRATE_ROOT ) . join ( BASE_DIR_IN ) . join ( subdirectory) ;
211+
212212 let entries = match std:: fs:: read_dir ( & input_directory) {
213213 Ok ( entries) => entries,
214214 Err ( err) => panic ! (
@@ -245,14 +245,12 @@ impl Input {
245245 /// Return the path to the input directory.
246246 fn input_directory ( & self ) -> PathBuf {
247247 let mut dir = Path :: new ( CRATE_ROOT ) . join ( BASE_DIR_IN ) ;
248- if let Some ( ref subdirectory) = self . subdirectory {
249- dir. push ( subdirectory) ;
250- }
248+ dir. push ( & self . subdirectory ) ;
251249 dir
252250 }
253251
254252 /// Return the path to the output directory.
255- fn output_directory ( & self , subdirectory : & str ) -> PathBuf {
253+ fn output_directory ( subdirectory : & str ) -> PathBuf {
256254 let mut dir = Path :: new ( CRATE_ROOT ) . join ( BASE_DIR_OUT ) ;
257255 dir. push ( subdirectory) ;
258256 dir
@@ -266,14 +264,24 @@ impl Input {
266264 }
267265
268266 fn output_path ( & self , subdirectory : & str , extension : & str ) -> PathBuf {
269- let mut output = self . output_directory ( subdirectory) ;
267+ let mut output = Self :: output_directory ( subdirectory) ;
270268 if self . keep_input_extension {
271- let mut file_name = self . file_name . as_os_str ( ) . to_owned ( ) ;
272- file_name. push ( "." ) ;
273- file_name. push ( extension) ;
269+ let file_name = format ! (
270+ "{}-{}.{}" ,
271+ self . subdirectory. display( ) ,
272+ self . file_name. display( ) ,
273+ extension
274+ ) ;
275+
274276 output. push ( & file_name) ;
275277 } else {
276- output. push ( & self . file_name ) ;
278+ let file_name = format ! (
279+ "{}-{}" ,
280+ self . subdirectory. display( ) ,
281+ self . file_name. display( )
282+ ) ;
283+
284+ output. push ( & file_name) ;
277285 output. set_extension ( extension) ;
278286 }
279287 output
@@ -792,7 +800,7 @@ fn write_output_wgsl(
792800fn convert_snapshots_wgsl ( ) {
793801 let _ = env_logger:: try_init ( ) ;
794802
795- for input in Input :: files_in_dir ( Some ( "wgsl" ) , & [ "wgsl" ] ) {
803+ for input in Input :: files_in_dir ( "wgsl" , & [ "wgsl" ] ) {
796804 let source = input. read_source ( ) ;
797805 // crlf will make the large split output different on different platform
798806 let source = source. replace ( '\r' , "" ) ;
@@ -813,7 +821,7 @@ fn convert_snapshots_spv() {
813821
814822 let _ = env_logger:: try_init ( ) ;
815823
816- for input in Input :: files_in_dir ( Some ( "spv" ) , & [ "spvasm" ] ) {
824+ for input in Input :: files_in_dir ( "spv" , & [ "spvasm" ] ) {
817825 println ! ( "Assembling '{}'" , input. file_name. display( ) ) ;
818826
819827 let command = Command :: new ( "spirv-as" )
@@ -861,7 +869,7 @@ fn convert_snapshots_spv() {
861869fn convert_snapshots_glsl ( ) {
862870 let _ = env_logger:: try_init ( ) ;
863871
864- for input in Input :: files_in_dir ( Some ( "glsl" ) , & [ "vert" , "frag" , "comp" ] ) {
872+ for input in Input :: files_in_dir ( "glsl" , & [ "vert" , "frag" , "comp" ] ) {
865873 let input = Input {
866874 keep_input_extension : true ,
867875 ..input
0 commit comments