diff --git a/lldb/cmake/XcodeHeaderGenerator/CMakeLists.txt b/lldb/cmake/XcodeHeaderGenerator/CMakeLists.txt deleted file mode 100644 --- a/lldb/cmake/XcodeHeaderGenerator/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.3) - -project(XcodeConfig C CXX) - -set(CMAKE_MODULE_PATH - ${CMAKE_MODULE_PATH} - "${CMAKE_CURRENT_SOURCE_DIR}/.." - "${CMAKE_CURRENT_SOURCE_DIR}/../modules" - ) - -set(LLDB_CONFIG_HEADER_INPUT - ${CMAKE_CURRENT_SOURCE_DIR}/../../include/lldb/Host/Config.h.cmake) - -include(LLDBGenerateConfig) diff --git a/lldb/scripts/Python/finish-swig-Python-LLDB.sh b/lldb/scripts/Python/finish-swig-Python-LLDB.sh deleted file mode 100755 --- a/lldb/scripts/Python/finish-swig-Python-LLDB.sh +++ /dev/null @@ -1,309 +0,0 @@ -#!/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 -makefile_flag=$6 - -# If we don't want Python, then just do nothing here. -# Note, at present iOS doesn't have Python, so if you're building for iOS be sure to -# set LLDB_DISABLE_PYTHON to 1. - -if [ ! "$LLDB_DISABLE_PYTHON" = "1" ] ; then - -if [ -n "$debug_flag" -a "$debug_flag" = "-debug" ] -then - Debug=1 -else - Debug=0 -fi - -if [ -n "$makefile_flag" -a "$makefile_flag" = "-m" ] -then - MakefileCalled=1 -else - MakefileCalled=0 -fi - -OS_NAME=`uname -s` -PYTHON=${PYTHON_EXECUTABLE:-/usr/bin/env python} -PYTHON_VERSION=`${PYTHON} -c 'import sys; print("{}.{}".format(sys.version_info.major, sys.version_info.minor))'` - -if [ $Debug -eq 1 ] -then - echo "The current OS is $OS_NAME" - echo "The Python version is $PYTHON_VERSION" -fi - -if [ ${OS_NAME} = "Darwin" ] -then - SOEXT=".dylib" -else - SOEXT=".so" -fi - -# -# Determine where to put the files. - -if [ $MakefileCalled -eq 0 ] -then - # We are being built by Xcode, 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 -eq 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/lldb" -else - # We are being built by LLVM, 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. - - if [ -n "${PYTHON_INSTALL_DIR}" ] - then - framework_python_dir=`${PYTHON} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(True, False, \"${PYTHON_INSTALL_DIR}\");"`/lldb - else - framework_python_dir=`${PYTHON} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(True, False);"`/lldb - fi -fi - -[ -n "${CONFIG_BUILD_DIR}" ] || CONFIG_BUILD_DIR=${framework_python_dir} - -# -# Look for the directory in which to put the Python files; if it does not -# already exist, attempt to make it. -# - -if [ $Debug -eq 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 -eq 1 ] - then - echo "Making directory ${python_dir}" - fi - mkdir -p "${python_dir}" - else - if [ $Debug -eq 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 - -# 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 -eq 1 ] - then - echo "Creating symlink for _lldb.so" - fi - cd "${framework_python_dir}" - if [ $MakefileCalled -eq 0 ] - then - ln -s "../../../LLDB" _lldb.so - else - ln -s "../../../liblldb${SOEXT}" _lldb.so - fi -else - if [ $Debug -eq 1 ] - then - echo "${framework_python_dir}/_lldb.so already exists." - fi -fi - -# Make symlink for darwin-debug on Darwin -if [ ${OS_NAME} = "Darwin" ] && [ $MakefileCalled -ne 0 ] -then - # We are being built by CMake on Darwin - - if [ ! -L "${framework_python_dir}/darwin-debug" ] - then - if [ $Debug -eq 1 ] - then - echo "Creating symlink for darwin-debug" - fi - cd "${framework_python_dir}" - else - if [ $Debug -eq 1 ] - then - echo "${framework_python_dir}/darwin-debug already exists." - fi - fi -fi - -# Make symlink for lldb-argdumper on any platform -if [ $MakefileCalled -ne 0 ] -then - # We are being built by CMake - - if [ ! -L "${framework_python_dir}/lldb-argdumper" ] - then - if [ $Debug -eq 1 ] - then - echo "Creating symlink for lldb-argdumper" - fi - cd "${framework_python_dir}" - ln -s "../../../../bin/lldb-argdumper" lldb-argdumper - else - if [ $Debug -eq 1 ] - then - echo "${framework_python_dir}/lldb-argdumper already exists." - fi - fi -fi - -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 - - - # Create a packate init file if there wasn't one - package_init_file="${package_dir}/__init__.py" - if [ ! -f "${package_init_file}" ] - then - printf "__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}") - printf "${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 - - -} - -# Copy the lldb.py file into the lldb package directory and rename to __init_.py -cp "${CONFIG_BUILD_DIR}/lldb.py" "${framework_python_dir}/__init__.py" - -# lldb -package_files="${SRC_ROOT}/source/Interpreter/embedded_interpreter.py" -create_python_package "" "${package_files}" - -# lldb/formatters/cpp -package_files="${SRC_ROOT}/examples/synthetic/gnu_libstdcpp.py -${SRC_ROOT}/examples/synthetic/libcxx.py" -create_python_package "/formatters/cpp" "${package_files}" - -# make an empty __init__.py in lldb/runtime -# this is required for Python to recognize lldb.runtime as a valid package -# (and hence, lldb.runtime.objc as a valid contained package) -create_python_package "/runtime" "" - -# lldb/formatters -# having these files copied here ensures that lldb/formatters is a valid package itself -package_files="${SRC_ROOT}/examples/summaries/cocoa/cache.py -${SRC_ROOT}/examples/summaries/synth.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}" - -# lldb/utils -package_files="${SRC_ROOT}/examples/python/symbolication.py" -create_python_package "/utils" "${package_files}" - -if [ ${OS_NAME} = "Darwin" ] -then - # lldb/macosx - package_files="${SRC_ROOT}/examples/python/crashlog.py - ${SRC_ROOT}/examples/darwin/heap_find/heap.py" - create_python_package "/macosx" "${package_files}" - - # lldb/diagnose - package_files="${SRC_ROOT}/examples/python/diagnose_unwind.py - ${SRC_ROOT}/examples/python/diagnose_nsstring.py" - create_python_package "/diagnose" "${package_files}" - - # Copy files needed by lldb/macosx/heap.py to build libheap.dylib - 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 - diff --git a/lldb/scripts/Xcode/build-llvm.py b/lldb/scripts/Xcode/build-llvm.py deleted file mode 100755 --- a/lldb/scripts/Xcode/build-llvm.py +++ /dev/null @@ -1,461 +0,0 @@ -#!/usr/bin/env python - -import errno -import hashlib -import fnmatch -import os -import platform -import re -import repo -import subprocess -import sys - -from lldbbuild import * - -#### SETTINGS #### - -def LLVM_HASH_INCLUDES_DIFFS(): - return False - -# For use with Xcode-style builds - -def process_vcs(vcs): - return { - "svn": VCS.svn, - "git": VCS.git - }[vcs] - -def process_root(name): - return { - "llvm": llvm_source_path(), - "clang": clang_source_path(), - "ninja": ninja_source_path() - }[name] - -def process_repo(r): - return { - 'name': r["name"], - 'vcs': process_vcs(r["vcs"]), - 'root': process_root(r["name"]), - 'url': r["url"], - 'ref': r["ref"] - } - -def fallback_repo(name): - return { - 'name': name, - 'vcs': None, - 'root': process_root(name), - 'url': None, - 'ref': None - } - -def dirs_exist(names): - for name in names: - if not os.path.isdir(process_root(name)): - return False - return True - -def XCODE_REPOSITORIES(): - names = ["llvm", "clang", "ninja"] - if dirs_exist(names): - return [fallback_repo(n) for n in names] - override = repo.get_override() - if override: - return [process_repo(r) for r in override] - identifier = repo.identifier() - if identifier == None: - identifier = "" # repo.find will just use the fallback file - set = repo.find(identifier) - return [process_repo(r) for r in set] - - -def get_c_compiler(): - return subprocess.check_output([ - 'xcrun', - '--sdk', 'macosx', - '-find', 'clang' - ]).rstrip() - - -def get_cxx_compiler(): - return subprocess.check_output([ - 'xcrun', - '--sdk', 'macosx', - '-find', 'clang++' - ]).rstrip() - -# CFLAGS="-isysroot $(xcrun --sdk macosx --show-sdk-path) -mmacosx-version-min=${DARWIN_DEPLOYMENT_VERSION_OSX}" \ -# LDFLAGS="-mmacosx-version-min=${DARWIN_DEPLOYMENT_VERSION_OSX}" \ - - -def get_deployment_target(): - return os.environ.get('MACOSX_DEPLOYMENT_TARGET', None) - - -def get_c_flags(): - cflags = '' - # sdk_path = subprocess.check_output([ - # 'xcrun', - # '--sdk', 'macosx', - # '--show-sdk-path']).rstrip() - # cflags += '-isysroot {}'.format(sdk_path) - - deployment_target = get_deployment_target() - if deployment_target: - # cflags += ' -mmacosx-version-min={}'.format(deployment_target) - pass - - return cflags - - -def get_cxx_flags(): - return get_c_flags() - - -def get_common_linker_flags(): - linker_flags = "" - deployment_target = get_deployment_target() - if deployment_target: - # if len(linker_flags) > 0: - # linker_flags += ' ' - # linker_flags += '-mmacosx-version-min={}'.format(deployment_target) - pass - - return linker_flags - - -def get_exe_linker_flags(): - return get_common_linker_flags() - - -def get_shared_linker_flags(): - return get_common_linker_flags() - - -def CMAKE_FLAGS(): - return { - "Debug": [ - "-DCMAKE_BUILD_TYPE=RelWithDebInfo", - "-DLLVM_ENABLE_ASSERTIONS=ON", - ], - "DebugClang": [ - "-DCMAKE_BUILD_TYPE=Debug", - "-DLLVM_ENABLE_ASSERTIONS=ON", - ], - "Release": [ - "-DCMAKE_BUILD_TYPE=Release", - "-DLLVM_ENABLE_ASSERTIONS=ON", - ], - "BuildAndIntegration": [ - "-DCMAKE_BUILD_TYPE=Release", - "-DLLVM_ENABLE_ASSERTIONS=OFF", - ], - } - - -def CMAKE_ENVIRONMENT(): - return { - } - -#### COLLECTING ALL ARCHIVES #### - - -def collect_archives_in_path(path): - files = os.listdir(path) - # Only use libclang and libLLVM archives, and exclude libclang_rt - regexp = "^lib(clang[^_]|LLVM|gtest).*$" - return [ - os.path.join( - path, - file) for file in files if file.endswith(".a") and re.match( - regexp, - file)] - - -def archive_list(): - paths = library_paths() - archive_lists = [collect_archives_in_path(path) for path in paths] - return [archive for archive_list in archive_lists for archive in archive_list] - - -def write_archives_txt(): - f = open(archives_txt(), 'w') - for archive in archive_list(): - f.write(archive + "\n") - f.close() - -#### COLLECTING REPOSITORY MD5S #### - - -def source_control_status(spec): - vcs_for_spec = vcs(spec) - if LLVM_HASH_INCLUDES_DIFFS(): - return vcs_for_spec.status() + vcs_for_spec.diff() - else: - return vcs_for_spec.status() - - -def source_control_status_for_specs(specs): - statuses = [source_control_status(spec) for spec in specs] - return "".join(statuses) - - -def all_source_control_status(): - return source_control_status_for_specs(XCODE_REPOSITORIES()) - - -def md5(string): - m = hashlib.md5() - m.update(string) - return m.hexdigest() - - -def all_source_control_status_md5(): - return md5(all_source_control_status()) - -#### CHECKING OUT AND BUILDING LLVM #### - - -def apply_patches(spec): - files = os.listdir(os.path.join(lldb_source_path(), 'scripts')) - patches = [ - f for f in files if fnmatch.fnmatch( - f, spec['name'] + '.*.diff')] - for p in patches: - run_in_directory(["patch", - "-p1", - "-i", - os.path.join(lldb_source_path(), - 'scripts', - p)], - spec['root']) - - -def check_out_if_needed(spec): - if not os.path.isdir(spec['root']): - vcs(spec).check_out() - apply_patches(spec) - - -def all_check_out_if_needed(): - for r in XCODE_REPOSITORIES(): - check_out_if_needed(r) - - -def should_build_llvm(): - if build_type() == BuildType.Xcode: - # TODO use md5 sums - return True - - -def do_symlink(source_path, link_path): - print("Symlinking " + source_path + " to " + link_path) - if os.path.islink(link_path): - os.remove(link_path) - if not os.path.exists(link_path): - os.symlink(source_path, link_path) - - -def setup_source_symlink(repo): - source_path = repo["root"] - link_path = os.path.join(lldb_source_path(), os.path.basename(source_path)) - do_symlink(source_path, link_path) - - -def setup_source_symlinks(): - for r in XCODE_REPOSITORIES(): - setup_source_symlink(r) - - -def setup_build_symlink(): - # We don't use the build symlinks in llvm.org Xcode-based builds. - if build_type() != BuildType.Xcode: - source_path = package_build_path() - link_path = expected_package_build_path() - do_symlink(source_path, link_path) - - -def should_run_cmake(cmake_build_dir): - # We need to run cmake if our llvm build directory doesn't yet exist. - if not os.path.exists(cmake_build_dir): - return True - - # Wee also need to run cmake if for some reason we don't have a ninja - # build file. (Perhaps the cmake invocation failed, which this current - # build may have fixed). - ninja_path = os.path.join(cmake_build_dir, "build.ninja") - return not os.path.exists(ninja_path) - - -def cmake_environment(): - cmake_env = join_dicts(os.environ, CMAKE_ENVIRONMENT()) - return cmake_env - - -def is_executable(path): - return os.path.isfile(path) and os.access(path, os.X_OK) - - -def find_executable_in_paths(program, paths_to_check): - program_dir, program_name = os.path.split(program) - if program_dir: - if is_executable(program): - return program - else: - for path_dir in paths_to_check: - path_dir = path_dir.strip('"') - executable_file = os.path.join(path_dir, program) - if is_executable(executable_file): - return executable_file - return None - - -def find_cmake(): - # First check the system PATH env var for cmake - cmake_binary = find_executable_in_paths( - "cmake", os.environ["PATH"].split(os.pathsep)) - if cmake_binary: - # We found it there, use it. - return cmake_binary - - # Check a few more common spots. Xcode launched from Finder - # will have the default environment, and may not have - # all the normal places present. - extra_cmake_dirs = [ - "/usr/local/bin", - "/opt/local/bin", - os.path.join(os.path.expanduser("~"), "bin") - ] - - if platform.system() == "Darwin": - # Add locations where an official CMake.app package may be installed. - extra_cmake_dirs.extend([ - os.path.join( - os.path.expanduser("~"), - "Applications", - "CMake.app", - "Contents", - "bin"), - os.path.join( - os.sep, - "Applications", - "CMake.app", - "Contents", - "bin")]) - - cmake_binary = find_executable_in_paths("cmake", extra_cmake_dirs) - if cmake_binary: - # We found it in one of the usual places. Use that. - return cmake_binary - - # We couldn't find cmake. Tell the user what to do. - raise Exception( - "could not find cmake in PATH ({}) or in any of these locations ({}), " - "please install cmake or add a link to it in one of those locations".format( - os.environ["PATH"], extra_cmake_dirs)) - - -def cmake_flags(): - cmake_flags = CMAKE_FLAGS()[lldb_configuration()] - cmake_flags += ["-GNinja", - "-DCMAKE_C_COMPILER={}".format(get_c_compiler()), - "-DCMAKE_CXX_COMPILER={}".format(get_cxx_compiler()), - "-DCMAKE_INSTALL_PREFIX={}".format(expected_package_build_path_for("llvm")), - "-DCMAKE_C_FLAGS={}".format(get_c_flags()), - "-DCMAKE_CXX_FLAGS={}".format(get_cxx_flags()), - "-DCMAKE_EXE_LINKER_FLAGS={}".format(get_exe_linker_flags()), - "-DCMAKE_SHARED_LINKER_FLAGS={}".format(get_shared_linker_flags()), - "-DHAVE_CRASHREPORTER_INFO=1"] - deployment_target = get_deployment_target() - if deployment_target: - cmake_flags.append( - "-DCMAKE_OSX_DEPLOYMENT_TARGET={}".format(deployment_target)) - return cmake_flags - - -def run_cmake(cmake_build_dir, ninja_binary_path): - cmake_binary = find_cmake() - print("found cmake binary: using \"{}\"".format(cmake_binary)) - - command_line = [cmake_binary] + cmake_flags() + [ - "-DCMAKE_MAKE_PROGRAM={}".format(ninja_binary_path), - llvm_source_path()] - print("running cmake like so: ({}) in dir ({})".format(command_line, cmake_build_dir)) - - subprocess.check_call( - command_line, - cwd=cmake_build_dir, - env=cmake_environment()) - - -def create_directories_as_needed(path): - try: - os.makedirs(path) - except OSError as error: - # An error indicating that the directory exists already is fine. - # Anything else should be passed along. - if error.errno != errno.EEXIST: - raise error - - -def run_cmake_if_needed(ninja_binary_path): - cmake_build_dir = package_build_path() - if should_run_cmake(cmake_build_dir): - # Create the build directory as needed - create_directories_as_needed(cmake_build_dir) - run_cmake(cmake_build_dir, ninja_binary_path) - - -def build_ninja_if_needed(): - # First check if ninja is in our path. If so, there's nothing to do. - ninja_binary_path = find_executable_in_paths( - "ninja", os.environ["PATH"].split(os.pathsep)) - if ninja_binary_path: - # It's on the path. cmake will find it. We're good. - print("found ninja here: \"{}\"".format(ninja_binary_path)) - return ninja_binary_path - - # Figure out if we need to build it. - ninja_build_dir = ninja_source_path() - ninja_binary_path = os.path.join(ninja_build_dir, "ninja") - if not is_executable(ninja_binary_path): - # Build ninja - command_line = ["python", "configure.py", "--bootstrap"] - print("building ninja like so: ({}) in dir ({})".format(command_line, ninja_build_dir)) - subprocess.check_call( - command_line, - cwd=ninja_build_dir, - env=os.environ) - - return ninja_binary_path - - -def join_dicts(dict1, dict2): - d = dict1.copy() - d.update(dict2) - return d - - -def build_llvm(ninja_binary_path): - cmake_build_dir = package_build_path() - subprocess.check_call( - [ninja_binary_path], - cwd=cmake_build_dir, - env=cmake_environment()) - - -def build_llvm_if_needed(): - if should_build_llvm(): - ninja_binary_path = build_ninja_if_needed() - run_cmake_if_needed(ninja_binary_path) - build_llvm(ninja_binary_path) - setup_build_symlink() - -#### MAIN LOGIC #### - -if __name__ == "__main__": - all_check_out_if_needed() - build_llvm_if_needed() - write_archives_txt() - sys.exit(0) diff --git a/lldb/scripts/Xcode/lldbbuild.py b/lldb/scripts/Xcode/lldbbuild.py deleted file mode 100644 --- a/lldb/scripts/Xcode/lldbbuild.py +++ /dev/null @@ -1,193 +0,0 @@ -import os -import subprocess -import sys - -#### UTILITIES #### - - -def enum(*sequential, **named): - enums = dict(zip(sequential, range(len(sequential))), **named) - return type('Enum', (), enums) - -#### SETTINGS #### - -#### INTERFACE TO THE XCODEPROJ #### - - -def lldb_source_path(): - path = os.environ.get('SRCROOT') - if path: - return path - else: - return "./" - - -def expected_llvm_build_path(): - if build_type() == BuildType.Xcode: - return package_build_path() - else: - return os.path.join( - os.environ.get('LLDB_PATH_TO_LLVM_BUILD'), - package_build_dir_name("llvm")) - - -def archives_txt(): - return os.path.join(expected_package_build_path(), "archives.txt") - - -def expected_package_build_path(): - return os.path.abspath(os.path.join(expected_llvm_build_path(), "..")) - -def is_host_build(): - rc_project_name = os.environ.get('RC_ProjectName') - if rc_project_name: - if rc_project_name == 'lldb_host': return True - return False - -def rc_release_target(): - return os.environ.get('RC_RELEASE', '') - -def rc_platform_name(): - return os.environ.get('RC_PLATFORM_NAME', 'macOS') - -def architecture(): - if is_host_build(): return 'macosx' - platform_name = os.environ.get('RC_PLATFORM_NAME') - if not platform_name: - platform_name = os.environ.get('PLATFORM_NAME') - platform_arch = os.environ.get('ARCHS').split()[-1] - return platform_name + "-" + platform_arch - - -def lldb_configuration(): - return os.environ.get('CONFIGURATION') - - -def llvm_configuration(): - return os.environ.get('LLVM_CONFIGURATION') - - -def llvm_build_dirtree(): - return os.environ.get('LLVM_BUILD_DIRTREE') - -# Edit the code below when adding build styles. - -BuildType = enum('Xcode') # (Debug,DebugClang,Release) - - -def build_type(): - return BuildType.Xcode - -#### VCS UTILITIES #### - -VCS = enum('git', - 'svn') - - -def run_in_directory(args, path): - return subprocess.check_output([str(arg) for arg in args], cwd=path) - - -class Git: - - def __init__(self, spec): - self.spec = spec - - def status(self): - return run_in_directory(["git", "branch", "-v"], self.spec['root']) - - def diff(self): - return run_in_directory(["git", "diff"], self.spec['root']) - - def check_out(self): - run_in_directory(["git", - "clone", - "--depth=1", - self.spec['url'], - self.spec['root']], - lldb_source_path()) - run_in_directory(["git", "fetch", "--all"], self.spec['root']) - run_in_directory(["git", "checkout", self.spec[ - 'ref']], self.spec['root']) - - -class SVN: - - def __init__(self, spec): - self.spec = spec - - def status(self): - return run_in_directory(["svn", "info"], self.spec['root']) - - def diff(self): - return run_in_directory(["svn", "diff"], self.spec['root']) - # TODO implement check_out - - -def vcs(spec): - if spec['vcs'] == VCS.git: - return Git(spec) - elif spec['vcs'] == VCS.svn: - return SVN(spec) - else: - return None - -#### SOURCE PATHS #### - - -def llvm_source_path(): - if build_type() == BuildType.Xcode: - return os.path.join(lldb_source_path(), "llvm") - - -def clang_source_path(): - if build_type() == BuildType.Xcode: - return os.path.join(llvm_source_path(), "tools", "clang") - - -def ninja_source_path(): - if build_type() == BuildType.Xcode: - return os.path.join(lldb_source_path(), "ninja") - -#### BUILD PATHS #### - - -def packages(): - return ["llvm"] - - -def package_build_dir_name(package): - return package + "-" + architecture() - - -def expected_package_build_path_for(package): - if build_type() == BuildType.Xcode: - if package != "llvm": - raise "On Xcode build, we only support the llvm package: requested {}" - return package_build_path() - return os.path.join( - expected_package_build_path(), - package_build_dir_name(package)) - - -def expected_package_build_paths(): - return [expected_package_build_path_for(package) for package in packages()] - - -def library_path(build_path): - return build_path + "/lib" - - -def library_paths(): - if build_type() == BuildType.Xcode: - package_build_paths = [package_build_path()] - else: - package_build_paths = expected_package_build_paths() - return [library_path(build_path) for build_path in package_build_paths] - - -def package_build_path(): - return os.path.join( - llvm_build_dirtree(), - os.environ["LLVM_CONFIGURATION"], - "x86_64") diff --git a/lldb/scripts/Xcode/package-clang-resource-headers.py b/lldb/scripts/Xcode/package-clang-resource-headers.py deleted file mode 100644 --- a/lldb/scripts/Xcode/package-clang-resource-headers.py +++ /dev/null @@ -1,85 +0,0 @@ -#! /usr/bin/env python - -# package-clang-resource-headers.py -# -# The Clang module loader depends on built-in headers for the Clang compiler. -# We grab these from the Clang build and move them into the LLDB module. - -# TARGET_DIR is where the lldb framework/shared library gets put. -# LLVM_BUILD_DIR is where LLVM and Clang got built -# LLVM_BUILD_DIR/lib/clang should exist and contain headers - -import os -import re -import shutil -import sys - -import lldbbuild - -if len(sys.argv) != 3: - print("usage: " + sys.argv[0] + " TARGET_DIR LLVM_BUILD_DIR") - sys.exit(1) - -target_dir = sys.argv[1] -llvm_build_dir = lldbbuild.expected_package_build_path_for("llvm") - -if not os.path.isdir(target_dir): - print(target_dir + " doesn't exist") - sys.exit(1) - -if not os.path.isdir(llvm_build_dir): - llvm_build_dir = re.sub("-macosx-", "-iphoneos-", llvm_build_dir) - -if not os.path.isdir(llvm_build_dir): - llvm_build_dir = re.sub("-iphoneos-", "-appletvos-", llvm_build_dir) - -if not os.path.isdir(llvm_build_dir): - llvm_build_dir = re.sub("-appletvos-", "-watchos-", llvm_build_dir) - -if not os.path.isdir(llvm_build_dir): - llvm_build_dir = re.sub("-watchos-", "-bridgeos-", llvm_build_dir) - -if not os.path.isdir(llvm_build_dir): - print(llvm_build_dir + " doesn't exist") - sys.exit(1) - -resources = os.path.join(target_dir, "LLDB.framework", "Resources") - -if not os.path.isdir(resources): - print(resources + " must exist") - sys.exit(1) - -clang_dir = os.path.join(llvm_build_dir, "lib", "clang") - -if not os.path.isdir(clang_dir): - print(clang_dir + " must exist") - sys.exit(1) - -version_dir = None - -for subdir in os.listdir(clang_dir): - if (re.match("^[0-9]+(\.[0-9]+)*$", subdir)): - version_dir = os.path.join(clang_dir, subdir) - break - -if version_dir is None: - print("Couldn't find a subdirectory of the form #(.#)... in " + clang_dir) - sys.exit(1) - -if not os.path.isdir(version_dir): - print(version_dir + " is not a directory") - sys.exit(1) - -# Just checking... we're actually going to copy all of version_dir -include_dir = os.path.join(version_dir, "include") - -if not os.path.isdir(include_dir): - print(version_dir + " is not a directory") - sys.exit(1) - -clang_resources = os.path.join(resources, "Clang") - -if os.path.isdir(clang_resources): - shutil.rmtree(clang_resources) - -shutil.copytree(version_dir, clang_resources) diff --git a/lldb/scripts/Xcode/prepare-gtest-run-dir.sh b/lldb/scripts/Xcode/prepare-gtest-run-dir.sh deleted file mode 100755 --- a/lldb/scripts/Xcode/prepare-gtest-run-dir.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -RUNTIME_INPUTS_DIR="${TARGET_BUILD_DIR}/Inputs" -echo "Making runtime Inputs directory: $RUNTIME_INPUTS_DIR" -mkdir -p "$RUNTIME_INPUTS_DIR" - -for input_dir in $(find unittests -type d -name Inputs); do - echo "Copying $input_dir into $RUNTIME_INPUTS_DIR" - cp -r "${input_dir}"/* "${RUNTIME_INPUTS_DIR}/" -done diff --git a/lldb/scripts/Xcode/repo.py b/lldb/scripts/Xcode/repo.py deleted file mode 100644 --- a/lldb/scripts/Xcode/repo.py +++ /dev/null @@ -1,54 +0,0 @@ -import json -import os -import re -import shutil -import subprocess -import sys - -def identifier(): - try: - svn_output = subprocess.check_output(["svn", "info", "--show-item", "url"], stderr=subprocess.STDOUT).rstrip() - return svn_output - except: - pass - try: - git_remote_and_branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"], stderr=subprocess.STDOUT).rstrip() - git_remote = git_remote_and_branch.split("/")[0] - git_branch = "/".join(git_remote_and_branch.split("/")[1:]) - git_url = subprocess.check_output(["git", "remote", "get-url", git_remote]).rstrip() - return git_url + ":" + git_branch - except: - pass - return None - -def get_override(): - dir = os.path.dirname(os.path.realpath(__file__)) - repos_dir = os.path.join(dir, "repos") - json_regex = re.compile(r"^.*.json$") - override_path = os.path.join(repos_dir, "OVERRIDE") - if os.path.isfile(override_path): - override_set = json.load(open(override_path)) - return override_set["repos"] - else: - return None - -def find(identifier): - dir = os.path.dirname(os.path.realpath(__file__)) - repos_dir = os.path.join(dir, "repos") - json_regex = re.compile(r"^.*.json$") - override_path = os.path.join(repos_dir, "OVERRIDE") - if os.path.isfile(override_path): - override_set = json.load(open(override_path)) - return override_set["repos"] - fallback_path = os.path.join(repos_dir, "FALLBACK") - for path in [os.path.join(repos_dir, f) for f in filter(json_regex.match, os.listdir(repos_dir))]: - fd = open(path) - set = json.load(fd) - fd.close() - if any(re.match(set_regex, identifier) for set_regex in set["regexs"]): - shutil.copyfile(path, fallback_path) - return set["repos"] - if os.path.isfile(fallback_path): - fallback_set = json.load(open(fallback_path)) - return fallback_set["repos"] - sys.exit("Couldn't find a branch configuration for " + identifier + " and there was no " + fallback_path) diff --git a/lldb/scripts/Xcode/repos/FALLBACK b/lldb/scripts/Xcode/repos/FALLBACK deleted file mode 100644 --- a/lldb/scripts/Xcode/repos/FALLBACK +++ /dev/null @@ -1,19 +0,0 @@ -{ - "regexs" : [".*llvm\\.org.*"], - "repos" : [ - {"name": "llvm", - "vcs": "git", - "url": "http://llvm.org/git/llvm.git", - "ref": "master"}, - - {"name": "clang", - "vcs": "git", - "url": "http://llvm.org/git/clang.git", - "ref": "master"}, - - {"name": "ninja", - "vcs": "git", - "url": "https://github.com/ninja-build/ninja.git", - "ref": "master"} - ] -} diff --git a/lldb/scripts/Xcode/repos/svn-trunk.json b/lldb/scripts/Xcode/repos/svn-trunk.json deleted file mode 100644 --- a/lldb/scripts/Xcode/repos/svn-trunk.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "regexs" : [".*llvm\\.org.*"], - "repos" : [ - {"name": "llvm", - "vcs": "git", - "url": "http://llvm.org/git/llvm.git", - "ref": "master"}, - - {"name": "clang", - "vcs": "git", - "url": "http://llvm.org/git/clang.git", - "ref": "master"}, - - {"name": "ninja", - "vcs": "git", - "url": "https://github.com/ninja-build/ninja.git", - "ref": "master"} - ] -} diff --git a/lldb/scripts/build-lldb-llvm-clang b/lldb/scripts/build-lldb-llvm-clang deleted file mode 100755 --- a/lldb/scripts/build-lldb-llvm-clang +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/sh -x - -# Usage: -# build-lldb-llvm-clang [Debug|Release|BuildAndIntegration] -# build-lldb-llvm-clang [Debug|Release|BuildAndIntegration] - -LLVM_REVISION=$1 -CLANG_REVISION=$2 -LLVM_CONFIGURATION=$3 - -if [ "$LLVM_REVISION" = "" ]; then - echo "Usage:\n build-lldb-llvm-clang [ Debug|Release||BuildAndIntegration]" - exit 1 -fi - -if [ "$CLANG_REVISION" = "" ]; then - $CLANG_REVISION = $LLVM_REVISION -fi - -# Checkout LLVM -svn co -q -r $LLVM_REVISION http://llvm.org/svn/llvm-project/llvm/trunk llvm - -# change directory to "./llvm" -cd llvm - -# Checkout Clang -# change directory to "./llvm/tools" -cd tools -svn co -q -r $CLANG_REVISION http://llvm.org/svn/llvm-project/cfe/trunk clang - -# change directory to "./llvm" -cd .. -for patch_file in ../scripts/llvm.*.diff -do - echo "Applying patch from '$patch_file'" - patch -p1 < "$patch_file" -done - -# change directory to "./llvm/tools/clang" -cd tools/clang -for patch_file in ../../../scripts/clang.*.diff -do - echo "Applying patch from '$patch_file'" - patch -p1 < "$patch_file" -done - -# change directory to "./" -cd ../../.. -pwd - -if [ "$LLVM_CONFIGURATION" = "Debug" ]; then - # Configure "Debug+Asserts" build - mkdir llvm-debug - cd llvm-debug - ../llvm/configure --enable-targets=x86_64,arm - make -j8 clang-only VERBOSE=1 PROJECT_NAME='llvm' - make -j8 tools-only VERBOSE=1 PROJECT_NAME='llvm' EDIS_VERSION=1 -elif [ "$LLVM_CONFIGURATION" = "Release" ]; then - # Configure "Release" build - mkdir llvm-release - cd llvm-release - ../llvm/configure --enable-targets=x86_64,arm --enable-optimized --disable-assertions - make -j8 clang-only VERBOSE=1 PROJECT_NAME='llvm' - make -j8 tools-only VERBOSE=1 PROJECT_NAME='llvm' EDIS_VERSION=1 -elif [ "$LLVM_CONFIGURATION" = "BuildAndIntegration" ]; then - # Don't configure or build for "BuildAndIntegration", this configuration - # is a preparation step for a build submission - - # Remove all patches, and the llvm and clang "test" directories - rm -rf ./scripts/*.diff ./llvm/test ./llvm/tools/clang/test -else - echo "checked out llvm (revision $LLVM_REVISION) and clang (revision $CLANG_REVISION)." - exit 0 -fi diff --git a/lldb/scripts/checkpoint-llvm.pl b/lldb/scripts/checkpoint-llvm.pl deleted file mode 100755 --- a/lldb/scripts/checkpoint-llvm.pl +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/perl - -# This script should be pointed to a valid llvm.build folder that -# was created using the "build-llvm.pl" shell script. It will create -# a new llvm.zip file that can be checked into the repository -# at lldb/llvm.zip - -use strict; -use Cwd 'abs_path'; -use File::Basename; -use File::Temp qw/ tempfile tempdir /; -our $debug = 1; - - -sub do_command -{ - my $cmd = shift; - my $description = @_ ? shift : "command"; - my $die_on_fail = @_ ? shift : undef; - $debug and print "% $cmd\n"; - system ($cmd); - if ($? == -1) - { - $debug and printf ("error: %s failed to execute: $!\n", $description); - $die_on_fail and $? and exit(1); - return $?; - } - elsif ($? & 127) - { - $debug and printf("error: %s child died with signal %d, %s coredump\n", - $description, - ($? & 127), - ($? & 128) ? 'with' : 'without'); - $die_on_fail and $? and exit(1); - return $?; - } - else - { - my $exit = $? >> 8; - if ($exit) - { - $debug and printf("error: %s child exited with value %d\n", $description, $exit); - $die_on_fail and exit(1); - } - return $exit; - } -} - -sub do_rsync_paths -{ - while (@_) - { - my $rsync_src = shift @_; - my $rsync_dst = shift @_; - print "rsync_src = '$rsync_src'\n"; - print "rsync_dst = '$rsync_dst'\n"; - - if (!-d $rsync_dst) - { - mkdir $rsync_dst; - } - - if (-e $rsync_src) - { - my ($rsync_dst_file, $rsync_dst_dir) = fileparse ($rsync_dst); - print "rsync_dst_dir = '$rsync_dst_dir'\n"; - -e $rsync_dst_dir or do_command ("mkdir -p '$rsync_dst_dir'"); - do_command ("rsync -amvC --exclude='*.tmp' --exclude='*.txt' --exclude='*.TXT' --exclude='*.td' --exclude='\.dir' --exclude=Makefile '$rsync_src' '$rsync_dst'"); - } - else - { - die "$rsync_src does not exist!\n"; - } - } -} - -if (@ARGV > 4) -{ - my $llvm_source_dir = abs_path(shift @ARGV); # The llvm source that contains full llvm and clang sources - my $llvm_build_dir = abs_path(shift @ARGV); # The llvm build directory that contains headers and - my $lldb_build_dir = abs_path(shift @ARGV); # the build directory that contains the fat libEnhancedDisassembly.dylib - my $llvm_zip_file = abs_path(shift @ARGV); - - printf("LLVM sources : '%s'\n", $llvm_source_dir); - printf("LLVM build : '%s'\n", $llvm_build_dir); - printf("LLDB build : '%s'\n", $lldb_build_dir); - printf("LLVM zip file: '%s'\n", $llvm_zip_file); - - -e $llvm_build_dir or die "LLVM build directory doesn't exist: '$llvm_build_dir': $!\n"; - - my $temp_dir = tempdir( CLEANUP => 1 ); - print "temp dir = '$temp_dir'\n"; - my $llvm_checkpoint_dir = "$temp_dir/llvm"; - mkdir "$llvm_checkpoint_dir" or die "Couldn't make 'llvm' in '$temp_dir'\n"; - - my @generic_rsync_src_dst_paths = - ( - "$llvm_source_dir/include", "$llvm_checkpoint_dir", - "$llvm_source_dir/tools/clang/include", "$llvm_checkpoint_dir/tools/clang", - ); - - do_rsync_paths (@generic_rsync_src_dst_paths); - - for my $arch (@ARGV) - { - my @specific_rsync_src_dst_paths = - ( - "$llvm_build_dir/$arch/include", "$llvm_checkpoint_dir/$arch", - "$llvm_build_dir/$arch/tools/clang/include", "$llvm_checkpoint_dir/$arch/tools/clang", - ); - - do_rsync_paths (@specific_rsync_src_dst_paths); - - do_command ("cp '$llvm_build_dir/$arch/libllvmclang.a' '$llvm_checkpoint_dir/$arch/libllvmclang.a'", "Copying .a file", 1); - - } - - #do_command ("cp '$llvm_build_dir/libllvmclang.a' '$llvm_checkpoint_dir'", "Copying libllvmclang.a", 1); - do_command ("rm -rf '$llvm_zip_file'", "Removing old llvm checkpoint file '$llvm_zip_file'", 1); - do_command ("(cd '$temp_dir' ; zip -r '$llvm_zip_file' 'llvm')", "Zipping llvm checkpoint directory '$llvm_checkpoint_dir' to '$llvm_zip_file'", 1); -} -else -{ - print "USAGE\n\tcheckpoint-llvm.pl [ ...]\n\n"; - print "EXAMPLE\n\tcd lldb\n\t./scripts/checkpoint-llvm.pl llvm build/llvm build/BuildAndIntegration llvm.zip x86_64 i386\n"; -} diff --git a/lldb/scripts/finish-swig-wrapper-classes.sh b/lldb/scripts/finish-swig-wrapper-classes.sh deleted file mode 100755 --- a/lldb/scripts/finish-swig-wrapper-classes.sh +++ /dev/null @@ -1,101 +0,0 @@ -#! /bin/sh - -# finish-swig-wrapper-classes.sh -# -# For each scripting language liblldb supports, we need to create the -# appropriate Script Bridge wrapper classes for that language so that -# users can call Script Bridge functions from within the script interpreter. -# -# We use SWIG to create a C++ file containing the appropriate wrapper classes -# and funcitons for each scripting language, before liblldb is built (thus -# the C++ file can be compiled into liblldb. In some cases, additional work -# may need to be done after liblldb has been compiled, to make the scripting -# language stuff fully functional. Any such post-processing is handled through -# the shell scripts called here. - -# 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 generated from running SWIG. -# PREFIX is the root directory used to determine where third-party modules -# for scripting languages should be installed. -# debug_flag (optional) determines whether or not this script outputs -# additional information when running. - -SRC_ROOT=$1 -TARGET_DIR=$2 -CONFIG_BUILD_DIR=$3 -PREFIX=$4 - -shift 4 - -if [ -n "$1" -a "$1" = "-debug" ] -then - debug_flag=$1 - Debug=1 - shift -else - debug_flag="" - Debug=0 -fi - -if [ -n "$1" -a "$1" = "-m" ] -then - makefile_flag="$1" - shift -else - makefile_flag="" -fi - -# -# For each scripting language, see if a post-processing script for that -# language exists, and if so, call it. -# -# For now the only language we support is Python, but we expect this to -# change. - -languages="Python" -cwd=${SRC_ROOT}/scripts - -for curlang in $languages -do - if [ $Debug -eq 1 ] - then - echo "Current language is $curlang" - fi - - if [ ! -d "$cwd/$curlang" ] - then - echo "error: unable to find $curlang script sub-dirctory" >&2 - continue - else - - if [ $Debug -eq 1 ] - then - echo "Found $curlang sub-directory" - fi - - cd $cwd/$curlang - - filename="./finish-swig-${curlang}-LLDB.sh" - - if [ -f $filename ] - then - if [ $Debug -eq 1 ] - then - echo "Found $curlang post-processing script for LLDB" - echo "Executing $curlang post-processing script..." - fi - - - ./finish-swig-${curlang}-LLDB.sh $SRC_ROOT $TARGET_DIR $CONFIG_BUILD_DIR "${PREFIX}" "${debug_flag}" "${makefile_flag}" - retval=$? - if [ $retval -ne 0 ]; then - echo "$(pwd)/finish-swig-${curlang}-LLDB.sh failed with exit code $retval" - exit $retval - fi - fi - fi -done - -exit 0 diff --git a/lldb/scripts/install-lldb.sh b/lldb/scripts/install-lldb.sh deleted file mode 100755 --- a/lldb/scripts/install-lldb.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/sh - - -# This script will install the files from a "Debug" or "Release" build -# directory into the developer folder specified. - -NUM_EXPECTED_ARGS=2 - -PROGRAM=`basename $0` - -if [ $# -ne $NUM_EXPECTED_ARGS ]; then - echo This script will install the files from a 'Debug' or 'Release' build directory into the developer folder specified. - echo "usage: $PROGRAM "; - echo "example: $PROGRAM ./Debug /Developer" - echo "example: $PROGRAM /build/Release /Xcode4" - exit 1; -fi - -BUILD_DIR=$1 -DEVELOPER_DIR=$2 - -if [ -d $BUILD_DIR ]; then - if [ -d $DEVELOPER_DIR ]; then - if [ -e "$BUILD_DIR/debugserver" ]; then - echo Updating "$DEVELOPER_DIR/usr/bin/debugserver" - sudo rm -rf "$DEVELOPER_DIR/usr/bin/debugserver" - sudo cp "$BUILD_DIR/debugserver" "$DEVELOPER_DIR/usr/bin/debugserver" - fi - - if [ -e "$BUILD_DIR/lldb" ]; then - echo Updating "$DEVELOPER_DIR/usr/bin/lldb" - sudo rm -rf "$DEVELOPER_DIR/usr/bin/lldb" - sudo cp "$BUILD_DIR/lldb" "$DEVELOPER_DIR/usr/bin/lldb" - fi - - if [ -e "$BUILD_DIR/libEnhancedDisassembly.dylib" ]; then - echo Updating "$DEVELOPER_DIR/usr/lib/libEnhancedDisassembly.dylib" - sudo rm -rf "$DEVELOPER_DIR/usr/lib/libEnhancedDisassembly.dylib" - sudo cp "$BUILD_DIR/libEnhancedDisassembly.dylib" "$DEVELOPER_DIR/usr/lib/libEnhancedDisassembly.dylib" - fi - - if [ -d "$BUILD_DIR/LLDB.framework" ]; then - echo Updating "$DEVELOPER_DIR/Library/PrivateFrameworks/LLDB.framework" - sudo rm -rf "$DEVELOPER_DIR/Library/PrivateFrameworks/LLDB.framework" - sudo cp -r "$BUILD_DIR/LLDB.framework" "$DEVELOPER_DIR/Library/PrivateFrameworks/LLDB.framework" - elif [ -e "$BUILD_DIR/LLDB.framework" ]; then - echo BUILD_DIR path to LLDB.framework is not a directory: "$BUILD_DIR/LLDB.framework" - exit 2; - fi - - else - echo DEVELOPER_DIR must be a directory: "$DEVELOPER_DIR" - exit 3; - fi - -else - echo BUILD_DIR must be a directory: "$BUILD_DIR" - exit 4; -fi diff --git a/lldb/scripts/sed-sources b/lldb/scripts/sed-sources deleted file mode 100755 --- a/lldb/scripts/sed-sources +++ /dev/null @@ -1,251 +0,0 @@ -#!/usr/bin/perl - -use strict; -use File::Find; -use File::Temp qw/ tempfile tempdir /; -use Getopt::Std; -use Pod::Usage; -use Text::Tabs; - -=head1 NAME - -B -- Performs multiple sed commands on files with the ability to expand or unexpand tabs. - -=head1 SYNOPSIS - -B [options] [file dir ...] - -=head1 DESCRIPTION - -Performs multiple sed commands (modify builtin %seds hash) on source files -or any sources in directories. If no arguments are given, STDIN will be used -as the source. If source files or directories are specified as arguments, -all files will be transformed and overwritten with new versions. Use the B<-p> -option to preview changes to STDOUT, or use the B<-b> option to make a backup -or the original files. - -=head1 OPTIONS - -=over - -=item B<-b> - -Backup original source file by appending ".bak" before overwriting with the -newly transformed file. - -=item B<-g> - -Display verbose debug logging. - -=item B<-e> - -Expand tabs to spaces (in addition to doing sed substitutions). - -=item B<-u> - -Unexpand spaces to tabs (in addition to doing sed substitutions). - -=item B<-p> - -Preview changes to STDOUT without modifying original source files. - -=item B<-r> - -Skip variants when doing multiple files (no _profile or _debug variants). - -=item B<-t N> - -Set the number of spaces per tab (default is 4) to use when expanding or -unexpanding. - -=back - -=head1 EXAMPLES - -# Recursively process all source files in the current working directory -# and subdirectories and also expand tabs to spaces. All source files -# will be overwritten with the newly transformed source files. - -% sed-sources -e $cwd - -# Recursively process all source files in the current working directory -# and subdirectories and also unexpand spaces to tabs and preview the -# results to STDOUT - -% sed-sources -p -u $cwd - -# Same as above except use 8 spaces per tab. - -% sed-sources -p -u -t8 $cwd - -=cut - - -our $opt_b = 0; # Backup original file? -our $opt_g = 0; # Verbose debug output? -our $opt_e = 0; # Expand tabs to spaces? -our $opt_h = 0; # Show help? -our $opt_m = 0; # Show help manpage style? -our $opt_p = 0; # Preview changes to STDOUT? -our $opt_t = 4; # Number of spaces per tab? -our $opt_u = 0; # Unexpand spaces to tabs? -getopts('eghmpt:u'); - -$opt_m and show_manpage(); -$opt_h and help(); - -our %seds = ( - '\s+$' => "\n", # Get rid of spaces at the end of a line - '^\s+$' => "\n", # Get rid spaces on lines that are all spaces -); - - -sub show_manpage { exit pod2usage( verbose => 2 ); }; -sub help { exit pod2usage( verbose => 3, noperldoc => 1 ); }; - - -#---------------------------------------------------------------------- -# process_opened_file_handle -#---------------------------------------------------------------------- -sub process_opened_file_handle -{ - my $in_fh = shift; - my $out_fh = shift; - - # Set the number of spaces per tab for expand/unexpand - $tabstop = $opt_t; - - while (my $line = <$in_fh>) - { - foreach my $key (keys %seds) - { - my $value = $seds{"$key"}; - $line =~ s/$key/$value/g; - } - if ($opt_e) { - print $out_fh expand $line; - } elsif ($opt_u) { - print $out_fh unexpand $line; - } else { - print $out_fh $line; - } - } -} - -#---------------------------------------------------------------------- -# process_file -#---------------------------------------------------------------------- -sub process_file -{ - my $in_path = shift; - if (-T $in_path) - { - my $out_fh; - my $out_path; - if ($opt_p) - { - # Preview to STDOUT - $out_fh = *STDOUT; - print "#---------------------------------------------------------------------- \n"; - print "# BEGIN: '$in_path'\n"; - print "#---------------------------------------------------------------------- \n"; - } - else - { - ($out_fh, $out_path) = tempfile(); - $opt_g and print "temporary for '$in_path' is '$out_path'\n"; - } - open (IN, "<$in_path") or die "error: can't open '$in_path' for reading: $!"; - process_opened_file_handle (*IN, $out_fh); - - - # Close our input file - close (IN); - - if ($opt_p) - { - print "#---------------------------------------------------------------------- \n"; - print "# END: '$in_path'\n"; - print "#---------------------------------------------------------------------- \n"; - print "\n\n"; - } - else - { - # Close the output file if it wasn't STDOUT - close ($out_fh); - - # Backup file if requested - if ($opt_b) - { - my $backup_command = "cp '$in_path' '$in_path.bak'"; - $opt_g and print "\% $backup_command\n"; - system ($backup_command); - } - - # Copy temp file over original - my $copy_command = "cp '$out_path' '$in_path'"; - $opt_g and print "\% $copy_command\n"; - system ($copy_command); - } - } -} - -our @valid_extensions = ( "h", "cpp", "c", "m", "mm" ); - -#---------------------------------------------------------------------- -# find_callback -#---------------------------------------------------------------------- -sub find_callback -{ - my $file = $_; - my $fullpath = $File::Find::name; - - foreach my $ext (@valid_extensions) - { - my $ext_regex = "\\.$ext\$"; - if ($fullpath =~ /$ext_regex/i) - { - print "processing: '$fullpath'\n"; - process_file ($fullpath); - return; - } - } - print " ignoring: '$fullpath'\n"; -} - - -#---------------------------------------------------------------------- -# main -#---------------------------------------------------------------------- -sub main -{ - if (@ARGV == 0) - { - # no args, take from STDIN and put to STDOUT - process_opened_file_handle (*STDIN, *STDOUT); - } - else - { - # Got args, any files we run into parse them, any directories - # we run into, search them for files - my $path; - foreach $path (@ARGV) - { - if (-f $path) - { - print "processing: '$path'\n"; - process_file ($path); - } - else - { - print " searching: '$path'\n"; - find(\&find_callback, $path); - } - } - } -} - - - -# call the main function -main();