at 18.09-beta 75 lines 2.3 kB view raw
1# Since the same derivation can be depend on in multiple ways, we need to 2# accumulate *each* role (i.e. host and target platforms relative the depending 3# derivation) in which the derivation is used. 4# 5# The role is intened to be use as part of other variables names like 6# - $NIX_${role_pre}_SOMETHING 7# - $NIX_SOMETHING_${role_post} 8 9function getRole() { 10 case $1 in 11 -1) 12 role_pre='BUILD_' 13 role_post='_FOR_BUILD' 14 ;; 15 0) 16 role_pre='' 17 role_post='' 18 ;; 19 1) 20 role_pre='TARGET_' 21 role_post='_FOR_TARGET' 22 ;; 23 *) 24 echo "@name@: used as improper sort of dependency" >2 25 return 1 26 ;; 27 esac 28} 29 30# `hostOffset` describes how the host platform of the package is slid relative 31# to the depending package. `targetOffset` likewise describes the target 32# platform of the package. Both are brought into scope of the setup hook defined 33# for dependency whose setup hook is being processed relative to the package 34# being built. 35 36function getHostRole() { 37 getRole "$hostOffset" 38} 39function getTargetRole() { 40 getRole "$targetOffset" 41} 42 43# `depHostOffset` describes how the host platform of the dependencies are slid 44# relative to the depending package. `depTargetOffset` likewise describes the 45# target platform of dependenices. Both are brought into scope of the 46# environment hook defined for the dependency being applied relative to the 47# package being built. 48 49function getHostRoleEnvHook() { 50 getRole "$depHostOffset" 51} 52function getTargetRoleEnvHook() { 53 getRole "$depTargetOffset" 54} 55 56# This variant is inteneded specifically for code-prodocing tool wrapper scripts 57# `NIX_@wrapperName@_@infixSalt@_TARGET_*` tracks this (needs to be an exported 58# env var so can't use fancier data structures). 59function getTargetRoleWrapper() { 60 case $targetOffset in 61 -1) 62 export NIX_@wrapperName@_@infixSalt@_TARGET_BUILD=1 63 ;; 64 0) 65 export NIX_@wrapperName@_@infixSalt@_TARGET_HOST=1 66 ;; 67 1) 68 export NIX_@wrapperName@_@infixSalt@_TARGET_TARGET=1 69 ;; 70 *) 71 echo "@name@: used as improper sort of dependency" >2 72 return 1 73 ;; 74 esac 75}