Skip to content

Commit

Permalink
Support multiple FilesystemIo's in IoSetup
Browse files Browse the repository at this point in the history
  • Loading branch information
ralismark committed Apr 24, 2021
1 parent 1f63089 commit d2e3269
Show file tree
Hide file tree
Showing 2 changed files with 34 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 handle OutputDestination::Default?
if let OutputDestination::Path(ref p) = self.output_dest {
io.include_path(p.clone());
}

let output_path = match self.output_dest {
OutputDestination::Default => Some(default_output_path),
OutputDestination::Path(p) => Some(p),
Expand Down
37 changes: 29 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>,
include_paths: Vec<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(),
include_paths: Vec::new(),
}
}
}
Expand Down Expand Up @@ -212,6 +216,12 @@ impl IoSetupBuilder {
self
}

/// Add a directory to read files from
pub fn include_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.include_paths.push(path.as_ref().to_owned());
self
}

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

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

for include_path in self.include_paths {
filesystems.push(FilesystemIo::new(
&include_path,
false,
false,
self.hidden_input_paths.clone(),
));
}

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 d2e3269

Please sign in to comment.