Filipe Cabecinhas | 4bb4f30 | 2012-09-14 17:09:15 +0000 | [diff] [blame] | 1 | #!/bin/sh |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2 | |
| 3 | # finish-swig-Python.sh |
| 4 | # |
| 5 | # For the Python script interpreter (external to liblldb) to be able to import |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 6 | # and use the lldb module, there must be two files, lldb.py and _lldb.so, that |
| 7 | # it can find. lldb.py is generated by SWIG at the same time it generates the |
| 8 | # C++ file. _lldb.so is actually a symlink file that points to the |
| 9 | # LLDB shared library/framework. |
| 10 | # |
| 11 | # The Python script interpreter needs to be able to automatically find |
| 12 | # these two files. On Darwin systems it searches in the LLDB.framework, as |
| 13 | # well as in all the normal Python search paths. On non-Darwin systems |
| 14 | # these files will need to be put someplace where Python will find them. |
| 15 | # |
| 16 | # This shell script creates the _lldb.so symlink in the appropriate place, |
| 17 | # and copies the lldb.py (and embedded_interpreter.py) file to the correct |
| 18 | # directory. |
| 19 | # |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 21 | # SRC_ROOT is the root of the lldb source tree. |
| 22 | # TARGET_DIR is where the lldb framework/shared library gets put. |
| 23 | # CONFIG_BUILD_DIR is where the build-swig-Python-LLDB.sh shell script |
| 24 | # put the lldb.py file it was generated from running SWIG. |
| 25 | # PYTHON_INSTALL_DIR is where non-Darwin systems want to put the .py and .so |
| 26 | # files so that Python can find them automatically. |
| 27 | # debug_flag (optional) determines whether or not this script outputs |
| 28 | # additional information when running. |
| 29 | |
| 30 | SRC_ROOT=$1 |
| 31 | TARGET_DIR=$2 |
| 32 | CONFIG_BUILD_DIR=$3 |
| 33 | PYTHON_INSTALL_DIR=$4 |
| 34 | debug_flag=$5 |
| 35 | |
Jim Ingham | f4ec2ea | 2012-05-26 00:23:52 +0000 | [diff] [blame] | 36 | # If we don't want Python, then just do nothing here. |
| 37 | # Note, at present iOS doesn't have Python, so if you're building for iOS be sure to |
| 38 | # set LLDB_DISABLE_PYTHON to 1. |
| 39 | |
Filipe Cabecinhas | 4bb4f30 | 2012-09-14 17:09:15 +0000 | [diff] [blame] | 40 | if [ ! "$LLDB_DISABLE_PYTHON" = "1" ] ; then |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 41 | |
Jason Molenda | e2801e1 | 2012-09-27 21:26:57 +0000 | [diff] [blame^] | 42 | if [ -n "$debug_flag" -a "$debug_flag" = "-debug" ] |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | then |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 44 | Debug=1 |
| 45 | else |
| 46 | Debug=0 |
| 47 | fi |
| 48 | |
| 49 | OS_NAME=`uname -s` |
Filipe Cabecinhas | 4bb4f30 | 2012-09-14 17:09:15 +0000 | [diff] [blame] | 50 | PYTHON_VERSION=`/usr/bin/env python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'` |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 51 | |
| 52 | |
Jason Molenda | e2801e1 | 2012-09-27 21:26:57 +0000 | [diff] [blame^] | 53 | if [ $Debug -eq 1 ] |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 54 | then |
| 55 | echo "The current OS is $OS_NAME" |
| 56 | echo "The Python version is $PYTHON_VERSION" |
| 57 | fi |
| 58 | |
| 59 | # |
| 60 | # Determine where to put the files. |
| 61 | |
Jason Molenda | e2801e1 | 2012-09-27 21:26:57 +0000 | [diff] [blame^] | 62 | if [ ${OS_NAME} = "Darwin" ] |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 63 | then |
| 64 | # We are on a Darwin system, so all the lldb Python files can go |
| 65 | # into the LLDB.framework/Resources/Python subdirectory. |
| 66 | |
| 67 | if [ ! -d "${TARGET_DIR}/LLDB.framework" ] |
| 68 | then |
| 69 | echo "Error: Unable to find LLDB.framework" >&2 |
| 70 | exit 1 |
| 71 | else |
Jason Molenda | e2801e1 | 2012-09-27 21:26:57 +0000 | [diff] [blame^] | 72 | if [ $Debug -eq 1 ] |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 73 | then |
| 74 | echo "Found ${TARGET_DIR}/LLDB.framework." |
| 75 | fi |
| 76 | fi |
| 77 | |
| 78 | # Make the Python directory in the framework if it doesn't already exist |
| 79 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 80 | framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python/lldb" |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 81 | else |
| 82 | # We are on a non-Darwin system, so use the PYTHON_INSTALL_DIR argument, |
| 83 | # and append the python version directory to the end of it. Depending on |
| 84 | # the system other stuff may need to be put here as well. |
| 85 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 86 | framework_python_dir="${PYTHON_INSTALL_DIR}/python${PYTHON_VERSION}/lldb" |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 87 | fi |
| 88 | |
| 89 | # |
| 90 | # Look for the directory in which to put the Python files; if it does not |
| 91 | # already exist, attempt to make it. |
| 92 | # |
| 93 | |
Jason Molenda | e2801e1 | 2012-09-27 21:26:57 +0000 | [diff] [blame^] | 94 | if [ $Debug -eq 1 ] |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 95 | then |
| 96 | echo "Python files will be put in ${framework_python_dir}" |
| 97 | fi |
| 98 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 99 | python_dirs="${framework_python_dir}" |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 100 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 101 | for python_dir in $python_dirs |
| 102 | do |
| 103 | if [ ! -d "${python_dir}" ] |
| 104 | then |
Jason Molenda | e2801e1 | 2012-09-27 21:26:57 +0000 | [diff] [blame^] | 105 | if [ $Debug -eq 1 ] |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 106 | then |
| 107 | echo "Making directory ${python_dir}" |
| 108 | fi |
| 109 | mkdir -p "${python_dir}" |
| 110 | else |
Jason Molenda | e2801e1 | 2012-09-27 21:26:57 +0000 | [diff] [blame^] | 111 | if [ $Debug -eq 1 ] |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 112 | then |
| 113 | echo "${python_dir} already exists." |
| 114 | fi |
| 115 | fi |
| 116 | |
| 117 | if [ ! -d "${python_dir}" ] |
| 118 | then |
| 119 | echo "Error: Unable to find or create ${python_dir}" >&2 |
| 120 | exit 1 |
| 121 | fi |
| 122 | done |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 123 | |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 124 | # Make the symlink that the script bridge for Python will need in the |
| 125 | # Python framework directory |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 126 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 127 | if [ ! -L "${framework_python_dir}/_lldb.so" ] |
| 128 | then |
Jason Molenda | e2801e1 | 2012-09-27 21:26:57 +0000 | [diff] [blame^] | 129 | if [ $Debug -eq 1 ] |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 130 | then |
| 131 | echo "Creating symlink for _lldb.so" |
| 132 | fi |
Jason Molenda | e2801e1 | 2012-09-27 21:26:57 +0000 | [diff] [blame^] | 133 | if [ ${OS_NAME} = "Darwin" ] |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 134 | then |
| 135 | cd "${framework_python_dir}" |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 136 | ln -s "../../../LLDB" _lldb.so |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 137 | fi |
| 138 | else |
Jason Molenda | e2801e1 | 2012-09-27 21:26:57 +0000 | [diff] [blame^] | 139 | if [ $Debug -eq 1 ] |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 140 | then |
| 141 | echo "${framework_python_dir}/_lldb.so already exists." |
| 142 | fi |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 143 | fi |
| 144 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | |
Filipe Cabecinhas | 4bb4f30 | 2012-09-14 17:09:15 +0000 | [diff] [blame] | 146 | create_python_package () { |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 147 | package_dir="${framework_python_dir}$1" |
| 148 | package_files="$2" |
Enrico Granata | a5c2ce0 | 2012-04-25 17:53:41 +0000 | [diff] [blame] | 149 | package_name=`echo $1 | tr '/' '.'` |
| 150 | package_name="lldb${package_name}" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 151 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 152 | if [ ! -d "${package_dir}" ] |
Enrico Granata | 074e3b6 | 2011-08-17 19:07:52 +0000 | [diff] [blame] | 153 | then |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 154 | mkdir -p "${package_dir}" |
Enrico Granata | 074e3b6 | 2011-08-17 19:07:52 +0000 | [diff] [blame] | 155 | fi |
Enrico Granata | 074e3b6 | 2011-08-17 19:07:52 +0000 | [diff] [blame] | 156 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 157 | for package_file in $package_files |
| 158 | do |
| 159 | if [ -f "${package_file}" ] |
| 160 | then |
| 161 | cp "${package_file}" "${package_dir}" |
| 162 | package_file_basename=$(basename "${package_file}") |
| 163 | fi |
| 164 | done |
Enrico Granata | 66205ce | 2012-03-12 19:47:17 +0000 | [diff] [blame] | 165 | |
Enrico Granata | b8dc733 | 2012-01-31 17:01:51 +0000 | [diff] [blame] | 166 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 167 | # Create a packate init file if there wasn't one |
| 168 | package_init_file="${package_dir}/__init__.py" |
| 169 | if [ ! -f "${package_init_file}" ] |
Enrico Granata | 8f84cfb | 2012-02-23 23:10:03 +0000 | [diff] [blame] | 170 | then |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 171 | echo -n "__all__ = [" > "${package_init_file}" |
| 172 | python_module_separator="" |
| 173 | for package_file in $package_files |
| 174 | do |
| 175 | if [ -f "${package_file}" ] |
| 176 | then |
| 177 | package_file_basename=$(basename "${package_file}") |
| 178 | echo -n "${python_module_separator}\"${package_file_basename%.*}\"" >> "${package_init_file}" |
| 179 | python_module_separator=", " |
| 180 | fi |
| 181 | done |
| 182 | echo "]" >> "${package_init_file}" |
Enrico Granata | a5c2ce0 | 2012-04-25 17:53:41 +0000 | [diff] [blame] | 183 | echo "for x in __all__:" >> "${package_init_file}" |
| 184 | echo " __import__('${package_name}.'+x)" >> "${package_init_file}" |
Enrico Granata | 8f84cfb | 2012-02-23 23:10:03 +0000 | [diff] [blame] | 185 | fi |
Enrico Granata | 8f84cfb | 2012-02-23 23:10:03 +0000 | [diff] [blame] | 186 | |
Enrico Granata | 8f84cfb | 2012-02-23 23:10:03 +0000 | [diff] [blame] | 187 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 188 | } |
Enrico Granata | 8f84cfb | 2012-02-23 23:10:03 +0000 | [diff] [blame] | 189 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 190 | # Copy the lldb.py file into the lldb package directory and rename to __init_.py |
| 191 | cp "${CONFIG_BUILD_DIR}/lldb.py" "${framework_python_dir}/__init__.py" |
Enrico Granata | 8f84cfb | 2012-02-23 23:10:03 +0000 | [diff] [blame] | 192 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 193 | # lldb |
| 194 | package_files="${SRC_ROOT}/source/Interpreter/embedded_interpreter.py" |
| 195 | create_python_package "" "${package_files}" |
Enrico Granata | 8f84cfb | 2012-02-23 23:10:03 +0000 | [diff] [blame] | 196 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 197 | # lldb/formatters/cpp |
| 198 | package_files="${SRC_ROOT}/examples/synthetic/gnu_libstdcpp.py |
| 199 | ${SRC_ROOT}/examples/synthetic/libcxx.py" |
| 200 | create_python_package "/formatters/cpp" "${package_files}" |
Enrico Granata | 8f84cfb | 2012-02-23 23:10:03 +0000 | [diff] [blame] | 201 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 202 | # lldb/formatters/objc |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 203 | package_files="${SRC_ROOT}/examples/summaries/cocoa/Selector.py |
| 204 | ${SRC_ROOT}/examples/summaries/objc.py |
| 205 | ${SRC_ROOT}/examples/summaries/cocoa/Class.py |
| 206 | ${SRC_ROOT}/examples/summaries/cocoa/CFArray.py |
| 207 | ${SRC_ROOT}/examples/summaries/cocoa/CFBag.py |
| 208 | ${SRC_ROOT}/examples/summaries/cocoa/CFBinaryHeap.py |
| 209 | ${SRC_ROOT}/examples/summaries/cocoa/CFBitVector.py |
| 210 | ${SRC_ROOT}/examples/summaries/cocoa/CFDictionary.py |
| 211 | ${SRC_ROOT}/examples/summaries/cocoa/CFString.py |
| 212 | ${SRC_ROOT}/examples/summaries/cocoa/NSBundle.py |
| 213 | ${SRC_ROOT}/examples/summaries/cocoa/NSData.py |
| 214 | ${SRC_ROOT}/examples/summaries/cocoa/NSDate.py |
| 215 | ${SRC_ROOT}/examples/summaries/cocoa/NSException.py |
| 216 | ${SRC_ROOT}/examples/summaries/cocoa/NSIndexSet.py |
| 217 | ${SRC_ROOT}/examples/summaries/cocoa/NSMachPort.py |
| 218 | ${SRC_ROOT}/examples/summaries/cocoa/NSNotification.py |
| 219 | ${SRC_ROOT}/examples/summaries/cocoa/NSNumber.py |
| 220 | ${SRC_ROOT}/examples/summaries/cocoa/NSSet.py |
| 221 | ${SRC_ROOT}/examples/summaries/cocoa/NSURL.py" |
| 222 | create_python_package "/formatters/objc" "${package_files}" |
Enrico Granata | 8f84cfb | 2012-02-23 23:10:03 +0000 | [diff] [blame] | 223 | |
Enrico Granata | 8f84cfb | 2012-02-23 23:10:03 +0000 | [diff] [blame] | 224 | |
Enrico Granata | 65e3dcb | 2012-04-25 01:26:37 +0000 | [diff] [blame] | 225 | # make an empty __init__.py in lldb/runtime |
| 226 | # this is required for Python to recognize lldb.runtime as a valid package |
| 227 | # (and hence, lldb.runtime.objc as a valid contained package) |
| 228 | create_python_package "/runtime" "" |
| 229 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 230 | # lldb/runtime/objc |
| 231 | package_files="${SRC_ROOT}/examples/summaries/cocoa/objc_runtime.py" |
| 232 | create_python_package "/runtime/objc" "${package_files}" |
Enrico Granata | 8f84cfb | 2012-02-23 23:10:03 +0000 | [diff] [blame] | 233 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 234 | # lldb/formatters |
Enrico Granata | 65e3dcb | 2012-04-25 01:26:37 +0000 | [diff] [blame] | 235 | # having these files copied here ensures that lldb/formatters is a valid package itself |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 236 | package_files="${SRC_ROOT}/examples/summaries/cocoa/cache.py |
| 237 | ${SRC_ROOT}/examples/summaries/cocoa/metrics.py |
| 238 | ${SRC_ROOT}/examples/summaries/cocoa/attrib_fromdict.py |
| 239 | ${SRC_ROOT}/examples/summaries/cocoa/Logger.py" |
| 240 | create_python_package "/formatters" "${package_files}" |
Enrico Granata | 8f84cfb | 2012-02-23 23:10:03 +0000 | [diff] [blame] | 241 | |
Greg Clayton | 4e651b1 | 2012-04-25 00:58:03 +0000 | [diff] [blame] | 242 | # lldb/utils |
| 243 | package_files="${SRC_ROOT}/examples/python/symbolication.py" |
| 244 | create_python_package "/utils" "${package_files}" |
Enrico Granata | 8f84cfb | 2012-02-23 23:10:03 +0000 | [diff] [blame] | 245 | |
Jason Molenda | e2801e1 | 2012-09-27 21:26:57 +0000 | [diff] [blame^] | 246 | if [ ${OS_NAME} = "Darwin" ] |
Greg Clayton | 6f2f0ab | 2012-04-25 01:49:50 +0000 | [diff] [blame] | 247 | then |
| 248 | # lldb/macosx |
| 249 | package_files="${SRC_ROOT}/examples/python/crashlog.py |
| 250 | ${SRC_ROOT}/examples/darwin/heap_find/heap.py" |
| 251 | create_python_package "/macosx" "${package_files}" |
Enrico Granata | 1328b14 | 2012-02-29 03:28:49 +0000 | [diff] [blame] | 252 | |
Greg Clayton | 6f2f0ab | 2012-04-25 01:49:50 +0000 | [diff] [blame] | 253 | # Copy files needed by lldb/macosx/heap.py to build libheap.dylib |
| 254 | heap_dir="${framework_python_dir}/macosx/heap" |
| 255 | if [ ! -d "${heap_dir}" ] |
| 256 | then |
| 257 | mkdir -p "${heap_dir}" |
| 258 | cp "${SRC_ROOT}/examples/darwin/heap_find/heap/heap_find.cpp" "${heap_dir}" |
| 259 | cp "${SRC_ROOT}/examples/darwin/heap_find/heap/Makefile" "${heap_dir}" |
| 260 | fi |
| 261 | fi |
Enrico Granata | 8f84cfb | 2012-02-23 23:10:03 +0000 | [diff] [blame] | 262 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 263 | fi |
Greg Clayton | 6f2f0ab | 2012-04-25 01:49:50 +0000 | [diff] [blame] | 264 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 265 | exit 0 |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 266 | |