diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-09-02 16:44:15 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-09-02 16:44:15 +0200 |
| commit | 54a585e751e77c2406005b04ababbd93f23eba7e (patch) | |
| tree | 85231e11754944d2259e6fc1a1e60e234610b829 /lib/xixanta | |
| parent | fd393833497aeaf0e9eb9d69509c1d04f7549201 (diff) | |
| download | tools.nes-54a585e751e77c2406005b04ababbd93f23eba7e.tar.gz tools.nes-54a585e751e77c2406005b04ababbd93f23eba7e.zip | |
assembler: Preserve the original working directory
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta')
| -rw-r--r-- | lib/xixanta/src/assembler.rs | 10 |
1 files changed, 10 insertions, 0 deletions
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 { |
