@@ -68,41 +68,45 @@ impl Compiler {
68
68
optional,
69
69
path,
70
70
} => {
71
- let import_base = current
71
+ let import = current
72
72
. path
73
73
. parent ( )
74
74
. unwrap ( )
75
75
. join ( Self :: expand_tilde ( & relative. cooked ) ?)
76
76
. lexiclean ( ) ;
77
77
78
- println ! ( "IMPORT: {}" , import. display( ) ) ;
79
-
80
- let glob_options = glob:: MatchOptions {
81
- case_sensitive : true ,
82
- require_literal_separator : false ,
83
- require_literal_leading_dot : false ,
84
- } ;
85
-
86
- let import_paths = glob:: glob_with ( & import_base. display ( ) . to_string ( ) , glob_options) ;
87
- for import in import_paths {
88
- if import. is_file ( ) {
89
-
78
+ let import_base_str = import. to_string_lossy ( ) ;
79
+ let has_glob = import_base_str. find ( '*' ) . is_some ( ) ;
80
+
81
+ if has_glob {
82
+ let glob_options = glob:: MatchOptions {
83
+ case_sensitive : true ,
84
+ require_literal_separator : false ,
85
+ require_literal_leading_dot : false ,
86
+ } ;
87
+ let import_paths = glob:: glob_with ( & import_base_str, glob_options) . unwrap ( ) ;
88
+ for import in import_paths {
89
+ let import = import. unwrap ( ) ;
90
+
91
+ if import. is_file ( ) {
92
+ if current. file_path . contains ( & import) {
93
+ return Err ( Error :: CircularImport {
94
+ current : current. path ,
95
+ import,
96
+ } ) ;
97
+ }
98
+ absolute_paths. push ( import. clone ( ) ) ;
99
+ stack. push ( current. import ( import, path. offset ) ) ;
100
+ }
90
101
}
91
-
92
- }
93
-
94
-
95
-
96
-
97
- if import. is_file ( ) {
102
+ } else if import. is_file ( ) {
98
103
if current. file_path . contains ( & import) {
99
104
return Err ( Error :: CircularImport {
100
105
current : current. path ,
101
106
import,
102
107
} ) ;
103
108
}
104
- //*absolute = Some(import.clone());
105
- * absolute_paths = vec ! [ import. clone( ) ] ;
109
+ absolute_paths. push ( import. clone ( ) ) ;
106
110
stack. push ( current. import ( import, path. offset ) ) ;
107
111
} else if !* optional {
108
112
return Err ( Error :: MissingImportFile { path : * path } ) ;
@@ -312,6 +316,33 @@ recipe_b: recipe_c
312
316
) ;
313
317
}
314
318
319
+ #[ test]
320
+ fn glob_imports ( ) {
321
+ let justfile_top = r#"
322
+ import "./subdir/*.just"
323
+ "# ;
324
+ let justfile_a = r#"
325
+ a:
326
+ "# ;
327
+ let justfile_b = r#"
328
+ b:
329
+ "# ;
330
+ let unused_justfile = r#"
331
+ x:
332
+ "# ;
333
+ let tmp = temptree ! {
334
+ justfile: justfile_top,
335
+ subdir: {
336
+ "a.just" : justfile_a,
337
+ "b.just" : justfile_b,
338
+ unusued: unused_justfile,
339
+ }
340
+ } ;
341
+ let loader = Loader :: new ( ) ;
342
+ let justfile_path = tmp. path ( ) . join ( "justfile" ) ;
343
+ let _compilation = Compiler :: compile ( & loader, & justfile_path) . unwrap ( ) ;
344
+ }
345
+
315
346
#[ test]
316
347
fn find_module_file ( ) {
317
348
#[ track_caller]
0 commit comments