Skip to content

Commit

Permalink
Merge pull request #46834 from grahamc/check-outputs-in-meta
Browse files Browse the repository at this point in the history
stdenv: Validate meta.outputsToInstall
  • Loading branch information
grahamc committed Sep 18, 2018
2 parents 0a30853 + 301109a commit 11c76c9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkgs/development/libraries/elf-header/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ stdenvNoCC.mkDerivation {
'';

meta = libc.meta // {
outputsToInstall = [ "out" ];
description = "The datastructures of ELF according to the target platform's libc";
longDescription = ''
The Executable and Linkable Format (ELF, formerly named Extensible Linking
Expand Down
25 changes: 25 additions & 0 deletions pkgs/stdenv/generic/check-meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ let
unsupported = remediate_whitelist "UnsupportedSystem";
blacklisted = x: "";
insecure = remediate_insecure;
broken-outputs = remediateOutputsToInstall;
unknown-meta = x: "";
};
remediate_whitelist = allow_attr: attrs:
Expand Down Expand Up @@ -125,6 +126,20 @@ let
'';

remediateOutputsToInstall = attrs: let
expectedOutputs = attrs.meta.outputsToInstall or [];
actualOutputs = attrs.outputs or [ "out" ];
missingOutputs = builtins.filter (output: ! builtins.elem output actualOutputs) expectedOutputs;
in ''
The package ${attrs.name} has set meta.outputsToInstall to: ${builtins.concatStringsSep ", " expectedOutputs}
however ${attrs.name} only has the outputs: ${builtins.concatStringsSep ", " actualOutputs}
and is missing the following ouputs:
${lib.concatStrings (builtins.map (output: " - ${output}\n") missingOutputs)}
'';

handleEvalIssue = attrs: { reason , errormsg ? "" }:
let
msg = ''
Expand Down Expand Up @@ -185,6 +200,14 @@ let
in anyMatch (attrs.meta.platforms or lib.platforms.all) &&
! anyMatch (attrs.meta.badPlatforms or []);

checkOutputsToInstall = attrs: let
expectedOutputs = attrs.meta.outputsToInstall or [];
actualOutputs = attrs.outputs or [ "out" ];
missingOutputs = builtins.filter (output: ! builtins.elem output actualOutputs) expectedOutputs;
in if shouldCheckMeta
then builtins.length missingOutputs > 0
else false;

# Check if a derivation is valid, that is whether it passes checks for
# e.g brokenness or license.
#
Expand All @@ -202,6 +225,8 @@ let
{ valid = false; reason = "unsupported"; errormsg = "is not supported on ‘${hostPlatform.config}’"; }
else if !(hasAllowedInsecure attrs) then
{ valid = false; reason = "insecure"; errormsg = "is marked as insecure"; }
else if checkOutputsToInstall attrs then
{ valid = false; reason = "broken-outputs"; errormsg = "has invalid meta.outputsToInstall"; }
else let res = checkMeta (attrs.meta or {}); in if res != [] then
{ valid = false; reason = "unknown-meta"; errormsg = "has an invalid meta attrset:${lib.concatMapStrings (x: "\n\t - " + x) res}"; }
else { valid = true; };
Expand Down

0 comments on commit 11c76c9

Please sign in to comment.