Skip to content

Commit

Permalink
[fud2] Generate intermediate files in workdir. (#2205)
Browse files Browse the repository at this point in the history
Fix a regression where intermediate files were not generated in workdir.
  • Loading branch information
jku20 authored Jul 12, 2024
1 parent 93303f4 commit b7ccc79
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions fud2/fud-core/src/exec/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ impl Driver {
/// Generate a filename with an extension appropriate for the given State, `state_ref` relative
/// to `workdir`.
///
/// If `user_visible`, then the path should not be in the working directory because the user
/// should see the generated file (or provides the file).
///
/// If `used` is false, the state is neither an output to the user, or used as input an op. In
/// this case, the filename associated with the state will be prefixed by `_unused_`.
fn gen_name(
&self,
state_ref: StateRef,
used: bool,
user_visible: bool,
workdir: &Utf8PathBuf,
) -> IO {
let state = &self.states[state_ref];
Expand All @@ -39,14 +43,21 @@ impl Driver {
""
};

// Only make the path relative, i.e. not in the workdir if the file should be user visible.
let post_process = if user_visible {
utils::relative_path
} else {
|x: &Utf8Path, _y: &Utf8Path| x.to_path_buf()
};

IO::File(if state.is_pseudo() {
utils::relative_path(
post_process(
&Utf8PathBuf::from(format!("{}pseudo_{}", prefix, state.name)),
workdir,
)
} else {
// TODO avoid collisions in case of reused extensions...
utils::relative_path(
post_process(
&Utf8PathBuf::from(format!("{}{}", prefix, state.name))
.with_extension(extension),
workdir,
Expand Down Expand Up @@ -79,17 +90,24 @@ impl Driver {
""
};

// If the state is found in `states` the user should see this file. Amoung other things,
// this means it should be in their directory and not the working directory.
let user_visible = states.contains(&state_ref);

if let Some(idx) = states.iter().position(|&s| s == state_ref) {
if let Some(filename) = files.get(idx) {
IO::File(utils::relative_path(&filename.clone(), workdir))
if user_visible {
IO::File(utils::relative_path(&filename.clone(), workdir))
} else {
IO::File(filename.clone())
}
} else {
IO::StdIO(utils::relative_path(
&Utf8PathBuf::from(stdio_name).with_extension(extension),
workdir,
))
IO::StdIO(
Utf8PathBuf::from(stdio_name).with_extension(extension),
)
}
} else {
self.gen_name(state_ref, used, workdir)
self.gen_name(state_ref, used, user_visible, workdir)
}
}

Expand Down Expand Up @@ -132,6 +150,7 @@ impl Driver {
} else {
format!("_to_stdout_{}", self.states[state].name)
};

self.gen_name_or_use_given(
state,
req_states,
Expand Down

0 comments on commit b7ccc79

Please sign in to comment.