File: prepare_deps_macos.sh

package info (click to toggle)
renderdoc 1.11%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 93,988 kB
  • sloc: cpp: 662,188; ansic: 350,046; python: 22,871; xml: 14,473; java: 11,365; cs: 7,181; makefile: 6,703; yacc: 5,682; ruby: 4,648; perl: 3,461; sh: 2,277; php: 2,119; lisp: 1,835; javascript: 1,524; tcl: 1,068; ml: 747
file content (155 lines) | stat: -rwxr-xr-x 4,570 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/sh

framework_name() {
  echo $1 | grep -o '[a-zA-Z0-9]*\.framework' | sed 's/.framework$//'
}

framework_version() {
  echo $1 | grep -o 'Versions/[0-9.]*' | sed 's/^Versions.//'
}

relative_dylib_path() {
  name=`framework_name $1`
  version=`framework_version $1`
  echo "${name}.framework/Versions/${version}/${name}"
}

install_framework_base_path() {
  echo $1 | grep -o '.*/[A-Za-z0-9]*.framework'
}

change_framework_id() {
  install_name_tool -id "@executable_path/../Frameworks/"`relative_dylib_path "${1}"` "${1}"
}

change_framework_dep() {
  install_name_tool -change "${1}" "@executable_path/../Frameworks/"`relative_dylib_path "${1}"` "${2}"
}

bundle_dir=`dirname $1`/../..
binary_name=`basename $1`

cd $bundle_dir

if [ ! -f Contents/MacOS/$binary_name ]; then
  echo "Usage: $0 Contents/MacOS/<binary>";
  exit 1;
fi

bin_deps=`otool -L Contents/MacOS/$binary_name | grep /usr/local | awk '{print $1}'`

# Find the Qt install and copy our plugins over that we need, then add their dependencies
# since for some reason qcocoa depends on QtPrintSupport :(
first_dep=`echo $bin_deps | tr ' ' '\n' | grep 'Qt' | tail -n 1`
first_dep_loC=`install_framework_base_path "${first_dep}"`
qt_install=`dirname "${first_dep_loC}" | sed 's#/lib##'`

echo "Copying plugins from $qt_install"
plugins="imageformats/libqsvg.dylib platforms/libqcocoa.dylib"

# Remove any symlink that might exist here
if [ -L Contents/qtplugins ]; then
	rm Contents/qtplugins;
fi

for plugin in $plugins; do
  mkdir -p "Contents/qtplugins/"`dirname "${plugin}"`

  cp "${qt_install}/plugins/${plugin}" "contents/qtplugins/"`dirname "${plugin}"`;

  install_name_tool -id "@executable_path/../qtplugins/${plugin}" "contents/qtplugins/${plugin}"
done

for I in `otool -L Contents/qtplugins/*/* | grep /usr/local | awk '{print $1}'`; do
  name=`framework_name $I`

  if echo $bin_deps | grep -q "${name}"; then
    continue;
  fi

  echo "Plugins need new dependency ${name}";

  bin_deps+=" ${I}";
done

# First copy in all the binary's dependencies and update their IDs
for I in $bin_deps; do
  name=`framework_name $I`
  version=`framework_version $I`
  echo "Application depends on $name version $version from $I"

  # Create and copy the framework locally
  local_path="Contents/Frameworks/${name}.framework/Versions/${version}"

  echo "Copying to ${local_path}"
  mkdir -p "${local_path}"
  cp -R `install_framework_base_path $I`/Versions/${version}/* "${local_path}"/

  chmod -R +w "${local_path}"/

  change_framework_id "${local_path}/${name}"
done

# Now check all of those libraries have repointed dependencies and that nothing is missing
for I in $bin_deps; do
  name=`framework_name $I`
  version=`framework_version $I`

  local_path="Contents/Frameworks/${name}.framework/Versions/${version}"

  for dep in `otool -L "${local_path}/${name}" | grep /usr/local | awk '{print $1}'`; do
    echo "Library ${local_path}/${name} depends on $dep"

    dep_name=`framework_name $dep`
    dep_version=`framework_version $dep`

    dep_local_path="Contents/Frameworks/${dep_name}.framework/Versions/${dep_version}"

    if [ ! -f "${dep_local_path}/${dep_name}" ]; then
      echo "Which is missing (expected ${dep_local_path}/${dep_name})";
      exit 1;
    fi

    echo "Patching..."

    change_framework_dep $dep "${local_path}/${name}"
  done

  # Finally change this dependency in the binary
  change_framework_dep "${I}" Contents/MacOS/$binary_name
done

# And the same for plugins
for plugin in $plugins; do
  for dep in `otool -L "Contents/qtplugins/${plugin}" | grep /usr/local | awk '{print $1}'`; do
    echo "Plugin ${plugin} depends on $dep"

    dep_name=`framework_name $dep`
    dep_version=`framework_version $dep`

    dep_local_path="Contents/Frameworks/${dep_name}.framework/Versions/${dep_version}"

    if [ ! -f "${dep_local_path}/${dep_name}" ]; then
      echo "Which is missing (expected ${dep_local_path}/${dep_name})";
      exit 1;
    fi

    echo "Patching..."

    change_framework_dep $dep "contents/qtplugins/${plugin}"
  done
done

# Remove Qt headers folders
rm -rf Contents/Frameworks/Qt*/Versions/*/Headers

# Remove python binaries, headers, and docs
rm -rf Contents/Frameworks/Python.framework/Versions/*/{bin,Resources,include,share/doc}

# Trim python libraries
rm -rf Contents/Frameworks/Python.framework/Versions/*/lib/python*/{site-packages,test,ensurepip,distutils,idlelib,config-*}

# Remove any __pycache__ folders
for pycache in `find Contents/Frameworks/Python.framework -name __pycache__`; do
  rm -rf ./"${pycache}";
done