File tree Expand file tree Collapse file tree 3 files changed +19
-12
lines changed
Expand file tree Collapse file tree 3 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -92,13 +92,15 @@ pub fn build(b: *std.Build) void {
9292 .root_source_file = b .path ("src/rewriter.zig" ),
9393 .target = target ,
9494 .optimize = optimize ,
95+ .strip = if (kcov != null ) false else null ,
96+ .single_threaded = true ,
9597 });
9698 rewriter .root_module .addImport ("zigpak" , core );
9799
98100 stepCheck .dependOn (& rewriter .step );
99101
100102 if (kcov ) | args | {
101- const COMPAT_RUN_CMD = "ZIGPAK_REWRITER=$1 KCOV=kcov KCOV_ARGS=\" --include-path=$2 $3\" KCOV_REPORT=$4 bun test" ;
103+ const COMPAT_RUN_CMD = "ZIGPAK_REWRITER=$1 KCOV=kcov KCOV_ARGS=\" --include-path=$2 --skip-solibs $3\" KCOV_REPORT=$4 bun test" ;
102104
103105 const kcovArgs = std .mem .join (
104106 b .allocator ,
@@ -136,7 +138,8 @@ pub fn build(b: *std.Build) void {
136138 run .addArg (includeArg );
137139 run .addArgs (args );
138140 run .addArtifactArg (tests );
139- run .enableTestRunnerMode ();
141+ // run.enableTestRunnerMode();
142+ // Kcov does not respect the test runner protocol
140143 stepTest .dependOn (& run .step );
141144 } else {
142145 const run = b .addRunArtifact (tests );
Original file line number Diff line number Diff line change @@ -2,15 +2,17 @@ import { afterAll } from "bun:test";
22import { mkdir , rm } from "node:fs/promises" ;
33
44export const KCOV = process . env [ "KCOV" ] ;
5- export const KCOV_ARGS = process . env [ "KCOV_ARGS" ] ?? "" ;
5+ export const KCOV_ARGS = ( process . env [ "KCOV_ARGS" ] ?? "" ) . split ( " " ) . filter ( x => x ) ;
66const KCOV_REPORT = process . env [ "KCOV_REPORT" ] ?? "./zig-out/cov" ;
77
88export const coverages = [ ] as string [ ] ;
99
1010if ( KCOV ) {
11+ console . debug ( KCOV , KCOV_ARGS , KCOV_REPORT )
12+
1113 afterAll ( async ( ) => {
1214 await mkdir ( KCOV_REPORT , { recursive : true } ) ;
13- await Bun . $ `${ KCOV } ${ KCOV_ARGS } --merge ${ KCOV_REPORT . split ( " " ) } ${ coverages } ` ;
15+ await Bun . $ `${ KCOV } ${ KCOV_ARGS } --merge ${ KCOV_REPORT } ${ coverages } ` ;
1416 await Promise . all ( coverages . map ( ( x ) => rm ( x , { recursive : true } ) ) ) ;
1517 } ) ;
1618}
Original file line number Diff line number Diff line change @@ -6,16 +6,18 @@ import { tmpdir } from "node:os";
66const REWRITER =
77 process . env [ "ZIGPAK_REWRITER" ] || "./zig-out/bin/zigpak-rewriter" ;
88
9- function runRewriter ( data : Uint8Array | ArrayBuffer | Buffer ) {
10- if ( KCOV ) {
11- const collectPath = mkdtempSync ( join ( tmpdir ( ) , "zigpak-" ) ) ;
12- coverages . push ( collectPath ) ;
13- return Bun . $ ` ${ KCOV } ${ KCOV_ARGS } --collect-only ${ collectPath } ${ REWRITER } < ${ data } ` ;
14- } else {
15- return Bun . $ ` ${ REWRITER } < ${ data } ` ;
16- }
9+ function runRewriterKcov ( data : Uint8Array | ArrayBuffer | Buffer ) {
10+ const collectPath = mkdtempSync ( join ( tmpdir ( ) , "zigpak-" ) ) ;
11+ coverages . push ( collectPath ) ;
12+ return Bun . $ ` ${ KCOV } ${ KCOV_ARGS } --collect-only ${ collectPath } ${ REWRITER } < ${ data } ` ;
13+ }
14+
15+ function runRewriterRegular ( data : Uint8Array | ArrayBuffer | Buffer ) {
16+ return Bun . $ ` ${ REWRITER } < ${ data } ` ;
1717}
1818
19+ const runRewriter = KCOV ? runRewriterKcov : runRewriterRegular ;
20+
1921export async function rewriter ( data : Uint8Array | ArrayBuffer | Buffer ) {
2022 const { stdout, stderr, exitCode } = await runRewriter ( data )
2123 . quiet ( )
You can’t perform that action at this time.
0 commit comments