[libcxxabi] Teach CMake better ways to find the libc++ source directory (and misc cleanup).

Summary:
The main section of this patch teaches CMake  a new option `LIBCXXABI_LIBCXX_PATH` that specifies the path to the libcxx source root. This information is passed to lit so that it can better find libc++'s python module. `LIBCXXABI_LIBCXX_PATH` is also used to help find the libc++ headers.

The rest of this patch is misc cleanup, mostly to make pep8 and pylint happy.
I've also copied libc++'s .gitignore into libc++abi.



Reviewers: jroelofs, danalbert

Reviewed By: danalbert

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D7130

llvm-svn: 226855
This commit is contained in:
Eric Fiselier 2015-01-22 20:00:06 +00:00
parent 7a2421095c
commit 753f7c306b
6 changed files with 114 additions and 48 deletions

54
libcxxabi/.gitignore vendored Normal file
View File

@ -0,0 +1,54 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
#lib/ # We actually have things checked in to lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/

View File

@ -97,6 +97,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(LIBCXXABI_BUILT_STANDALONE 1)
else()
set(LLVM_MAIN_SRC_DIR "${CMAKE_SOURCE_DIR}" CACHE PATH "Path to LLVM source tree")
set(LLVM_LIT "${CMAKE_SOURCE_DIR}/utils/lit/lit.py")
set(LIBCXXABI_LIBDIR_SUFFIX ${LLVM_LIBDIR_SUFFIX})
endif()
@ -126,14 +127,32 @@ find_path(
LIBCXXABI_LIBCXX_INCLUDES
vector
PATHS ${LIBCXXABI_LIBCXX_INCLUDES}
${LIBCXXABI_LIBCXX_PATH}/include
${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBCXX_INCLUDES}
${LLVM_MAIN_SRC_DIR}/projects/libcxx/include
${LLVM_INCLUDE_DIR}/c++/v1
)
set(LIBCXXABI_LIBCXX_INCLUDES "${LIBCXXABI_LIBCXX_INCLUDES}" CACHE STRING
set(LIBCXXABI_LIBCXX_INCLUDES "${LIBCXXABI_LIBCXX_INCLUDES}" CACHE PATH
"Specify path to libc++ includes." FORCE)
find_path(
LIBCXXABI_LIBCXX_PATH
test/libcxx/__init__.py
PATHS ${LIBCXXABI_LIBCXX_PATH}
${LIBCXXABI_LIBCXX_INCLUDES}/../
${LLVM_MAIN_SRC_DIR}/projects/libcxx/
NO_DEFAULT_PATH
)
if (LIBCXXABI_LIBCXX_PATH STREQUAL "LIBCXXABI_LIBCXX_PATH-NOTFOUND")
message(WARNING "LIBCXXABI_LIBCXX_PATH was not specified and couldn't be infered.")
set(LIBCXXABI_LIBCXX_PATH "")
endif()
set(LIBCXXABI_LIBCXX_PATH "${LIBCXXABI_LIBCXX_PATH}" CACHE PATH
"Specify path to libc++ source." FORCE)
#===============================================================================
# Configure System
#===============================================================================

View File

@ -1,26 +1,23 @@
import locale
import os
import platform
import re
import shlex
import sys
import lit.Test # pylint: disable=import-error,no-name-in-module
import lit.util # pylint: disable=import-error,no-name-in-module
from libcxx.test.format import LibcxxTestFormat
from libcxx.test.config import Configuration as LibcxxConfiguration
from libcxx.compiler import CXXCompiler
class Configuration(LibcxxConfiguration):
# pylint: disable=redefined-outer-name
def __init__(self, lit_config, config):
super(Configuration, self).__init__(lit_config, config)
self.libcxxabi_src_root = None
self.libcxx_src_root = None
self.obj_root = None
def configure_src_root(self):
self.libcxxabi_src_root = self.get_lit_conf('libcxxabi_src_root',
self.libcxxabi_src_root = self.get_lit_conf(
'libcxxabi_src_root',
os.path.dirname(self.config.test_source_root))
self.libcxx_src_root = self.get_lit_conf('libcxx_src_root',
self.libcxx_src_root = self.get_lit_conf(
'libcxx_src_root',
os.path.join(self.libcxxabi_src_root, '/../libcxx'))
def configure_obj_root(self):
@ -32,16 +29,17 @@ class Configuration(LibcxxConfiguration):
super(Configuration, self).configure_compile_flags()
def configure_compile_flags_header_includes(self):
cxx_headers = self.get_lit_conf('cxx_headers',
cxx_headers = self.get_lit_conf(
'cxx_headers',
os.path.join(self.libcxx_src_root, '/include'))
if not os.path.isdir(cxx_headers):
self.lit_config.fatal("cxx_headers='%s' is not a directory."
% cxx_headers)
self.cxx.compile_flags += ['-I' + cxx_headers]
libcxxabi_headers = self.get_lit_conf('libcxxabi_headers',
os.path.join(self.libcxxabi_src_root,
'include'))
libcxxabi_headers = self.get_lit_conf(
'libcxxabi_headers',
os.path.join(self.libcxxabi_src_root, 'include'))
if not os.path.isdir(libcxxabi_headers):
self.lit_config.fatal("libcxxabi_headers='%s' is not a directory."
% libcxxabi_headers)

View File

@ -26,42 +26,32 @@ config.test_source_root = os.path.dirname(__file__)
# Infer the libcxx_test_source_root for configuration import.
# If libcxx_source_root isn't specified in the config, assume that the libcxx
# and libcxxabi source directories are sibling directories.
libcxx_source_root = getattr(config, 'libcxx_source_root',
os.path.join(config.test_source_root,
'../../libcxx'))
libcxx_test_source_root = os.path.join(libcxx_source_root, 'test')
if os.path.isdir(libcxx_test_source_root):
sys.path.insert(0, libcxx_test_source_root)
libcxx_src_root = getattr(config, 'libcxx_src_root', None)
if not libcxx_src_root:
libcxx_src_root = os.path.join(config.test_source_root, '../../libcxx')
libcxx_test_src_root = os.path.join(libcxx_src_root, 'test')
if os.path.isfile(os.path.join(libcxx_test_src_root, 'libcxx', '__init__.py')):
site.addsitedir(libcxx_test_src_root)
else:
lit_config.fatal('Could not find libcxx test directory for test imports'
' in: %s' % libcxx_test_source_root)
' in: %s' % libcxx_test_src_root)
# Infer the test_exec_root from the libcxxabi_object root.
libcxxabi_obj_root = getattr(config, 'libcxxabi_obj_root', None)
if libcxxabi_obj_root is not None:
config.test_exec_root = os.path.join(libcxxabi_obj_root, 'test')
# Infer the test_exec_root from the libcxx_object root.
obj_root = getattr(config, 'libcxx_obj_root', None)
# Check that the test exec root is known.
if config.test_exec_root is None:
# Otherwise, we haven't loaded the site specific configuration (the user is
# probably trying to run on a test file directly, and either the site
# configuration hasn't been created by the build system, or we are in an
# out-of-tree build situation).
site_cfg = lit_config.params.get('libcxxabi_site_config',
os.environ.get('LIBCXX_SITE_CONFIG'))
if not site_cfg:
lit_config.warning('No site specific configuration file found!'
' Running the tests in the default configuration.')
# TODO: Set test_exec_root to a temporary directory where output files
# can be placed. This is needed for ShTest.
elif not os.path.isfile(site_cfg):
lit_config.fatal(
"Specified site configuration file does not exist: '%s'" %
site_cfg)
else:
lit_config.note('using site specific configuration at %s' % site_cfg)
lit_config.load_config(config, site_cfg)
raise SystemExit()
if obj_root is None:
import libcxx.test.config
libcxx.test.config.loadSiteConfig(
lit_config, config, 'libcxxabi_site_config', 'LIBCXXABI_SITE_CONFIG')
obj_root = getattr(config, 'libcxxabi_obj_root', None)
if obj_root is None:
import tempfile
obj_root = tempfile.mkdtemp(prefix='libcxxabi-testsuite-')
lit_config.warning('Creating temporary directory for object root: %s' %
obj_root)
config.test_exec_root = os.path.join(obj_root, 'test')
cfg_variant = getattr(config, 'configuration_variant', 'libcxxabi')
if cfg_variant:
@ -73,4 +63,5 @@ config_module = __import__(config_module_name, fromlist=['Configuration'])
configuration = config_module.Configuration(lit_config, config)
configuration.configure()
configuration.print_config_info()
config.test_format = configuration.get_test_format()

View File

@ -2,6 +2,7 @@
config.cxx_under_test = "@LIBCXXABI_COMPILER@"
config.libcxxabi_src_root = "@LIBCXXABI_SOURCE_DIR@"
config.libcxxabi_obj_root = "@LIBCXXABI_LIBRARY_DIR@"
config.libcxx_src_root = "@LIBCXXABI_LIBCXX_PATH@"
config.cxx_headers = "@LIBCXXABI_LIBCXX_INCLUDES@"
config.llvm_unwinder = "@LIBCXXABI_USE_LLVM_UNWINDER@"
config.enable_threads = "@LIBCXXABI_ENABLE_THREADS@"

View File

@ -90,9 +90,12 @@
<p>To do a standalone build:</p>
<ul>
<li>
Check out the <a href="http://libcxx.llvm.org">libcxx source</a> tree.
</li>
<li><code>cd libcxxabi</code></li>
<li><code>mkdir build &amp;&amp; cd build</code></li>
<li><code>cmake -DLIBCXXABI_LIBCXX_INCLUDES=path/to/libcxx/include .. # on
<li><code>cmake -DLIBCXXABI_LIBCXX_PATH=path/to/libcxx .. # on
linux you may need -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++</code></li>
<li><code>make</code></li>
</ul>