--- a/cmds/jrsonnet/src/main.rs +++ b/cmds/jrsonnet/src/main.rs @@ -11,6 +11,7 @@ error::{Error as JrError, ErrorKind}, ResultExt, State, Val, }; +use jrsonnet_parser::{SourceDefaultIgnoreJpath, SourcePath}; #[cfg(feature = "mimalloc")] #[global_allocator] @@ -182,7 +183,7 @@ let input_str = std::str::from_utf8(&input)?; s.evaluate_snippet("".to_owned(), input_str)? } else { - s.import(input.as_str())? + s.import_from(&SourcePath::new(SourceDefaultIgnoreJpath), input.as_str())? }; let tla = opts.tla.tla_opts()?; --- a/crates/jrsonnet-evaluator/src/import.rs +++ b/crates/jrsonnet-evaluator/src/import.rs @@ -10,7 +10,9 @@ use fs::File; use jrsonnet_gcmodule::Acyclic; use jrsonnet_interner::IBytes; -use jrsonnet_parser::{IStr, SourceDirectory, SourceFifo, SourceFile, SourcePath}; +use jrsonnet_parser::{ + IStr, SourceDefaultIgnoreJpath, SourceDirectory, SourceFifo, SourceFile, SourcePath, +}; use crate::{ bail, @@ -183,6 +185,13 @@ o } else if let Some(d) = from.downcast_ref::() { d.path().to_owned() + } else if from.downcast_ref::().is_some() { + let mut direct = current_dir().map_err(|e| ImportIo(e.to_string()))?; + direct.push(path); + if let Some(direct) = check_path(&direct)? { + return Ok(direct); + } + bail!(ImportFileNotFound(from.clone(), path.to_owned())) } else if from.is_default() { current_dir().map_err(|e| ImportIo(e.to_string()))? } else { --- a/crates/jrsonnet-parser/src/lib.rs +++ b/crates/jrsonnet-parser/src/lib.rs @@ -12,7 +12,8 @@ mod unescape; pub use location::CodeLocation; pub use source::{ - Source, SourceDirectory, SourceFifo, SourceFile, SourcePath, SourcePathT, SourceVirtual, + Source, SourceDefaultIgnoreJpath, SourceDirectory, SourceFifo, SourceFile, SourcePath, + SourcePathT, SourceVirtual, }; pub struct ParserSettings { --- a/crates/jrsonnet-parser/src/source.rs +++ b/crates/jrsonnet-parser/src/source.rs @@ -134,6 +134,23 @@ any_ext_impl!(SourcePathT); } +#[derive(Acyclic, Hash, PartialEq, Eq, Debug)] +pub struct SourceDefaultIgnoreJpath; +impl Display for SourceDefaultIgnoreJpath { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "") + } +} +impl SourcePathT for SourceDefaultIgnoreJpath { + fn is_default(&self) -> bool { + true + } + fn path(&self) -> Option<&Path> { + None + } + any_ext_impl!(SourcePathT); +} + /// Represents path to the file on the disk /// Directories shouldn't be put here, as resolution for files differs from resolution for directories: ///