robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
e684a3dd18
master
1const std =@import ( "std" ); 2const gen =@import ( "gen/gen_steps.zig" ); 3 4pub fn lintSources ( 5b : * std . Build , 6nvim_sources : std . ArrayList ( gen . SourceItem ), 7nvim_headers : std . ArrayList ([] u8 ), 8) ! std . ArrayList ([] const u8 ) { 9var lint_sources : std . ArrayList ([] const u8 ) =try . initCapacity ( b . allocator , 0 ); 10for ( nvim_sources . items ) |source |{ 11try lint_sources . append ( b . allocator , b . fmt ( "src/nvim/ { s } " , .{ source . name })); 12} 13for ( nvim_headers . items ) |header |{ 14try lint_sources . append ( b . allocator , b . fmt ( "src/nvim/ { s } " , .{ header })); 15} 16try lint_sources . append ( b . allocator , "src/tee/tee.c" ); 17try lint_sources . append ( b . allocator , "src/xxd/xxd.c" ); 18return lint_sources ; 19} 20 21pub fn addSteps ( 22b : * std . Build , 23target : std . Build . ResolvedTarget , 24cdb_step : * std . Build . Step , 25nvim_exe_install : * std . Build . Step . InstallArtifact , 26nvim_sources : std . ArrayList ( gen . SourceItem ), 27nvim_headers : std . ArrayList ([] u8 ), 28ci_build : bool , 29) ! void { 30const lintc =b . step ( "lintc" , "Lint C source" ); 31var lint_sources =try lintSources ( b , nvim_sources , nvim_headers ); 32defer lint_sources . deinit ( b . allocator ); 33const lintc_uncrustify =addLintcUncrustifyStep ( b , lint_sources ); 34lintc . dependOn ( lintc_uncrustify ); 35const lintc_clint =addLintcClintStep ( b , nvim_exe_install , lint_sources , ci_build ); 36lintc . dependOn ( lintc_clint ); 37const lintc_clang_tidy =try addLintcClangtidyStep ( b , cdb_step , nvim_exe_install , target , lint_sources ); 38lintc . dependOn ( lintc_clang_tidy ); 39try addFormatcStep ( b , lint_sources ); 40} 41 42fn addLintcUncrustifyStep ( 43b : * std . Build , 44lint_sources : std . ArrayList ([] const u8 ), 45) * std . Build . Step { 46const lintc_uncrustify =b . step ( "lintc-uncrustify" , "Check formatting of C source with uncrustify" ); 47const uncrustify =b . dependency ( "uncrustify" , .{ 48. target =b . graph . host , 49. optimize =. ReleaseFast , 50}); 51const uncrustify_exe =uncrustify . artifact ( "uncrustify" ); 52for ( lint_sources . items ) |file |{ 53const run =b . addRunArtifact ( uncrustify_exe ); 54run . addArgs ( & .{ "-c" , "src/uncrustify.cfg" , "-q" , "--check" }); 55run . addFileArg ( b . path ( file )); 56run . expectExitCode ( 0 ); 57lintc_uncrustify . dependOn ( & run . step ); 58} 59return lintc_uncrustify ; 60} 61 62fn addLintcClangtidyStep ( 63b : * std . Build , 64cdb_step : * std . Build . Step , 65nvim_exe_install : * std . Build . Step . InstallArtifact , 66target : std . Build . ResolvedTarget , 67lint_sources : std . ArrayList ([] const u8 ), 68) ! * std . Build . Step { 69const lintc_clang_tidy =b . step ( "lintc-clang-tidy" , "Lint C source with clang-tidy" ); 70var exclusions : std . ArrayList ([] const u8 ) =try . initCapacity ( b . allocator , 0 ); 71defer exclusions . deinit ( b . allocator ); 72try exclusions . appendSlice ( b . allocator , & .{ 73"src/nvim/eval/typval_encode.c.h" , 74"src/nvim/api/ui_events.in.h" , 75"src/xxd/xxd.c" , 76}); 77if ( target . result . os . tag == . windows ) { 78try exclusions . appendSlice ( b . allocator , & .{ 79"src/nvim/os/pty_proc_unix.h" , 80"src/nvim/os/unix_defs.h" , 81}); 82} else { 83try exclusions . appendSlice ( b . allocator , & .{ 84"src/nvim/os/win_defs.h" , 85"src/nvim/os/pty_proc_win.h" , 86"src/nvim/os/pty_conpty_win.h" , 87"src/nvim/os/os_win_console.h" , 88}); 89} 90 91outer : for ( lint_sources . items ) |file |{ 92for ( exclusions . items ) |exclusion |{ 93if ( std . mem . eql ( u8 , exclusion , file )) continue : outer ; 94} 95const run =b . addSystemCommand ( & .{ "clang-tidy" }); 96run . step . dependOn ( cdb_step ); 97run . step . dependOn ( & nvim_exe_install . step ); 98run . addFileArg ( b . path ( file )); 99run . addArg ( "--quiet" ); 100run . expectStdOutEqual ( "" ); 101lintc_clang_tidy . dependOn ( & run . step ); 102} 103return lintc_clang_tidy ; 104} 105 106fn addLintcClintStep ( 107b : * std . Build , 108// use InstallArtifact instead of nvim_exe so that cache is not busted 109// for every file to be linted 110nvim_exe_install : * std . Build . Step . InstallArtifact , 111lint_sources : std . ArrayList ([] const u8 ), 112ci_build : bool , 113) * std . Build . Step { 114const lintc_clint =b . step ( "lintc-clint" , "Lint C source with clint" ); 115const exclusions =[ _ ][] const u8 { "src/nvim/tui/terminfo_defs.h" , "src/xxd/xxd.c" }; 116const nvim_path =b . getInstallPath (. bin , nvim_exe_install . artifact . out_filename ); 117 118outer : for ( lint_sources . items ) |file |{ 119for ( exclusions ) |exclusion |{ 120if ( std . mem . endsWith ( u8 , file , exclusion )) continue : outer ; 121} 122const run =b . addSystemCommand ( & .{ nvim_path }); 123run . step . dependOn ( & nvim_exe_install . step ); 124run . addArgs ( & .{ "-u" , "NONE" , "-l" }); 125run . addFileArg ( b . path ( "src/clint.lua" )); 126if ( ci_build ) { 127run . addArg ( "--output=gh_action" ); 128} else { 129run . addArg ( "--output=vs7" ); 130} 131run . addFileArg ( b . path ( file )); 132run . expectStdOutEqual ( "" ); 133lintc_clint . dependOn ( & run . step ); 134} 135return lintc_clint ; 136} 137 138fn addFormatcStep ( 139b : * std . Build , 140lint_sources : std . ArrayList ([] const u8 ), 141) ! void { 142const formatc =b . step ( "formatc" , "Format C source with uncrustify" ); 143const uncrustify =b . dependency ( "uncrustify" , .{ 144. target =b . graph . host , 145. optimize =. ReleaseFast , 146}); 147const uncrustify_exe =uncrustify . artifact ( "uncrustify" ); 148 149const update =b . addUpdateSourceFiles (); 150for ( lint_sources . items ) |file |{ 151const run =b . addRunArtifact ( uncrustify_exe ); 152run . addArgs ( & .{ "-c" , "src/uncrustify.cfg" , "-f" }); 153run . addFileArg ( b . path ( file )); 154run . addArg ( "-o" ); 155const output_name =try std . mem . replaceOwned ( u8 , b . allocator , file , "/" , "-" ); 156const output =run . addOutputFileArg ( output_name ); 157update . addCopyFileToSource ( output , file ); 158} 159formatc . dependOn ( & update . step ); 160}