python311Packages.moto: 4.2.6 -> 4.2.10
[NixPkgs.git] / pkgs / build-support / setup-hooks / win-dll-link.sh
blob14594bcba93703906bbd3f301162f1e125b2217d
1 fixupOutputHooks+=(_linkDLLs)
3 addEnvHooks "$targetOffset" linkDLLGetFolders
5 linkDLLGetFolders() {
6 addToSearchPath "LINK_DLL_FOLDERS" "$1/lib"
7 addToSearchPath "LINK_DLL_FOLDERS" "$1/bin"
10 _linkDLLs() {
11 linkDLLsInfolder "$prefix/bin"
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.
18 linkDLLsInfolder() {
20 local folder
21 folder="$1"
22 if [ ! -d "$folder" ]; then
23 echo "Not linking DLLs in the non-existent folder $folder"
24 return
26 cd "$folder" || exit
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
34 markFileAsDone() {
35 if [ ! "${filesDone[$1]+a}" ]; then filesDone[$1]=a; fi
36 if [ "${filesToChecks[$1]+a}" ]; then unset 'filesToChecks[$1]'; fi
39 addFileToLink() {
40 if [ "${filesDone[$1]+a}" ]; then return; fi
41 if [ ! "${filesToChecks[$1]+a}" ]; then filesToChecks[$1]=a; fi
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"
53 echo DLLPATH="'$DLLPATH'"
55 for peFile in *.{exe,dll}; do
56 if [ -e "./$peFile" ]; then
57 addFileToLink "$peFile"
59 done
61 local searchPaths
62 readarray -td: searchPaths < <(printf -- "%s" "$DLLPATH")
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 "${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))
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
87 echo "Created $linkCount DLL link(s) in $folder"