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 94fd369
Showing 1 changed file with 64 additions and 22 deletions.
86 changes: 64 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,44 @@ 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();
let imported_files: HashSet<&PathBuf> = compilation.srcs.keys().collect();
assert_eq!(
imported_files,
[
justfile_path,
tmp.path().join("subdir/a.just"),
tmp.path().join("subdir/b.just")
]
.iter()
.collect()
);
}

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

0 comments on commit 94fd369

Please sign in to comment.