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.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.rsdiffbeforeafterboth--- 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, "<default (ignoring jpath)>")
+ }
+}
+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:
///