From 54a585e751e77c2406005b04ababbd93f23eba7e Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 2 Sep 2025 16:44:15 +0200 Subject: assembler: Preserve the original working directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/assembler.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/xixanta/src/assembler.rs') diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index 37f9004..bdc2e9d 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -227,6 +227,10 @@ pub fn assemble_with_mapping( source: &SourceInfo, asan: bool, ) -> AssemblerResult { + // Save the original current working directory in case it changes after a + // directive like '.incbin' or '.include'. + let original_directory = std::env::current_dir().unwrap(); + let mut asm = Assembler::new(mapping); let mut memory = MemoryResult::default(); asm.asan_enabled = asan; @@ -317,6 +321,12 @@ pub fn assemble_with_mapping( } } + // Return back to the original directory for this session. This is important + // so after calling this function the environment is not completely borked, + // but it's not so important that in (the very unlikely) case that the call + // fails we have to bail out. + let _ = std::env::set_current_dir(original_directory); + // All set, fill the vector of bundles to be returned. match asm.fill() { Ok(bundles) => AssemblerResult { -- cgit v1.2.3