summaryrefslogtreecommitdiffstats
path: root/lldb/scripts/Python/finish-swig-Python-LLDB.sh
blob: 66dfd9978ced7c0fdb8ff61a950a35929031358e (plain)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#! /bin/sh

# finish-swig-Python.sh
#
# For the Python script interpreter (external to liblldb) to be able to import
# and use the lldb module, there must be two files, lldb.py and _lldb.so, that
# it can find. lldb.py is generated by SWIG at the same time it generates the
# C++ file.  _lldb.so is actually a symlink file that points to the 
# LLDB shared library/framework.
#
# The Python script interpreter needs to be able to automatically find 
# these two files. On Darwin systems it searches in the LLDB.framework, as
# well as in all the normal Python search paths.  On non-Darwin systems
# these files will need to be put someplace where Python will find them.
#
# This shell script creates the _lldb.so symlink in the appropriate place,
# and copies the lldb.py (and embedded_interpreter.py) file to the correct
# directory.
#

# SRC_ROOT is the root of the lldb source tree.
# TARGET_DIR is where the lldb framework/shared library gets put.
# CONFIG_BUILD_DIR is where the build-swig-Python-LLDB.sh  shell script 
#           put the lldb.py file it was generated from running SWIG.
# PYTHON_INSTALL_DIR is where non-Darwin systems want to put the .py and .so
#           files so that Python can find them automatically.
# debug_flag (optional) determines whether or not this script outputs 
#           additional information when running.

SRC_ROOT=$1
TARGET_DIR=$2
CONFIG_BUILD_DIR=$3
PYTHON_INSTALL_DIR=$4
debug_flag=$5

# Make sure SDKROOT is not set, since if it is this is an iOS build where python
# is disabled
if [ "x$SDKROOT" = "x" ] ; then

if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ]
then
    Debug=1
else
    Debug=0
fi

OS_NAME=`uname -s`
PYTHON_VERSION=`/usr/bin/python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'`


if [ $Debug == 1 ]
then
    echo "The current OS is $OS_NAME"
    echo "The Python version is $PYTHON_VERSION"
fi

#
#  Determine where to put the files.

if [ ${OS_NAME} == "Darwin" ]
then
    # We are on a Darwin system, so all the lldb Python files can go 
    # into the LLDB.framework/Resources/Python subdirectory.

    if [ ! -d "${TARGET_DIR}/LLDB.framework" ]
    then
        echo "Error:  Unable to find LLDB.framework" >&2
        exit 1
    else
        if [ $Debug == 1 ]
        then
            echo "Found ${TARGET_DIR}/LLDB.framework."
        fi
    fi

    # Make the Python directory in the framework if it doesn't already exist

    framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python"
else
    # We are on a non-Darwin system, so use the PYTHON_INSTALL_DIR argument,
    # and append the python version directory to the end of it.  Depending on
    # the system other stuff may need to be put here as well.

    framework_python_dir="${PYTHON_INSTALL_DIR}/python${PYTHON_VERSION}"
fi

#
# Look for the directory in which to put the Python files;  if it does not
# already exist, attempt to make it.
#

if [ $Debug == 1 ]
then
    echo "Python files will be put in ${framework_python_dir}"
fi

if [ ! -d "${framework_python_dir}" ]
then
    if [ $Debug == 1 ]
    then
        echo "Making directory ${framework_python_dir}"
    fi
    mkdir -p "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "${framework_python_dir} already exists."
    fi
fi

if [ ! -d "${framework_python_dir}" ]
then
    echo "Error: Unable to find or create ${framework_python_dir}" >&2
    exit 1
fi

# Make the symlink that the script bridge for Python will need in the
# Python framework directory

if [ ! -L "${framework_python_dir}/_lldb.so" ]
then
    if [ $Debug == 1 ]
    then
        echo "Creating symlink for _lldb.so"
    fi
    if [ ${OS_NAME} == "Darwin" ]
    then
        cd "${framework_python_dir}"
        ln -s "../../LLDB" _lldb.so
    else
        cd "${TARGET_DIR}"
        ln -s "./LLDB" _lldb.so
    fi
else
    if [ $Debug == 1 ]
    then
        echo "${framework_python_dir}/_lldb.so already exists."
    fi
fi

# Copy the python module (lldb.py) that was generated by SWIG 
# over to the framework Python directory
if [ -f "${CONFIG_BUILD_DIR}/lldb.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying lldb.py to ${framework_python_dir}"
    fi
    cp "${CONFIG_BUILD_DIR}/lldb.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${CONFIG_BUILD_DIR}/lldb.py"
    fi
fi

# Copy the embedded interpreter script over to the framework Python directory
if [ -f "${SRC_ROOT}/source/Interpreter/embedded_interpreter.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying embedded_interpreter.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/source/Interpreter/embedded_interpreter.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/source/Interpreter/embedded_interpreter.py"
    fi
fi

# Copy the C++ STL formatters over to the framework Python directory
if [ -f "${SRC_ROOT}/examples/synthetic/gnu_libstdcpp.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying gnu_libstdcpp.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/synthetic/gnu_libstdcpp.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/synthetic/gnu_libstdcpp.py"
    fi
fi

# Copy the ObjC formatters over to the framework Python directory
if [ -f "${SRC_ROOT}/examples/summaries/objc.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying objc.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/objc.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/objc.py"
    fi
fi

# Copy the Cocoa formatters over to the framework Python directory
if [ -f "${SRC_ROOT}/examples/summaries/cocoa/CFArray.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying CFArray.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/CFArray.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/CFArray.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/CFDictionary.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying CFDictionary.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/CFDictionary.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/CFDictionary.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/CFString.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying CFString.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/CFString.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/CFString.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSData.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying NSData.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/NSData.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSData.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSMachPort.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying NSMachPort.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/NSMachPort.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSMachPort.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSSet.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying NSSet.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/NSSet.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSSet.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSNotification.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying NSNotification.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/NSNotification.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSNotification.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSException.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying NSException.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/NSException.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSException.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/CFBag.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying CFBag.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/CFBag.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/CFBag.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/CFBinaryHeap.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying CFBinaryHeap.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/CFBinaryHeap.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/CFBinaryHeap.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSURL.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying NSURL.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/NSURL.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSURL.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSBundle.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying NSBundle.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/NSBundle.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSBundle.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSNumber.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying NSNumber.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/NSNumber.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSNumber.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSDate.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying NSDate.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/NSDate.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSDate.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSIndexSet.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying NSIndexSet.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/NSIndexSet.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSIndexSet.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/cache.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying cache.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/cache.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/cache.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/metrics.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying metrics.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/metrics.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/metrics.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/objc_lldb.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying objc_lldb.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/objc_lldb.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/objc_lldb.py"
    fi
fi

if [ -f "${SRC_ROOT}/examples/summaries/cocoa/objc_runtime.py" ]
then
    if [ $Debug == 1 ]
    then
        echo "Copying objc_runtime.py to ${framework_python_dir}"
    fi
    cp "${SRC_ROOT}/examples/summaries/cocoa/objc_runtime.py" "${framework_python_dir}"
else
    if [ $Debug == 1 ]
    then
        echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/objc_runtime.py"
    fi
fi

fi

exit 0

OpenPOWER on IntegriCloud