Merge pull request #261115 from con-f-use/master

writeShellApplication: exclude shell checks

authored by Thiago Kenji Okada and committed by GitHub a00733f5 24a1589e

+35 -1
+5 -1
pkgs/build-support/trivial-builders/default.nix
··· 311 Similar to writeShellScriptBin and writeScriptBin. 312 Writes an executable Shell script to /nix/store/<store path>/bin/<name> and 313 checks its syntax with shellcheck and the shell's -n option. 314 Automatically includes sane set of shellopts (errexit, nounset, pipefail) 315 and handles creation of PATH based on runtimeInputs 316 ··· 338 , runtimeInputs ? [ ] 339 , meta ? { } 340 , checkPhase ? null 341 }: 342 writeTextFile { 343 inherit name meta; ··· 363 # but we still want to use writeShellApplication on those platforms 364 let 365 shellcheckSupported = lib.meta.availableOn stdenv.buildPlatform shellcheck.compiler; 366 shellcheckCommand = lib.optionalString shellcheckSupported '' 367 # use shellcheck which does not include docs 368 # pandoc takes long to build and documentation isn't needed for just running the cli 369 - ${lib.getExe (haskell.lib.compose.justStaticExecutables shellcheck.unwrapped)} "$target" 370 ''; 371 in 372 if checkPhase == null then ''
··· 311 Similar to writeShellScriptBin and writeScriptBin. 312 Writes an executable Shell script to /nix/store/<store path>/bin/<name> and 313 checks its syntax with shellcheck and the shell's -n option. 314 + Individual checks can be foregone by putting them in the excludeShellChecks 315 + list, e.g. [ "SC2016" ]. 316 Automatically includes sane set of shellopts (errexit, nounset, pipefail) 317 and handles creation of PATH based on runtimeInputs 318 ··· 340 , runtimeInputs ? [ ] 341 , meta ? { } 342 , checkPhase ? null 343 + , excludeShellChecks ? [ ] 344 }: 345 writeTextFile { 346 inherit name meta; ··· 366 # but we still want to use writeShellApplication on those platforms 367 let 368 shellcheckSupported = lib.meta.availableOn stdenv.buildPlatform shellcheck.compiler; 369 + excludeOption = lib.optionalString (excludeShellChecks != [ ]) "--exclude '${lib.concatStringsSep "," excludeShellChecks}'"; 370 shellcheckCommand = lib.optionalString shellcheckSupported '' 371 # use shellcheck which does not include docs 372 # pandoc takes long to build and documentation isn't needed for just running the cli 373 + ${lib.getExe (haskell.lib.compose.justStaticExecutables shellcheck.unwrapped)} ${excludeOption} "$target" 374 ''; 375 in 376 if checkPhase == null then ''
+1
pkgs/build-support/trivial-builders/test/default.nix
··· 25 then callPackage ./references.nix {} 26 else null; 27 writeCBin = callPackage ./writeCBin.nix {}; 28 writeScriptBin = callPackage ./writeScriptBin.nix {}; 29 writeShellScript = callPackage ./write-shell-script.nix {}; 30 writeShellScriptBin = callPackage ./writeShellScriptBin.nix {};
··· 25 then callPackage ./references.nix {} 26 else null; 27 writeCBin = callPackage ./writeCBin.nix {}; 28 + writeShellApplication = callPackage ./writeShellApplication.nix {}; 29 writeScriptBin = callPackage ./writeScriptBin.nix {}; 30 writeShellScript = callPackage ./write-shell-script.nix {}; 31 writeShellScriptBin = callPackage ./writeShellScriptBin.nix {};
+29
pkgs/build-support/trivial-builders/test/writeShellApplication.nix
···
··· 1 + /* 2 + Run with: 3 + 4 + cd nixpkgs 5 + nix-build -A tests.trivial-builders.writeShellApplication 6 + */ 7 + 8 + { lib, writeShellApplication, runCommand }: 9 + let 10 + pkg = writeShellApplication { 11 + name = "test-script"; 12 + excludeShellChecks = [ "SC2016" ]; 13 + text = '' 14 + echo -e '#!/usr/bin/env bash\n' \ 15 + 'echo "$SHELL"' > /tmp/something.sh # this line would normally 16 + # ...cause shellcheck error 17 + ''; 18 + }; 19 + in 20 + assert pkg.meta.mainProgram == "test-script"; 21 + runCommand "test-writeShellApplication" { } '' 22 + 23 + echo Testing if writeShellApplication builds without shellcheck error... 24 + 25 + target=${lib.getExe pkg} 26 + 27 + touch $out 28 + '' 29 +