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
--- 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 {
modifiedcrates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth
12mod 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};
1718
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:
 ///