Skip to content

Commit 94fd369

Browse files
committed
Work
1 parent 592228b commit 94fd369

File tree

1 file changed

+64
-22
lines changed

1 file changed

+64
-22
lines changed

src/compiler.rs

+64-22
Original file line numberDiff line numberDiff line change
@@ -68,41 +68,45 @@ impl Compiler {
6868
optional,
6969
path,
7070
} => {
71-
let import_base = current
71+
let import = current
7272
.path
7373
.parent()
7474
.unwrap()
7575
.join(Self::expand_tilde(&relative.cooked)?)
7676
.lexiclean();
7777

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+
}
90101
}
91-
92-
}
93-
94-
95-
96-
97-
if import.is_file() {
102+
} else if import.is_file() {
98103
if current.file_path.contains(&import) {
99104
return Err(Error::CircularImport {
100105
current: current.path,
101106
import,
102107
});
103108
}
104-
//*absolute = Some(import.clone());
105-
*absolute_paths = vec![import.clone()];
109+
absolute_paths.push(import.clone());
106110
stack.push(current.import(import, path.offset));
107111
} else if !*optional {
108112
return Err(Error::MissingImportFile { path: *path });
@@ -312,6 +316,44 @@ recipe_b: recipe_c
312316
);
313317
}
314318

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+
let imported_files: HashSet<&PathBuf> = compilation.srcs.keys().collect();
345+
assert_eq!(
346+
imported_files,
347+
[
348+
justfile_path,
349+
tmp.path().join("subdir/a.just"),
350+
tmp.path().join("subdir/b.just")
351+
]
352+
.iter()
353+
.collect()
354+
);
355+
}
356+
315357
#[test]
316358
fn find_module_file() {
317359
#[track_caller]

0 commit comments

Comments
 (0)