kerep sources

This commit is contained in:
2023-07-12 13:53:20 +03:00
parent 683395983c
commit 44ee9e210f
88 changed files with 3051 additions and 98 deletions

View File

@@ -125,5 +125,5 @@ Maybe CompilationScenario_exec(CompilationScenario* sc){
return false;
}
);*/
return true;
return MaybeNull;
}

View File

@@ -1,4 +1,4 @@
#include "../kerep-headers/DtsodParser/DtsodV24.h"
#include "../kerep/src/DtsodParser/DtsodV24.h"
extern const char* os;
extern const char* arch;

View File

@@ -1,6 +1,6 @@
#include "../kerep-headers/base/base.h"
#include "../kerep-headers/Filesystem/filesystem.h"
#include "../kerep-headers/DtsodParser/DtsodV24.h"
#include "../kerep/src/base/base.h"
#include "../kerep/src/Filesystem/filesystem.h"
#include "../kerep/src/DtsodParser/DtsodV24.h"
#include "CompilationScenario.h"
#ifndef OS
@@ -15,9 +15,8 @@ const char* arch=ARCH;
const char* global_out_dir="bin";
const char* configuration="release";
const char* task="exe";
const char** projects=NULL;
u16 project_count = 0;
const char* project_dir_or_file="./";
Autoarr(Pointer)* tasks;
int erri(ErrorId err_code){
throw(err_code);
@@ -37,72 +36,66 @@ int main(const int argc, const char** argv){
kt_initKerepTypes();
kt_endInit();
if(cptr_equals(os, "UNDEFINED"))
throw("Operation system undefined. Recompile cbuild with flag -DOS=$(./detect_os.sh)");
if(cptr_equals(arch, "UNDEFINED"))
throw("CPU architecture undefined. Recompile cbuild with flag -DARCH=$(./detect_arch.sh)");
tasks = Autoarr_create(Pointer, 16, 32);
Autoarr(Pointer)* projects_ar = Autoarr_create(Pointer, 16, 32);
if(cptr_equals(os, "UNDEFINED"))
throw("Operation system undefined. Recompile cbuild with flag -DOS=\\\"$(./detect_os.sh)\\\"");
if(cptr_equals(arch, "UNDEFINED"))
throw("CPU architecture undefined. Recompile cbuild with flag -DARCH=\\\"$(./detect_arch.sh)\\\"");
for(int argi = 1; argi < argc; argi++){
const char* arg = argv[argi];
kprintf("arg: %s\n", arg);
if(argIs("-h") || argIs("--help") || argIs("/?"))
kprintf("Usage: cbuild [options] [projects files/dirs]\n"
if(argIs("-h") || argIs("--help") || argIs("/?")){
kprintf("Usage: cbuild [options] [tasks0 task1...]\n"
" Options:\n"
" -h, --help, /? Display this message.\n"
" -o, --out-dir Set global output directory (default=bin).\n"
" -c, --configuration Select project configuration (default=release).\n"
" -t, --task Select build task from project.\n");
" -p, --project Set project directory/file (default=./).\n");
return 0;
}
else if(argIs("-o") || argIs("--out-dir"))
global_out_dir = argNext();
else if(argIs("-c") || argIs("--configuration"))
configuration = argNext();
else if(argIs("-t") || argIs("--task"))
task = argNext();
else if(argIs("-p") || argIs("--project"))
project_dir_or_file = argNext();
else {
if(arg[0] == '-')
throw(cptr_concat("invalid argument: ", arg));
Autoarr_add(projects_ar, arg);
Autoarr_add(tasks, arg);
}
}
project_count = Autoarr_length(projects_ar);
projects = (const char**)Autoarr_toArray(projects_ar);
Autoarr_freeWithoutMembers(projects_ar, true);
if(project_count == 0){
projects = malloc(sizeof(char*));
projects[0] = projectFileFromDir(".");
}
const char* proj_file_path = NULL;
if(file_exists(project_dir_or_file))
proj_file_path = project_dir_or_file;
else if(dir_exists(project_dir_or_file))
proj_file_path = projectFileFromDir(project_dir_or_file);
else throw(cptr_concat("can't find a project at path '", project_dir_or_file, "'"));
tryLast(file_open(proj_file_path, FileOpenMode_Read), _m1, ;);
FileHandle proj_file = _m1.value.VoidPtr;
char* proj_file_text = NULL;
tryLast(file_readAll(proj_file, &proj_file_text), _m2, file_close(proj_file));
file_close(proj_file);
for(u16 i=0; i < project_count; i++){
const char* proj = projects[i];
const char* proj_file_path = NULL;
if(file_exists(proj))
proj_file_path = proj;
else if(dir_exists(proj))
proj_file_path = projectFileFromDir(proj);
tryLast(file_open(proj_file_path, FileOpenMode_Read), _m1, ;);
FileHandle proj_file = _m1.value.VoidPtr;
char* proj_file_text;
tryLast(file_readAll(proj_file, &proj_file_text), _m2, file_close(proj_file));
file_close(proj_file);
tryLast(DtsodV24_deserialize(proj_file_text), _m3, free(proj_file_text));
Hashtable* proj_dtsod = _m3.value.VoidPtr;
tryLast(DtsodV24_deserialize(proj_file_text), _m3, free(proj_file_text));
Hashtable* proj_dtsod = _m3.value.VoidPtr;
Autoarr_foreach(tasks, task,
CompilationScenario proj_sc;
CompilationScenario_construct(&proj_sc);
tryLast(CompilationScenario_applyProjectOptions(&proj_sc, proj_dtsod, configuration, task), _m4, free(proj_file_text))
if(!CompilationScenario_exec(&proj_sc))
throw("compilation error");
tryLast(CompilationScenario_applyProjectOptions(&proj_sc, proj_dtsod, configuration, task), _m4, )
tryLast(CompilationScenario_exec(&proj_sc), _m5, ;)
CompilationScenario_destruct(&proj_sc);
Hashtable_free(proj_dtsod);
free(proj_file_text);
}
)
#if DEBUG
Hashtable_free(proj_dtsod);
free(proj_file_text);
kt_free();
#endif
return 0;
}