about summary refs log tree commit diff
path: root/users/fogti/store-ref-scanner/default.nix
blob: 38f3fd64ecd70644599346d423bd327e35fc7afc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{ depot, lib, pkgs, ... }:

let
  sourceFilter = name: type:
    let
      baseName = builtins.baseNameOf (builtins.toString name);
    in
    (baseName == "Cargo.toml")
    || (type == "directory" && baseName == "src")
    || (lib.hasSuffix ".rs" baseName)
  ;
in

pkgs.buildRustCrate rec {
  pname = "store-ref-scanner";
  crateName = "store-ref-scanner";
  version = "0.1.0";
  edition = "2021";
  src = lib.cleanSourceWith { filter = sourceFilter; src = ./.; };

  passthru.tests = pkgs.buildRustCrate {
    pname = "store-ref-scanner-tests";
    inherit crateName src version edition;
    buildTests = true;
    postInstall = ''
      set -ex
      export RUST_BACKTRACE=1
      # recreate a file hierarchy as when running tests with cargo
      # the source for test data
      # build outputs
      testRoot=target/debug
      mkdir -p $testRoot
      chmod +w -R .
      # test harness executables are suffixed with a hash,
      # like cargo does this allows to prevent name collision
      # with the main executables of the crate
      hash=$(basename $out)
      ls -lasR $out
      for file in $out/tests/*; do
        f=$testRoot/$(basename $file)-$hash
        cp $file $f
        $f 2>&1 | tee -a $out/tests.log
      done
      rm -rf $out/tests
      set +ex
    '';
  };

}