Fix scripts not running.
Signed-off-by: xSlendiX <slendi@socopon.com>
This commit is contained in:
parent
1628da0e96
commit
cfe452374a
31
main.c
31
main.c
@ -22,6 +22,10 @@
|
||||
|
||||
#define RESET "\e[0m"
|
||||
|
||||
#ifdef __linux__
|
||||
#include <pwd.h>
|
||||
#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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user