Skip to content

Commit

Permalink
Work
Browse files Browse the repository at this point in the history
  • Loading branch information
neunenak committed Sep 19, 2024
1 parent 592228b commit 55a246a
Showing 1 changed file with 53 additions and 22 deletions.
75 changes: 53 additions & 22 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,41 +68,45 @@ impl Compiler {
optional,
path,
} => {
let import_base = current
let import = current
.path
.parent()
.unwrap()
.join(Self::expand_tilde(&relative.cooked)?)
.lexiclean();

println!("IMPORT: {}", import.display());

let glob_options = glob::MatchOptions {
case_sensitive: true,
require_literal_separator: false,
require_literal_leading_dot: false,
};

let import_paths = glob::glob_with(&import_base.display().to_string(), glob_options);
for import in import_paths {
if import.is_file() {

let import_base_str = import.to_string_lossy();
let has_glob = import_base_str.find('*').is_some();

if has_glob {
let glob_options = glob::MatchOptions {
case_sensitive: true,
require_literal_separator: false,
require_literal_leading_dot: false,
};
let import_paths = glob::glob_with(&import_base_str, glob_options).unwrap();
for import in import_paths {
let import = import.unwrap();

if import.is_file() {
if current.file_path.contains(&import) {
return Err(Error::CircularImport {
current: current.path,
import,
});
}
absolute_paths.push(import.clone());
stack.push(current.import(import, path.offset));
}
}

}




if import.is_file() {
} else if import.is_file() {
if current.file_path.contains(&import) {
return Err(Error::CircularImport {
current: current.path,
import,
});
}
//*absolute = Some(import.clone());
*absolute_paths = vec![import.clone()];
absolute_paths.push(import.clone());
stack.push(current.import(import, path.offset));
} else if !*optional {
return Err(Error::MissingImportFile { path: *path });
Expand Down Expand Up @@ -312,6 +316,33 @@ recipe_b: recipe_c
);
}

#[test]
fn glob_imports() {
let justfile_top = r#"
import "./subdir/*.just"
"#;
let justfile_a = r#"
a:
"#;
let justfile_b = r#"
b:
"#;
let unused_justfile = r#"
x:
"#;
let tmp = temptree! {
justfile: justfile_top,
subdir: {
"a.just": justfile_a,
"b.just": justfile_b,
unusued: unused_justfile,
}
};
let loader = Loader::new();
let justfile_path = tmp.path().join("justfile");
let _compilation = Compiler::compile(&loader, &justfile_path).unwrap();
}

#[test]
fn find_module_file() {
#[track_caller]
Expand Down

0 comments on commit 55a246a

Please sign in to comment.