保留日志文件以防测试套件成功
您可以指定一个在postCheck 运行测试套件后执行的shell 脚本。只有在测试套件成功时才会执行此操作。
使用或不使用--shell 调用cabal2nix 将在输出中包含类似的派生:
{ mkDerivation, base, stdenv }:
mkDerivation {
pname = "sample";
version = "0.0.0.1";
src = ./.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [ base ];
testHaskellDepends = [ base ];
license = stdenv.lib.licenses.unfree;
hydraPlatforms = stdenv.lib.platforms.none;
};
你要补充的是
postCheck = ''
mkdir -p $out/logs
find dist/test -name \*log -exec cp '{}' $out/logs \;
'';
您将在result/logs 中找到您的日志文件。
整个推导现在看起来像:
{ mkDerivation, base, stdenv }:
mkDerivation {
pname = "sample";
version = "0.0.0.1";
src = ./.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [ base ];
testHaskellDepends = [ base ];
license = stdenv.lib.licenses.unfree;
hydraPlatforms = stdenv.lib.platforms.none;
postCheck = ''
mkdir -p $out/logs
find dist/test -name \*log -exec cp '{}' $out/logs \;
'';
};
保留日志文件以防测试套件失败
如果您想查看这些日志文件以防测试套件失败,您可以使用选项--keep-failed 或-K 调用nix-build。这样它将保留临时构建目录并打印类似
的消息
note: keeping build directory '/tmp/nix-build-sample-0.0.0.1.drv-0'
接近其输出的末尾(对我来说是倒数第三行)。您将在该目录中找到日志文件。在我的
例如,它们被放置在
/tmp/nix-build-sample-0.0.0.1.drv-0/sample/dist/test