Skip to content

Commit

Permalink
fix: activate dmon by default on all supported platforms
Browse files Browse the repository at this point in the history
removes the need for the cli option --dmon
  • Loading branch information
jaromil committed Dec 9, 2024
1 parent ca487ef commit a06a28b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
1 change: 1 addition & 0 deletions build/win-wsl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ deps:
@bash build/embed-headers.sh win
@sed -i 's/unsigned char/const char/' src/embed-headers.c
@sed -i 's/unsigned int/const unsigned int/' src/embed-headers.c
@bash build/embed-dmon.sh

.c.o:
$(cc) \
Expand Down
38 changes: 17 additions & 21 deletions src/cjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ const char cli_help[] =
" -e fun\t entry point function (default 'main')\n"
" -p pid\t write pid of executed program to file\n"
" --live\t run interactive editor for live coding\n"
" --tgen\t create the runtime temporary dir and exit\n"
" --dmon\t activate the filesystem monitoring extension\n";
" --tgen\t create the runtime temporary dir and exit\n";

int main(int argc, char **argv) {
TCCState *TCC = NULL;
Expand Down Expand Up @@ -120,7 +119,6 @@ int main(int argc, char **argv) {
{ "help", ko_no_argument, 100 },
{ "live", ko_no_argument, 301 },
{ "tgen", ko_no_argument, 401 },
{ "dmon", ko_no_argument, 501 },
{ NULL, 0, 0 }
};
ketopt_t opt = KETOPT_INIT;
Expand Down Expand Up @@ -196,8 +194,6 @@ int main(int argc, char **argv) {
if(!quiet)_err("Live mode activated");
live_mode = true;
#endif
} else if (c == 501) {
CJIT.dmon = true;
} else if (c == 401) {
#ifndef LIBC_MINGW32
posix_mkdtemp(&CJIT);
Expand All @@ -217,6 +213,22 @@ int main(int argc, char **argv) {
}
if(!quiet)_err("CJIT %s by Dyne.org",VERSION);

// DMON is activated on all supported platforms by default
CJIT.dmon = true;
tcc_define_symbol(TCC,"DMON_IMPL",NULL);
#if defined(CJIT_BUILD_LINUX)
tcc_define_symbol(TCC,"DMON_OS_LINUX",NULL);
// TODO: test dmon on OSX (missing library frameworks)
// #elif defined(CJIT_BUILD_OSX)
// tcc_define_symbol(TCC,"DMON_OS_MACOS",NULL);
#elif defined(CJIT_BUILD_WIN)
tcc_define_symbol(TCC,"DMON_OS_WINDOWS",NULL);
#else
tcc_undefine_symbol(TCC,"DMON_OS");
tcc_undefine_symbol(TCC,"DMON_IMPL");
CJIT.dmon = false;
#endif

//////////////////////////////////////
// initialize the tmpdir for execution
// from here onwards use goto endgame
Expand Down Expand Up @@ -251,22 +263,6 @@ int main(int argc, char **argv) {
tcc_add_libc_symbols(TCC);
#endif

if(CJIT.dmon) {
_err("Activated DMON extension for filesystem monitoring");
tcc_define_symbol(TCC,"DMON_IMPL",NULL);
#if defined(CJIT_BUILD_LINUX)
tcc_define_symbol(TCC,"DMON_OS_LINUX",NULL);

#elif defined(CJIT_BUILD_OSX)
tcc_define_symbol(TCC,"DMON_OS_MACOS",NULL);
#elif defined(CJIT_BUILD_WIN)
tcc_define_symbol(TCC,"DMON_OS_WINDOWS",NULL);
#else
_err("Unsupported platform for DMON extension");
tcc_undefine_symbol(TCC,"DMON_OS");
#endif
}

if (argc == 0 ) {
_err("No input file: live mode!");
live_mode = true;
Expand Down
1 change: 1 addition & 0 deletions src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ bool cjit_extensions_mkdtemp(CJITState *CJIT, const char *tmpdir) {
(char*)&lib_dmon_dmon_h,
lib_dmon_dmon_h_len)) return(false);
}
// setup the tmpdir path in CJIT
CJIT->tmpdir = malloc(strlen(tmpdir)+1);
strcpy(CJIT->tmpdir, tmpdir);
return(true);
Expand Down
2 changes: 1 addition & 1 deletion test/dmon.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ load bats_setup
sleep 2;
kill -HUP `cat ${TMP}/test_dmon.pid`) &

run ${CJIT} -p ${TMP}/test_dmon.pid --dmon ${T}/dmon.c -- ${TMP}
run ${CJIT} -p ${TMP}/test_dmon.pid ${T}/dmon.c -- ${TMP}
# assert_failure # TODO: cleaner way than kill -HUP
assert_line --regexp '^CREATE:.*dmon_test_create.txt$'
assert_line --regexp '^DELETE:.*dmon_test_create.txt$'
Expand Down

0 comments on commit a06a28b

Please sign in to comment.