diff options
author | Robert Hensing <roberth@users.noreply.github.com> | 2021-05-17 15:44:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-17 15:44:10 +0200 |
commit | ea0c94f50d2f1b901ef1434eac2dc31c241ffa9a (patch) | |
tree | 8298ae729a4fc1ec76d381198dfb3b6b6e24a5a7 /pkgs/build-support | |
parent | d26bd805a2d568362af4f2e7134cfd617f11d5c1 (diff) | |
parent | ed4523186e452d185d8ba1d1eabe07ace33a4f87 (diff) | |
download | nixlib-ea0c94f50d2f1b901ef1434eac2dc31c241ffa9a.tar nixlib-ea0c94f50d2f1b901ef1434eac2dc31c241ffa9a.tar.gz nixlib-ea0c94f50d2f1b901ef1434eac2dc31c241ffa9a.tar.bz2 nixlib-ea0c94f50d2f1b901ef1434eac2dc31c241ffa9a.tar.lz nixlib-ea0c94f50d2f1b901ef1434eac2dc31c241ffa9a.tar.xz nixlib-ea0c94f50d2f1b901ef1434eac2dc31c241ffa9a.tar.zst nixlib-ea0c94f50d2f1b901ef1434eac2dc31c241ffa9a.zip |
Merge pull request #123111 from hercules-ci/writeDirectReferencesToFile
writeDirectReferencesToFile and maintenance
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/trivial-builders.nix | 29 | ||||
-rw-r--r-- | pkgs/build-support/trivial-builders/test.nix | 20 | ||||
-rwxr-xr-x | pkgs/build-support/trivial-builders/test.sh | 57 |
3 files changed, 106 insertions, 0 deletions
diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix index 142a04f9a10c..0bf67d21b3be 100644 --- a/pkgs/build-support/trivial-builders.nix +++ b/pkgs/build-support/trivial-builders.nix @@ -438,6 +438,35 @@ rec { done < graph ''; + /* + Write the set of references to a file, that is, their immediate dependencies. + + This produces the equivalent of `nix-store -q --references`. + */ + writeDirectReferencesToFile = path: runCommand "runtime-references" + { + exportReferencesGraph = ["graph" path]; + inherit path; + } + '' + touch ./references + while read p; do + read dummy + read nrRefs + if [[ $p == $path ]]; then + for ((i = 0; i < nrRefs; i++)); do + read ref; + echo $ref >>./references + done + else + for ((i = 0; i < nrRefs; i++)); do + read ref; + done + fi + done < graph + sort ./references >$out + ''; + /* Print an error message if the file with the specified name and * hash doesn't exist in the Nix store. This function should only diff --git a/pkgs/build-support/trivial-builders/test.nix b/pkgs/build-support/trivial-builders/test.nix new file mode 100644 index 000000000000..0902a5372221 --- /dev/null +++ b/pkgs/build-support/trivial-builders/test.nix @@ -0,0 +1,20 @@ +{ lib, nixosTest, path, writeText, hello, figlet, stdenvNoCC }: + +nixosTest { + name = "nixpkgs-trivial-builders"; + nodes.machine = { ... }: { + virtualisation.writableStore = true; + + # Test runs without network, so we don't substitute and prepare our deps + nix.binaryCaches = lib.mkForce []; + environment.etc."pre-built-paths".source = writeText "pre-built-paths" ( + builtins.toJSON [hello figlet stdenvNoCC] + ); + }; + testScript = '' + machine.succeed(""" + cd ${lib.cleanSource path} + ./pkgs/build-support/trivial-builders/test.sh 2>/dev/console + """) + ''; +} diff --git a/pkgs/build-support/trivial-builders/test.sh b/pkgs/build-support/trivial-builders/test.sh new file mode 100755 index 000000000000..3e21b0008155 --- /dev/null +++ b/pkgs/build-support/trivial-builders/test.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +# -------------------------------------------------------------------------- # +# +# trivial-builders test +# +# -------------------------------------------------------------------------- # +# +# This file can be run independently (quick): +# +# $ pkgs/build-support/trivial-builders/test.sh +# +# or in the build sandbox with a ~20s VM overhead +# +# $ nix-build -A tests.trivial-builders +# +# -------------------------------------------------------------------------- # + +# strict bash +set -euo pipefail + +# debug +# set -x +# PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' + +cd "$(dirname ${BASH_SOURCE[0]})" # nixpkgs root + +testDirectReferences() { + expr="$1" + diff -U3 \ + <(sort <$(nix-build --no-out-link --expr "with import ../../.. {}; writeDirectReferencesToFile ($expr)")) \ + <(nix-store -q --references $(nix-build --no-out-link --expr "with import ../../.. {}; ($expr)") | sort) +} + +testDirectReferences 'hello' +testDirectReferences 'figlet' +testDirectReferences 'writeText "hi" "hello"' +testDirectReferences 'writeText "hi" "hello ${hello}"' +testDirectReferences 'writeText "hi" "hello ${hello} ${figlet}"' + + + +testClosure() { + expr="$1" + diff -U3 \ + <(sort <$(nix-build --no-out-link --expr "with import ../../.. {}; writeReferencesToFile ($expr)")) \ + <(nix-store -q --requisites $(nix-build --no-out-link --expr "with import ../../.. {}; ($expr)") | sort) +} + +testClosure 'hello' +testClosure 'figlet' +testClosure 'writeText "hi" "hello"' +testClosure 'writeText "hi" "hello ${hello}"' +testClosure 'writeText "hi" "hello ${hello} ${figlet}"' + + +echo 'OK!' |