Skip to content

Commit

Permalink
Require workingdir to be passed to runsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
ralismark committed Apr 24, 2021
1 parent d2e3269 commit 5b7b586
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
11 changes: 9 additions & 2 deletions crates/bridge_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,13 +923,15 @@ const SHELL: [&str; 2] = ["cmd.exe", "/c"];
///
/// # Safety
///
/// This function is unsafe because it dereferences raw pointers from C.
/// This function is unsafe because it dereferences raw pointers from C and accepts a raw C string.
#[no_mangle]
pub unsafe extern "C" fn ttbc_runsystem(
es: &mut CoreBridgeState,
cmd: *const u16,
len: libc::size_t,
working_dir: *const libc::c_char,
) -> libc::c_int {
let rworking_dir = CStr::from_ptr(working_dir).to_string_lossy();
let rcmd = slice::from_raw_parts(cmd, len);
let rcmd = match String::from_utf16(rcmd) {
Ok(cmd) => cmd,
Expand All @@ -939,7 +941,12 @@ pub unsafe extern "C" fn ttbc_runsystem(
}
};

match Command::new(SHELL[0]).arg(SHELL[1]).arg(&rcmd).status() {
match Command::new(SHELL[0])
.arg(SHELL[1])
.arg(&rcmd)
.current_dir(&*rworking_dir)
.status()
{
Ok(status) => match status.code() {
Some(0) => 0,
Some(n) => {
Expand Down
4 changes: 2 additions & 2 deletions crates/bridge_core/support/support.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ ttstub_get_file_md5(char const *path, char *digest)
}

int
ttstub_runsystem(const unsigned short *cmd, size_t len)
ttstub_runsystem(const unsigned short *cmd, size_t len, char const* working_dir)
{
return ttbc_runsystem(tectonic_global_bridge_core, cmd, len);
return ttbc_runsystem(tectonic_global_bridge_core, cmd, len, working_dir);
}
2 changes: 1 addition & 1 deletion crates/bridge_core/support/tectonic_bridge_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ int ttstub_input_close(rust_input_handle_t handle);

int ttstub_get_file_md5(char const *path, char *digest);

int ttstub_runsystem(const unsigned short *cmd, size_t len);
int ttstub_runsystem(const unsigned short *cmd, size_t len, char const* working_dir);

END_EXTERN_C

Expand Down
3 changes: 2 additions & 1 deletion crates/engine_xetex/xetex/xetex-shipout.c
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,8 @@ write_out(int32_t p)
// finish diagnostic here to emit it *before* command gets run
capture_to_diagnostic(NULL);

ttstub_runsystem(&str_pool[str_start[str_ptr - TOO_BIG_CHAR]], cur_length());
// TODO pass in correct working dir
ttstub_runsystem(&str_pool[str_start[str_ptr - TOO_BIG_CHAR]], cur_length(), ".");
}

print_nl_cstr("");
Expand Down

0 comments on commit 5b7b586

Please sign in to comment.