Skip to content

Commit

Permalink
build(pkgs): Implement build-status infrastructure
Browse files Browse the repository at this point in the history
Why this change is needed?
==========================

The test matrix { package x version x system } contains various elements with
problems and the sheer size of the matrix makes it difficult to manage (e.g. to
know which CI jobs to mark as allowed to fail, to know on which elements the
checkPhase can be run or which tests need to be removed.

Investigation of the problems shows that many of the failures are caused by a
handful of tests that fail on a specific version and system. Instead of marking
the whole job as failed, it is better to omit the failing tests, as the rest of
the suite (more than 99%!) will still pass.

What does this change do?
=========================

For each package:
* Add a `pkgs/${packageName}/build-status.json` file containing
  * each version known to have problems
    * each system on which this version is known to have problems
      * `build` - does it build succesfully
        * if `false` the CI will be marked as allowed to fail
      * `check` - does the check phase complete
      * `skippedTests` - any tests that are necessary to be skipped to allow the
        checkPhase to succeed
* Add to its derivation `passthru.buildStatus` field surfacing this information
  on the Nix eval level
* Set `doCheck` to `buildStatus.check`
* Add to the `checkPhase`
  * for each `test_file` in buildStatus.skippedTests
    * a line `rm -v ${test_file}` that will remove the test on the corresponding
      tripple (package, version, system)
  • Loading branch information
PetarKirov committed Jan 25, 2024
1 parent bb83f12 commit fd109c3
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 25 deletions.
13 changes: 13 additions & 0 deletions lib/build-status.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{lib, ...}: {
getBuildStatus = package: version: system: let
data = lib.importJSON ./../pkgs/${package}/build-status.json;
in
data.${version}.${system}
or {
# If not build status is found, we assume that the package builds
# successfully with no workarounds.
build = true;
check = true;
skippedTests = [];
};
}
4 changes: 3 additions & 1 deletion lib/mk-gh-actions-matrix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# "macos-latest-xlarge" = "aarch64-darwin";
};

inherit (import ./build-status.nix {inherit lib;}) getBuildStatus;

mkGHActionsMatrix = {
include = lib.pipe (builtins.attrNames nixSystemToGHPlatform) [
(builtins.concatMap
Expand All @@ -23,7 +25,7 @@
p = self.packages.${system}.${package};
in {
os = platform;
allowedToFail = builtins.elem system (p.passthru.allowedToFailOn or []);
allowedToFail = !(p.passthru.buildStatus or (throw "${package} does not expose build status")).build;
inherit system package;
attrPath = "packages.${system}.${lib.strings.escapeNixIdentifier package}";
})
Expand Down
8 changes: 8 additions & 0 deletions pkgs/dmd/binary.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
...
}: let
inherit (stdenv) hostPlatform;

inherit (import ../../lib/build-status.nix {inherit lib;}) getBuildStatus;
buildStatus = getBuildStatus "dmd" version stdenv.system;

OS =
if hostPlatform.isDarwin
then "osx"
Expand All @@ -26,6 +30,10 @@ in
pname = "dmd-binary";
inherit version;

passthru = {
inherit buildStatus;
};

src = fetchurl rec {
name = "dmd.${version}.${OS}.tar.xz";
url = "http://downloads.dlang.org/releases/2.x/${version}/${name}";
Expand Down
22 changes: 22 additions & 0 deletions pkgs/dmd/build-status.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"2.098.1": {
"x86_64-darwin": {
"build": true,
"check": true,
"skippedTests": [
"dmd/test/runnable/test17868.d",
"dmd/test/runnable/test17868b.d"
]
}
},
"2.102.2": {
"x86_64-darwin": {
"build": true,
"check": true,
"skippedTests": [
"dmd/compiler/test/runnable/objc_class.d",
"dmd/compiler/test/runnable/objc_self_test.d"
]
}
}
}
17 changes: 13 additions & 4 deletions pkgs/dmd/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
druntimeSha256 ? "",
phobosSha256,
toolsSha256,
doCheck ? true,
enableAsserts ? false,
enableCoverage ? false,
enableDebug ? false,
Expand Down Expand Up @@ -35,6 +34,10 @@
unzip,
HOST_DMD ? "${callPackage ./bootstrap.nix {}}/bin/dmd",
}: let
inherit (import ../../lib/build-status.nix {inherit lib;}) getBuildStatus;

buildStatus = getBuildStatus "dmd" version stdenv.system;

pathConfig = runCommand "phobos-tzdata-curl-paths" {} ''
mkdir $out
echo '${tzdata}/share/zoneinfo/' > $out/TZDatabaseDirFile
Expand Down Expand Up @@ -110,6 +113,10 @@ in
pname = "dmd";
inherit version;

passthru = {
inherit buildStatus;
};

enableParallelBuilding = true;

srcs =
Expand Down Expand Up @@ -264,19 +271,21 @@ in
runHook postBuild
'';

inherit doCheck;
doCheck = buildStatus.check;

checkInputs = lib.optional stdenv.isDarwin Foundation;

checkFlags = commonBuildFlags ++ ["N=$(checkJobs)"];

# many tests are disbled because they are failing

