Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

buildRustCrate: Add tests for checking files in outputs.

...and remove superfluous dependency files (*.d).
...and copy dSYM directories on Mac OS when in release=false mode.

(cherry picked from commit 782b304dba903ca82763b152e0727187628a32b0)

authored by

Peter Kolloch and committed by
Andreas Rammhold
040f6116 32cbd89e

+133 -9
+2 -2
pkgs/build-support/rust/build-rust-crate/install-crate.nix
··· 14 14 fi 15 15 if [[ "$(ls -A target/lib)" ]]; then 16 16 mkdir -p $lib/lib 17 - cp target/lib/* $lib/lib #*/ 17 + cp -r target/lib/* $lib/lib #*/ 18 18 for library in $lib/lib/*.so $lib/lib/*.dylib; do #*/ 19 19 ln -s $library $(echo $library | sed -e "s/-${metadata}//") 20 20 done ··· 26 26 if [[ -d target/bin ]]; then 27 27 if [[ "$(ls -A target/bin)" ]]; then 28 28 mkdir -p $out/bin 29 - cp -P target/bin/* $out/bin # */ 29 + cp -rP target/bin/* $out/bin # */ 30 30 fi 31 31 fi 32 32 runHook postInstall
-2
pkgs/build-support/rust/build-rust-crate/lib.sh
··· 14 14 --crate-name $CRATE_NAME \ 15 15 $lib_src \ 16 16 --out-dir target/lib \ 17 - --emit=dep-info,link \ 18 17 -L dependency=target/deps \ 19 18 --cap-lints allow \ 20 19 $LIB_RUSTC_OPTS \ ··· 45 44 --crate-type bin \ 46 45 $BIN_RUSTC_OPTS \ 47 46 --out-dir target/bin \ 48 - --emit=dep-info,link \ 49 47 -L dependency=target/deps \ 50 48 $LINK \ 51 49 $EXTRA_LIB \
+131 -5
pkgs/build-support/rust/build-rust-crate/test/default.nix
··· 1 1 { lib 2 - , stdenv 3 2 , buildRustCrate 3 + , callPackage 4 + , releaseTools 4 5 , runCommand 5 6 , runCommandCC 7 + , stdenv 8 + , symlinkJoin 6 9 , writeTextFile 7 - , symlinkJoin 8 - , callPackage 9 - , releaseTools 10 10 }: 11 + 11 12 let 12 13 mkCrate = args: let 13 14 p = { ··· 102 103 ${lib.concatMapStringsSep "\n" (o: "grep '${o}' $out || { echo 'output \"${o}\" not found in:'; cat $out; exit 23; }") expectedTestOutputs} 103 104 '' 104 105 ); 106 + 107 + /* Returns a derivation that asserts that the crate specified by `crateArgs` 108 + has the specified files as output. 109 + 110 + `name` is used as part of the derivation name that performs the checking. 111 + 112 + `crateArgs` is passed to `mkCrate` to build the crate with `buildRustCrate`. 113 + 114 + `expectedFiles` contains a list of expected file paths in the output. E.g. 115 + `[ "./bin/my_binary" ]`. 116 + 117 + `output` specifies the name of the output to use. By default, the default 118 + output is used but e.g. `output = "lib";` will cause the lib output 119 + to be checked instead. You do not need to specify any directories. 120 + */ 121 + assertOutputs = { name, crateArgs, expectedFiles, output? null }: 122 + assert (builtins.isString name); 123 + assert (builtins.isAttrs crateArgs); 124 + assert (builtins.isList expectedFiles); 125 + 126 + let 127 + crate = mkCrate (builtins.removeAttrs crateArgs ["expectedTestOutput"]); 128 + crateOutput = if output == null then crate else crate."${output}"; 129 + expectedFilesFile = writeTextFile { 130 + name = "expected-files-${name}"; 131 + text = 132 + let sorted = builtins.sort (a: b: a<b) expectedFiles; 133 + concatenated = builtins.concatStringsSep "\n" sorted; 134 + in "${concatenated}\n"; 135 + }; 136 + in 137 + runCommand "assert-outputs-${name}" { 138 + } '' 139 + local actualFiles=$(mktemp) 140 + 141 + cd "${crateOutput}" 142 + find . -type f | sort >$actualFiles 143 + diff -q ${expectedFilesFile} $actualFiles >/dev/null || { 144 + echo -e "\033[0;1;31mERROR: Difference in expected output files in ${crateOutput} \033[0m" >&2 145 + echo === Got: 146 + sed -e 's/^/ /' $actualFiles 147 + echo === Expected: 148 + sed -e 's/^/ /' ${expectedFilesFile} 149 + echo === Diff: 150 + diff -u ${expectedFilesFile} $actualFiles |\ 151 + tail -n +3 |\ 152 + sed -e 's/^/ /' 153 + exit 1 154 + } 155 + touch $out 156 + '' 157 + ; 105 158 106 159 in rec { 107 160 ··· 361 414 }; 362 415 }; 363 416 brotliCrates = (callPackage ./brotli-crates.nix {}); 364 - in lib.mapAttrs (key: value: mkTest (value // lib.optionalAttrs (!value?crateName) { crateName = key; })) cases // { 417 + tests = lib.mapAttrs (key: value: mkTest (value // lib.optionalAttrs (!value?crateName) { crateName = key; })) cases; 418 + in tests // rec { 419 + 420 + crateBinWithPathOutputs = assertOutputs { 421 + name="crateBinWithPath"; 422 + crateArgs = { 423 + crateBin = [{ name = "test_binary1"; path = "src/foobar.rs"; }]; 424 + src = mkBin "src/foobar.rs"; 425 + }; 426 + expectedFiles = [ 427 + "./bin/test_binary1" 428 + ]; 429 + }; 430 + 431 + crateBinWithPathOutputsDebug = assertOutputs { 432 + name="crateBinWithPath"; 433 + crateArgs = { 434 + release = false; 435 + crateBin = [{ name = "test_binary1"; path = "src/foobar.rs"; }]; 436 + src = mkBin "src/foobar.rs"; 437 + }; 438 + expectedFiles = [ 439 + "./bin/test_binary1" 440 + ] ++ lib.optionals stdenv.isDarwin [ 441 + # On Darwin, the debug symbols are in a seperate directory. 442 + "./bin/test_binary1.dSYM/Contents/Info.plist" 443 + "./bin/test_binary1.dSYM/Contents/Resources/DWARF/test_binary1" 444 + ]; 445 + }; 446 + 447 + crateBinNoPath1Outputs = assertOutputs { 448 + name="crateBinNoPath1"; 449 + crateArgs = { 450 + crateBin = [{ name = "my-binary2"; }]; 451 + src = mkBin "src/my_binary2.rs"; 452 + }; 453 + expectedFiles = [ 454 + "./bin/my-binary2" 455 + ]; 456 + }; 457 + 458 + crateLibOutputs = assertOutputs { 459 + name="crateLib"; 460 + output="lib"; 461 + crateArgs = { 462 + libName = "test_lib"; 463 + type = [ "rlib" ]; 464 + libPath = "src/lib.rs"; 465 + src = mkLib "src/lib.rs"; 466 + }; 467 + expectedFiles = [ 468 + "./nix-support/propagated-build-inputs" 469 + "./lib/libtest_lib-042a1fdbef.rlib" 470 + "./lib/link" 471 + ]; 472 + }; 473 + 474 + crateLibOutputsDebug = assertOutputs { 475 + name="crateLib"; 476 + output="lib"; 477 + crateArgs = { 478 + release = false; 479 + libName = "test_lib"; 480 + type = [ "rlib" ]; 481 + libPath = "src/lib.rs"; 482 + src = mkLib "src/lib.rs"; 483 + }; 484 + expectedFiles = [ 485 + "./nix-support/propagated-build-inputs" 486 + "./lib/libtest_lib-042a1fdbef.rlib" 487 + "./lib/link" 488 + ]; 489 + }; 490 + 365 491 brotliTest = let 366 492 pkg = brotliCrates.brotli_2_5_0 {}; 367 493 in runCommand "run-brotli-test-cmd" {