Skip to content

Commit 8af7a6d

Browse files
committed
Add coverage to nix matrix
1 parent 23190e2 commit 8af7a6d

File tree

4 files changed

+84
-10
lines changed

4 files changed

+84
-10
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ jobs:
176176
with:
177177
file: coverage.info
178178
token: ${{ secrets.CODECOV_TOKEN }}
179-
slug: jbboehr/php-perf
179+
slug: jbboehr/php-perfifidous
180180

181181
- name: Coveralls
182182
uses: coverallsapp/github-action@v2
@@ -187,7 +187,9 @@ jobs:
187187
parallel: true
188188

189189
finish:
190-
needs: coverage
190+
needs:
191+
- coverage
192+
- nix
191193
if: ${{ always() }}
192194
runs-on: ubuntu-latest
193195
steps:
@@ -244,7 +246,22 @@ jobs:
244246

245247
- run: nix build -L ".#${{ matrix.attr }}"
246248

247-
# - run: nix flake check -L
249+
- name: Upload coverage reports to Codecov
250+
if: ${{ hashFiles('result-coverage/coverage.info') != '' }}
251+
uses: codecov/codecov-action@v4
252+
with:
253+
file: result-coverage/coverage.info
254+
token: ${{ secrets.CODECOV_TOKEN }}
255+
slug: jbboehr/php-perfifidous
256+
257+
- name: Coveralls
258+
if: ${{ hashFiles('result-coverage/coverage.info') != '' }}
259+
uses: coverallsapp/github-action@v2
260+
continue-on-error: true
261+
with:
262+
file: result-coverage/coverage.info
263+
format: lcov
264+
parallel: true
248265

249266
- name: Export Nix Store Cache
250267
shell: bash

config.m4

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ PHP_ARG_ENABLE(perfidious, whether to enable perfidious,
2121
PHP_ARG_ENABLE(perfidious-debug, whether to enable perfidious debug support,
2222
[AS_HELP_STRING([--enable-perfidious-debug], [Enable perfidious debug support])], [no], [no])
2323

24+
PHP_ARG_ENABLE(perfidious-coverage, whether to enable perfidious coverage support,
25+
[AS_HELP_STRING([--enable-perfidious-coverage], [Enable perfidious coverage support])], [no], [no])
26+
2427
AC_DEFUN([PHP_PERFIDIOUS_ADD_SOURCES], [
2528
PHP_PERFIDIOUS_SOURCES="$PHP_PERFIDIOUS_SOURCES $1"
2629
])
@@ -53,6 +56,11 @@ if test "$PHP_PERFIDIOUS" != "no"; then
5356
AC_DEFINE([NDEBUG], [1], [Disable debug support])
5457
fi
5558

59+
if test "$PHP_PERFIDIOUS_COVERAGE" == "yes"; then
60+
CFLAGS="-fprofile-arcs -ftest-coverage $CFLAGS"
61+
LDFLAGS="--coverage $LDFLAGS"
62+
fi
63+
5664
PHP_ADD_LIBRARY(cap, , PERFIDIOUS_SHARED_LIBADD)
5765
PHP_ADD_LIBRARY(pfm, , PERFIDIOUS_SHARED_LIBADD)
5866

flake.nix

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@
8080
php ? pkgs.php,
8181
libpfm ? pkgs.libpfm,
8282
debugSupport ? false,
83+
coverageSupport ? false,
8384
}:
8485
pkgs.callPackage ./nix/derivation.nix {
8586
inherit src;
8687
inherit stdenv php libpfm;
87-
inherit debugSupport;
88+
inherit debugSupport coverageSupport;
8889
buildPecl = pkgs.callPackage (nixpkgs + "/pkgs/build-support/php/build-pecl.nix") {
8990
inherit php stdenv;
9091
};
@@ -212,6 +213,7 @@
212213
# "musl"
213214
];
214215
libpfm = ["libpfm" "libpfm-unstable"];
216+
coverageSupport = [false];
215217
})
216218
++ [
217219
{
@@ -220,13 +222,21 @@
220222
libpfm = "libpfm";
221223
debugSupport = true;
222224
}
223-
];
225+
]
226+
++ (lib.cartesianProductOfSets {
227+
php = ["php81" "php82" "php83"];
228+
stdenv = ["gcc"];
229+
libpfm = ["libpfm"];
230+
debugSupport = [false true];
231+
coverageSupport = [true];
232+
});
224233