# NOTE: Purity check is disabled for checkPhase because it doesn't fare well
# with the DMD linker. See https://github.com/NixOS/nixpkgs/issues/97420
checkPhase = ''
runHook preCheck
${
lib.optionalString (buildStatus.skippedTests != [])
(lib.concatMapStringsSep "\n" (test: ''rm -v ${test}'') buildStatus.skippedTests)
}
export checkJobs=$NIX_BUILD_CORES
if [ -z $enableParallelChecking ]; then
checkJobs=1
Expand Down
3 changes: 3 additions & 0 deletions pkgs/dub/build-status.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
13 changes: 11 additions & 2 deletions pkgs/dub/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
dcompiler ? ldc,
}:
assert dcompiler != null; let
inherit (import ../../lib/build-status.nix {inherit lib;}) getBuildStatus;
buildStatus = getBuildStatus "dub" version stdenv.system;

version = "1.30.0";

xdmdName =
if lib.hasPrefix "ldc" dcompiler.pname
then "ldmd2"
Expand All @@ -18,7 +23,11 @@ assert dcompiler != null; let
in
stdenv.mkDerivation rec {
pname = "dub";
version = "1.30.0";
inherit version;

passthru = {
inherit buildStatus;
};

enableParallelBuilding = true;

Expand Down Expand Up @@ -58,7 +67,7 @@ in
./build
'';

doCheck = !stdenv.isDarwin;
doCheck = buildStatus.check;

checkPhase = ''
export DUB=$NIX_BUILD_TOP/source/bin/dub
Expand Down
7 changes: 7 additions & 0 deletions pkgs/ldc/binary.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
}: let
inherit (stdenv) hostPlatform system;

inherit (import ../../lib/build-status.nix {inherit lib;}) getBuildStatus;
buildStatus = getBuildStatus "ldc" version stdenv.system;

systemToArchivePlatform = {
# FIXME: How should Android be supported?
# (It is not a separate Nixpkgs platform.)
Expand All @@ -37,6 +40,10 @@ in
pname = "ldc-binary";
inherit version;

passthru = {
inherit buildStatus;
};

src = fetchurl rec {
name = "ldc2-${version}-${archivePlatform}.${tarballSuffix}";
url = "https://github.com/ldc-developers/ldc/releases/download/v${version}/${name}";
Expand Down
14 changes: 14 additions & 0 deletions pkgs/ldc/build-status.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"1.30.0": {
"x86_64-linux": {
"build": true,
"check": false,
"skippedTests": []
},
"x86_64-darwin": {
"build": true,
"check": false,
"skippedTests": []
}
}
}
46 changes: 28 additions & 18 deletions pkgs/ldc/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
targetPackages,
ldcBootstrap ? callPackage ./bootstrap.nix {},
}: let
inherit (import ../../lib/build-status.nix {inherit lib;}) getBuildStatus;
buildStatus = getBuildStatus "ldc" version stdenv.system;

pathConfig = runCommand "phobos-tzdata-curl-paths" {} ''
mkdir $out
echo ${tzdata}/share/zoneinfo/ > $out/TZDatabaseDirFile
Expand Down Expand Up @@ -67,6 +70,10 @@ in
pname = "ldc";
inherit version;

passthru = {
inherit buildStatus;
};

src = fetchurl {
url = "https://github.com/ldc-developers/ldc/releases/download/v${version}/ldc-${version}-src.tar.gz";
inherit sha256;
Expand Down Expand Up @@ -162,25 +169,32 @@ in
lib.optionalString stdenv.hostPlatform.isDarwin
"|druntime-test-shared";

checkPhase = ''
# Build default lib test runners
ninja -j$NIX_BUILD_CORES all-test-runners
doCheck = buildStatus.check;

${fixNames}
checkPhase =
(
lib.optionalString (buildStatus.skippedTests != [])
(lib.concatMapStringsSep "\n" (test: ''rm -v ${test}'') buildStatus.skippedTests)
)
+ ''
# Build default lib test runners
ninja -j$NIX_BUILD_CORES all-test-runners
# Run dmd testsuite
export DMD_TESTSUITE_MAKE_ARGS="-j$NIX_BUILD_CORES DMD=$DMD"
ctest -V -R "dmd-testsuite"
${fixNames}
# Build and run LDC D unittests.
ctest --output-on-failure -R "ldc2-unittest"
# Run dmd testsuite
export DMD_TESTSUITE_MAKE_ARGS="-j$NIX_BUILD_CORES DMD=$DMD"
ctest -V -R "dmd-testsuite"
# Run LIT testsuite.
ctest -V -R "lit-tests"
# Build and run LDC D unittests.
ctest --output-on-failure -R "ldc2-unittest"
# Run default lib unittests
ctest -j$NIX_BUILD_CORES --output-on-failure -E "ldc2-unittest|lit-tests|dmd-testsuite${additionalExceptions}"
'';
# Run LIT testsuite.
ctest -V -R "lit-tests"
# Run default lib unittests
ctest -j$NIX_BUILD_CORES --output-on-failure -E "ldc2-unittest|lit-tests|dmd-testsuite${additionalExceptions}"
'';

postInstall = ''
substitute ${ldcConfFile} "$out/etc/ldc2.conf" --subst-var out
Expand All @@ -190,10 +204,6 @@ in
--set-default CC "${targetPackages.stdenv.cc}/bin/cc"
'';

passthru = {
allowedToFailOn = ["x86_64-darwin" "aarch64-darwin"];
};

meta = with lib; {
description = "The LLVM-based D compiler";
homepage = "https://github.com/ldc-developers/ldc";
Expand Down

0 comments on commit fd109c3

Please sign in to comment.