1{
2 lib,
3 buildPythonPackage,
4 callPackage,
5 fetchFromGitHub,
6 runCommandLocal,
7 # Build inputs
8 gfal2-python,
9 # For tests
10 xrootd, # pkgs.xrootd
11}:
12(buildPythonPackage rec {
13 pname = "gfal2-util";
14 version = "1.8.1";
15 src = fetchFromGitHub {
16 owner = "cern-fts";
17 repo = "gfal2-util";
18 rev = "v${version}";
19 hash = "sha256-3JbJgKD17aYkrB/aaww7IQU8fLFrTCh868KWlLPxmlk=";
20 };
21
22 # Replace the ad-hoc python executable finding
23 # and change the shebangs from `#!/bin/sh` to `#!/usr/bin/env python`
24 # for fixup phase to work correctly.
25 postPatch = ''
26 for script in src/gfal-*; do
27 patch "$script" ${./gfal-util-script.patch}
28 done
29 '';
30
31 propagatedBuildInputs = [ gfal2-python ];
32
33 pythonImportsCheck = [ "gfal2_util" ];
34
35 meta = with lib; {
36 description = "CLI for gfal2";
37 homepage = "https://github.com/cern-fts/gfal2-utils";
38 license = licenses.asl20;
39 maintainers = with maintainers; [ ShamrockLee ];
40 };
41}).overrideAttrs
42 (
43 finalAttrs: previousAttrs:
44 lib.recursiveUpdate previousAttrs {
45 passthru = {
46 inherit (gfal2-python) gfal2;
47
48 fetchGfal2 = lib.makeOverridable (
49 callPackage ./fetchgfal2.nix { gfal2-util = finalAttrs.finalPackage; }
50 );
51
52 # With these functionality tests, it should be safe to merge version bumps once all the tests are passed.
53 tests =
54 let
55 # Use the the bin output hash of gfal2-util as version to ensure that
56 # the test gets rebuild everytime gfal2-util gets rebuild
57 versionFODTests =
58 finalAttrs.version + "-" + lib.substring (lib.stringLength builtins.storeDir + 1) 32 "${self}";
59 self = finalAttrs.finalPackage;
60 in
61 lib.optionalAttrs gfal2-python.gfal2.enablePluginStatus.xrootd (
62 let
63 # Test against a real-world dataset from CERN Open Data
64 # borrowed from `xrootd.tests`.
65 urlTestFile = xrootd.tests.test-xrdcp.url;
66 hashTestFile = xrootd.tests.test-xrdcp.outputHash;
67 urlTestDir = dirOf urlTestFile;
68 in
69 {
70 test-copy-file-xrootd = finalAttrs.passthru.fetchGfal2 {
71 url = urlTestFile;
72 hash = hashTestFile;
73 extraGfalCopyFlags = [ "--verbose" ];
74 pname = "gfal2-util-test-copy-file-xrootd";
75 version = versionFODTests;
76 allowSubstitutes = false;
77 };
78
79 test-copy-dir-xrootd = finalAttrs.passthru.fetchGfal2 {
80 url = urlTestDir;
81 hash = "sha256-vOahIhvx1oE9sfkqANMGUvGeLHS737wyfYWo4rkvrxw=";
82 recursive = true;
83 extraGfalCopyFlags = [ "--verbose" ];
84 pname = "gfal2-util-test-copy-dir-xrootd";
85 version = versionFODTests;
86 allowSubstitutes = false;
87 };
88
89 test-ls-dir-xrootd =
90 (runCommandLocal "test-gfal2-util-ls-dir-xrootd" { } ''
91 set -eu -o pipefail
92 gfal-ls "$url" | grep "$baseNameExpected" | tee "$out"
93 '').overrideAttrs
94 (
95 finalAttrs: previousAttrs: {
96 pname = previousAttrs.name;
97 version = versionFODTests;
98 name = "${finalAttrs.pname}-${finalAttrs.version}";
99 nativeBuildInputs = [ self ];
100 url = urlTestDir;
101 baseNameExpected = baseNameOf urlTestFile;
102 outputHashMode = "flat";
103 outputHashAlgo = "sha256";
104 outputHash = builtins.hashString finalAttrs.outputHashAlgo (finalAttrs.baseNameExpected + "\n");
105 }
106 );
107 }
108 );
109 };
110 }
111 )