225234
buildFn = {
226235
php,
227236
libpfm,
228237
stdenv,
229238
debugSupport ? false,
239+
coverageSupport ? false,
230240
}:
231241
lib.nameValuePair
232242
(lib.concatStringsSep "-" (lib.filter (v: v != "") [
@@ -243,13 +253,18 @@
243253
then "debug"
244254
else ""
245255
)
256+
(
257+
if coverageSupport
258+
then "coverage"
259+
else ""
260+
)
246261
]))
247262
(
248263
makePackage {
249264
php = matrix.php.${php};
250265
libpfm = matrix.libpfm.${libpfm};
251266
stdenv = matrix.stdenv.${stdenv};
252-
inherit debugSupport;
267+
inherit debugSupport coverageSupport;
253268
}
254269
);
255270

nix/derivation.nix

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
autoreconfHook,
1010
buildPecl,
1111
src,
12+
lcov,
1213
checkSupport ? false,
1314
debugSupport ? false,
1415
WerrorSupport ? checkSupport,
1516
valgrindSupport ? true,
17+
coverageSupport ? false,
1618
}:
1719
(buildPecl rec {
1820
pname = "perfidious";
@@ -24,7 +26,8 @@
2426
buildInputs = [libcap libpfm];
2527
nativeBuildInputs =
2628
[php.unwrapped.dev pkg-config]
27-
++ lib.optional valgrindSupport valgrind;
29+
++ lib.optional valgrindSupport valgrind
30+
++ lib.optional coverageSupport lcov;
2831

2932
passthru = {
3033
inherit php libpfm stdenv;
@@ -34,19 +37,50 @@
3437
[]
3538
++ lib.optional WerrorSupport "--enable-compile-warnings=error"
3639
++ lib.optionals (!WerrorSupport) ["--enable-compile-warnings=yes" "--disable-Werror"]
37-
++ lib.optional debugSupport "--enable-perfidious-debug";
40+
++ lib.optional debugSupport "--enable-perfidious-debug"
41+
++ lib.optional coverageSupport ["--enable-perfidious-coverage"];
3842

3943
makeFlags = ["phpincludedir=$(dev)/include"];
40-
outputs = ["out" "dev"];
44+
outputs =
45+
lib.optional (checkSupport && coverageSupport) "coverage"
46+
++ ["out" "dev"];
4147

4248
doCheck = checkSupport;
4349
theRealFuckingCheckPhase =
4450
''
51+
runHook preCheck
4552
REPORT_EXIT_STATUS=1 NO_INTERACTION=1 make test TEST_PHP_ARGS="-n" || (find tests -name '*.log' | xargs cat ; exit 1)
4653
''
4754
+ (lib.optionalString valgrindSupport ''
4855
USE_ZEND_ALLOC=0 REPORT_EXIT_STATUS=1 NO_INTERACTION=1 make test TEST_PHP_ARGS="-n -m" || (find tests -name '*.mem' | xargs cat ; exit 1)
49-
'');
56+
'')
57+
+ ''
58+
runHook postCheck
59+
'';
60+
61+
preBuild = lib.optionalString coverageSupport ''
62+
lcov --directory . --zerocounters
63+
lcov --directory . --capture --compat-libtool --initial --output-file coverage.info
64+
'';
65+
66+
postCheck = lib.optionalString coverageSupport ''
67+
lcov --no-checksum --directory . --capture --no-markers --compat-libtool --output-file coverage.info
68+
set -o noglob
69+
lcov --remove coverage.info '${builtins.storeDir}/*' \
70+
--compat-libtool \
71+
--output-file coverage.info
72+
set +o noglob
73+
mkdir -p $coverage
74+
cp coverage.info $coverage/coverage.info
75+
genhtml coverage.info -o $coverage/html/
76+
'';
77+
78+
meta = with lib; {
79+
homepage = "https://github.com/jbboehr/php-perfidious";
80+
license = licenses.agpl3Plus;
81+
platforms = platforms.linux;
82+
outputsToInstall = outputs;
83+
};
5084

5185
#TEST_PHP_DETAILED = 1;
5286
})

0 commit comments

Comments
 (0)