@@ -8,6 +8,7 @@ use std::{
8
8
use anyhow:: Result ;
9
9
use fnv:: FnvHashSet ;
10
10
use serde:: { Deserialize , Serialize } ;
11
+ use walkdir:: WalkDir ;
11
12
12
13
use super :: Test ;
13
14
@@ -250,19 +251,12 @@ fn get_kcl_metadata(project_path: &Path, files: &[String]) -> Option<KclMetadata
250
251
let title = lines[ 0 ] . trim_start_matches ( COMMENT_PREFIX ) . trim ( ) . to_string ( ) ;
251
252
let description = lines[ 1 ] . trim_start_matches ( COMMENT_PREFIX ) . trim ( ) . to_string ( ) ;
252
253
253
- // Get the path components
254
- let path_components: Vec < String > = full_path_to_primary_kcl
255
- . components ( )
256
- . map ( |comp| comp. as_os_str ( ) . to_string_lossy ( ) . to_string ( ) )
257
- . collect ( ) ;
258
-
259
- // Get the last two path components
260
- let len = path_components. len ( ) ;
261
- let path_from_project_dir = if len >= 2 {
262
- format ! ( "{}/{}" , path_components[ len - 2 ] , path_components[ len - 1 ] )
263
- } else {
264
- primary_kcl_file. clone ( )
265
- } ;
254
+ // Get the relative path from the project directory to the primary KCL file
255
+ let path_from_project_dir = full_path_to_primary_kcl
256
+ . strip_prefix ( INPUTS_DIR . as_path ( ) )
257
+ . unwrap_or ( & full_path_to_primary_kcl)
258
+ . to_string_lossy ( )
259
+ . to_string ( ) ;
266
260
267
261
let mut files = files. to_vec ( ) ;
268
262
files. sort ( ) ;
@@ -281,21 +275,23 @@ fn get_kcl_metadata(project_path: &Path, files: &[String]) -> Option<KclMetadata
281
275
fn generate_kcl_manifest ( dir : & Path ) -> Result < ( ) > {
282
276
let mut manifest = Vec :: new ( ) ;
283
277
284
- // Collect all directory entries first and sort them by name for consistent ordering
285
- let mut entries: Vec < _ > = fs:: read_dir ( dir) ?
286
- . filter_map ( Result :: ok)
287
- . filter ( |e| e. path ( ) . is_dir ( ) )
278
+ // Collect all directory entries first
279
+ let mut entries: Vec < _ > = WalkDir :: new ( dir)
280
+ . follow_links ( true )
281
+ . into_iter ( )
282
+ . filter_map ( |e| e. ok ( ) )
288
283
. collect ( ) ;
289
284
290
285
// Sort directories by name for consistent ordering
291
- entries. sort_by_key ( |a| a. file_name ( ) ) ;
286
+ entries. sort_by_key ( |a| a. file_name ( ) . to_string_lossy ( ) . to_string ( ) ) ;
292
287
288
+ // Loop through all directories and add to manifest if KCL sample
293
289
for entry in entries {
294
- let project_path = entry. path ( ) ;
290
+ let path = entry. path ( ) ;
295
291
296
- if project_path . is_dir ( ) {
292
+ if path . is_dir ( ) {
297
293
// Get all .kcl files in the directory
298
- let files: Vec < String > = fs:: read_dir ( & project_path ) ?
294
+ let files: Vec < String > = fs:: read_dir ( path ) ?
299
295
. filter_map ( Result :: ok)
300
296
. filter ( |e| {
301
297
if let Some ( ext) = e. path ( ) . extension ( ) {
@@ -311,7 +307,7 @@ fn generate_kcl_manifest(dir: &Path) -> Result<()> {
311
307
continue ;
312
308
}
313
309
314
- if let Some ( metadata) = get_kcl_metadata ( & project_path , & files) {
310
+ if let Some ( metadata) = get_kcl_metadata ( path , & files) {
315
311
manifest. push ( metadata) ;
316
312
}
317
313
}
0 commit comments