llvm-project/llvm/unittests
Sam McCall c2b310aedf [VFS] Allow multiple RealFileSystem instances with independent CWDs.
Summary:
Previously only one RealFileSystem instance was available, and its working
directory is shared with the process. This doesn't work well for multithreaded
programs that want to work with relative paths - the vfs::FileSystem is assumed
to provide the working directory, but a thread cannot control this exclusively.

The new vfs::createPhysicalFileSystem() factory copies the process's working
directory initially, and then allows it to be independently modified.

This implementation records the working directory path, and glues it to relative
paths to provide the correct absolute path to the sys::fs:: functions.
This will give different results in unusual situations (e.g. the CWD is moved).

The main alternative is the use of openat(), fstatat(), etc to ask the OS to
resolve paths relative to a directory handle which can be kept open. This is
more robust. There are two reasons not to do this initially:
1. these functions are not available on all supported Unixes, and are somewhere
   between difficult and unavailable on Windows. So we need a path-based
   fallback anyway.
2. this would mean also adding support at the llvm::sys::fs level, which is a
   larger project. My clearest idea is an OS-specific `BaseDirectory` object
   that can be optionally passed to functions there. Eventually this could be
   backed by either paths or a fd where openat() is supported.
   This is a large project, and demonstrating here that a path-based fallback
   works is a useful prerequisite.

There is some subtlety to the path-manipulation mechanism:
  - when setting the working directory, both Specified=makeAbsolute(path) and
    Resolved=realpath(path) are recorded. These may differ in the presence of
    symlinks.
  - getCurrentWorkingDirectory() and makeAbsolute() use Specified - this is
    similar to the behavior of $PWD and sys::path::current_path
  - IO operations like openFileForRead use Resolved. This is similar to the
    behavior of an openat() based implementation, that doesn't see changes
    in symlinks.
There may still be combinations of operations and FS states that yield unhelpful
behavior. This is hard to avoid with symlinks and FS abstractions :(

The caching behavior of the current working directory is removed in this patch.
getRealFileSystem() is now specified to link to the process CWD, so the caching
is incorrect.
The user who needed this so far is clangd, which will immediately switch to
createPhysicalFileSystem().

Reviewers: ilya-biryukov, bkramer, labath

Subscribers: ioeric, kadircet, kristina, llvm-commits

Differential Revision: https://reviews.llvm.org/D56545

llvm-svn: 351050
2019-01-14 10:56:35 +00:00
..
ADT [ADT] IntervalMap: add overlaps(a, b) method 2018-12-21 13:04:34 +00:00
Analysis [CaptureTracking] Add a unit test for MaxUsesToExplore 2019-01-03 20:16:33 +00:00
AsmParser
BinaryFormat [BinaryFormat] Add MsgPackTypes 2018-11-15 18:50:01 +00:00
Bitcode Pass a reference to a module to the bitcode writer. 2018-02-14 19:11:32 +00:00
CodeGen [AArch64] Always use the version of computeKnownBits that returns a value. NFCI. 2018-12-21 15:05:10 +00:00
DebugInfo [DebugInfo] Define base function on DWARFDie reverse iterators 2018-10-30 18:25:28 +00:00
Demangle [Demangle] remove itaniumFindTypesInMangledName 2018-11-27 16:11:24 +00:00
ExecutionEngine Remove TypeBuilder.h, and fix the few locations using it. 2019-01-13 16:09:28 +00:00
FuzzMutate [FuzzMutate] Inst deleter doesn't work with PhiNodes 2018-01-25 09:22:18 +00:00
IR Remove TypeBuilder.h, and fix the few locations using it. 2019-01-13 16:09:28 +00:00
LineEditor
Linker Inline a few CMake variables into their only uses. 2018-05-14 19:23:31 +00:00
MC [WebAssembly] Added default stack-only instruction mode for MC. 2018-08-27 15:45:51 +00:00
MI MachineModuleInfo: Store more specific reference to LLVMTargetMachine; NFC 2018-11-05 23:49:13 +00:00
Object Fix unittest for buildbot with mips host (32bit big endian) from r295174 2017-02-15 16:03:22 +00:00
ObjectYAML
OptRemarks Reland: [OptRemarks] Add library for parsing optimization remarks 2018-10-10 18:43:42 +00:00
Option [opt] Change the parameter of OptTable::PrintHelp from Name to Usage and don't append "[options] <inputs>" 2018-10-10 00:15:31 +00:00
Passes cmake: Remove add_llvm_loadable_module() 2018-12-20 22:04:08 +00:00
ProfileData Fix gcc7 -Wdangling-else warning. NFCI. 2018-12-20 14:09:15 +00:00
Support [VFS] Allow multiple RealFileSystem instances with independent CWDs. 2019-01-14 10:56:35 +00:00
Target MachineModuleInfo: Store more specific reference to LLVMTargetMachine; NFC 2018-11-05 23:49:13 +00:00
TextAPI Rename TapiTests to TextAPITests 2019-01-03 18:24:58 +00:00
Transforms [CodeExtractor] Store outputs at the first valid insertion point 2018-12-07 03:01:54 +00:00
XRay [XRay] Improve FDR trace handling and error messaging 2018-11-09 06:26:48 +00:00
tools [llvm-exegesis][NFC] Some code style cleanup 2018-11-20 14:41:59 +00:00
CMakeLists.txt [llvm-tapi] initial commit, supports ELF text stubs 2018-12-03 19:30:52 +00:00
unittest.cfg.in Add support for unittest inputs. 2018-09-05 23:30:17 +00:00