diff options
author | Robert Hensing <robert@roberthensing.nl> | 2023-07-26 13:46:42 +0200 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2023-07-26 18:22:26 +0200 |
commit | d1dc8384cab7ef1bf0a79510295c1e91da0556ff (patch) | |
tree | b8b28b818f4c82ab8be945e17fe235d898fafb9a /pkgs/build-support/trivial-builders | |
parent | 86af7da8c40276e09d8085b155c57bd6de85ffd2 (diff) | |
download | nixpkgs-d1dc8384cab7ef1bf0a79510295c1e91da0556ff.tar nixpkgs-d1dc8384cab7ef1bf0a79510295c1e91da0556ff.tar.gz nixpkgs-d1dc8384cab7ef1bf0a79510295c1e91da0556ff.tar.bz2 nixpkgs-d1dc8384cab7ef1bf0a79510295c1e91da0556ff.tar.lz nixpkgs-d1dc8384cab7ef1bf0a79510295c1e91da0556ff.tar.xz nixpkgs-d1dc8384cab7ef1bf0a79510295c1e91da0556ff.tar.zst nixpkgs-d1dc8384cab7ef1bf0a79510295c1e91da0556ff.zip |
writeCBin: Add meta.mainProgram
... and add tests.
Diffstat (limited to 'pkgs/build-support/trivial-builders')
4 files changed, 129 insertions, 1 deletions
diff --git a/pkgs/build-support/trivial-builders/default.nix b/pkgs/build-support/trivial-builders/default.nix index 9099a38b75b..d095974513c 100644 --- a/pkgs/build-support/trivial-builders/default.nix +++ b/pkgs/build-support/trivial-builders/default.nix @@ -242,7 +242,11 @@ rec { */ - writeScriptBin = name: text: writeTextFile {inherit name text; executable = true; destination = "/bin/${name}";}; + writeScriptBin = name: text: writeTextFile { + inherit name text; + executable = true; + destination = "/bin/${name}"; + }; /* Similar to writeScript. Writes a Shell script and checks its syntax. @@ -374,6 +378,9 @@ rec { # Pointless to do this on a remote machine. preferLocalBuild = true; allowSubstitutes = false; + meta = { + mainProgram = name; + }; } '' n=$out/bin/$name diff --git a/pkgs/build-support/trivial-builders/test/writeCBin.nix b/pkgs/build-support/trivial-builders/test/writeCBin.nix new file mode 100644 index 00000000000..56cab45b380 --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/writeCBin.nix @@ -0,0 +1,43 @@ +/* + Run with: + + cd nixpkgs + nix-build -A tests.trivial-builders.writeCBin +*/ + +{ lib, writeCBin, runCommand }: +let + output = "hello"; + pkg = writeCBin "test-script" '' + #include <stdio.h> + int main () { + printf("hello\n"); + return 0; + } + ''; +in + assert pkg.meta.mainProgram == "test-script"; + runCommand "test-writeCBin" { } '' + + echo Testing with getExe... + + target=${lib.getExe pkg} + expected=${lib.escapeShellArg output} + got=$("$target") + if [[ "$got" != "$expected" ]]; then + echo "wrong output: expected $expected, got $got" + exit 1 + fi + + echo Testing with makeBinPath... + + PATH="${lib.makeBinPath [ pkg ]}:$PATH" + got=$(test-script) + if [[ "$got" != "$expected" ]]; then + echo "wrong output: expected $expected, got $got" + exit 1 + fi + + touch $out + '' + diff --git a/pkgs/build-support/trivial-builders/test/writeScriptBin.nix b/pkgs/build-support/trivial-builders/test/writeScriptBin.nix new file mode 100644 index 00000000000..1487443130d --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/writeScriptBin.nix @@ -0,0 +1,39 @@ +/* + Run with: + + cd nixpkgs + nix-build -A tests.trivial-builders.writeShellScriptBin +*/ + +{ lib, writeScriptBin, runCommand }: +let + output = "hello"; + pkg = writeScriptBin "test-script" '' + echo ${lib.escapeShellArg output} + ''; +in + assert pkg.meta.mainProgram == "test-script"; + runCommand "test-writeScriptBin" { } '' + + echo Testing with getExe... + + target=${lib.getExe pkg} + expected=${lib.escapeShellArg output} + got=$("$target") + if [[ "$got" != "$expected" ]]; then + echo "wrong output: expected $expected, got $got" + exit 1 + fi + + echo Testing with makeBinPath... + + PATH="${lib.makeBinPath [ pkg ]}:$PATH" + got=$(test-script) + if [[ "$got" != "$expected" ]]; then + echo "wrong output: expected $expected, got $got" + exit 1 + fi + + touch $out + '' + diff --git a/pkgs/build-support/trivial-builders/test/writeShellScriptBin.nix b/pkgs/build-support/trivial-builders/test/writeShellScriptBin.nix new file mode 100644 index 00000000000..e93410e25bc --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/writeShellScriptBin.nix @@ -0,0 +1,39 @@ +/* + Run with: + + cd nixpkgs + nix-build -A tests.trivial-builders.writeShellScriptBin +*/ + +{ lib, writeShellScriptBin, runCommand }: +let + output = "hello"; + pkg = writeShellScriptBin "test-script" '' + echo ${lib.escapeShellArg output} + ''; +in + assert pkg.meta.mainProgram == "test-script"; + runCommand "test-writeShellScriptBin" { } '' + + echo Testing with getExe... + + target=${lib.getExe pkg} + expected=${lib.escapeShellArg output} + got=$("$target") + if [[ "$got" != "$expected" ]]; then + echo "wrong output: expected $expected, got $got" + exit 1 + fi + + echo Testing with makeBinPath... + + PATH="${lib.makeBinPath [ pkg ]}:$PATH" + got=$(test-script) + if [[ "$got" != "$expected" ]]; then + echo "wrong output: expected $expected, got $got" + exit 1 + fi + + touch $out + '' + |