From cfe452374a250005e41ea42a335c1bc4bd9859da Mon Sep 17 00:00:00 2001 From: xSlendiX Date: Sat, 3 Jun 2023 04:25:04 +0300 Subject: [PATCH] Fix scripts not running. Signed-off-by: xSlendiX --- main.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/main.c b/main.c index 2ba8488..382c057 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,10 @@ #define RESET "\e[0m" +#ifdef __linux__ +#include +#endif + typedef struct { bool zeal_build; bool watch; @@ -38,9 +42,6 @@ void unixify_path(char *str) { #endif } -// FIXME: This is hardcoded, fix it. -char *python_interpreter_path = "/usr/local/bin/python3"; - bool can_run_command(const char *cmd) { if(strchr(cmd, '/')) { return access(cmd, X_OK)==0; @@ -424,6 +425,15 @@ bool file_exists(char const *path) { #endif } +bool is_dir(char const *path) { + DIR *dir = opendir(path); + if (dir) { + closedir(dir); + return true; + } + return false; +} + // FIXME: Implement for Windows. bool makedir(char const *path) { struct stat st = {0}; @@ -639,16 +649,11 @@ bool run_scripts(char const *path) { continue; } - if (fpath[len-3] != 'p' || fpath[len-2] != 'y' || fpath[len-3] != '.') - continue; + //if (fpath[len-3] != 'p' || fpath[len-2] != 'y' || fpath[len-3] != '.') + // continue; printf(" -> Running %s\n", entry->d_name); - char *argv[] = { - fpath, - NULL - }; - - execve(python_interpreter_path, argv, NULL); + system(text_format("python3 %s", fpath)); } while ((entry = readdir(dir))); closedir(dir); @@ -722,7 +727,7 @@ int build_project(char *project_path, build_options options) { text_format("%s/scripts", project_path); char *scripts_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char)); strcpy(scripts_dir, buffer_text_format); - if (file_exists(scripts_dir)) { + if (is_dir(scripts_dir)) { if (!run_scripts(scripts_dir)) { fputs(RED "Failed running script!\b" RESET, stderr); return 1; @@ -740,7 +745,7 @@ int build_project(char *project_path, build_options options) { char *out_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char)); strcpy(out_dir, buffer_text_format); unixify_path(out_dir); - if (!file_exists(out_dir)) { + if (!is_dir(out_dir)) { bool status = makedir(out_dir); if (!status) { fputs(RED "Error: Cannot build project: Cannot create output directory.\n" RESET, stderr);