difftreelog
fix ignore jpath when resolving filename passed to jrsonnet
in: master
4 files changed
cmds/jrsonnet/src/main.rsdiffbeforeafterboth--- 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("<stdin>".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()?;
crates/jrsonnet-evaluator/src/import.rsdiffbeforeafterboth--- 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::<SourceDirectory>() {
d.path().to_owned()
+ } else if from.downcast_ref::<SourceDefaultIgnoreJpath>().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 {
crates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth--- 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 {
crates/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: