Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using nob.h to check if nob executable need rebuild #13

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions nob.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ bool build_and_run_test(Cmd *cmd, const char *test_name)
int main(int argc, char **argv)
{
NOB_GO_REBUILD_URSELF(argc, argv);

const char *nob_header = nob_header_path();
if(nob_file_exists(nob_header) != 1)
nob_log(NOB_ERROR, "nob.h not found at '%s'", nob_header);
else
nob_log(NOB_INFO, "nob.h found at '%s'", nob_header);

Cmd cmd = {0};

Expand Down
8 changes: 7 additions & 1 deletion nob.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ bool nob_set_current_dir(const char *path);
void nob__go_rebuild_urself(const char *source_path, int argc, char **argv);
#define NOB_GO_REBUILD_URSELF(argc, argv) nob__go_rebuild_urself(__FILE__, argc, argv)

const char *nob_header_path(void);

typedef struct {
size_t count;
const char *data;
Expand Down Expand Up @@ -565,6 +567,8 @@ char *nob_win32_error_message(DWORD err);
// Any messages with the level below nob_minimal_log_level are going to be suppressed.
Nob_Log_Level nob_minimal_log_level = NOB_INFO;

const char *nob_header_path(void) {return __FILE__;}

#ifdef _WIN32

// Base on https://stackoverflow.com/a/75644008
Expand Down Expand Up @@ -617,7 +621,9 @@ void nob__go_rebuild_urself(const char *source_path, int argc, char **argv)
}
#endif

int rebuild_is_needed = nob_needs_rebuild1(binary_path, source_path);
const char* inputs[] = {source_path, nob_header_path()};
int rebuild_is_needed = nob_needs_rebuild(binary_path, inputs, NOB_ARRAY_LEN(inputs));
// int rebuild_is_needed = nob_needs_rebuild1(binary_path, source_path);
if (rebuild_is_needed < 0) exit(1); // error
if (!rebuild_is_needed) return; // no rebuild is needed

Expand Down