Added support for monolithic packages

Not sure if the base name for them, lets the user by specifying a .ODIN_MONOLITHIC_PACKAGE;
make compiler assume that all files in child directories are part of the same package (making a uniform prackage across subdirectoreis).
This commit is contained in:
2024-05-16 17:18:32 -04:00
parent 05577a2378
commit 427d2e0d83
2 changed files with 46 additions and 6 deletions
+7 -5
View File
@@ -12,6 +12,7 @@ using namespace gen;
#ifdef GEN_SYSTEM_WINDOWS
#include <process.h>
// #include <Windows.h>
#endif
#pragma region Directories
@@ -33,12 +34,13 @@ CodeBody parse_file( char const* path ) {
inline
void git_restore_file( char const* path )
{
#define git_restore "git restore "
String command = String::make( GlobalAllocator, git_restore );
#define git_restore_cmd "git restore "
String command = String::make( GlobalAllocator, git_restore_cmd );
command.append( path );
log_fmt("Running git restore on: %s\n", path);
log_fmt("Running git restore on: %s", path);
system(command);
#undef git_restore
#undef git_restore_cmd
Sleep(5);
}
inline
@@ -254,7 +256,7 @@ int gen_main()
// Note this doesn't account for an already swapped file. Make sure to discard changes or shut this path off if already generated.
if (1)
{
char const* path_parser = path_src "parser.cpp";
char const* path_parser = path_src "parser.hpp";
git_restore_file( path_parser );
CodeBody src_parser_header = parse_file( path_src "parser.hpp" );
CodeBody body = def_body( ECode::Global_Body );
+39 -1
View File
@@ -5433,6 +5433,43 @@ gb_internal void parser_add_foreign_file_to_process(Parser *p, AstPackage *pkg,
thread_pool_add_task(foreign_file_worker_proc, wd);
}
gb_internal ReadDirectoryError read_directory_recursive(String path, Array<FileInfo> *fi, String const &FILE_EXT) {
Array<FileInfo> sub_list = {};
ReadDirectoryError rd_err = read_directory(path, &sub_list);
defer(array_free(&sub_list));
if (rd_err != ReadDirectory_None) {
return rd_err;
}
String const FILE_EXT_MONLITHIC = str_lit(".ODIN_MONOLITHIC_PACKAGE");
String ext = path_extension(sub_list[0].name);
bool monolithic_specified = false;
if (ext == FILE_EXT_MONLITHIC) {
monolithic_specified = true;
}
for (FileInfo sub_fi : sub_list)
{
String ext = path_extension(sub_fi.name);
if (monolithic_specified && sub_fi.is_dir) {
rd_err = read_directory_recursive(sub_fi.fullpath, fi, FILE_EXT);
if (rd_err != ReadDirectory_None) {
return rd_err;
}
}
else
{
if (ext != FILE_EXT_MONLITHIC && (ext == FILE_EXT || ext == ".S" || ext == ".s")) {
if (fi->data == nullptr) {
array_init(fi, heap_allocator(), 0, 100);
}
array_add(fi, sub_fi);
}
}
}
return rd_err;
}
// NOTE(bill): Returns true if it's added
gb_internal AstPackage *try_add_import_path(Parser *p, String path, String const &rel_path, TokenPos pos, PackageKind kind = Package_Normal) {
@@ -5469,7 +5506,8 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String path, String const
Array<FileInfo> list = {};
ReadDirectoryError rd_err = read_directory(path, &list);
ReadDirectoryError rd_err;
rd_err = read_directory_recursive( path, &list, FILE_EXT );
defer (array_free(&list));
if (list.count == 1) {