@@ -1,71 +1,61 @@
1−{ language, buildInputs ? [], binaries ? [], setFlags ? false, pkgName ? language, versionArg ? "" }:
1+{ language, buildInputs ? [ ], binaries ? [ ], setFlags ? false
2+, pkgName ? language }:
23
3−{ lib, buildGoModule, fetchFromGitHub, bash, expect, pkg-config, runCommand, git, python3, copyPathToStore }:
4+{ lib, buildGoModule, fetchFromGitHub, bash, expect, pkg-config, runCommand, git
5+, python3, copyPathToStore, rev }:
46
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;
7+buildGoModule {
8+ pname = "prybar-${language}";
9+ version = rev;
2110
22− inherit src;
11+ src = ./.;
2312
24− inherit buildInputs;
25− nativeBuildInputs = [ pkg-config ];
13+ inherit buildInputs;
14+ nativeBuildInputs = [ pkg-config ];
2615
27− subPackages = [ "languages/${language}" ];
16+ subPackages = [ "languages/${language}" ];
2817
29− vendorSha256 = null;
18+ vendorSha256 = null;
3019
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 ""}
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+ ""}
4030
41− ${bash}/bin/bash ./scripts/inject.sh ${language}
42− go generate ./languages/${language}/main.go
43− '';
31+ ${bash}/bin/bash ./scripts/inject.sh ${language}
32+ go generate ./languages/${language}/main.go
33+ '';
4434
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− '';
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+ '';
4939
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;
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;
5343
54− # Run the end-to-end tests for this specific language
55− checkPhase = ''
56− runHook preCheck
44+ # Run the end-to-end tests for this specific language
45+ checkPhase = ''
46+ runHook preCheck
5747
58− "${bash}/bin/bash" "./run_tests_language" "${language}" "${expect}/bin"
48+ "${bash}/bin/bash" "./run_tests_language" "${language}" "${expect}/bin"
5949
60− runHook postCheck
61− '';
50+ runHook postCheck
51+ '';
6252
63− # Delete the test binary we copied in the preCheck
64− postCheck = ''
65− rm -f ./prybar-${language}
66− '';
53+ # Delete the test binary we copied in the preCheck
54+ postCheck = ''
55+ rm -f ./prybar-${language}
56+ '';
6757
68− postInstall = ''
69− mv $out/bin/${language} $out/bin/prybar-${language}
70− '';
58+ postInstall = ''
59+ mv $out/bin/${language} $out/bin/prybar-${language}
60+ '';
7161}