Skip to content

Commit

Permalink
Add coverage to nix matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
jbboehr committed Apr 7, 2024
1 parent 23190e2 commit 2c553cc
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 10 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ jobs:
with:
file: coverage.info
token: ${{ secrets.CODECOV_TOKEN }}
slug: jbboehr/php-perf
slug: jbboehr/php-perfifidous

- name: Coveralls
uses: coverallsapp/github-action@v2
Expand All @@ -187,7 +187,9 @@ jobs:
parallel: true

finish:
needs: coverage
needs:
- coverage
- nix
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -244,7 +246,22 @@ jobs:

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

# - run: nix flake check -L
- name: Upload coverage reports to Codecov
if: ${{ hashFiles('result-coverage') != '' }}
uses: codecov/codecov-action@v4
with:
file: result-coverage/coverage.info
token: ${{ secrets.CODECOV_TOKEN }}
slug: jbboehr/php-perfifidous

- name: Coveralls
if: ${{ hashFiles('result-coverage') != '' }}
uses: coverallsapp/github-action@v2
continue-on-error: true
with:
file: result-coverage/coverage.info
format: lcov
parallel: true

- name: Export Nix Store Cache
shell: bash
Expand Down
8 changes: 8 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ PHP_ARG_ENABLE(perfidious, whether to enable perfidious,
PHP_ARG_ENABLE(perfidious-debug, whether to enable perfidious debug support,
[AS_HELP_STRING([--enable-perfidious-debug], [Enable perfidious debug support])], [no], [no])

PHP_ARG_ENABLE(perfidious-coverage, whether to enable perfidious coverage support,
[AS_HELP_STRING([--enable-perfidious-coverage], [Enable perfidious coverage support])], [no], [no])

AC_DEFUN([PHP_PERFIDIOUS_ADD_SOURCES], [
PHP_PERFIDIOUS_SOURCES="$PHP_PERFIDIOUS_SOURCES $1"
])
Expand Down Expand Up @@ -53,6 +56,11 @@ if test "$PHP_PERFIDIOUS" != "no"; then
AC_DEFINE([NDEBUG], [1], [Disable debug support])
fi

if test "$PHP_PERFIDIOUS_COVERAGE" == "yes"; then
CFLAGS="-fprofile-arcs -ftest-coverage $CFLAGS"
LDFLAGS="--coverage $LDFLAGS"
fi

PHP_ADD_LIBRARY(cap, , PERFIDIOUS_SHARED_LIBADD)
PHP_ADD_LIBRARY(pfm, , PERFIDIOUS_SHARED_LIBADD)

Expand Down
21 changes: 18 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@
php ? pkgs.php,
libpfm ? pkgs.libpfm,
debugSupport ? false,
coverageSupport ? false,
}:
pkgs.callPackage ./nix/derivation.nix {
inherit src;
inherit stdenv php libpfm;
inherit debugSupport;
inherit debugSupport coverageSupport;
buildPecl = pkgs.callPackage (nixpkgs + "/pkgs/build-support/php/build-pecl.nix") {
inherit php stdenv;
};
Expand Down Expand Up @@ -212,6 +213,7 @@
# "musl"
];
libpfm = ["libpfm" "libpfm-unstable"];
coverageSupport = [false];
})
++ [
{
Expand All @@ -220,13 +222,21 @@
libpfm = "libpfm";
debugSupport = true;
}
];
]
++ (lib.cartesianProductOfSets {
php = ["php81" "php82" "php83"];
stdenv = ["gcc"];
libpfm = ["libpfm"];
debugSupport = [false true];
coverageSupport = [true];
});

buildFn = {
php,
libpfm,
stdenv,
debugSupport ? false,
coverageSupport ? false,
}:
lib.nameValuePair
(lib.concatStringsSep "-" (lib.filter (v: v != "") [
Expand All @@ -243,13 +253,18 @@
then "debug"
else ""
)
(
if coverageSupport
then "coverage"
else ""
)
]))
(
makePackage {
php = matrix.php.${php};
libpfm = matrix.libpfm.${libpfm};
stdenv = matrix.stdenv.${stdenv};
inherit debugSupport;
inherit debugSupport coverageSupport;
}
);

Expand Down
35 changes: 31 additions & 4 deletions nix/derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
autoreconfHook,
buildPecl,
src,
lcov,
checkSupport ? false,
debugSupport ? false,
WerrorSupport ? checkSupport,
valgrindSupport ? true,
coverageSupport ? false,
}:
(buildPecl rec {
pname = "perfidious";
Expand All @@ -24,7 +26,8 @@
buildInputs = [libcap libpfm];
nativeBuildInputs =
[php.unwrapped.dev pkg-config]
++ lib.optional valgrindSupport valgrind;
++ lib.optional valgrindSupport valgrind
++ lib.optional coverageSupport lcov;

passthru = {
inherit php libpfm stdenv;
Expand All @@ -34,19 +37,43 @@
[]
++ lib.optional WerrorSupport "--enable-compile-warnings=error"
++ lib.optionals (!WerrorSupport) ["--enable-compile-warnings=yes" "--disable-Werror"]
++ lib.optional debugSupport "--enable-perfidious-debug";
++ lib.optional debugSupport "--enable-perfidious-debug"
++ lib.optional coverageSupport ["--enable-perfidious-coverage"];

makeFlags = ["phpincludedir=$(dev)/include"];
outputs = ["out" "dev"];
outputs =
lib.optional (checkSupport && coverageSupport) "coverage"
++ ["out" "dev"];

doCheck = checkSupport;
theRealFuckingCheckPhase =
''
runHook preCheck
REPORT_EXIT_STATUS=1 NO_INTERACTION=1 make test TEST_PHP_ARGS="-n" || (find tests -name '*.log' | xargs cat ; exit 1)
''
+ (lib.optionalString valgrindSupport ''
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)
'');
'')
+ ''
runHook postCheck
'';

preBuild = lib.optionalString coverageSupport ''
lcov --directory . --zerocounters
lcov --directory . --capture --compat-libtool --initial --output-file coverage.info
'';

postCheck = lib.optionalString coverageSupport ''
lcov --no-checksum --directory . --capture --no-markers --compat-libtool --output-file coverage.info
set -o noglob
lcov --remove coverage.info '${builtins.storeDir}/*' \
--compat-libtool \
--output-file coverage.info
set +o noglob
mkdir -p $coverage
cp coverage.info $coverage/coverage.info
genhtml coverage.info -o $coverage/html/
'';

#TEST_PHP_DETAILED = 1;
})
Expand Down

0 comments on commit 2c553cc

Please sign in to comment.