From 427d2e0d8356eb8e06eb07096fd07efaf50a3bf2 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Thu, 16 May 2024 17:18:32 -0400 Subject: [PATCH] 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). --- codegen/gen_src.cpp | 12 +++++++----- src/parser.cpp | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/codegen/gen_src.cpp b/codegen/gen_src.cpp index afff7ed17..7c4062bf9 100644 --- a/codegen/gen_src.cpp +++ b/codegen/gen_src.cpp @@ -12,6 +12,7 @@ using namespace gen; #ifdef GEN_SYSTEM_WINDOWS #include + // #include #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 ); diff --git a/src/parser.cpp b/src/parser.cpp index ddf4b29d9..32aa08b91 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -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 *fi, String const &FILE_EXT) { + Array 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 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) {