Merge pull request #40139 from obsidiansystems/modular-setup-hooks

treewide: Modular setup hooks

Changed files
+287 -317
pkgs
+1 -10
pkgs/build-support/bintools-wrapper/add-flags.sh
···
NIX+DONT_SET_RPATH
)
-
declare -a role_infixes=()
-
if [ "${NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_BUILD:-}" ]; then
-
role_infixes+=(_BUILD_)
-
fi
-
if [ "${NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_HOST:-}" ]; then
-
role_infixes+=(_)
-
fi
-
if [ "${NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_TARGET:-}" ]; then
-
role_infixes+=(_TARGET_)
-
fi
for var in "${var_templates_list[@]}"; do
mangleVarList "$var" ${role_infixes[@]+"${role_infixes[@]}"}
···
NIX+DONT_SET_RPATH
)
+
accumulateRoles
for var in "${var_templates_list[@]}"; do
mangleVarList "$var" ${role_infixes[@]+"${role_infixes[@]}"}
+8 -3
pkgs/build-support/bintools-wrapper/default.nix
···
depsTargetTargetPropagated = extraPackages;
-
setupHook = ./setup-hook.sh;
postFixup =
''
···
set +u
substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh
-
substituteAll ${../cc-wrapper/utils.sh} $out/nix-support/utils.sh
##
## Extra custom steps
···
inherit dynamicLinker expand-response-params;
-
# for substitution in utils.sh
expandResponseParams = "${expand-response-params}/bin/expand-response-params";
meta =
···
depsTargetTargetPropagated = extraPackages;
+
wrapperName = "BINTOOLS_WRAPPER";
+
+
setupHooks = [
+
../setup-hooks/role.bash
+
./setup-hook.sh
+
];
postFixup =
''
···
set +u
substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh
+
substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
##
## Extra custom steps
···
inherit dynamicLinker expand-response-params;
+
# for substitution in utils.bash
expandResponseParams = "${expand-response-params}/bin/expand-response-params";
meta =
+1 -1
pkgs/build-support/bintools-wrapper/ld-wrapper.sh
···
PATH="@coreutils_bin@/bin"
fi
-
source @out@/nix-support/utils.sh
if [ -z "${NIX_BINTOOLS_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then
source @out@/nix-support/add-flags.sh
···
PATH="@coreutils_bin@/bin"
fi
+
source @out@/nix-support/utils.bash
if [ -z "${NIX_BINTOOLS_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then
source @out@/nix-support/add-flags.sh
+8 -30
pkgs/build-support/bintools-wrapper/setup-hook.sh
···
[[ -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
if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then
-
export NIX_${role}LDFLAGS+=" -L$1/lib64"
fi
if [[ -d "$1/lib" ]]; then
-
export NIX_${role}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
addEnvHooks "$targetOffset" bintoolsWrapper_addLDVars
···
[[ -z ${crossConfig-} ]] || (( "$hostOffset" < 0 )) || return 0
bintoolsWrapper_addLDVars () {
+
# See ../setup-hooks/role.bash
+
local role_post role_pre
+
getTargetRoleEnvHook
if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then
+
export NIX_${role_pre}LDFLAGS+=" -L$1/lib64"
fi
if [[ -d "$1/lib" ]]; then
+
export NIX_${role_pre}LDFLAGS+=" -L$1/lib"
fi
}
+
# See ../setup-hooks/role.bash
+
getTargetRole
+
getTargetRoleWrapper
addEnvHooks "$targetOffset" bintoolsWrapper_addLDVars
+1 -12
pkgs/build-support/cc-wrapper/add-flags.sh
···
NIX+ENFORCE_NO_NATIVE
)
-
# Accumulate infixes for taking in the right input parameters. See setup-hook
-
# for details.
-
declare -a role_infixes=()
-
if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD:-}" ]; then
-
role_infixes+=(_BUILD_)
-
fi
-
if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST:-}" ]; then
-
role_infixes+=(_)
-
fi
-
if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_TARGET:-}" ]; then
-
role_infixes+=(_TARGET_)
-
fi
# We need to mangle names for hygiene, but also take parameters/overrides
# from the environment.
···
NIX+ENFORCE_NO_NATIVE
)
+
accumulateRoles
# We need to mangle names for hygiene, but also take parameters/overrides
# from the environment.
+1 -1
pkgs/build-support/cc-wrapper/cc-wrapper.sh
···
PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin"
fi
-
source @out@/nix-support/utils.sh
# Flirting with a layer violation here.
if [ -z "${NIX_BINTOOLS_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then
···
PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin"
fi
+
source @out@/nix-support/utils.bash
# Flirting with a layer violation here.
if [ -z "${NIX_BINTOOLS_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then
+8 -3
pkgs/build-support/cc-wrapper/default.nix
···
propagatedBuildInputs = [ bintools ];
depsTargetTargetPropagated = extraPackages;
-
setupHook = ./setup-hook.sh;
postFixup =
''
···
+ ''
substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh
-
substituteAll ${./utils.sh} $out/nix-support/utils.sh
##
## Extra custom steps
···
inherit expand-response-params;
-
# for substitution in utils.sh
expandResponseParams = "${expand-response-params}/bin/expand-response-params";
meta =
···
propagatedBuildInputs = [ bintools ];
depsTargetTargetPropagated = extraPackages;
+
wrapperName = "CC_WRAPPER";
+
+
setupHooks = [
+
../setup-hooks/role.bash
+
./setup-hook.sh
+
];
postFixup =
''
···
+ ''
substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh
+
substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
##
## Extra custom steps
···
inherit expand-response-params;
+
# for substitution in utils.bash
expandResponseParams = "${expand-response-params}/bin/expand-response-params";
meta =
+8 -41
pkgs/build-support/cc-wrapper/setup-hook.sh
···
# 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
if [[ -d "$1/include" ]]; then
-
export NIX_${role}CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include"
fi
if [[ -d "$1/Library/Frameworks" ]]; then
-
export NIX_${role}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
# We use the `targetOffset` to choose the right env hook to accumulate the right
# sort of deps (those with that offset).
···
# over no state, and there's no @-substitutions within, so any redefined
# function is guaranteed to be exactly the same.
ccWrapper_addCVars () {
+
# See ../setup-hooks/role.bash
+
local role_post role_pre
+
getTargetRoleEnvHook
if [[ -d "$1/include" ]]; then
+
export NIX_${role_pre}CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include"
fi
if [[ -d "$1/Library/Frameworks" ]]; then
+
export NIX_${role_pre}CFLAGS_COMPILE+=" -F$1/Library/Frameworks"
fi
}
+
# 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).
+15
pkgs/build-support/cc-wrapper/utils.sh pkgs/build-support/wrapper-common/utils.bash
···
mangleVarList() {
local var="$1"
shift
···
+
# Accumulate infixes for taking in the right input parameters with the `mangle*`
+
# functions below. See setup-hook for details.
+
accumulateRoles() {
+
declare -ga role_infixes=()
+
if [ "${NIX_@wrapperName@_@infixSalt@_TARGET_BUILD:-}" ]; then
+
role_infixes+=(_BUILD_)
+
fi
+
if [ "${NIX_@wrapperName@_@infixSalt@_TARGET_HOST:-}" ]; then
+
role_infixes+=(_)
+
fi
+
if [ "${NIX_@wrapperName@_@infixSalt@_TARGET_TARGET:-}" ]; then
+
role_infixes+=(_TARGET_)
+
fi
+
}
+
mangleVarList() {
local var="$1"
shift
+75
pkgs/build-support/setup-hooks/role.bash
···
···
+
# 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
+
}
+4 -12
pkgs/development/compilers/gcc/libstdc++-hook.sh
···
-
# 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
-
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++"
···
+
# See pkgs/build-support/setup-hooks/role.bash
+
getHostRole
+
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++"
+4 -1
pkgs/development/compilers/llvm/3.5/libc++/default.nix
···
linkCxxAbi = stdenv.isLinux;
-
setupHook = ./setup-hook.sh;
meta = {
homepage = http://libcxx.llvm.org/;
···
linkCxxAbi = stdenv.isLinux;
+
setupHooks = [
+
../../../../../build-support/setup-hooks/role.bash
+
./setup-hook.sh
+
];
meta = {
homepage = http://libcxx.llvm.org/;
+4 -12
pkgs/development/compilers/llvm/3.5/libc++/setup-hook.sh
···
-
# 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
linkCxxAbi="@linkCxxAbi@"
-
export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
-
export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
···
+
# See pkgs/build-support/setup-hooks/role.bash
+
getHostRole
linkCxxAbi="@linkCxxAbi@"
+
export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
+
export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
+4 -1
pkgs/development/compilers/llvm/3.7/libc++/default.nix
···
linkCxxAbi = stdenv.isLinux;
-
setupHook = ./setup-hook.sh;
meta = {
homepage = http://libcxx.llvm.org/;
···
linkCxxAbi = stdenv.isLinux;
+
setupHooks = [
+
../../../../../build-support/setup-hooks/role.bash
+
./setup-hook.sh
+
];
meta = {
homepage = http://libcxx.llvm.org/;
+4 -12
pkgs/development/compilers/llvm/3.7/libc++/setup-hook.sh
···
-
# 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
linkCxxAbi="@linkCxxAbi@"
-
export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
-
export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
···
+
# See pkgs/build-support/setup-hooks/role.bash
+
getHostRole
linkCxxAbi="@linkCxxAbi@"
+
export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
+
export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
+4 -1
pkgs/development/compilers/llvm/3.8/libc++/default.nix
···
linkCxxAbi = stdenv.isLinux;
-
setupHook = ./setup-hook.sh;
meta = {
homepage = http://libcxx.llvm.org/;
···
linkCxxAbi = stdenv.isLinux;
+
setupHooks = [
+
../../../../../build-support/setup-hooks/role.bash
+
./setup-hook.sh
+
];
meta = {
homepage = http://libcxx.llvm.org/;
+4 -12
pkgs/development/compilers/llvm/3.8/libc++/setup-hook.sh
···
-
# 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
linkCxxAbi="@linkCxxAbi@"
-
export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
-
export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
···
+
# See pkgs/build-support/setup-hooks/role.bash
+
getHostRole
linkCxxAbi="@linkCxxAbi@"
+
export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
+
export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
+4 -1
pkgs/development/compilers/llvm/3.9/libc++/default.nix
···
linkCxxAbi = stdenv.isLinux;
-
setupHook = ./setup-hook.sh;
meta = {
homepage = http://libcxx.llvm.org/;
···
linkCxxAbi = stdenv.isLinux;
+
setupHooks = [
+
../../../../../build-support/setup-hooks/role.bash
+
./setup-hook.sh
+
];
meta = {
homepage = http://libcxx.llvm.org/;
+4 -12
pkgs/development/compilers/llvm/3.9/libc++/setup-hook.sh
···
-
# 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
linkCxxAbi="@linkCxxAbi@"
-
export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
-
export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
···
+
# See pkgs/build-support/setup-hooks/role.bash
+
getHostRole
linkCxxAbi="@linkCxxAbi@"
+
export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
+
export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
+4 -1
pkgs/development/compilers/llvm/4/libc++/default.nix
···
linkCxxAbi = stdenv.isLinux;
-
setupHook = ./setup-hook.sh;
meta = {
homepage = http://libcxx.llvm.org/;
···
linkCxxAbi = stdenv.isLinux;
+
setupHooks = [
+
../../../../../build-support/setup-hooks/role.bash
+
./setup-hook.sh
+
];
meta = {
homepage = http://libcxx.llvm.org/;
+4 -12
pkgs/development/compilers/llvm/4/libc++/setup-hook.sh
···
-
# 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
linkCxxAbi="@linkCxxAbi@"
-
export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
-
export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
···
+
# See pkgs/build-support/setup-hooks/role.bash
+
getHostRole
linkCxxAbi="@linkCxxAbi@"
+
export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
+
export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
+4 -1
pkgs/development/compilers/llvm/5/libc++/default.nix
···
linkCxxAbi = stdenv.isLinux;
-
setupHook = ./setup-hook.sh;
meta = {
homepage = http://libcxx.llvm.org/;
···
linkCxxAbi = stdenv.isLinux;
+
setupHooks = [
+
../../../../../build-support/setup-hooks/role.bash
+
./setup-hook.sh
+
];
meta = {
homepage = http://libcxx.llvm.org/;
+4 -12
pkgs/development/compilers/llvm/5/libc++/setup-hook.sh
···
-
# 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
linkCxxAbi="@linkCxxAbi@"
-
export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
-
export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
···
+
# See pkgs/build-support/setup-hooks/role.bash
+
getHostRole
linkCxxAbi="@linkCxxAbi@"
+
export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
+
export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
+4 -1
pkgs/development/compilers/llvm/6/libc++/default.nix
···
linkCxxAbi = stdenv.isLinux;
-
setupHook = ./setup-hook.sh;
meta = {
homepage = http://libcxx.llvm.org/;
···
linkCxxAbi = stdenv.isLinux;
+
setupHooks = [
+
../../../../../build-support/setup-hooks/role.bash
+
./setup-hook.sh
+
];
meta = {
homepage = http://libcxx.llvm.org/;
+4 -12
pkgs/development/compilers/llvm/6/libc++/setup-hook.sh
···
-
# 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
linkCxxAbi="@linkCxxAbi@"
-
export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
-
export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
···
+
# See pkgs/build-support/setup-hooks/role.bash
+
getHostRole
linkCxxAbi="@linkCxxAbi@"
+
export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1"
+
export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
+4 -1
pkgs/development/libraries/gettext/default.nix
···
# HACK, see #10874 (and 14664)
buildInputs = stdenv.lib.optional (!stdenv.isLinux && !hostPlatform.isCygwin) libiconv;
-
setupHook = ./gettext-setup-hook.sh;
gettextNeedsLdflags = hostPlatform.libc != "glibc" && !hostPlatform.isMusl;
enableParallelBuilding = true;
···
# HACK, see #10874 (and 14664)
buildInputs = stdenv.lib.optional (!stdenv.isLinux && !hostPlatform.isCygwin) libiconv;
+
setupHooks = [
+
../../../build-support/setup-hooks/role.bash
+
./gettext-setup-hook.sh
+
];
gettextNeedsLdflags = hostPlatform.libc != "glibc" && !hostPlatform.isMusl;
enableParallelBuilding = true;
+6 -17
pkgs/development/libraries/gettext/gettext-setup-hook.sh
···
gettextDataDirsHook() {
if [ -d "$1/share/gettext" ]; then
-
addToSearchPath GETTEXTDATADIRS "$1/share/gettext"
fi
}
···
# 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
fi
···
gettextDataDirsHook() {
+
# See pkgs/build-support/setup-hooks/role.bash
+
getHostRoleEnvHook
if [ -d "$1/share/gettext" ]; then
+
addToSearchPath "GETTEXTDATADIRS${role_post}" "$1/share/gettext"
fi
}
···
# libintl must be listed in load flags on non-Glibc
# it doesn't hurt to have it in Glibc either though
if [ ! -z "@gettextNeedsLdflags@" ]; then
+
# See pkgs/build-support/setup-hooks/role.bash
+
getHostRole
+
export NIX_${role_pre}LDFLAGS+=" -lintl"
fi
+4 -1
pkgs/development/libraries/libiconv/default.nix
···
sha256 = "0y1ij745r4p48mxq84rax40p10ln7fc7m243p8k8sia519i3dxfc";
};
-
setupHook = ./setup-hook.sh;
postPatch =
lib.optionalString ((hostPlatform != buildPlatform && hostPlatform.libc == "msvcrt") || stdenv.cc.nativeLibc)
···
sha256 = "0y1ij745r4p48mxq84rax40p10ln7fc7m243p8k8sia519i3dxfc";
};
+
setupHooks = [
+
../../../build-support/setup-hooks/role.bash
+
./setup-hook.sh
+
];
postPatch =
lib.optionalString ((hostPlatform != buildPlatform && hostPlatform.libc == "msvcrt") || stdenv.cc.nativeLibc)
+3 -15
pkgs/development/libraries/libiconv/setup-hook.sh
···
# 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
···
# libiconv must be listed in load flags on non-Glibc
# it doesn't hurt to have it in Glibc either though
+
# See pkgs/build-support/setup-hooks/role.bash
+
getHostRole
+
export NIX_${role_pre}LDFLAGS+=" -liconv"
+5 -17
pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh
···
-
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
-
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
···
+
# See pkgs/build-support/setup-hooks/role.bash
+
getHostRole
+
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"
+8 -2
pkgs/os-specific/bsd/netbsd/default.nix
···
sha256 = "17phkfafybxwhzng44k5bhmag6i55br53ky1nwcmw583kg2fa86z";
version = "7.1.2";
-
setupHook = ./compat-setup-hook.sh;
# override defaults to prevent infinite recursion
nativeBuildInputs = [ makeMinimal ];
···
runHook postInstall
'';
-
setupHook = ./fts-setup-hook.sh;
};
stat = netBSDDerivation {
···
sha256 = "17phkfafybxwhzng44k5bhmag6i55br53ky1nwcmw583kg2fa86z";
version = "7.1.2";
+
setupHooks = [
+
../../../build-support/setup-hooks/role.bash
+
./compat-setup-hook.sh
+
];
# override defaults to prevent infinite recursion
nativeBuildInputs = [ makeMinimal ];
···
runHook postInstall
'';
+
setupHooks = [
+
../../../build-support/setup-hooks/role.bash
+
./fts-setup-hook.sh
+
];
};
stat = netBSDDerivation {
+3 -15
pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh
···
-
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"
+3 -16
pkgs/os-specific/linux/musl/fts-setup-hook.sh
···
-
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"
+4 -1
pkgs/os-specific/linux/musl/fts.nix
···
nativeBuildInputs = [ autoreconfHook pkgconfig ];
-
setupHook = ./fts-setup-hook.sh;
}
···
nativeBuildInputs = [ autoreconfHook pkgconfig ];
+
setupHooks = [
+
../../../build-support/setup-hooks/role.bash
+
./fts-setup-hook.sh
+
];
}
+61 -28
pkgs/stdenv/generic/setup.sh
···
# Textual substitution functions.
-
substitute() {
-
local input="$1"
-
local output="$2"
-
shift 2
-
-
if [ ! -f "$input" ]; then
-
echo "substitute(): ERROR: file '$input' does not exist" >&2
-
return 1
-
fi
-
-
local content
-
# read returns non-0 on EOF, so we want read to fail
-
if IFS='' read -r -N 0 content < "$input"; then
-
echo "substitute(): ERROR: File \"$input\" has null bytes, won't process" >&2
-
return 1
-
fi
while (( "$#" )); do
case "$1" in
···
shift 2
# check if the used nix attribute name is a valid bash name
if ! [[ "$varName" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then
-
echo "substitute(): ERROR: substitution variables must be valid Bash names, \"$varName\" isn't." >&2
return 1
fi
pattern="@$varName@"
···
;;
*)
-
echo "substitute(): ERROR: Invalid command line argument: $1" >&2
return 1
;;
esac
-
content="${content//"$pattern"/$replacement}"
done
-
if [ -e "$output" ]; then chmod +w "$output"; fi
-
printf "%s" "$content" > "$output"
}
substituteInPlace() {
local fileName="$1"
···
substitute "$fileName" "$fileName" "$@"
}
# Substitute all environment variables that start with a lowercase character and
# are valid Bash names.
substituteAll() {
local input="$1"
local output="$2"
local -a args=()
-
-
for varName in $(awk 'BEGIN { for (v in ENVIRON) if (v ~ /^[a-z][a-zA-Z0-9_]*$/) print v }'); do
-
if (( "${NIX_DEBUG:-0}" >= 1 )); then
-
printf "@%s@ -> %q\n" "${varName}" "${!varName}"
-
fi
-
args+=("--subst-var" "$varName")
-
done
substitute "$input" "$output" "${args[@]}"
}
···
if [ -n "${setupHook:-}" ]; then
mkdir -p "${!outputDev}/nix-support"
substituteAll "$setupHook" "${!outputDev}/nix-support/setup-hook"
fi
# Propagate user-env packages into the output with binaries, TODO?
···
# Textual substitution functions.
+
substituteStream() {
+
local var=$1
+
shift
while (( "$#" )); do
case "$1" in
···
shift 2
# check if the used nix attribute name is a valid bash name
if ! [[ "$varName" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then
+
echo "substituteStream(): ERROR: substitution variables must be valid Bash names, \"$varName\" isn't." >&2
return 1
fi
pattern="@$varName@"
···
;;
*)
+
echo "substituteStream(): ERROR: Invalid command line argument: $1" >&2
return 1
;;
esac
+
eval "$var"'=${'"$var"'//"$pattern"/"$replacement"}'
done
+
printf "%s" "${!var}"
}
+
consumeEntire() {
+
# read returns non-0 on EOF, so we want read to fail
+
if IFS='' read -r -N 0 $1; then
+
echo "consumeEntire(): ERROR: Input null bytes, won't process" >&2
+
return 1
+
fi
+
}
+
+
substitute() {
+
local input="$1"
+
local output="$2"
+
shift 2
+
+
if [ ! -f "$input" ]; then
+
echo "substitute(): ERROR: file '$input' does not exist" >&2
+
return 1
+
fi
+
+
local content
+
consumeEntire content < "$input"
+
+
if [ -e "$output" ]; then chmod +w "$output"; fi
+
substituteStream content "$@" > "$output"
+
}
substituteInPlace() {
local fileName="$1"
···
substitute "$fileName" "$fileName" "$@"
}
+
_allFlags() {
+
for varName in $(awk 'BEGIN { for (v in ENVIRON) if (v ~ /^[a-z][a-zA-Z0-9_]*$/) print v }'); do
+
if (( "${NIX_DEBUG:-0}" >= 1 )); then
+
printf "@%s@ -> %q\n" "${varName}" "${!varName}"
+
fi
+
args+=("--subst-var" "$varName")
+
done
+
}
+
+
substituteAllStream() {
+
local -a args=()
+
_allFlags
+
+
substituteStream "$1" "${args[@]}"
+
}
# Substitute all environment variables that start with a lowercase character and
# are valid Bash names.
substituteAll() {
local input="$1"
local output="$2"
+
local -a args=()
+
_allFlags
substitute "$input" "$output" "${args[@]}"
}
···
if [ -n "${setupHook:-}" ]; then
mkdir -p "${!outputDev}/nix-support"
substituteAll "$setupHook" "${!outputDev}/nix-support/setup-hook"
+
fi
+
+
# TODO(@Ericson2314): Remove after https://github.com/NixOS/nixpkgs/pull/31414
+
if [ -n "${setupHooks:-}" ]; then
+
mkdir -p "${!outputDev}/nix-support"
+
local hook
+
for hook in $setupHooks; do
+
local content
+
consumeEntire content < "$hook"
+
substituteAllStream content >> "${!outputDev}/nix-support/setup-hook"
+
unset -v content
+
done
+
unset -v hook
fi
# Propagate user-env packages into the output with binaries, TODO?