diff options
author | mlatus <wqseleven@gmail.com> | 2023-05-07 01:17:14 -0700 |
---|---|---|
committer | Artturin <Artturin@artturin.com> | 2023-11-07 03:31:26 +0200 |
commit | 707a5c09db955f8435f26377df9a543a660035ed (patch) | |
tree | df512af297eb11732d9abc9b3b30a8c7392f124f /pkgs/stdenv | |
parent | 3e8e17821822ef190d72db3a612ea9be5a441ca9 (diff) | |
download | nixpkgs-707a5c09db955f8435f26377df9a543a660035ed.tar nixpkgs-707a5c09db955f8435f26377df9a543a660035ed.tar.gz nixpkgs-707a5c09db955f8435f26377df9a543a660035ed.tar.bz2 nixpkgs-707a5c09db955f8435f26377df9a543a660035ed.tar.lz nixpkgs-707a5c09db955f8435f26377df9a543a660035ed.tar.xz nixpkgs-707a5c09db955f8435f26377df9a543a660035ed.tar.zst nixpkgs-707a5c09db955f8435f26377df9a543a660035ed.zip |
stdenv: wrap phase running actions of genericBuild
Provide a `runPhase` function which wraps the phase running action of genericBuild. The new function can be used as an interface by `nix develop`, i.e. `nix develop some#flake --build` may just call `runPhase build`, which makes its behavior more consistent with `nix build`. In preparation of fixing https://github.com/NixOS/nix/issues/6202
Diffstat (limited to 'pkgs/stdenv')
-rw-r--r-- | pkgs/stdenv/generic/setup.sh | 72 |
1 files changed, 39 insertions, 33 deletions
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index ad9857fc9d6..aa2ff8578f4 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -1539,6 +1539,44 @@ showPhaseFooter() { } +runPhase() { + local curPhase="$*" + if [[ "$curPhase" = unpackPhase && -n "${dontUnpack:-}" ]]; then return; fi + if [[ "$curPhase" = patchPhase && -n "${dontPatch:-}" ]]; then return; fi + if [[ "$curPhase" = configurePhase && -n "${dontConfigure:-}" ]]; then return; fi + if [[ "$curPhase" = buildPhase && -n "${dontBuild:-}" ]]; then return; fi + if [[ "$curPhase" = checkPhase && -z "${doCheck:-}" ]]; then return; fi + if [[ "$curPhase" = installPhase && -n "${dontInstall:-}" ]]; then return; fi + if [[ "$curPhase" = fixupPhase && -n "${dontFixup:-}" ]]; then return; fi + if [[ "$curPhase" = installCheckPhase && -z "${doInstallCheck:-}" ]]; then return; fi + if [[ "$curPhase" = distPhase && -z "${doDist:-}" ]]; then return; fi + + if [[ -n $NIX_LOG_FD ]]; then + echo "@nix { \"action\": \"setPhase\", \"phase\": \"$curPhase\" }" >&"$NIX_LOG_FD" + fi + + showPhaseHeader "$curPhase" + dumpVars + + local startTime=$(date +"%s") + + # Evaluate the variable named $curPhase if it exists, otherwise the + # function named $curPhase. + eval "${!curPhase:-$curPhase}" + + local endTime=$(date +"%s") + + showPhaseFooter "$curPhase" "$startTime" "$endTime" + + if [ "$curPhase" = unpackPhase ]; then + # make sure we can cd into the directory + [ -n "${sourceRoot:-}" ] && chmod +x "${sourceRoot}" + + cd "${sourceRoot:-.}" + fi +} + + genericBuild() { # variable used by our gzip wrapper to add -n. # gzip is in common-path.nix and is added to nix-shell but we only want to change its behaviour in nix builds. do not move to a setupHook in gzip. @@ -1565,39 +1603,7 @@ genericBuild() { # phase name is space-free, which it must be because it's the name # of either a shell variable or a shell function. for curPhase in ${phases[*]}; do - if [[ "$curPhase" = unpackPhase && -n "${dontUnpack:-}" ]]; then continue; fi - if [[ "$curPhase" = patchPhase && -n "${dontPatch:-}" ]]; then continue; fi - if [[ "$curPhase" = configurePhase && -n "${dontConfigure:-}" ]]; then continue; fi - if [[ "$curPhase" = buildPhase && -n "${dontBuild:-}" ]]; then continue; fi - if [[ "$curPhase" = checkPhase && -z "${doCheck:-}" ]]; then continue; fi - if [[ "$curPhase" = installPhase && -n "${dontInstall:-}" ]]; then continue; fi - if [[ "$curPhase" = fixupPhase && -n "${dontFixup:-}" ]]; then continue; fi - if [[ "$curPhase" = installCheckPhase && -z "${doInstallCheck:-}" ]]; then continue; fi - if [[ "$curPhase" = distPhase && -z "${doDist:-}" ]]; then continue; fi - - if [[ -n $NIX_LOG_FD ]]; then - echo "@nix { \"action\": \"setPhase\", \"phase\": \"$curPhase\" }" >&"$NIX_LOG_FD" - fi - - showPhaseHeader "$curPhase" - dumpVars - - local startTime=$(date +"%s") - - # Evaluate the variable named $curPhase if it exists, otherwise the - # function named $curPhase. - eval "${!curPhase:-$curPhase}" - - local endTime=$(date +"%s") - - showPhaseFooter "$curPhase" "$startTime" "$endTime" - - if [ "$curPhase" = unpackPhase ]; then - # make sure we can cd into the directory - [ -n "${sourceRoot:-}" ] && chmod +x "${sourceRoot}" - - cd "${sourceRoot:-.}" - fi + runPhase "$curPhase" done } |