Skip to content

Commit

Permalink
Add FilesystemIo to read from output dir
Browse files Browse the repository at this point in the history
  • Loading branch information
ralismark committed Apr 23, 2021
1 parent 1f63089 commit c9efbd1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,11 @@ impl ProcessingSessionBuilder {
io.filesystem_root(fsr);
}

// TODO do we also need to OutputDestination::Default?
if let OutputDestination::Path(ref p) = self.output_dest {
io.output_directory(p.clone());
}

let output_path = match self.output_dest {
OutputDestination::Default => Some(default_output_path),
OutputDestination::Path(p) => Some(p),
Expand Down
39 changes: 31 additions & 8 deletions src/io/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct IoSetup {
primary_input: Box<dyn IoProvider>,
pub bundle: Option<Box<dyn Bundle>>,
pub mem: MemoryIo,
filesystem: FilesystemIo,
filesystems: Vec<FilesystemIo>,
pub format_cache: Option<FormatCache>,
genuine_stdout: Option<GenuineStdoutIo>,
format_primary: Option<BufferedPrimaryIo>,
Expand All @@ -48,7 +48,9 @@ impl IoSetup {

providers.push(&mut *self.primary_input);
providers.push(&mut self.mem);
providers.push(&mut self.filesystem);
for fs in self.filesystems.iter_mut() {
providers.push(fs);
}

if let Some(ref mut b) = self.bundle {
providers.push(b.as_ioprovider_mut());
Expand Down Expand Up @@ -123,6 +125,7 @@ pub struct IoSetupBuilder {
bundle: Option<Box<dyn Bundle>>,
use_genuine_stdout: bool,
hidden_input_paths: HashSet<PathBuf>,
output_directory: Option<PathBuf>,
}

impl Default for IoSetupBuilder {
Expand All @@ -134,6 +137,7 @@ impl Default for IoSetupBuilder {
bundle: None,
use_genuine_stdout: false,
hidden_input_paths: HashSet::new(),
output_directory: None,
}
}
}
Expand Down Expand Up @@ -212,6 +216,12 @@ impl IoSetupBuilder {
self
}

/// Set the output directory.
pub fn output_directory<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.output_directory = Some(path.as_ref().to_owned());
self
}

/// Creates an `IoSetup`.
///
/// # Panics
Expand Down Expand Up @@ -240,15 +250,28 @@ impl IoSetupBuilder {
}
};

let mut filesystems = vec![FilesystemIo::new(
&self.filesystem_root,
false,
true,
self.hidden_input_paths.clone(),
)];

// We want to also allow reading from the output directory. This is to support e.g.
// shell-escape, which writes its outputs to this directory (rather than filesystem_root).
if let Some(output_directory) = self.output_directory.as_ref() {
filesystems.push(FilesystemIo::new(
output_directory,
false,
false,
self.hidden_input_paths,
));
}

Ok(IoSetup {
primary_input: pio,
mem: MemoryIo::new(true),
filesystem: FilesystemIo::new(
&self.filesystem_root,
false,
true,
self.hidden_input_paths,
),
filesystems,
format_cache,
bundle: self.bundle,
genuine_stdout: if self.use_genuine_stdout {
Expand Down

0 comments on commit c9efbd1

Please sign in to comment.