From 55a246ab85be02a158c0d1b8606286ef48d900e6 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Thu, 19 Sep 2024 01:37:55 -0700 Subject: [PATCH] Work --- src/compiler.rs | 75 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/src/compiler.rs b/src/compiler.rs index f39529727f..f1c20a6cda 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -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 }); @@ -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]