diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/default.nix b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/default.nix index b3185140f2ea..ff9eed6bdeef 100644 --- a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/default.nix +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/default.nix @@ -10,4 +10,6 @@ makeSetupHook { substitutions = { objdump = "${lib.getBin binutils-unwrapped}/${stdenv.targetPlatform.config}/bin/objdump"; }; + + passthru.tests = callPackage ./tests { }; } ./cygwin-dll-link.sh diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/default.nix b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/default.nix new file mode 100644 index 000000000000..a8744001dc2d --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/default.nix @@ -0,0 +1,130 @@ +{ + dieHook, + lib, + stdenv, + testers, + runCommand, +}: + +rec { + dll = stdenv.mkDerivation { + name = "dll"; + src = ./dll; + outputs = [ + "out" + "dev" + ]; + buildInputs = [ dll2 ]; + strictDeps = true; + }; + + dll2 = stdenv.mkDerivation { + name = "dll2"; + src = ./dll2; + outputs = [ + "out" + "dev" + ]; + }; + + exe = stdenv.mkDerivation { + name = "exe"; + src = ./exe; + buildInputs = [ dll ]; + nativeBuildInputs = [ dieHook ]; + strictDeps = true; + doCheck = true; + postFixup = ''[[ -e "$out"/bin/cyghello2.dll ]] || die missing indirect dependency''; + }; + + link-dll = exe.overrideAttrs { + name = "link-dll"; + preFixup = '' + ln -s ${lib.getLib dll}/bin/cyghello.dll "$out"/bin/ + ''; + }; + + user32 = stdenv.mkDerivation { + name = "user32"; + src = ./user32; + allowedImpureDLLs = [ "USER32.dll" ]; + }; + + impure-dll = testers.testBuildFailure ( + user32.overrideAttrs { + name = "impure-dll"; + allowedImpureDLLs = [ ]; + } + ); + + user32-dll = stdenv.mkDerivation { + name = "user32-dll"; + src = ./user32-dll; + outputs = [ + "out" + "dev" + ]; + allowedImpureDLLs = [ "USER32.dll" ]; + }; + + user32-exe = stdenv.mkDerivation { + name = "user32-exe"; + src = ./user32-exe; + buildInputs = [ user32-dll ]; + strictDeps = true; + doCheck = true; + }; + + link-dir-dll = exe.overrideAttrs { + name = "link-dir-dll"; + preFixup = '' + mkdir "$out"/libexec + ln -s ${lib.getLib user32-dll}/bin/cygpeek.dll "$out"/libexec/ + linkDLLsDir="$out"/bin linkDLLs "$out"/libexec/cygpeek.dll + ''; + }; + + link-dir-exe = exe.overrideAttrs { + name = "link-dir-exe"; + preFixup = '' + mkdir "$out"/libexec + ln -s ${lib.getLib user32-exe}/bin/{peek.exe,cygpeek.dll} "$out"/libexec/ + linkDLLsDir="$out"/bin linkDLLs "$out"/libexec/peek.exe + ''; + }; + + link-user32-dll = exe.overrideAttrs { + name = "link-user32-dll"; + preFixup = '' + ln -s ${lib.getLib user32-dll}/bin/cygpeek.dll "$out"/bin/ + ''; + }; + + copy-dll-impure = testers.testBuildFailure ( + user32-exe.overrideAttrs { + name = "copy-dll-impure"; + preFixup = '' + cp ${lib.getLib user32-dll}/bin/cygpeek.dll "$out"/bin/ + ''; + } + ); + + copy-dll = user32-exe.overrideAttrs { + name = "copy-dll"; + preFixup = '' + cp ${lib.getLib user32-dll}/bin/cygpeek.dll "$out"/bin/ + linkDLLs "$out"/bin/cygpeek.dll + ''; + allowedImpureDLLs = [ "USER32.dll" ]; + }; + + double-link = user32-exe.overrideAttrs { + name = "double-link"; + preFixup = ''linkDLLs "$out"''; + }; + + utf8-glob = runCommand "utf8-glob" { } '' + touch NetLock_Arany_=Class_Gold=_Főtanstvny:49412ce40010.crt + ls -l NetLock* > "$out" + ''; +} diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll/Makefile b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll/Makefile new file mode 100644 index 000000000000..25e1e53c38e4 --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll/Makefile @@ -0,0 +1,16 @@ +.PHONY: all install +all: cyghello.dll + +install: $(out)/bin/cyghello.dll $(out)/lib/libhello.dll.a $(out)/include/hello.h + +cyghello.dll libhello.dll.a: hello.c + $(CC) -o $@ $^ -shared -Wl,--out-implib,libhello.dll.a -Wl,--export-all-symbols -lhello2 + +$(out)/bin/cyghello.dll: cyghello.dll + install -m755 -D $< $@ + +$(out)/lib/libhello.dll.a: libhello.dll.a + install -m644 -D $< $@ + +$(out)/include/hello.h: hello.h + install -m644 -D $< $@ diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll/hello.c b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll/hello.c new file mode 100644 index 000000000000..db1a301c91a4 --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll/hello.c @@ -0,0 +1,7 @@ +#include "hello.h" +#include +#include + +void hello() { + hello2(); +} diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll/hello.h b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll/hello.h new file mode 100644 index 000000000000..a4a0b54c6052 --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll/hello.h @@ -0,0 +1,2 @@ +#pragma once +void hello(); diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll2/Makefile b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll2/Makefile new file mode 100644 index 000000000000..87c5c1a9b9cc --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll2/Makefile @@ -0,0 +1,16 @@ +.PHONY: all install +all: cyghello2.dll + +install: $(out)/bin/cyghello2.dll $(out)/lib/libhello2.dll.a $(out)/include/hello2.h + +cyghello2.dll libhello2.dll.a: hello2.c + $(CC) -o $@ $^ -shared -Wl,--out-implib,libhello2.dll.a -Wl,--export-all-symbols + +$(out)/bin/cyghello2.dll: cyghello2.dll + install -m755 -D $< $@ + +$(out)/lib/libhello2.dll.a: libhello2.dll.a + install -m644 -D $< $@ + +$(out)/include/hello2.h: hello2.h + install -m644 -D $< $@ diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll2/hello2.c b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll2/hello2.c new file mode 100644 index 000000000000..d23050fbb776 --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll2/hello2.c @@ -0,0 +1,6 @@ +#include +#include "hello2.h" + +void hello2() { + printf("Hello, World!\n"); +} diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll2/hello2.h b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll2/hello2.h new file mode 100644 index 000000000000..34e200a07e95 --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/dll2/hello2.h @@ -0,0 +1,2 @@ +#pragma once +void hello2(); diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/exe/Makefile b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/exe/Makefile new file mode 100644 index 000000000000..da16b5d08c79 --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/exe/Makefile @@ -0,0 +1,13 @@ +.PHONY: all check install +all: hello.exe + +install: $(out)/bin/hello.exe + +hello.exe: main.c + $(CC) -o $@ $^ -lhello + +check: hello.exe + ./hello.exe + +$(out)/bin/hello.exe: hello.exe + install -m755 -D $< $@ diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/exe/main.c b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/exe/main.c new file mode 100644 index 000000000000..9dbc882ea430 --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/exe/main.c @@ -0,0 +1,6 @@ +#include + +int main() { + hello(); + return 0; +} diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-dll/Makefile b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-dll/Makefile new file mode 100644 index 000000000000..483ad8854a06 --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-dll/Makefile @@ -0,0 +1,16 @@ +.PHONY: all install +all: cygpeek.dll + +install: $(out)/bin/cygpeek.dll $(out)/lib/libpeek.dll.a $(out)/include/peek.h + +cygpeek.dll libpeek.dll.a: peek.c + $(CC) -o $@ $^ -shared -Wl,--out-implib,libpeek.dll.a -Wl,--export-all-symbols + +$(out)/bin/cygpeek.dll: cygpeek.dll + install -m755 -D $< $@ + +$(out)/lib/libpeek.dll.a: libpeek.dll.a + install -m644 -D $< $@ + +$(out)/include/peek.h: peek.h + install -m644 -D $< $@ diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-dll/peek.c b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-dll/peek.c new file mode 100644 index 000000000000..715adb003c15 --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-dll/peek.c @@ -0,0 +1,7 @@ +#include + +int peek() +{ + MSG msg; + PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); +} diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-dll/peek.h b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-dll/peek.h new file mode 100644 index 000000000000..800f23f77da5 --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-dll/peek.h @@ -0,0 +1,2 @@ +#pragma once +void peek(); diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-exe/Makefile b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-exe/Makefile new file mode 100644 index 000000000000..231601818914 --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-exe/Makefile @@ -0,0 +1,13 @@ +.PHONY: all check install +all: peek.exe + +install: $(out)/bin/peek.exe + +peek.exe: main.c + $(CC) -o $@ $^ -lpeek + +check: peek.exe + ./peek.exe + +$(out)/bin/peek.exe: peek.exe + install -m755 -D $< $@ diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-exe/main.c b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-exe/main.c new file mode 100644 index 000000000000..cddc78c91cab --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32-exe/main.c @@ -0,0 +1,6 @@ +#include + +int main() { + peek(); + return 0; +} diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32/Makefile b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32/Makefile new file mode 100644 index 000000000000..6c696a2e8cd0 --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32/Makefile @@ -0,0 +1,13 @@ +.PHONY: all check install +all: hello.exe + +install: $(out)/bin/hello.exe + +hello.exe: main.c + $(CC) -o $@ $^ + +check: hello.exe + ./hello.exe + +$(out)/bin/hello.exe: hello.exe + install -m755 -D $< $@ diff --git a/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32/main.c b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32/main.c new file mode 100644 index 000000000000..9cc135770d21 --- /dev/null +++ b/pkgs/os-specific/cygwin/cygwin-dll-link-hook/tests/user32/main.c @@ -0,0 +1,7 @@ +#include + +int main() +{ + MSG msg; + PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); +}