Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,25 @@ in {
}]) (packageNames coverageProject));

# Flake package names that are flat and match the cabal component names.
# Only expose components that are actually part of the cabal install plan.
# `plan-to-nix` sets `planned = true` for every component in `plan.json`
# (set project-wide for stack projects); a component that is not planned
# — e.g. a private sub-library that exists only to serve a disabled test
# suite — should not be built by `hydraJobs.packages` (see #2028). This
# mirrors the `buildable && planned` filter already used for
# `config.allComponent` (modules/package.nix) and `applyComponents`.
flakeComponentIsPlanned = component:
(component.config.buildable or true) && (component.config.planned or false);

mkFlakePackages =
foldrAttrVals
(package: acc:
foldComponents
subComponentTypes
(component: a: a // {
${component.passthru.identifier.component-id} = component;
})
(component: a:
if flakeComponentIsPlanned component
then a // { ${component.passthru.identifier.component-id} = component; }
else a)
acc
package)
{ };
Expand All @@ -473,13 +484,16 @@ in {
(package: acc:
foldComponents
[ "exes" "tests" "benchmarks" ]
(component: a: a // {
${component.passthru.identifier.component-id} = {
type = "app";
program = component.exePath;
inherit (component) meta;
};
})
(component: a:
if flakeComponentIsPlanned component
then a // {
${component.passthru.identifier.component-id} = {
type = "app";
program = component.exePath;
inherit (component) meta;
};
}
else a)
acc
package)
{ };
Expand Down
43 changes: 43 additions & 0 deletions test/unit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ let
rev = "487eea1c249537d34c27f6143dff2b9d5586c657";
sha256 = "077j5j3j86qy1wnabjlrg4dmqy1fv037dyq3xb8ch4ickpxxs123";
};

# Built-component-shaped fixture for the `mkFlakePackages` filter (#2028):
# each component carries `passthru.identifier.component-id` and a `config`
# with the `buildable`/`planned` flags (as comp-builder exposes via
# `passthru.config`). `priv` is a private sub-library that is not in the
# install plan; `disabled` is an unbuildable test suite.
mkFakeComponent = id: buildable: planned: {
passthru.identifier.component-id = id;
config = { inherit buildable planned; };
};
flakePackagesInput = {
nnn = {
components = {
library = mkFakeComponent "nnn:lib:nnn" true true;
sublibs.used = mkFakeComponent "nnn:lib:used" true true;
sublibs.priv = mkFakeComponent "nnn:lib:priv" true false;
exes.eee = mkFakeComponent "nnn:exe:eee" true true;
tests.disabled = mkFakeComponent "nnn:test:disabled" false false;
};
};
};
in
lib.runTests {
# identity function for applyComponents
Expand All @@ -57,6 +78,28 @@ lib.runTests {
expected = 1;
};

# `flakeComponentIsPlanned` keeps only buildable components that are in the
# install plan; `buildable` defaults to true and `planned` to false when a
# config omits them (see #2028).
test-flakeComponentIsPlanned = {
expr = map haskellLib.flakeComponentIsPlanned [
{ config = { buildable = true; planned = true; }; }
{ config = { buildable = true; planned = false; }; }
{ config = { buildable = false; planned = true; }; }
{ config = { }; } # planned defaults false -> excluded
{ config = { planned = true; }; } # buildable defaults true -> included
];
expected = [ true false false false true ];
};

# `mkFlakePackages` must drop the unplanned private sub-library and the
# disabled test suite, keeping the planned library, sub-library and exe.
test-mkFlakePackages-filters-unplanned = {
expr = lib.sort (a: b: a < b)
(builtins.attrNames (haskellLib.mkFlakePackages flakePackagesInput));
expected = [ "nnn:exe:eee" "nnn:lib:nnn" "nnn:lib:used" ];
};

testParseBlock1 = {
expr = __toJSON (haskellLib.parseSourceRepositoryPackageBlock "cabal.project" {} {} "" ''
type: git
Expand Down
Loading