From 5527a27f7bafde3e2e425a9e53b0882a55b000d4 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 30 Nov 2024 16:54:03 -0500 Subject: [PATCH] prepare c_library meta-program a bit --- gen_c_library/c_library.cpp | 45 +++++++++++++++++++++++++++++++++++++ scripts/build.ci.ps1 | 12 ++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/gen_c_library/c_library.cpp b/gen_c_library/c_library.cpp index 5ced522..adbe936 100644 --- a/gen_c_library/c_library.cpp +++ b/gen_c_library/c_library.cpp @@ -18,4 +18,49 @@ GEN_NS_END using namespace gen; +void format_file( char const* path ) +{ + String resolved_path = String::make(GlobalAllocator, to_str(path)); + String style_arg = String::make(GlobalAllocator, txt("-style=file:")); + style_arg.append("../scripts/.clang-format "); + + // Need to execute clang format on the generated file to get it to match the original. + #define clang_format "clang-format " + #define cf_format_inplace "-i " + #define cf_verbose "-verbose " + String command = String::make( GlobalAllocator, clang_format ); + command.append( cf_format_inplace ); + command.append( cf_verbose ); + command.append( style_arg ); + command.append( resolved_path ); + log_fmt("\tRunning clang-format on file:\n"); + system( command ); + log_fmt("\tclang-format finished reformatting.\n"); + #undef cf_cmd + #undef cf_format_inplace + #undef cf_style + #undef cf_verbse +} + +Code dump_to_scratch_and_retireve( Code code ) +{ + Builder ecode_file_temp = Builder::open("gen/scratch.hpp"); + ecode_file_temp.print(code); + ecode_file_temp.write(); + format_file("gen/scratch.hpp"); + Code result = scan_file( "gen/scratch.hpp" ); + remove("gen/scratch.hpp"); + return result; +} + +int gen_main() +{ +#define project_dir "../project/" + gen::init(); + + + gen::deinit(); + return 0; +#undef project_dir +} diff --git a/scripts/build.ci.ps1 b/scripts/build.ci.ps1 index 4f0f970..877d522 100644 --- a/scripts/build.ci.ps1 +++ b/scripts/build.ci.ps1 @@ -44,6 +44,7 @@ Push-Location $path_root $verbose = $false [bool] $bootstrap = $false [bool] $singleheader = $false +[bool] $c_library = $false [bool] $unreal = $false [bool] $test = $false @@ -59,6 +60,7 @@ if ( $args ) { $args | ForEach-Object { "debug" { $release = $false } "bootstrap" { $bootstrap = $true } "singleheader" { $singleheader = $true } + "c_library" { $c_library = $true } "unreal" { $unreal = $true } "test" { $test = $true } } @@ -103,8 +105,9 @@ write-host "Build Type: $(if ($release) {"Release"} else {"Debug"} )" $path_build = Join-Path $path_root build $path_project = Join-Path $path_root project $path_scripts = Join-Path $path_root scripts -$path_singleheader = Join-Path $path_root singleheader -$path_unreal = Join-Path $path_root unreal_engine +$path_c_library = join-Path $path_root gen_c_library +$path_singleheader = Join-Path $path_root gen_singleheader +$path_unreal = Join-Path $path_root gen_unreal_engine $path_test = Join-Path $path_root test if ( $bootstrap ) @@ -187,6 +190,11 @@ if ( $singleheader ) Pop-Location } +if ( $c_library ) +{ + +} + if ( $unreal ) { $path_build = join-path $path_unreal build