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"
|
#define RESET "\e[0m"
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
#include <pwd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool zeal_build;
|
bool zeal_build;
|
||||||
bool watch;
|
bool watch;
|
||||||
@ -38,9 +42,6 @@ void unixify_path(char *str) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: This is hardcoded, fix it.
|
|
||||||
char *python_interpreter_path = "/usr/local/bin/python3";
|
|
||||||
|
|
||||||
bool can_run_command(const char *cmd) {
|
bool can_run_command(const char *cmd) {
|
||||||
if(strchr(cmd, '/')) {
|
if(strchr(cmd, '/')) {
|
||||||
return access(cmd, X_OK)==0;
|
return access(cmd, X_OK)==0;
|
||||||
@ -424,6 +425,15 @@ bool file_exists(char const *path) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_dir(char const *path) {
|
||||||
|
DIR *dir = opendir(path);
|
||||||
|
if (dir) {
|
||||||
|
closedir(dir);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: Implement for Windows.
|
// FIXME: Implement for Windows.
|
||||||
bool makedir(char const *path) {
|
bool makedir(char const *path) {
|
||||||
struct stat st = {0};
|
struct stat st = {0};
|
||||||
@ -639,16 +649,11 @@ bool run_scripts(char const *path) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fpath[len-3] != 'p' || fpath[len-2] != 'y' || fpath[len-3] != '.')
|
//if (fpath[len-3] != 'p' || fpath[len-2] != 'y' || fpath[len-3] != '.')
|
||||||
continue;
|
// continue;
|
||||||
|
|
||||||
printf(" -> Running %s\n", entry->d_name);
|
printf(" -> Running %s\n", entry->d_name);
|
||||||
char *argv[] = {
|
system(text_format("python3 %s", fpath));
|
||||||
fpath,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
execve(python_interpreter_path, argv, NULL);
|
|
||||||
|
|
||||||
} while ((entry = readdir(dir)));
|
} while ((entry = readdir(dir)));
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
@ -722,7 +727,7 @@ int build_project(char *project_path, build_options options) {
|
|||||||
text_format("%s/scripts", project_path);
|
text_format("%s/scripts", project_path);
|
||||||
char *scripts_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char));
|
char *scripts_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char));
|
||||||
strcpy(scripts_dir, buffer_text_format);
|
strcpy(scripts_dir, buffer_text_format);
|
||||||
if (file_exists(scripts_dir)) {
|
if (is_dir(scripts_dir)) {
|
||||||
if (!run_scripts(scripts_dir)) {
|
if (!run_scripts(scripts_dir)) {
|
||||||
fputs(RED "Failed running script!\b" RESET, stderr);
|
fputs(RED "Failed running script!\b" RESET, stderr);
|
||||||
return 1;
|
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));
|
char *out_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char));
|
||||||
strcpy(out_dir, buffer_text_format);
|
strcpy(out_dir, buffer_text_format);
|
||||||
unixify_path(out_dir);
|
unixify_path(out_dir);
|
||||||
if (!file_exists(out_dir)) {
|
if (!is_dir(out_dir)) {
|
||||||
bool status = makedir(out_dir);
|
bool status = makedir(out_dir);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
fputs(RED "Error: Cannot build project: Cannot create output directory.\n" RESET, stderr);
|
fputs(RED "Error: Cannot build project: Cannot create output directory.\n" RESET, stderr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user