[go: up one dir, main page]

Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
(#35) Pass command line args to second phase of GO_REBUILD_URSELF
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed Jul 14, 2021
1 parent 74150e5 commit a1a74d4
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions nobuild.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,24 @@ void chain_echo(Chain chain);
#endif

// NOTE: The implementation idea is stolen from https://github.com/zhiayang/nabs
#define GO_REBUILD_URSELF(argc, argv) \
do { \
const char *source_path = __FILE__; \
assert(argc >= 1); \
const char *binary_path = argv[0]; \
\
if (is_path1_modified_after_path2(source_path, binary_path)) { \
RENAME(binary_path, CONCAT(binary_path, ".old")); \
REBUILD_URSELF(binary_path, source_path); \
CMD(binary_path); \
exit(0); \
} \
#define GO_REBUILD_URSELF(argc, argv) \
do { \
const char *source_path = __FILE__; \
assert(argc >= 1); \
const char *binary_path = argv[0]; \
\
if (is_path1_modified_after_path2(source_path, binary_path)) { \
RENAME(binary_path, CONCAT(binary_path, ".old")); \
REBUILD_URSELF(binary_path, source_path); \
Cmd cmd = { \
.line = { \
.elems = (Cstr*) argv, \
.count = argc, \
}, \
}; \
cmd_run_sync(cmd); \
exit(0); \
} \
} while(0)

void rebuild_urself(const char *binary_path, const char *source_path);
Expand Down

0 comments on commit a1a74d4

Please sign in to comment.