difftreelog
fix ignore jpath when resolving filename passed to jrsonnet
in: master
4 files changed
cmds/jrsonnet/src/main.rsdiffbeforeafterboth11 error::{Error as JrError, ErrorKind},11 error::{Error as JrError, ErrorKind},12 ResultExt, State, Val,12 ResultExt, State, Val,13};13};14use jrsonnet_parser::{SourceDefaultIgnoreJpath, SourcePath};141515#[cfg(feature = "mimalloc")]16#[cfg(feature = "mimalloc")]16#[global_allocator]17#[global_allocator]182 let input_str = std::str::from_utf8(&input)?;183 let input_str = std::str::from_utf8(&input)?;183 s.evaluate_snippet("<stdin>".to_owned(), input_str)?184 s.evaluate_snippet("<stdin>".to_owned(), input_str)?184 } else {185 } else {185 s.import(input.as_str())?186 s.import_from(&SourcePath::new(SourceDefaultIgnoreJpath), input.as_str())?186 };187 };187188188 let tla = opts.tla.tla_opts()?;189 let tla = opts.tla.tla_opts()?;crates/jrsonnet-evaluator/src/import.rsdiffbeforeafterboth11use jrsonnet_gcmodule::Acyclic;11use jrsonnet_gcmodule::Acyclic;12use jrsonnet_interner::IBytes;12use jrsonnet_interner::IBytes;13use jrsonnet_parser::{IStr, SourceDirectory, SourceFifo, SourceFile, SourcePath};13use jrsonnet_parser::{14 IStr, SourceDefaultIgnoreJpath, SourceDirectory, SourceFifo, SourceFile, SourcePath,15};141615use crate::{17use crate::{183 o185 o184 } else if let Some(d) = from.downcast_ref::<SourceDirectory>() {186 } else if let Some(d) = from.downcast_ref::<SourceDirectory>() {185 d.path().to_owned()187 d.path().to_owned()186 } else if from.is_default() {188 } else if from.downcast_ref::<SourceDefaultIgnoreJpath>().is_some() {189 let mut direct = current_dir().map_err(|e| ImportIo(e.to_string()))?;190 direct.push(path);191 if let Some(direct) = check_path(&direct)? {192 return Ok(direct);193 }194 bail!(ImportFileNotFound(from.clone(), path.to_owned()))195 } else if from.is_default() {187 current_dir().map_err(|e| ImportIo(e.to_string()))?196 current_dir().map_err(|e| ImportIo(e.to_string()))?188 } else {197 } else {189 unreachable!("resolver can't return this path")198 unreachable!("resolver can't return this path")crates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth12mod unescape;12mod unescape;13pub use location::CodeLocation;13pub use location::CodeLocation;14pub use source::{14pub use source::{15 Source, SourceDirectory, SourceFifo, SourceFile, SourcePath, SourcePathT, SourceVirtual,15 Source, SourceDefaultIgnoreJpath, SourceDirectory, SourceFifo, SourceFile, SourcePath,16 SourcePathT, SourceVirtual,16};17};1718crates/jrsonnet-parser/src/source.rsdiffbeforeafterboth134 any_ext_impl!(SourcePathT);134 any_ext_impl!(SourcePathT);135}135}136137#[derive(Acyclic, Hash, PartialEq, Eq, Debug)]138pub struct SourceDefaultIgnoreJpath;139impl Display for SourceDefaultIgnoreJpath {140 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {141 write!(f, "<default (ignoring jpath)>")142 }143}144impl SourcePathT for SourceDefaultIgnoreJpath {145 fn is_default(&self) -> bool {146 true147 }148 fn path(&self) -> Option<&Path> {149 None150 }151 any_ext_impl!(SourcePathT);152}136153137/// Represents path to the file on the disk154/// Represents path to the file on the disk138/// Directories shouldn't be put here, as resolution for files differs from resolution for directories:155/// Directories shouldn't be put here, as resolution for files differs from resolution for directories: