Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* eol=lf
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
nob
nob.old
nob.exe
build/
build/
**/*.obj
30 changes: 28 additions & 2 deletions nob.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@
#ifndef NOB_H_
#define NOB_H_
#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS (1)
# ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS (1)
# endif
#endif

#ifndef NOBDEF
Expand Down Expand Up @@ -858,12 +860,36 @@ NOBDEF void nob__go_rebuild_urself(int argc, char **argv, const char *source_pat
// TODO: this is an experimental behavior behind a compilation flag.
// Once it is confirmed that it does not cause much problems on both POSIX and Windows
// we may turn it on by default.
# ifdef _WIN32
nob_log(NOB_INFO, "Defer deleting of %s...", old_binary_path);
# else
nob_delete_file(old_binary_path);
# endif
#endif // NOB_EXPERIMENTAL_DELETE_OLD

nob_cmd_append(&cmd, binary_path);
nob_da_append_many(&cmd, argv, argc);
if (!nob_cmd_run_opt(&cmd, opt)) exit(1);

#if defined(NOB_EXPERIMENTAL_DELETE_OLD) && defined(_WIN32)
// Workaround to delete the old nob from a script instead, only after we exit this process.
// If we don't do this, Windows will complain with "Access is denied" error, since
// the current process is still being executed from the old nob executable.
Nob_String_Builder sb = {0};
nob_sb_appendf(&sb, "$Attempts = 0; While ($Attempts++ -Lt 10) {\n");
nob_sb_appendf(&sb, " Remove-Item -Path \"%s\" -ErrorAction SilentlyContinue\n", old_binary_path);
nob_sb_appendf(&sb, " If (Test-Path -Path \"%s\") { Start-Sleep -Milliseconds 100 }\n", old_binary_path);
nob_sb_appendf(&sb, "}");
nob_sb_append_null(&sb);
Nob_Procs procs = {0};
opt.async = &procs;
// WARN: Running a PowerShell script like this might trigger anti-virus software
// to think we are trying to run malicious code.
nob_cmd_append(&cmd, "PowerShell", "-Command", sb.items);
if (!nob_cmd_run_opt(&cmd, opt)) exit(1);
nob_sb_free(sb);
#endif // NOB_EXPERIMENTAL_DELETE_OLD

exit(0);
}

Expand Down Expand Up @@ -1860,7 +1886,7 @@ NOBDEF bool nob_rename(const char *old_path, const char *new_path)
{
nob_log(NOB_INFO, "renaming %s -> %s", old_path, new_path);
#ifdef _WIN32
if (!MoveFileEx(old_path, new_path, MOVEFILE_REPLACE_EXISTING)) {
if (!MoveFileEx(old_path, new_path, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)) {
nob_log(NOB_ERROR, "could not rename %s to %s: %s", old_path, new_path, nob_win32_error_message(GetLastError()));
return false;
}
Expand Down