finish-swig-Python-LLDB.sh [plain text]
#! /bin/sh
SRC_ROOT=$1
TARGET_DIR=$2
CONFIG_BUILD_DIR=$3
PYTHON_INSTALL_DIR=$4
debug_flag=$5
if [ ! $LLDB_DISABLE_PYTHON = "1" ] ; 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
if [ ${OS_NAME} == "Darwin" ]
then
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
framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python/lldb"
else
framework_python_dir="${PYTHON_INSTALL_DIR}/python${PYTHON_VERSION}/lldb"
fi
if [ $Debug == 1 ]
then
echo "Python files will be put in ${framework_python_dir}"
fi
python_dirs="${framework_python_dir}"
for python_dir in $python_dirs
do
if [ ! -d "${python_dir}" ]
then
if [ $Debug == 1 ]
then
echo "Making directory ${python_dir}"
fi
mkdir -p "${python_dir}"
else
if [ $Debug == 1 ]
then
echo "${python_dir} already exists."
fi
fi
if [ ! -d "${python_dir}" ]
then
echo "Error: Unable to find or create ${python_dir}" >&2
exit 1
fi
done
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
function create_python_package {
package_dir="${framework_python_dir}$1"
package_files="$2"
package_name=`echo $1 | tr '/' '.'`
package_name="lldb${package_name}"
if [ ! -d "${package_dir}" ]
then
mkdir -p "${package_dir}"
fi
for package_file in $package_files
do
if [ -f "${package_file}" ]
then
cp "${package_file}" "${package_dir}"
package_file_basename=$(basename "${package_file}")
fi
done
package_init_file="${package_dir}/__init__.py"
if [ ! -f "${package_init_file}" ]
then
echo -n "__all__ = [" > "${package_init_file}"
python_module_separator=""
for package_file in $package_files
do
if [ -f "${package_file}" ]
then
package_file_basename=$(basename "${package_file}")
echo -n "${python_module_separator}\"${package_file_basename%.*}\"" >> "${package_init_file}"
python_module_separator=", "
fi
done
echo "]" >> "${package_init_file}"
echo "for x in __all__:" >> "${package_init_file}"
echo " __import__('${package_name}.'+x)" >> "${package_init_file}"
fi
}
cp "${CONFIG_BUILD_DIR}/lldb.py" "${framework_python_dir}/__init__.py"
package_files="${SRC_ROOT}/source/Interpreter/embedded_interpreter.py"
create_python_package "" "${package_files}"
package_files="${SRC_ROOT}/examples/synthetic/gnu_libstdcpp.py
${SRC_ROOT}/examples/synthetic/libcxx.py"
create_python_package "/formatters/cpp" "${package_files}"
package_files="${SRC_ROOT}/examples/summaries/cocoa/Selector.py
${SRC_ROOT}/examples/summaries/objc.py
${SRC_ROOT}/examples/summaries/cocoa/Class.py
${SRC_ROOT}/examples/summaries/cocoa/CFArray.py
${SRC_ROOT}/examples/summaries/cocoa/CFBag.py
${SRC_ROOT}/examples/summaries/cocoa/CFBinaryHeap.py
${SRC_ROOT}/examples/summaries/cocoa/CFBitVector.py
${SRC_ROOT}/examples/summaries/cocoa/CFDictionary.py
${SRC_ROOT}/examples/summaries/cocoa/CFString.py
${SRC_ROOT}/examples/summaries/cocoa/NSBundle.py
${SRC_ROOT}/examples/summaries/cocoa/NSData.py
${SRC_ROOT}/examples/summaries/cocoa/NSDate.py
${SRC_ROOT}/examples/summaries/cocoa/NSException.py
${SRC_ROOT}/examples/summaries/cocoa/NSIndexSet.py
${SRC_ROOT}/examples/summaries/cocoa/NSMachPort.py
${SRC_ROOT}/examples/summaries/cocoa/NSNotification.py
${SRC_ROOT}/examples/summaries/cocoa/NSNumber.py
${SRC_ROOT}/examples/summaries/cocoa/NSSet.py
${SRC_ROOT}/examples/summaries/cocoa/NSURL.py"
create_python_package "/formatters/objc" "${package_files}"
create_python_package "/runtime" ""
package_files="${SRC_ROOT}/examples/summaries/cocoa/objc_runtime.py"
create_python_package "/runtime/objc" "${package_files}"
package_files="${SRC_ROOT}/examples/summaries/cocoa/cache.py
${SRC_ROOT}/examples/summaries/cocoa/metrics.py
${SRC_ROOT}/examples/summaries/cocoa/attrib_fromdict.py
${SRC_ROOT}/examples/summaries/cocoa/Logger.py"
create_python_package "/formatters" "${package_files}"
package_files="${SRC_ROOT}/examples/python/symbolication.py"
create_python_package "/utils" "${package_files}"
if [ ${OS_NAME} == "Darwin" ]
then
package_files="${SRC_ROOT}/examples/python/crashlog.py
${SRC_ROOT}/examples/darwin/heap_find/heap.py"
create_python_package "/macosx" "${package_files}"
heap_dir="${framework_python_dir}/macosx/heap"
if [ ! -d "${heap_dir}" ]
then
mkdir -p "${heap_dir}"
cp "${SRC_ROOT}/examples/darwin/heap_find/heap/heap_find.cpp" "${heap_dir}"
cp "${SRC_ROOT}/examples/darwin/heap_find/heap/Makefile" "${heap_dir}"
fi
fi
fi
exit 0