@@ -1,71 +1,65 @@
1−{ language, buildInputs ? [], binaries ? [], setFlags ? false, pkgName ? language, versionArg ? "" }:
2−
3−{ lib, buildGoModule, fetchFromGitHub, bash, expect, pkg-config, runCommand, git, python3, copyPathToStore }:
4−
5−let
6− src = copyPathToStore ./.;
7− revision = runCommand "get-rev" {
8− nativeBuildInputs = [ git python3 ];
9− dummy = builtins.currentTime;
10− } ''
11− if [ -d ${src}/.git ]; then
12− cd ${src}
13− git rev-parse --short HEAD | tr -d '\n' > $out
14− else
15− echo ${versionArg} | tr -d '\n' > $out
16− fi
17− '';
18−in buildGoModule {
19− pname = "prybar-${language}";
20− version = builtins.readFile revision;
21−
22− inherit src;
23−
24− inherit buildInputs;
25− nativeBuildInputs = [ pkg-config ];
26−
27− subPackages = [ "languages/${language}" ];
28−
29− vendorSha256 = null;
30−
31− # This prebiuild hook will setup the compiler flags on demand based on the package
32− # If a language requires this, it MUST expost a ${pkgName}.pc file in its `lib/pkg-config`
33− # for pkg-config to detect it. Otherwise, we can't find the required flags.
34− preBuild = ''
35− export CGO_LDFLAGS_ALLOW="-Wl,--compress-debug-sections=zlib"
36− ${if setFlags then ''
37− export NIX_CFLAGS_COMPILE="$(pkg-config --cflags ${pkgName}) $NIX_CFLAGS_COMPILE"
38− export NIX_LDFLAGS="$(pkg-config --libs-only-L ${pkgName}) $(pkg-config --libs-only-l ${pkgName}) $NIX_LDFLAGS"
39− '' else ""}
40−
41− ${bash}/bin/bash ./scripts/inject.sh ${language}
42− go generate ./languages/${language}/main.go
43− '';
44−
45− # The test file expect the binary to be in the current directory rather than bin
46− preCheck = ''
47− cp $GOPATH/bin/${language} ./prybar-${language}
48− '';
49−
50− # Add all the dependencies to the check. Binaries should include the language interpreter/binaries
51− # for testing the language.
52− checkInputs = [ expect ] ++ buildInputs ++ binaries;
53−
54− # Run the end-to-end tests for this specific language
55− checkPhase = ''
56− runHook preCheck
57−
58− "${bash}/bin/bash" "./run_tests_language" "${language}" "${expect}/bin"
59−
60− runHook postCheck
61− '';
62−
63− # Delete the test binary we copied in the preCheck
64− postCheck = ''
65− rm -f ./prybar-${language}
66− '';
67−
68− postInstall = ''
69− mv $out/bin/${language} $out/bin/prybar-${language}
70− '';
1+{ language, buildInputs ? [ ], binaries ? [ ], setFlags ? false
2+, pkgName ? language }:
3+
4+{ lib, buildGoModule, fetchFromGitHub, bash, expect, pkg-config, runCommand, git
5+, python3, copyPathToStore, rev }:
6+
7+buildGoModule {
8+ pname = "prybar-${language}";
9+ version = rev;
10+
11+ src = ./.;
12+
13+ inherit buildInputs;
14+ nativeBuildInputs = [ pkg-config ];
15+
16+ subPackages = [ "languages/${language}" ];
17+
18+ vendorSha256 = null;
19+
20+ # This prebiuild hook will setup the compiler flags on demand based on the package
21+ # If a language requires this, it MUST expost a ${pkgName}.pc file in its `lib/pkg-config`
22+ # for pkg-config to detect it. Otherwise, we can't find the required flags.
23+ preBuild = ''
24+ export CGO_LDFLAGS_ALLOW="-Wl,--compress-debug-sections=zlib"
25+ ${if setFlags then ''
26+ export NIX_CFLAGS_COMPILE="$(pkg-config --cflags ${pkgName}) $NIX_CFLAGS_COMPILE"
27+ export NIX_LDFLAGS="$(pkg-config --libs-only-L ${pkgName}) $(pkg-config --libs-only-l ${pkgName}) $NIX_LDFLAGS"
28+ '' else
29+ ""}
30+
31+ ${bash}/bin/bash ./scripts/inject.sh ${language}
32+ go generate ./languages/${language}/main.go
33+ '';
34+
35+ # The test file expect the binary to be in the current directory rather than bin
36+ preCheck = ''
37+ cp $GOPATH/bin/${language} ./prybar-${language}
38+ '';
39+
40+ # Add all the dependencies to the check. Binaries should include the language interpreter/binaries
41+ # for testing the language.
42+ checkInputs = [ expect ] ++ buildInputs ++ binaries;
43+
44+ # Run the end-to-end tests for this specific language
45+ checkPhase = ''
46+ runHook preCheck
47+
48+ # Nix unsets HOME but some tests rely on it, let's set it to whatever tmp dir the check
49+ # is running in.
50+ export HOME=$(echo pwd)
51+
52+ "${bash}/bin/bash" "./run_tests_language" "${language}" "${expect}/bin"
53+
54+ runHook postCheck
55+ '';
56+
57+ # Delete the test binary we copied in the preCheck
58+ postCheck = ''
59+ rm -f ./prybar-${language}
60+ '';
61+
62+ postInstall = ''
63+ mv $out/bin/${language} $out/bin/prybar-${language}
64+ '';
7165}