nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 89 lines 3.1 kB view raw
1fixupOutputHooks+=(_linkDLLs) 2 3addEnvHooks "$targetOffset" linkDLLGetFolders 4 5linkDLLGetFolders() { 6 addToSearchPath "LINK_DLL_FOLDERS" "$1/lib" 7 addToSearchPath "LINK_DLL_FOLDERS" "$1/bin" 8} 9 10_linkDLLs() { 11 linkDLLsInfolder "$prefix/bin" 12} 13 14# Try to links every known dependency of exe/dll in the folder of the 1str input 15# into said folder, so they are found on invocation. 16# (DLLs are first searched in the directory of the running exe file.) 17# The links are relative, so relocating whole /nix/store won't break them. 18linkDLLsInfolder() { 19 ( 20 local folder 21 folder="$1" 22 if [ ! -d "$folder" ]; then 23 echo "Not linking DLLs in the non-existent folder $folder" 24 return 25 fi 26 cd "$folder" || exit 27 28 # Use associative arrays as set 29 local filesToChecks 30 local filesDone 31 declare -A filesToChecks # files that still needs to have their dependancies checked 32 declare -A filesDone # files that had their dependancies checked and who is copied to the bin folder if found 33 34 markFileAsDone() { 35 if [ ! "${filesDone[$1]+a}" ]; then filesDone[$1]=a; fi 36 if [ "${filesToChecks[$1]+a}" ]; then unset 'filesToChecks[$1]'; fi 37 } 38 39 addFileToLink() { 40 if [ "${filesDone[$1]+a}" ]; then return; fi 41 if [ ! "${filesToChecks[$1]+a}" ]; then filesToChecks[$1]=a; fi 42 } 43 44 # Compose path list where DLLs should be located: 45 # prefix $PATH by currently-built outputs 46 local DLLPATH="" 47 local outName 48 for outName in $(getAllOutputNames); do 49 addToSearchPath DLLPATH "${!outName}/bin" 50 done 51 DLLPATH="$DLLPATH:$LINK_DLL_FOLDERS" 52 53 echo DLLPATH="'$DLLPATH'" 54 55 for peFile in *.{exe,dll}; do 56 if [ -e "./$peFile" ]; then 57 addFileToLink "$peFile" 58 fi 59 done 60 61 local searchPaths 62 readarray -td: searchPaths < <(printf -- "%s" "$DLLPATH") 63 64 local linkCount=0 65 while [ ${#filesToChecks[*]} -gt 0 ]; do 66 local listOfDlls=("${!filesToChecks[@]}") 67 local file=${listOfDlls[0]} 68 markFileAsDone "$file" 69 if [ ! -e "./$file" ]; then 70 local pathsFound 71 readarray -d '' pathsFound < <(find -L "${searchPaths[@]}" -name "$file" -type f -print0) 72 if [ ${#pathsFound[@]} -eq 0 ]; then continue; fi 73 local dllPath 74 dllPath="${pathsFound[0]}" 75 CYGWIN+=" winsymlinks:nativestrict" ln -sr "$dllPath" . 76 echo "linking $dllPath" 77 file="$dllPath" 78 linkCount=$((linkCount + 1)) 79 fi 80 # local dep_file 81 # Look at the file’s dependancies 82 for dep_file in $($OBJDUMP -p "$file" | sed -n 's/.*DLL Name: \(.*\)/\1/p' | sort -u); do 83 addFileToLink "$dep_file" 84 done 85 done 86 87 echo "Created $linkCount DLL link(s) in $folder" 88 ) 89}