From ac980bb01de02bb97d075bc3c5e5ff7d32c2d834 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Thu, 27 Apr 2023 14:32:04 -0700 Subject: [PATCH] gcc: flatten nested conditionals in libgcc.nix This commit improves readability in libgcc.nix by flattening the conditionals. This commit has no effect on eval except that when `langC && !enableLibGccOutput` the empty string will be added as a `preFixupLibGccPhase`. This will cause a global rebuild on Darwin as well as all pkgsCross stdenvs, but improve maintainability and readability going forward. --- pkgs/development/compilers/gcc/common/libgcc.nix | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkgs/development/compilers/gcc/common/libgcc.nix b/pkgs/development/compilers/gcc/common/libgcc.nix index 312525dcf88ff..7c18098a88bde 100644 --- a/pkgs/development/compilers/gcc/common/libgcc.nix +++ b/pkgs/development/compilers/gcc/common/libgcc.nix @@ -8,11 +8,11 @@ let enableLibGccOutput = (with stdenv; targetPlatform == hostPlatform) && !langJit && !stdenv.hostPlatform.isDarwin; in -(pkg: pkg.overrideAttrs (previousAttrs: lib.optionalAttrs ((!langC) || langJit || enableLibGccOutput) { +(pkg: pkg.overrideAttrs (previousAttrs: { outputs = previousAttrs.outputs ++ lib.optionals enableLibGccOutput [ "libgcc" ]; # This is a separate phase because gcc assembles its phase scripts # in bash instead of nix (we should fix that). - preFixupPhases = (previousAttrs.preFixupPhases or []) ++ lib.optionals ((!langC) || enableLibGccOutput) [ "preFixupLibGccPhase" ]; + preFixupPhases = (previousAttrs.preFixupPhases or []) ++ [ "preFixupLibGccPhase" ]; preFixupLibGccPhase = # delete extra/unused builds of libgcc_s in non-langC builds # (i.e. libgccjit, gnat, etc) to avoid potential confusion @@ -28,7 +28,7 @@ in # - https://github.com/NixOS/nixpkgs/commit/404155c6acfa59456aebe6156b22fe385e7dec6f # # move `libgcc_s.so` into its own output, `$libgcc` - + lib.optionalString enableLibGccOutput ('' + + lib.optionalString enableLibGccOutput '' # move libgcc from lib to its own output (libgcc) mkdir -p $libgcc/lib mv $lib/lib/libgcc_s.so $libgcc/lib/ @@ -90,7 +90,11 @@ in # bootstrap-files). Copying `libgcc_s.so.1` from one outpath to # another eliminates the ability to make these queries. # - + '' + + lib.optionalString enableLibGccOutput '' patchelf --set-rpath "" $libgcc/lib/libgcc_s.so.1 - ''); + '' + # no-op, to prevent the empty string from being removed from the environment. + + '' + true + ''; }))