git.delta.rocks / jrsonnet / refs/commits / 5585b94101d8

difftreelog

fix ignore jpath when resolving filename passed to jrsonnet

rqvyxstzYaroslav Bolyukin2026-02-08parent: #772afa0.patch.diff
in: master

4 files changed

modifiedcmds/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()?;
modifiedcrates/jrsonnet-evaluator/src/import.rsdiffbeforeafterboth
11use 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};
1416
15use crate::{17use crate::{
183 o185 o
184 } 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")
modifiedcrates/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 {
modifiedcrates/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:
 ///