From 2110c0bd3009279ceec291f07bfbf063cb5ba6a0 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 7 May 2018 13:07:19 -0400 Subject: [PATCH] treewide: Use pkgs/build-support/roles.bash to remove copy pasta Also fix some setup hooks that unnecessarily used environment hooks, which revolted in the same variable being modified too many times. --- .../bintools-wrapper/default.nix | 7 +- .../bintools-wrapper/setup-hook.sh | 38 ++-------- pkgs/build-support/cc-wrapper/default.nix | 7 +- pkgs/build-support/cc-wrapper/setup-hook.sh | 49 ++---------- pkgs/build-support/setup-hooks/role.bash | 75 +++++++++++++++++++ .../compilers/gcc/libstdc++-hook.sh | 16 +--- .../compilers/llvm/3.5/libc++/default.nix | 5 +- .../compilers/llvm/3.5/libc++/setup-hook.sh | 16 +--- .../compilers/llvm/3.7/libc++/default.nix | 5 +- .../compilers/llvm/3.7/libc++/setup-hook.sh | 16 +--- .../compilers/llvm/3.8/libc++/default.nix | 5 +- .../compilers/llvm/3.8/libc++/setup-hook.sh | 16 +--- .../compilers/llvm/3.9/libc++/default.nix | 5 +- .../compilers/llvm/3.9/libc++/setup-hook.sh | 16 +--- .../compilers/llvm/4/libc++/default.nix | 5 +- .../compilers/llvm/4/libc++/setup-hook.sh | 16 +--- .../compilers/llvm/5/libc++/default.nix | 5 +- .../compilers/llvm/5/libc++/setup-hook.sh | 16 +--- .../compilers/llvm/6/libc++/default.nix | 5 +- .../compilers/llvm/6/libc++/setup-hook.sh | 16 +--- .../development/libraries/gettext/default.nix | 5 +- .../libraries/gettext/gettext-setup-hook.sh | 23 ++---- .../libraries/libiconv/default.nix | 5 +- .../libraries/libiconv/setup-hook.sh | 18 +---- .../bsd/netbsd/compat-setup-hook.sh | 22 ++---- pkgs/os-specific/bsd/netbsd/default.nix | 10 ++- pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh | 18 +---- pkgs/os-specific/linux/musl/fts-setup-hook.sh | 19 +---- pkgs/os-specific/linux/musl/fts.nix | 5 +- 29 files changed, 203 insertions(+), 261 deletions(-) create mode 100644 pkgs/build-support/setup-hooks/role.bash diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 47301bbdde69e..c0aea2d113123 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -190,7 +190,12 @@ stdenv.mkDerivation { depsTargetTargetPropagated = extraPackages; - setupHook = ./setup-hook.sh; + wrapperName = "BINTOOLS_WRAPPER"; + + setupHooks = [ + ../setup-hooks/role.bash + ./setup-hook.sh + ]; postFixup = '' diff --git a/pkgs/build-support/bintools-wrapper/setup-hook.sh b/pkgs/build-support/bintools-wrapper/setup-hook.sh index 48a00b0b9b074..dbe0a0572a48b 100644 --- a/pkgs/build-support/bintools-wrapper/setup-hook.sh +++ b/pkgs/build-support/bintools-wrapper/setup-hook.sh @@ -11,44 +11,22 @@ set -u [[ -z ${crossConfig-} ]] || (( "$hostOffset" < 0 )) || return 0 bintoolsWrapper_addLDVars () { - case $depHostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "bintools-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; - return 1 ;; - esac + # See ../setup-hooks/role.bash + local role_post role_pre + getTargetRoleEnvHook if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then - export NIX_${role}LDFLAGS+=" -L$1/lib64" + export NIX_${role_pre}LDFLAGS+=" -L$1/lib64" fi if [[ -d "$1/lib" ]]; then - export NIX_${role}LDFLAGS+=" -L$1/lib" + export NIX_${role_pre}LDFLAGS+=" -L$1/lib" fi } -case $targetOffset in - -1) - export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_BUILD=1 - role_pre='BUILD_' - role_post='_FOR_BUILD' - ;; - 0) - export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_HOST=1 - role_pre='' - role_post='' - ;; - 1) - export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_TARGET=1 - role_pre='TARGET_' - role_post='_FOR_TARGET' - ;; - *) - echo "cc-wrapper: used as improper sort of dependency" >2; - return 1 - ;; -esac +# See ../setup-hooks/role.bash +getTargetRole +getTargetRoleWrapper addEnvHooks "$targetOffset" bintoolsWrapper_addLDVars diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 43cd87fb45976..0ea9dd0cb9f4b 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -191,7 +191,12 @@ stdenv.mkDerivation { propagatedBuildInputs = [ bintools ]; depsTargetTargetPropagated = extraPackages; - setupHook = ./setup-hook.sh; + wrapperName = "CC_WRAPPER"; + + setupHooks = [ + ../setup-hooks/role.bash + ./setup-hook.sh + ]; postFixup = '' diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh index 29a7306b9b7e9..17d34c1e1f1be 100644 --- a/pkgs/build-support/cc-wrapper/setup-hook.sh +++ b/pkgs/build-support/cc-wrapper/setup-hook.sh @@ -66,55 +66,22 @@ set -u # over no state, and there's no @-substitutions within, so any redefined # function is guaranteed to be exactly the same. ccWrapper_addCVars () { - # The `depHostOffset` describes how the host platform of the dependencies - # are slid relative to the depending package. It is brought into scope of - # the environment hook defined as the role of the dependency being applied. - case $depHostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; - return 1 ;; - esac + # See ../setup-hooks/role.bash + local role_post role_pre + getTargetRoleEnvHook if [[ -d "$1/include" ]]; then - export NIX_${role}CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include" + export NIX_${role_pre}CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include" fi if [[ -d "$1/Library/Frameworks" ]]; then - export NIX_${role}CFLAGS_COMPILE+=" -F$1/Library/Frameworks" + export NIX_${role_pre}CFLAGS_COMPILE+=" -F$1/Library/Frameworks" fi } -# Since the same cc-wrapper derivation can be depend on in multiple ways, we -# need to accumulate *each* role (i.e. target platform relative the depending -# derivation) in which the cc-wrapper derivation is used. -# `NIX_CC_WRAPPER_@infixSalt@_TARGET_*` tracks this (needs to be an exported env -# var so can't use fancier data structures). -# -# We also need to worry about what role is being added on *this* invocation of -# setup-hook, which `role` tracks. -case $targetOffset in - -1) - export NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD=1 - role_pre='BUILD_' - role_post='_FOR_BUILD' - ;; - 0) - export NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST=1 - role_pre='' - role_post='' - ;; - 1) - export NIX_CC_WRAPPER_@infixSalt@_TARGET_TARGET=1 - role_pre='TARGET_' - role_post='_FOR_TARGET' - ;; - *) - echo "cc-wrapper: used as improper sort of dependency" >2; - return 1 - ;; -esac +# See ../setup-hooks/role.bash +getTargetRole +getTargetRoleWrapper # We use the `targetOffset` to choose the right env hook to accumulate the right # sort of deps (those with that offset). diff --git a/pkgs/build-support/setup-hooks/role.bash b/pkgs/build-support/setup-hooks/role.bash new file mode 100644 index 0000000000000..6f1c36f5c050d --- /dev/null +++ b/pkgs/build-support/setup-hooks/role.bash @@ -0,0 +1,75 @@ +# Since the same derivation can be depend on in multiple ways, we need to +# accumulate *each* role (i.e. host and target platforms relative the depending +# derivation) in which the derivation is used. +# +# The role is intened to be use as part of other variables names like +# - $NIX_${role_pre}_SOMETHING +# - $NIX_SOMETHING_${role_post} + +function getRole() { + case $1 in + -1) + role_pre='BUILD_' + role_post='_FOR_BUILD' + ;; + 0) + role_pre='' + role_post='' + ;; + 1) + role_pre='TARGET_' + role_post='_FOR_TARGET' + ;; + *) + echo "@name@: used as improper sort of dependency" >2 + return 1 + ;; + esac +} + +# `hostOffset` describes how the host platform of the package is slid relative +# to the depending package. `targetOffset` likewise describes the target +# platform of the package. Both are brought into scope of the setup hook defined +# for dependency whose setup hook is being processed relative to the package +# being built. + +function getHostRole() { + getRole "$hostOffset" +} +function getTargetRole() { + getRole "$targetOffset" +} + +# `depHostOffset` describes how the host platform of the dependencies are slid +# relative to the depending package. `depTargetOffset` likewise describes the +# target platform of dependenices. Both are brought into scope of the +# environment hook defined for the dependency being applied relative to the +# package being built. + +function getHostRoleEnvHook() { + getRole "$depHostOffset" +} +function getTargetRoleEnvHook() { + getRole "$depTargetOffset" +} + +# This variant is inteneded specifically for code-prodocing tool wrapper scripts +# `NIX_@wrapperName@_@infixSalt@_TARGET_*` tracks this (needs to be an exported +# env var so can't use fancier data structures). +function getTargetRoleWrapper() { + case $targetOffset in + -1) + export NIX_@wrapperName@_@infixSalt@_TARGET_BUILD=1 + ;; + 0) + export NIX_@wrapperName@_@infixSalt@_TARGET_HOST=1 + ;; + 1) + export NIX_@wrapperName@_@infixSalt@_TARGET_TARGET=1 + ;; + *) + echo "@name@: used as improper sort of dependency" >2 + return 1 + ;; + esac +} diff --git a/pkgs/development/compilers/gcc/libstdc++-hook.sh b/pkgs/development/compilers/gcc/libstdc++-hook.sh index 2325eeb9e2cfa..8b1d5d2da6782 100644 --- a/pkgs/development/compilers/gcc/libstdc++-hook.sh +++ b/pkgs/development/compilers/gcc/libstdc++-hook.sh @@ -1,13 +1,5 @@ -# The `hostOffset` describes how the host platform of the dependencies are slid -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem $(echo -n @gcc@/include/c++/*) -isystem $(echo -n @gcc@/include/c++/*)/$(@gcc@/bin/gcc -dumpmachine)" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libstdc++" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem $(echo -n @gcc@/include/c++/*) -isystem $(echo -n @gcc@/include/c++/*)/$(@gcc@/bin/gcc -dumpmachine)" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libstdc++" diff --git a/pkgs/development/compilers/llvm/3.5/libc++/default.nix b/pkgs/development/compilers/llvm/3.5/libc++/default.nix index 1f1129f578f47..6edd5e9798c78 100644 --- a/pkgs/development/compilers/llvm/3.5/libc++/default.nix +++ b/pkgs/development/compilers/llvm/3.5/libc++/default.nix @@ -39,7 +39,10 @@ stdenv.mkDerivation rec { linkCxxAbi = stdenv.isLinux; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; meta = { homepage = http://libcxx.llvm.org/; diff --git a/pkgs/development/compilers/llvm/3.5/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/3.5/libc++/setup-hook.sh index e18733b5ea3a5..6611259165ae2 100644 --- a/pkgs/development/compilers/llvm/3.5/libc++/setup-hook.sh +++ b/pkgs/development/compilers/llvm/3.5/libc++/setup-hook.sh @@ -1,14 +1,6 @@ -# The `hostOffset` describes how the host platform of the dependencies are slid -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole linkCxxAbi="@linkCxxAbi@" -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" diff --git a/pkgs/development/compilers/llvm/3.7/libc++/default.nix b/pkgs/development/compilers/llvm/3.7/libc++/default.nix index 4296c0fd192c3..462e35a483f4e 100644 --- a/pkgs/development/compilers/llvm/3.7/libc++/default.nix +++ b/pkgs/development/compilers/llvm/3.7/libc++/default.nix @@ -33,7 +33,10 @@ stdenv.mkDerivation rec { linkCxxAbi = stdenv.isLinux; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; meta = { homepage = http://libcxx.llvm.org/; diff --git a/pkgs/development/compilers/llvm/3.7/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/3.7/libc++/setup-hook.sh index e18733b5ea3a5..6611259165ae2 100644 --- a/pkgs/development/compilers/llvm/3.7/libc++/setup-hook.sh +++ b/pkgs/development/compilers/llvm/3.7/libc++/setup-hook.sh @@ -1,14 +1,6 @@ -# The `hostOffset` describes how the host platform of the dependencies are slid -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole linkCxxAbi="@linkCxxAbi@" -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" diff --git a/pkgs/development/compilers/llvm/3.8/libc++/default.nix b/pkgs/development/compilers/llvm/3.8/libc++/default.nix index ea468b3772e0f..cc3f5545146cf 100644 --- a/pkgs/development/compilers/llvm/3.8/libc++/default.nix +++ b/pkgs/development/compilers/llvm/3.8/libc++/default.nix @@ -31,7 +31,10 @@ stdenv.mkDerivation rec { linkCxxAbi = stdenv.isLinux; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; meta = { homepage = http://libcxx.llvm.org/; diff --git a/pkgs/development/compilers/llvm/3.8/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/3.8/libc++/setup-hook.sh index bcd93cf486fff..6611259165ae2 100644 --- a/pkgs/development/compilers/llvm/3.8/libc++/setup-hook.sh +++ b/pkgs/development/compilers/llvm/3.8/libc++/setup-hook.sh @@ -1,14 +1,6 @@ -# The `hostOffset` describes how the host platform of the dependencies -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole linkCxxAbi="@linkCxxAbi@" -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" diff --git a/pkgs/development/compilers/llvm/3.9/libc++/default.nix b/pkgs/development/compilers/llvm/3.9/libc++/default.nix index ad514b0daa546..7e5c30bdfd359 100644 --- a/pkgs/development/compilers/llvm/3.9/libc++/default.nix +++ b/pkgs/development/compilers/llvm/3.9/libc++/default.nix @@ -31,7 +31,10 @@ stdenv.mkDerivation rec { linkCxxAbi = stdenv.isLinux; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; meta = { homepage = http://libcxx.llvm.org/; diff --git a/pkgs/development/compilers/llvm/3.9/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/3.9/libc++/setup-hook.sh index bcd93cf486fff..6611259165ae2 100644 --- a/pkgs/development/compilers/llvm/3.9/libc++/setup-hook.sh +++ b/pkgs/development/compilers/llvm/3.9/libc++/setup-hook.sh @@ -1,14 +1,6 @@ -# The `hostOffset` describes how the host platform of the dependencies -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole linkCxxAbi="@linkCxxAbi@" -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" diff --git a/pkgs/development/compilers/llvm/4/libc++/default.nix b/pkgs/development/compilers/llvm/4/libc++/default.nix index f28957c351856..718abc420a971 100644 --- a/pkgs/development/compilers/llvm/4/libc++/default.nix +++ b/pkgs/development/compilers/llvm/4/libc++/default.nix @@ -44,7 +44,10 @@ stdenv.mkDerivation rec { linkCxxAbi = stdenv.isLinux; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; meta = { homepage = http://libcxx.llvm.org/; diff --git a/pkgs/development/compilers/llvm/4/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/4/libc++/setup-hook.sh index bcd93cf486fff..6611259165ae2 100644 --- a/pkgs/development/compilers/llvm/4/libc++/setup-hook.sh +++ b/pkgs/development/compilers/llvm/4/libc++/setup-hook.sh @@ -1,14 +1,6 @@ -# The `hostOffset` describes how the host platform of the dependencies -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole linkCxxAbi="@linkCxxAbi@" -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" diff --git a/pkgs/development/compilers/llvm/5/libc++/default.nix b/pkgs/development/compilers/llvm/5/libc++/default.nix index 9ddeea7ef79a6..cb6dfe2808eb3 100644 --- a/pkgs/development/compilers/llvm/5/libc++/default.nix +++ b/pkgs/development/compilers/llvm/5/libc++/default.nix @@ -40,7 +40,10 @@ stdenv.mkDerivation rec { linkCxxAbi = stdenv.isLinux; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; meta = { homepage = http://libcxx.llvm.org/; diff --git a/pkgs/development/compilers/llvm/5/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/5/libc++/setup-hook.sh index bcd93cf486fff..6611259165ae2 100644 --- a/pkgs/development/compilers/llvm/5/libc++/setup-hook.sh +++ b/pkgs/development/compilers/llvm/5/libc++/setup-hook.sh @@ -1,14 +1,6 @@ -# The `hostOffset` describes how the host platform of the dependencies -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole linkCxxAbi="@linkCxxAbi@" -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" diff --git a/pkgs/development/compilers/llvm/6/libc++/default.nix b/pkgs/development/compilers/llvm/6/libc++/default.nix index 3c6c009a58fac..27d8cd18b6660 100644 --- a/pkgs/development/compilers/llvm/6/libc++/default.nix +++ b/pkgs/development/compilers/llvm/6/libc++/default.nix @@ -40,7 +40,10 @@ stdenv.mkDerivation rec { linkCxxAbi = stdenv.isLinux; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; meta = { homepage = http://libcxx.llvm.org/; diff --git a/pkgs/development/compilers/llvm/6/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/6/libc++/setup-hook.sh index bcd93cf486fff..6611259165ae2 100644 --- a/pkgs/development/compilers/llvm/6/libc++/setup-hook.sh +++ b/pkgs/development/compilers/llvm/6/libc++/setup-hook.sh @@ -1,14 +1,6 @@ -# The `hostOffset` describes how the host platform of the dependencies -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole linkCxxAbi="@linkCxxAbi@" -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" diff --git a/pkgs/development/libraries/gettext/default.nix b/pkgs/development/libraries/gettext/default.nix index 6dec7747c7e86..a7c79ee600ece 100644 --- a/pkgs/development/libraries/gettext/default.nix +++ b/pkgs/development/libraries/gettext/default.nix @@ -48,7 +48,10 @@ stdenv.mkDerivation rec { # HACK, see #10874 (and 14664) buildInputs = stdenv.lib.optional (!stdenv.isLinux && !hostPlatform.isCygwin) libiconv; - setupHook = ./gettext-setup-hook.sh; + setupHooks = [ + ../../../build-support/setup-hooks/role.bash + ./gettext-setup-hook.sh + ]; gettextNeedsLdflags = hostPlatform.libc != "glibc" && !hostPlatform.isMusl; enableParallelBuilding = true; diff --git a/pkgs/development/libraries/gettext/gettext-setup-hook.sh b/pkgs/development/libraries/gettext/gettext-setup-hook.sh index 074d313e48aab..0a6bc0dd253af 100644 --- a/pkgs/development/libraries/gettext/gettext-setup-hook.sh +++ b/pkgs/development/libraries/gettext/gettext-setup-hook.sh @@ -1,6 +1,8 @@ gettextDataDirsHook() { + # See pkgs/build-support/setup-hooks/role.bash + getHostRoleEnvHook if [ -d "$1/share/gettext" ]; then - addToSearchPath GETTEXTDATADIRS "$1/share/gettext" + addToSearchPath "GETTEXTDATADIRS${role_post}" "$1/share/gettext" fi } @@ -8,21 +10,8 @@ addEnvHooks "$hostOffset" gettextDataDirsHook # libintl must be listed in load flags on non-Glibc # it doesn't hurt to have it in Glibc either though -gettextLdflags() { - # The `depHostOffset` describes how the host platform of the dependencies - # are slid relative to the depending package. It is brought into scope of - # the environment hook defined as the role of the dependency being applied. - case $depHostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; - return 1 ;; - esac - - export NIX_${role}LDFLAGS+=" -lintl" -} - if [ ! -z "@gettextNeedsLdflags@" ]; then - addEnvHooks "$hostOffset" gettextLdflags + # See pkgs/build-support/setup-hooks/role.bash + getHostRole + export NIX_${role_pre}LDFLAGS+=" -lintl" fi diff --git a/pkgs/development/libraries/libiconv/default.nix b/pkgs/development/libraries/libiconv/default.nix index a4e6fed88e1cd..169a4d38bb53c 100644 --- a/pkgs/development/libraries/libiconv/default.nix +++ b/pkgs/development/libraries/libiconv/default.nix @@ -14,7 +14,10 @@ stdenv.mkDerivation rec { sha256 = "0y1ij745r4p48mxq84rax40p10ln7fc7m243p8k8sia519i3dxfc"; }; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; postPatch = lib.optionalString ((hostPlatform != buildPlatform && hostPlatform.libc == "msvcrt") || stdenv.cc.nativeLibc) diff --git a/pkgs/development/libraries/libiconv/setup-hook.sh b/pkgs/development/libraries/libiconv/setup-hook.sh index 78222dddbf1d4..d20e94513e263 100644 --- a/pkgs/development/libraries/libiconv/setup-hook.sh +++ b/pkgs/development/libraries/libiconv/setup-hook.sh @@ -1,18 +1,6 @@ # libiconv must be listed in load flags on non-Glibc # it doesn't hurt to have it in Glibc either though -iconvLdflags() { - # The `depHostOffset` describes how the host platform of the dependencies - # are slid relative to the depending package. It is brought into scope of - # the environment hook defined as the role of the dependency being applied. - case $depHostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; - return 1 ;; - esac - export NIX_${role}LDFLAGS+=" -liconv" -} - -addEnvHooks "$hostOffset" iconvLdflags +# See pkgs/build-support/setup-hooks/role.bash +getHostRole +export NIX_${role_pre}LDFLAGS+=" -liconv" diff --git a/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh b/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh index d47d602e2edb9..81df09eba1765 100644 --- a/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh +++ b/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh @@ -1,18 +1,6 @@ -setupCompatFlags() { - # The `depHostOffset` describes how the host platform of the dependencies - # are slid relative to the depending package. It is brought into scope of - # the environment hook defined as the role of the dependency being applied. - case $depHostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; - return 1 ;; - esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole - export NIX_${role}LDFLAGS+=" -lnbcompat" - export NIX_${role}CFLAGS_COMPILE+=" -DHAVE_NBTOOL_CONFIG_H" - export NIX_${role}CFLAGS_COMPILE+=" -include nbtool_config.h" -} - -addEnvHooks "$hostOffset" setupCompatFlags +export NIX_${role_pre}LDFLAGS+=" -lnbcompat" +export NIX_${role_pre}CFLAGS_COMPILE+=" -DHAVE_NBTOOL_CONFIG_H" +export NIX_${role_pre}CFLAGS_COMPILE+=" -include nbtool_config.h" diff --git a/pkgs/os-specific/bsd/netbsd/default.nix b/pkgs/os-specific/bsd/netbsd/default.nix index b4fb99504ef2b..84d6926c50c77 100644 --- a/pkgs/os-specific/bsd/netbsd/default.nix +++ b/pkgs/os-specific/bsd/netbsd/default.nix @@ -167,7 +167,10 @@ let sha256 = "17phkfafybxwhzng44k5bhmag6i55br53ky1nwcmw583kg2fa86z"; version = "7.1.2"; - setupHook = ./compat-setup-hook.sh; + setupHooks = [ + ../../../build-support/setup-hooks/role.bash + ./compat-setup-hook.sh + ]; # override defaults to prevent infinite recursion nativeBuildInputs = [ makeMinimal ]; @@ -270,7 +273,10 @@ let runHook postInstall ''; - setupHook = ./fts-setup-hook.sh; + setupHooks = [ + ../../../build-support/setup-hooks/role.bash + ./fts-setup-hook.sh + ]; }; stat = netBSDDerivation { diff --git a/pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh b/pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh index 6b7064174931a..5cf8c753aec38 100644 --- a/pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh +++ b/pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh @@ -1,16 +1,4 @@ -ftsLdflags() { - # The `depHostOffset` describes how the host platform of the dependencies - # are slid relative to the depending package. It is brought into scope of - # the environment hook defined as the role of the dependency being applied. - case $depHostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; - return 1 ;; - esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole - export NIX_${role}LDFLAGS+=" -lfts" -} - -addEnvHooks "$hostOffset" ftsLdflags +export NIX_${role_pre}LDFLAGS+=" -lfts" diff --git a/pkgs/os-specific/linux/musl/fts-setup-hook.sh b/pkgs/os-specific/linux/musl/fts-setup-hook.sh index 3962dcb19a20c..5cf8c753aec38 100644 --- a/pkgs/os-specific/linux/musl/fts-setup-hook.sh +++ b/pkgs/os-specific/linux/musl/fts-setup-hook.sh @@ -1,17 +1,4 @@ -ftsLdflags() { - # The `depHostOffset` describes how the host platform of the dependencies - # are slid relative to the depending package. It is brought into scope of - # the environment hook defined as the role of the dependency being applied. - case $depHostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; - return 1 ;; - esac - - export NIX_${role}LDFLAGS+=" -lfts" -} - -addEnvHooks "$hostOffset" ftsLdflags +# See pkgs/build-support/setup-hooks/role.bash +getHostRole +export NIX_${role_pre}LDFLAGS+=" -lfts" diff --git a/pkgs/os-specific/linux/musl/fts.nix b/pkgs/os-specific/linux/musl/fts.nix index 0f16e8cc79bf8..24d25de3a2d9a 100644 --- a/pkgs/os-specific/linux/musl/fts.nix +++ b/pkgs/os-specific/linux/musl/fts.nix @@ -12,5 +12,8 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ autoreconfHook pkgconfig ]; - setupHook = ./fts-setup-hook.sh; + setupHooks = [ + ../../../build-support/setup-hooks/role.bash + ./fts-setup-hook.sh + ]; }