Merge pull request #261115 from con-f-use/master
writeShellApplication: exclude shell checks
This commit is contained in:
commit
a00733f592
3 changed files with 35 additions and 1 deletions
|
@ -311,6 +311,8 @@ rec {
|
||||||
Similar to writeShellScriptBin and writeScriptBin.
|
Similar to writeShellScriptBin and writeScriptBin.
|
||||||
Writes an executable Shell script to /nix/store/<store path>/bin/<name> and
|
Writes an executable Shell script to /nix/store/<store path>/bin/<name> and
|
||||||
checks its syntax with shellcheck and the shell's -n option.
|
checks its syntax with shellcheck and the shell's -n option.
|
||||||
|
Individual checks can be foregone by putting them in the excludeShellChecks
|
||||||
|
list, e.g. [ "SC2016" ].
|
||||||
Automatically includes sane set of shellopts (errexit, nounset, pipefail)
|
Automatically includes sane set of shellopts (errexit, nounset, pipefail)
|
||||||
and handles creation of PATH based on runtimeInputs
|
and handles creation of PATH based on runtimeInputs
|
||||||
|
|
||||||
|
@ -338,6 +340,7 @@ rec {
|
||||||
, runtimeInputs ? [ ]
|
, runtimeInputs ? [ ]
|
||||||
, meta ? { }
|
, meta ? { }
|
||||||
, checkPhase ? null
|
, checkPhase ? null
|
||||||
|
, excludeShellChecks ? [ ]
|
||||||
}:
|
}:
|
||||||
writeTextFile {
|
writeTextFile {
|
||||||
inherit name meta;
|
inherit name meta;
|
||||||
|
@ -363,10 +366,11 @@ rec {
|
||||||
# but we still want to use writeShellApplication on those platforms
|
# but we still want to use writeShellApplication on those platforms
|
||||||
let
|
let
|
||||||
shellcheckSupported = lib.meta.availableOn stdenv.buildPlatform shellcheck.compiler;
|
shellcheckSupported = lib.meta.availableOn stdenv.buildPlatform shellcheck.compiler;
|
||||||
|
excludeOption = lib.optionalString (excludeShellChecks != [ ]) "--exclude '${lib.concatStringsSep "," excludeShellChecks}'";
|
||||||
shellcheckCommand = lib.optionalString shellcheckSupported ''
|
shellcheckCommand = lib.optionalString shellcheckSupported ''
|
||||||
# use shellcheck which does not include docs
|
# use shellcheck which does not include docs
|
||||||
# pandoc takes long to build and documentation isn't needed for just running the cli
|
# pandoc takes long to build and documentation isn't needed for just running the cli
|
||||||
${lib.getExe (haskell.lib.compose.justStaticExecutables shellcheck.unwrapped)} "$target"
|
${lib.getExe (haskell.lib.compose.justStaticExecutables shellcheck.unwrapped)} ${excludeOption} "$target"
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
if checkPhase == null then ''
|
if checkPhase == null then ''
|
||||||
|
|
|
@ -25,6 +25,7 @@ recurseIntoAttrs {
|
||||||
then callPackage ./references.nix {}
|
then callPackage ./references.nix {}
|
||||||
else null;
|
else null;
|
||||||
writeCBin = callPackage ./writeCBin.nix {};
|
writeCBin = callPackage ./writeCBin.nix {};
|
||||||
|
writeShellApplication = callPackage ./writeShellApplication.nix {};
|
||||||
writeScriptBin = callPackage ./writeScriptBin.nix {};
|
writeScriptBin = callPackage ./writeScriptBin.nix {};
|
||||||
writeShellScript = callPackage ./write-shell-script.nix {};
|
writeShellScript = callPackage ./write-shell-script.nix {};
|
||||||
writeShellScriptBin = callPackage ./writeShellScriptBin.nix {};
|
writeShellScriptBin = callPackage ./writeShellScriptBin.nix {};
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
Run with:
|
||||||
|
|
||||||
|
cd nixpkgs
|
||||||
|
nix-build -A tests.trivial-builders.writeShellApplication
|
||||||
|
*/
|
||||||
|
|
||||||
|
{ lib, writeShellApplication, runCommand }:
|
||||||
|
let
|
||||||
|
pkg = writeShellApplication {
|
||||||
|
name = "test-script";
|
||||||
|
excludeShellChecks = [ "SC2016" ];
|
||||||
|
text = ''
|
||||||
|
echo -e '#!/usr/bin/env bash\n' \
|
||||||
|
'echo "$SHELL"' > /tmp/something.sh # this line would normally
|
||||||
|
# ...cause shellcheck error
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in
|
||||||
|
assert pkg.meta.mainProgram == "test-script";
|
||||||
|
runCommand "test-writeShellApplication" { } ''
|
||||||
|
|
||||||
|
echo Testing if writeShellApplication builds without shellcheck error...
|
||||||
|
|
||||||
|
target=${lib.getExe pkg}
|
||||||
|
|
||||||
|
touch $out
|
||||||
|
''
|
||||||
|
|
Loading…
Reference in a new issue