allow changing working directory for child processes#148
allow changing working directory for child processes#148ratchetfreak wants to merge 1 commit intotsoding:mainfrom
Conversation
| if (pwd) { | ||
| NOB_TODO("changing working directory not yet supported on linux") | ||
| } | ||
|
|
There was a problem hiding this comment.
I tested chdir on linux and it worked correctly.
I think you made a mistake in build_and_run_test that made it appear as if it did not work correctly.
| if (pwd) { | |
| NOB_TODO("changing working directory not yet supported on linux") | |
| } | |
| if (pwd) { | |
| if (chdir(pwd) < 0){ | |
| nob_log(NOB_ERROR, "Could not change directory for child process: %s", strerror(errno)); | |
| exit(1); | |
| } | |
| } |
| cmd_append(cmd, temp_sprintf("%s%s%s", BUILD_FOLDER, TESTS_FOLDER, test_name)); | ||
| if (!cmd_run(cmd, .pwd = test_cwd_path)) return false; |
There was a problem hiding this comment.
I think there is a mistake here.
Setting pwd to be test_cwd_path and then executing test_cwd_path/test_name doesn't make sense.
When pwd is test_cwd_path the relative path to the test would be ../test_name.
| cmd_append(cmd, temp_sprintf("%s%s%s", BUILD_FOLDER, TESTS_FOLDER, test_name)); | |
| if (!cmd_run(cmd, .pwd = test_cwd_path)) return false; | |
| cmd_append(cmd, temp_sprintf("../%s", test_name)); | |
| if (!cmd_run(cmd, .pwd = test_cwd_path)) return false; |
There was a problem hiding this comment.
the code I wrote worked for windows,
CreateProcess expects the relative program path to be relative to the current working directory, not the passed in working directory. At no point does CreateProcessA search the target working directory for the application binary.
chdir in the child process makes exec not search the parent working directory. This makes the behavior between the two platforms incompatible for relative binary names.
I defaulted to windows' behavior because that's what I use.
only windows is implemented yet
I thought that linux would let you do
chdirbeforeexecvpbut that means relative paths are no long relative to the current original directory.