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 311 Similar to writeShellScriptBin and writeScriptBin. 312 312 Writes an executable Shell script to /nix/store/<store path>/bin/<name> and 313 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" ]. 314 316 Automatically includes sane set of shellopts (errexit, nounset, pipefail) 315 317 and handles creation of PATH based on runtimeInputs 316 318 ··· 338 340 , runtimeInputs ? [ ] 339 341 , meta ? { } 340 342 , checkPhase ? null 343 + , excludeShellChecks ? [ ] 341 344 }: 342 345 writeTextFile { 343 346 inherit name meta; ··· 363 366 # but we still want to use writeShellApplication on those platforms 364 367 let 365 368 shellcheckSupported = lib.meta.availableOn stdenv.buildPlatform shellcheck.compiler; 369 + excludeOption = lib.optionalString (excludeShellChecks != [ ]) "--exclude '${lib.concatStringsSep "," excludeShellChecks}'"; 366 370 shellcheckCommand = lib.optionalString shellcheckSupported '' 367 371 # use shellcheck which does not include docs 368 372 # 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" 373 + ${lib.getExe (haskell.lib.compose.justStaticExecutables shellcheck.unwrapped)} ${excludeOption} "$target" 370 374 ''; 371 375 in 372 376 if checkPhase == null then ''
+1
pkgs/build-support/trivial-builders/test/default.nix
··· 25 25 then callPackage ./references.nix {} 26 26 else null; 27 27 writeCBin = callPackage ./writeCBin.nix {}; 28 + writeShellApplication = callPackage ./writeShellApplication.nix {}; 28 29 writeScriptBin = callPackage ./writeScriptBin.nix {}; 29 30 writeShellScript = callPackage ./write-shell-script.nix {}; 30 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 +