mirror of
https://github.com/darlinghq/darling-libcxx.git
synced 2024-12-13 23:08:46 +00:00
6e9a694dce
Add the completed std::experimental::filesystem implementation and tests. The implementation supports C++11 or newer. The TS is built as part of 'libc++experimental.a'. Users of the TS need to manually link this library. Building and testing the TS can be disabled using the CMake option '-DLIBCXX_ENABLE_FILESYSTEM=OFF'. Currently 'libc++experimental.a' is not installed by default. To turn on the installation of the library use '-DLIBCXX_INSTALL_EXPERIMENTAL_LIBRARY=ON'. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@273034 91177308-0d34-0410-b5e6-96231b3b80d8
86 lines
2.0 KiB
Python
86 lines
2.0 KiB
Python
import sys
|
|
import os
|
|
import stat
|
|
|
|
# Ensure that this is being run on a specific platform
|
|
assert sys.platform.startswith('linux') or sys.platform.startswith('darwin') \
|
|
or sys.platform.startswith('cygwin') or sys.platform.startswith('freebsd')
|
|
|
|
def env_path():
|
|
ep = os.environ.get('LIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT')
|
|
assert ep is not None
|
|
ep = os.path.realpath(ep)
|
|
assert os.path.isdir(ep)
|
|
return ep
|
|
|
|
env_path_global = env_path()
|
|
|
|
# Make sure we don't try and write outside of env_path.
|
|
# All paths used should be sanitized
|
|
def sanitize(p):
|
|
p = os.path.realpath(p)
|
|
if os.path.commonprefix([env_path_global, p]):
|
|
return p
|
|
assert False
|
|
|
|
"""
|
|
Some of the tests restrict permissions to induce failures.
|
|
Before we delete the test enviroment, we have to walk it and re-raise the
|
|
permissions.
|
|
"""
|
|
def clean_recursive(root_p):
|
|
if not os.path.islink(root_p):
|
|
os.chmod(root_p, 0o777)
|
|
for ent in os.listdir(root_p):
|
|
p = os.path.join(root_p, ent)
|
|
if os.path.islink(p) or not os.path.isdir(p):
|
|
os.remove(p)
|
|
else:
|
|
assert os.path.isdir(p)
|
|
clean_recursive(p)
|
|
os.rmdir(p)
|
|
|
|
|
|
def init_test_directory(root_p):
|
|
root_p = sanitize(root_p)
|
|
assert not os.path.exists(root_p)
|
|
os.makedirs(root_p)
|
|
|
|
|
|
def destroy_test_directory(root_p):
|
|
root_p = sanitize(root_p)
|
|
clean_recursive(root_p)
|
|
os.rmdir(root_p)
|
|
|
|
|
|
def create_file(fname, size):
|
|
with open(sanitize(fname), 'w') as f:
|
|
f.write('c' * size)
|
|
|
|
|
|
def create_dir(dname):
|
|
os.mkdir(sanitize(dname))
|
|
|
|
|
|
def create_symlink(source, link):
|
|
os.symlink(sanitize(source), sanitize(link))
|
|
|
|
|
|
def create_hardlink(source, link):
|
|
os.link(sanitize(source), sanitize(link))
|
|
|
|
|
|
def create_fifo(source):
|
|
os.mkfifo(sanitize(source))
|
|
|
|
|
|
def create_socket(source):
|
|
mode = 0600|stat.S_IFSOCK
|
|
os.mknod(sanitize(source), mode)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
command = " ".join(sys.argv[1:])
|
|
eval(command)
|
|
sys.exit(0)
|