diff options
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/bintools-wrapper/default.nix | 2 | ||||
-rw-r--r-- | pkgs/build-support/bintools-wrapper/setup-hook.sh | 45 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/default.nix | 3 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/setup-hook.sh | 55 | ||||
-rw-r--r-- | pkgs/build-support/emacs/setup-hook.sh | 6 | ||||
-rw-r--r-- | pkgs/build-support/gcc-wrapper-old/setup-hook.sh | 4 | ||||
-rw-r--r-- | pkgs/build-support/setup-hooks/find-xml-catalogs.sh | 2 | ||||
-rw-r--r-- | pkgs/build-support/setup-hooks/set-java-classpath.sh | 2 | ||||
-rw-r--r-- | pkgs/build-support/setup-hooks/setup-debug-info-dirs.sh | 2 | ||||
-rw-r--r-- | pkgs/build-support/setup-hooks/strip.sh | 37 | ||||
-rw-r--r-- | pkgs/build-support/setup-hooks/wrap-gapps-hook.sh | 2 |
11 files changed, 113 insertions, 47 deletions
diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 57859b2f371b..bb0e6b82aa5d 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -178,7 +178,7 @@ stdenv.mkDerivation { else throw "unknown emulation for platform: " + targetPlatform.config; in targetPlatform.platform.bfdEmulation or (fmt + "-" + arch); - propagatedBuildInputs = extraPackages; + depsTargetTargetPropagated = extraPackages; setupHook = ./setup-hook.sh; diff --git a/pkgs/build-support/bintools-wrapper/setup-hook.sh b/pkgs/build-support/bintools-wrapper/setup-hook.sh index 43f79ec59200..48a00b0b9b07 100644 --- a/pkgs/build-support/bintools-wrapper/setup-hook.sh +++ b/pkgs/build-support/bintools-wrapper/setup-hook.sh @@ -2,12 +2,20 @@ # # See comments in cc-wrapper's setup hook. This works exactly the same way. +set -u + +# Skip setup hook if we're neither a build-time dep, nor, temporarily, doing a +# native compile. +# +# TODO(@Ericson2314): No native exception +[[ -z ${crossConfig-} ]] || (( "$hostOffset" < 0 )) || return 0 + bintoolsWrapper_addLDVars () { - case $depOffset in + case $depHostOffset in -1) local role='BUILD_' ;; 0) local role='' ;; 1) local role='TARGET_' ;; - *) echo "bintools-wrapper: Error: Cannot be used with $depOffset-offset deps, " >2; + *) echo "bintools-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; return 1 ;; esac @@ -20,17 +28,29 @@ bintoolsWrapper_addLDVars () { fi } -if [ -n "${crossConfig:-}" ]; then - export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_BUILD=1 - role_pre='BUILD_' - role_post='_FOR_BUILD' -else - export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_HOST=1 - role_pre="" - role_post='' -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 -envHooks+=(bintoolsWrapper_addLDVars) +addEnvHooks "$targetOffset" bintoolsWrapper_addLDVars # shellcheck disable=SC2157 if [ -n "@bintools_bin@" ]; then @@ -65,3 +85,4 @@ done # No local scope in sourced file unset -v role_pre role_post cmd upper_case +set +u diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 218e9f6b957f..5d878d219f18 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -201,7 +201,8 @@ stdenv.mkDerivation { ln -s $ccPath/${targetPrefix}ghdl $out/bin/${targetPrefix}ghdl ''; - propagatedBuildInputs = [ bintools ] ++ extraPackages; + propagatedBuildInputs = [ bintools ]; + depsTargetTargetPropagated = extraPackages; setupHook = ./setup-hook.sh; diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh index a922193ad2e7..29a7306b9b7e 100644 --- a/pkgs/build-support/cc-wrapper/setup-hook.sh +++ b/pkgs/build-support/cc-wrapper/setup-hook.sh @@ -54,19 +54,26 @@ # For more details, read the individual files where the mechanisms used to # accomplish this will be individually documented. +set -u + +# Skip setup hook if we're neither a build-time dep, nor, temporarily, doing a +# native compile. +# +# TODO(@Ericson2314): No native exception +[[ -z ${crossConfig-} ]] || (( "$hostOffset" < 0 )) || return 0 # It's fine that any other cc-wrapper will redefine this. Bash functions close # over no state, and there's no @-substitutions within, so any redefined # function is guaranteed to be exactly the same. ccWrapper_addCVars () { - # The `depOffset` describes how the platforms 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 $depOffset in + # 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 $depOffset-offset deps, " >2; + *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; return 1 ;; esac @@ -87,20 +94,31 @@ ccWrapper_addCVars () { # # We also need to worry about what role is being added on *this* invocation of # setup-hook, which `role` tracks. -if [ -n "${crossConfig:-}" ]; then - export NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD=1 - role_pre='BUILD_' - role_post='_FOR_BUILD' -else - export NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST=1 - role_pre='' - role_post='' -fi +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 -# Eventually the exact sort of env-hook we create will depend on the role. This -# is because based on what relative platform we are targeting, we use different -# dependencies. -envHooks+=(ccWrapper_addCVars) +# We use the `targetOffset` to choose the right env hook to accumulate the right +# sort of deps (those with that offset). +addEnvHooks "$targetOffset" ccWrapper_addCVars # Note 1: these come *after* $out in the PATH (see setup.sh). # Note 2: phase separation makes this look useless to shellcheck. @@ -131,3 +149,4 @@ export CXX${role_post}=@named_cxx@ # No local scope in sourced file unset -v role_pre role_post +set +u diff --git a/pkgs/build-support/emacs/setup-hook.sh b/pkgs/build-support/emacs/setup-hook.sh index defef45b55f5..e1db3e828fd7 100644 --- a/pkgs/build-support/emacs/setup-hook.sh +++ b/pkgs/build-support/emacs/setup-hook.sh @@ -4,4 +4,8 @@ addEmacsVars () { fi } -envHooks+=(addEmacsVars) +# If this is for a wrapper derivation, emacs and the dependencies are all +# run-time dependencies. If this is for precompiling packages into bytecode, +# emacs is a compile-time dependency of the package. +addEnvHooks "$targetOffset" addEmacsVars +addEnvHooks "$targetOffset" addEmacsVars diff --git a/pkgs/build-support/gcc-wrapper-old/setup-hook.sh b/pkgs/build-support/gcc-wrapper-old/setup-hook.sh index d8bdf858ae58..ad3ffeffbbbc 100644 --- a/pkgs/build-support/gcc-wrapper-old/setup-hook.sh +++ b/pkgs/build-support/gcc-wrapper-old/setup-hook.sh @@ -1,4 +1,4 @@ -addCVars () { +gccWrapperOld_addCVars () { if test -d $1/include; then export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include" fi @@ -12,7 +12,7 @@ addCVars () { fi } -envHooks=(${envHooks[@]} addCVars) +envBuildBuildHooks+=(gccWrapperOld_addCVars) # Note: these come *after* $out in the PATH (see setup.sh). diff --git a/pkgs/build-support/setup-hooks/find-xml-catalogs.sh b/pkgs/build-support/setup-hooks/find-xml-catalogs.sh index b742d5a8ffd9..85364a61f612 100644 --- a/pkgs/build-support/setup-hooks/find-xml-catalogs.sh +++ b/pkgs/build-support/setup-hooks/find-xml-catalogs.sh @@ -18,5 +18,5 @@ if [ -z "$libxmlHookDone" ]; then # xmllint and xsltproc from looking in /etc/xml/catalog. export XML_CATALOG_FILES if [ -z "$XML_CATALOG_FILES" ]; then XML_CATALOG_FILES=" "; fi - envHooks+=(addXMLCatalogs) + addEnvHooks "$hostOffset" addXMLCatalogs fi diff --git a/pkgs/build-support/setup-hooks/set-java-classpath.sh b/pkgs/build-support/setup-hooks/set-java-classpath.sh index 047da91bc97c..5d3548dc2e88 100644 --- a/pkgs/build-support/setup-hooks/set-java-classpath.sh +++ b/pkgs/build-support/setup-hooks/set-java-classpath.sh @@ -10,4 +10,4 @@ addPkgToClassPath () { done } -envHooks+=(addPkgToClassPath) +addEnvHooks "$targetOffset" addPkgToClassPath diff --git a/pkgs/build-support/setup-hooks/setup-debug-info-dirs.sh b/pkgs/build-support/setup-hooks/setup-debug-info-dirs.sh index 2fd2a2d6da6f..96bf48cf123a 100644 --- a/pkgs/build-support/setup-hooks/setup-debug-info-dirs.sh +++ b/pkgs/build-support/setup-hooks/setup-debug-info-dirs.sh @@ -2,4 +2,4 @@ setupDebugInfoDirs () { addToSearchPath NIX_DEBUG_INFO_DIRS $1/lib/debug } -envHooks+=(setupDebugInfoDirs) +addEnvHooks "$targetOffset" setupDebugInfoDirs diff --git a/pkgs/build-support/setup-hooks/strip.sh b/pkgs/build-support/setup-hooks/strip.sh index a33968ca18de..fc4c7bfbaf95 100644 --- a/pkgs/build-support/setup-hooks/strip.sh +++ b/pkgs/build-support/setup-hooks/strip.sh @@ -3,24 +3,45 @@ fixupOutputHooks+=(_doStrip) _doStrip() { - if [ -z "$dontStrip" ]; then + # We don't bother to strip build platform code because it shouldn't make it + # to $out anyways---if it does, that's a bigger problem that a lack of + # stripping will help catch. + local -ra flags=(dontStripHost dontStripTarget) + local -ra stripCmds=(STRIP TARGET_STRIP) + + # Optimization + if [[ "$STRIP" == "$TARGET_STRIP" ]]; then + dontStripTarget+=1 + fi + + local i + for i in ${!stripCmds[@]}; do + local -n flag="${flags[$i]}" + local -n stripCmd="${stripCmds[$i]}" + + # `dontStrip` disables them all + if [[ "$dontStrip" || "$flag" ]] || ! type -f "$stripCmd" 2>/dev/null + then continue; fi + stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin} if [ -n "$stripDebugList" ]; then - stripDirs "$stripDebugList" "${stripDebugFlags:--S}" + stripDirs "$stripCmd" "$stripDebugList" "${stripDebugFlags:--S}" fi stripAllList=${stripAllList:-} if [ -n "$stripAllList" ]; then - stripDirs "$stripAllList" "${stripAllFlags:--s}" + stripDirs "$stripCmd" "$stripAllList" "${stripAllFlags:--s}" fi - fi + done } stripDirs() { - local dirs="$1" - local stripFlags="$2" + local cmd="$1" + local dirs="$2" + local stripFlags="$3" local dirsNew= + local d for d in ${dirs}; do if [ -d "$prefix/$d" ]; then dirsNew="${dirsNew} $prefix/$d " @@ -29,8 +50,8 @@ stripDirs() { dirs=${dirsNew} if [ -n "${dirs}" ]; then - header "stripping (with flags $stripFlags) in$dirs" - find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} $STRIP $commonStripFlags $stripFlags 2>/dev/null || true + header "stripping (with command $cmd and flags $stripFlags) in$dirs" + find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} $cmd $commonStripFlags $stripFlags 2>/dev/null || true stopNest fi } diff --git a/pkgs/build-support/setup-hooks/wrap-gapps-hook.sh b/pkgs/build-support/setup-hooks/wrap-gapps-hook.sh index 79b8d5b73fa1..25ac12996cc1 100644 --- a/pkgs/build-support/setup-hooks/wrap-gapps-hook.sh +++ b/pkgs/build-support/setup-hooks/wrap-gapps-hook.sh @@ -6,7 +6,7 @@ find_gio_modules() { fi } -envHooks+=(find_gio_modules) +addEnvHooks "$targetOffset" find_gio_modules # Note: $gappsWrapperArgs still gets defined even if $dontWrapGApps is set. wrapGAppsHook() { |