summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/VirtualFileSystem.cpp
AgeCommit message (Collapse)Author
2022-06-18[llvm] Use value_or instead of getValueOr (NFC)Kazu Hirata
2022-04-11[VFS] RedirectingFileSystem only replace path if not already mappedBen Barham
If the `ExternalFS` has already remapped to an external path then `RedirectingFileSystem` should not change it to the originally provided path. This fixes the original path always being used if multiple VFS overlays were provided and the path wasn't found in the highest (ie. first in the chain). For now this is accomplished through the use of a new `ExposesExternalVFSPath` field on `vfs::Status`. This flag is true when the `Status` has an external path that's different from its virtual path, ie. the contained path is the external path. See the plan in `FileManager::getFileRef` for where this is going - eventually we won't need `IsVFSMapped` any more and all returned paths should be virtual. Resolves rdar://90578880 and llvm-project#53306. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D123398
2022-04-05Revert "[VFS] RedirectingFileSystem only replace path if not already mapped"Ben Barham
This reverts commit 3fda0edc51fd68192a30e302d45db081bb02d7f9, which breaks crash reproducers in very specific circumstances. Specifically, since crash reproducers have `UseExternalNames` set to false, the `File->getFileEntry().getDir()->getName()` call in `DoFrameworkLookup` would use the *cached* directory name instead of the directory of the looked-up file. The plan is to re-commit this patch but to *add* `ExposesExternalVFSPath` rather than replace `IsVFSMapped`. Differential Revision: https://reviews.llvm.org/D123103
2022-03-30[VFS] RedirectingFileSystem only replace path if not already mappedBen Barham
If the `ExternalFS` has already remapped a path then the `RedirectingFileSystem` should not change it to the originally provided path. This fixes the original path always being used if multiple VFS overlays were provided and the path wasn't found in the highest (ie. first in the chain). This also renames `IsVFSMapped` to `ExposesExternalVFSPath` and only sets it if `UseExternalName` is true. This flag then represents that the `Status` has an external path that's different from its virtual path. Right now the contained path is still the external path, but further PRs will change this to *always* be the virtual path. Clients that need the external can then request it specifically. Note that even though `ExposesExternalVFSPath` isn't set for all VFS-mapped paths, `IsVFSMapped` was only being used by a hack in `FileManager` that was specific to module searching. In that case `UseExternalNames` is always `true` and so that hack still applies. Resolves rdar://90578880 and llvm-project#53306. Differential Revision: https://reviews.llvm.org/D122549
2022-03-17[VFS] Add print/dump to the whole FileSystem hierarchyBen Barham
For now most are implemented by printing out the name of the filesystem, but this can be expanded in the future. Only `OverlayFileSystem` and `RedirectingFileSystem` are properly implemented in this patch. - `OverlayFileSystem`: Prints each filesystem in the order that any operations are actually run on them. Optionally prints recursively. - `RedirectingFileSystem`: Prints out all mappings, as well as the `ExternalFS`. Most of this was already implemented other than the handling for the `DirectoryRemap` case and to actually print out the mapping. Each FS should implement `printImpl` rather than `print`, where the latter just fowards to the former. This is to avoid spreading the default arguments through to the subclasses (where we may miss updating in the future). Differential Revision: https://reviews.llvm.org/D121421
2022-03-14[VFS] Rename `RedirectingFileSystem::dump` to `print`Ben Barham
The rest of LLVM uses `print` for the method taking the `raw_ostream` and `dump` only for the method with no parameters. Use the same for `RedirectingFileSystem`. Differential Revision: https://reviews.llvm.org/D121494
2022-02-22[VFS] Use generic_category for errors generated from the VFSBen Barham
Errors are generally checked in clients by comparing to the portable error condition in `std::errc`, which will have the `generic_category` (eg. `std::errc::no_such_file_or_directory`). While in practice these are usually equivalent for the standard errno's, they are not in *all* implementations. One such example is CentOS 7. Differential Revision: https://reviews.llvm.org/D120299
2022-02-03[VFS] Add back setFallthrough for downstream usersBen Barham
This fixes lldb's build. We can remove this in the future if we want but for now this will be nicer to existing consumers.
2022-02-03[VFS] Add a "redirecting-with" field to overlaysBen Barham
Extend "fallthrough" to allow a third option: "fallback". Fallthrough allows the original path to used if the redirected (or mapped) path fails. Fallback is the reverse of this, ie. use the original path and fallback to the mapped path otherwise. While this result *can* be achieved today using multiple overlays, this adds a much more intuitive option. As an example, take two directories "A" and "B". We would like files from "A" to be used, unless they don't exist, in which case the VFS should fallback to those in "B". With the current fallthrough option this is possible by adding two overlays: one mapping from A -> B and another mapping from B -> A. Since the frontend *nests* the two RedirectingFileSystems, the result will be that "A" is mapped to "B" and back to "A", unless it isn't in "A" in which case it fallsthrough to "B" (or fails if it exists in neither). Using "fallback" semantics allows a single overlay instead: one mapping from "A" to "B" but only using that mapping if the operation in "A" fails first. "redirect-only" is used to represent the current "fallthrough: false" case. Differential Revision: https://reviews.llvm.org/D117937
2022-01-21[llvm] Cleanup header dependencies in ADT and Supportserge-sans-paille
The cleanup was manual, but assisted by "include-what-you-use". It consists in 1. Removing unused forward declaration. No impact expected. 2. Removing unused headers in .cpp files. No impact expected. 3. Removing unused headers in .h files. This removes implicit dependencies and is generally considered a good thing, but this may break downstream builds. I've updated llvm, clang, lld, lldb and mlir deps, and included a list of the modification in the second part of the commit. 4. Replacing header inclusion by forward declaration. This has the same impact as 3. Notable changes: - llvm/Support/TargetParser.h no longer includes llvm/Support/AArch64TargetParser.h nor llvm/Support/ARMTargetParser.h - llvm/Support/TypeSize.h no longer includes llvm/Support/WithColor.h - llvm/Support/YAMLTraits.h no longer includes llvm/Support/Regex.h - llvm/ADT/SmallVector.h no longer includes llvm/Support/MemAlloc.h nor llvm/Support/ErrorHandling.h You may need to add some of these headers in your compilation units, if needs be. As an hint to the impact of the cleanup, running clang++ -E -Iinclude -I../llvm/include ../llvm/lib/Support/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l before: 8000919 lines after: 7917500 lines Reduced dependencies also helps incremental rebuilds and is more ccache friendly, something not shown by the above metric :-) Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2022-01-20[llvm][vfs] Abstract in-memory node creationJan Svoboda
The creation of in-memory VFS nodes happens in a single function that deduces what kind of node to create from the arguments. This leads to complicated if-then-else logic that's difficult to cleanly extend. This patch abstracts away in-memory node creation via a type-erased factory function that's passed instead. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D117648
2022-01-20[llvm][vfs] NFC: Virtualize in-memory `getStatus`Jan Svoboda
This patch virtualizes the `getStatus` function on `InMemoryNode` in LLVM VFS. Currently, this is implemented via top-level function `getNodeStatus` that tries to cast `InMemoryNode *` into each subtype. Virtual functions seem to be the simpler solution here. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D117649
2022-01-19[clang] support relative roots to vfs overlaysRichard Howell
This diff adds support for relative roots to VFS overlays. The directory root will be made absolute from the current working directory and will be used to determine the path style to use. This supports the use of VFS overlays with remote build systems that might use a different working directory for each compilation. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D116174
2021-12-16[clang][deps] Squash caches for original and minimized filesJan Svoboda
The minimizing and caching filesystem used by the dependency scanner keeps minimized and original files in separate caches. This setup is not well suited for dealing with files that are sometimes minimized and sometimes not. Such files are being stat-ed and read twice, which is wasteful and also means the two versions of the file can get "out of sync". This patch squashes the two caches together. When a file is stat-ed or read, its original contents are populated. If a file needs to be minimized, we give the minimizer the already loaded contents instead of reading the file again. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D115346
2021-11-13reland: [VFS] Use original path when falling back to external FSKeith Smiley
This reverts commit f0cf544d6f6fe6cbca4c07772998272d6bb433d8. Just a small change to fix: ``` /home/buildbot/as-builder-4/llvm-clang-x86_64-expensive-checks-ubuntu/llvm-project/llvm/lib/Support/VirtualFileSystem.cpp: In static member function ‘static llvm::ErrorOr<std::unique_ptr<llvm::vfs::File> > llvm::vfs::File::getWithPath(llvm::ErrorOr<std::unique_ptr<llvm::vfs::File> >, const llvm::Twine&)’: /home/buildbot/as-builder-4/llvm-clang-x86_64-expensive-checks-ubuntu/llvm-project/llvm/lib/Support/VirtualFileSystem.cpp:2084:10: error: could not convert ‘F’ from ‘std::unique_ptr<llvm::vfs::File>’ to ‘llvm::ErrorOr<std::unique_ptr<llvm::vfs::File> >’ return F; ^ ``` Differential Revision: https://reviews.llvm.org/D113832
2021-11-13Revert "[VFS] Use original path when falling back to external FS"Keith Smiley
``` /work/omp-vega20-0/openmp-offload-amdgpu-runtime/llvm.src/llvm/lib/Support/VirtualFileSystem.cpp: In static member function 'static llvm::ErrorOr<std::unique_ptr<llvm::vfs::File> > llvm::vfs::File::getWithPath(llvm::ErrorOr<std::unique_ptr<llvm::vfs::File> >, const llvm::Twine&)': /work/omp-vega20-0/openmp-offload-amdgpu-runtime/llvm.src/llvm/lib/Support/VirtualFileSystem.cpp:2084:10: error: could not convert 'F' from 'std::unique_ptr<llvm::vfs::File>' to 'llvm::ErrorOr<std::unique_ptr<llvm::vfs::File> >' return F; ^ ``` This reverts commit c972175649f4bb50d40d911659a04d5620ce6fe0.
2021-11-13[VFS] Use original path when falling back to external FSKeith Smiley
This is a follow up to 0be9ca7c0f9a733f846bb6bc4e8e36d46b518162 to make paths in the case of falling back to the external file system use the original format, preserving relative paths, and allow the external filesystem to canonicalize them if needed. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D109128
2021-11-08[Support] [VirtualFileSystem] Detect the windows_slash path styleMartin Storsjö
This fixes the following clang VFS tests, if `windows_slash` is the default style: Clang :: VFS/implicit-include.c Clang :: VFS/relative-path.c Clang-Unit :: Frontend/./FrontendTests.exe/CompilerInstance.DefaultVFSOverlayFromInvocation Also clarify a couple references to `Style::windows` into `Style::windows_backslash`, to make it clearer that each of them are opinionated in different directions (even if it doesn't matter for calls to e.g. `is_absolute`). Differential Revision: https://reviews.llvm.org/D113272
2021-11-07Put implementation details into anonymous namespaces. NFCI.Benjamin Kramer
2021-09-29[VFS] InMemoryFilesystem's UniqueIDs are a function of path and content.Sam McCall
This ensures that re-creating "the same" FS results in the same UIDs for files. In turn, this means that creating a clang module (preamble) using one in-memory filesystem and consuming it using another doesn't create duplicate FileEntrys for files that are the same in both FSes. It's tempting to give the creator control over the UIDs instead. However that requires fiddly API changes, e.g. what should the UIDs of intermediate directories be? This change is more "magic" but seems safe given: - InMemoryFilesystem is used in testing more than production - comparing UIDs across filesystems is unusual - files with the same path and content are usually logically equivalent (The usual reason for re-creating virtual filesystems rather than reusing them is that typical use involves mutating their CWD and so is not threadsafe). Differential Revision: https://reviews.llvm.org/D110711
2021-09-06[Support] Qualify auto (NFC)Kazu Hirata
Identified with readability-qualified-auto.
2021-07-08PR51018: Remove explicit conversions from SmallString to StringRef to ↵David Blaikie
future-proof against C++23 C++23 will make these conversions ambiguous - so fix them to make the codebase forward-compatible with C++23 (& a follow-up change I've made will make this ambiguous/invalid even in <C++23 so we don't regress this & it generally improves the code anyway)
2021-06-25[llvm] Rename StringRef _lower() method calls to _insensitive()Martin Storsjö
This is a mechanical change. This actually also renames the similarly named methods in the SmallString class, however these methods don't seem to be used outside of the llvm subproject, so this doesn't break building of the rest of the monorepo.
2021-04-26[clang] Don't crash when loading invalid VFS for the module dep collectorAlex Lorenz
The VFS is null when it's invalid so return early in collectVFSFromYAML.
2021-02-02[VFS] Add support to RedirectingFileSystem for mapping a virtual directory ↵Nathan Hawes
to one in the external FS. Previously file entries in the -ivfsoverlay yaml could map to a file in the external file system, but directories had to list their contents in the form of other file entries or directories. Allowing directory entries to map to a directory in the external file system makes it possible to present an external directory's contents in a different location and (in combination with the 'fallthrough' option) overlay one directory's contents on top of another. rdar://problem/72485443 Differential Revision: https://reviews.llvm.org/D94844
2021-01-30[NFC][VFS] Fix a build warning due to an extra semicolonYang Fan
2021-01-30[VFS] Combine VFSFromYamlDirIterImpl and OverlayFSDirIterImpl into a single ↵Nathan Hawes
implementation (NFC) As a fixme notes, both of these directory iterator implementations are conceptually similar and duplicate the functionality of returning and uniquing entries across two or more directories. This patch combines them into a single class 'CombiningDirIterImpl'. This also drops the 'Redirecting' prefix from RedirectingDirEntry and RedirectingFileEntry to save horizontal space. There's no loss of clarity as they already have to be prefixed with 'RedirectingFileSystem::' whenever they're referenced anyway. rdar://problem/72485443 Differential Revision: https://reviews.llvm.org/D94857
2021-01-22[VFS] Fix inconsistencies between relative paths and fallthrough.Jonas Devlieghere
This patch addresses inconsistencies in the way fallthrough is handled in the RedirectingFileSystem. Rather than trying to change the working directory of the external filesystem, the RedirectingFileSystem will canonicalize every path before handing it down. This guarantees that relative paths are resolved relative to the RedirectingFileSystem's working directory. This allows us to have a strictly virtual working directory, and still fallthrough for absolute paths, but not for relative paths that would get resolved incorrectly at the lower layer (for example, in case of the RealFileSystem, because the strictly virtual path does not exist). Differential revision: https://reviews.llvm.org/D95188
2020-12-08Support: Add RedirectingFileSystem::create from simple list of redirectionsDuncan P. N. Exon Smith
Add an overload of `RedirectingFileSystem::create` that builds a redirecting filesystem off of a simple vector of string pairs. This is intended to be used to support `clang::arcmt::FileRemapper` and `clang::PreprocessorOptions::RemappedFiles`. Differential Revision: https://reviews.llvm.org/D91317
2020-12-08VFS: Return new file systems as uniquely owned when possible, almost NFCDuncan P. N. Exon Smith
Uniformly return uniquely-owned filesystems from VFS creation APIs. The one exception is `getRealFileSystem`, which has a single instance and needs to be shared. This is almost NFC, except that it fixes a memory leak in `vfs::collectVFSFromYAML()`. Depends on https://reviews.llvm.org/D92888 Differential Revision: https://reviews.llvm.org/D92890
2020-12-03Support: Change InMemoryFileSystem::addFileNoOwn to take a MemoryBufferRef, NFCDuncan P. N. Exon Smith
Found this by chance when looking at the InMemoryFileSystem API, seems like an easy cleanup. Differential Revision: https://reviews.llvm.org/D90893
2020-09-02[lldb] Add reproducer verifierJonas Devlieghere
Add a reproducer verifier that catches: - Missing or invalid home directory - Missing or invalid working directory - Missing or invalid module/symbol paths - Missing files from the VFS The verifier is enabled by default during replay, but can be skipped by passing --reproducer-no-verify. Differential revision: https://reviews.llvm.org/D86497
2020-09-01Revert "[lldb] Add reproducer verifier"Raphael Isemann
This reverts commit 297f69afac58fc9dc13897857a5e70131c5adc85. It broke the Fedora 33 x86-64 bot. See the review for more info.
2020-08-31[lldb] Add reproducer verifierJonas Devlieghere
Add a reproducer verifier that catches: - Missing or invalid home directory - Missing or invalid working directory - Missing or invalid module/symbol paths - Missing files from the VFS The verifier is enabled by default during replay, but can be skipped by passing --reproducer-no-verify. Differential revision: https://reviews.llvm.org/D86497
2020-05-12[YAMLVFSWriter] Fix for delimitersJan Korous
Differential Revision: https://reviews.llvm.org/D79809
2020-05-07[YAMLVFSWriter] Fix directory handlingJan Korous
For empty directories (except the first one) we've been adding a file with the same name as the directory to the result VFS mapping. Differential Revision: https://reviews.llvm.org/D79551
2020-03-27[VirtualFileSystem] Support directory entries in the YAMLVFSWriterJonas Devlieghere
The current implementation of the JSONWriter does not support writing out directory entries. Earlier today I added a unit test to illustrate the problem. When an entry is added to the YAMLVFSWriter and the path is a directory, it will incorrectly emit the directory as a file, and any files inside that directory will not be found by the VFS. It's possible to partially work around the issue by only adding "leaf nodes" (files) to the YAMLVFSWriter. However, this doesn't work for representing empty directories. This is a problem for clients of the VFS that want to iterate over a directory. The directory not being there is not the same as the directory being empty. This is not just a hypothetical problem. The FileCollector for example does not differentiate between file and directory paths. I temporarily worked around the issue for LLDB by ignoring directories, but I suspect this will prove problematic sooner rather than later. This patch fixes the issue by extending the JSONWriter to support writing out directory entries. We store whether an entry should be emitted as a file or directory. Differential revision: https://reviews.llvm.org/D76670
2020-02-05[VFS] More consistent support for WindowsAdrian McCarthy
Removed some #ifdefs specific to Windows handling of VFS paths. This eliminates most of the differences between the Windows and non-Windows code paths. Making this work required some changes to account for the fact that VFS file paths can be Posix style or Windows style, so you cannot just assume that they use the host's native path style. In one case, this means implementing our own version of make_absolute, since the filesystem code in Support doesn't have styles in the sense that the path code does. Differential Review: https://reviews.llvm.org/D71092
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2019-12-18Fix more VFS tests on WindowsAdrian McCarthy
Since VFS paths can be in either Posix or Windows style, we have to use a more flexible definition of "absolute" path. The key here is that FileSystem::makeAbsolute is now virtual, and the RedirectingFileSystem override checks for either concept of absolute before trying to make the path absolute by combining it with the current directory. Differential Revision: https://reviews.llvm.org/D70701
2019-11-14Improve VFS compatibility on WindowsAdrian McCarthy
Keys in a virtual file system can be in Posix or Windows form or even a combination of the two. Many VFS tests (and a few Clang tests) were XFAILed on Windows because of false negatives when comparing paths. First, we default CaseSenstive to false on Windows. This allows drive letters like "D:" to match "d:". Windows filesystems are, by default, case insensitive, so this makes sense even beyond the drive letter. Second, we allow slashes to match backslashes when they're used as the root component of a path. Both of these changes are limited to RedirectingFileSystems, so there's little chance of affecting other path handling. These changes allow eleven of the VFS tests to pass on Windows as well as three other Clang tests, so they have re-enabled. This solves the majority of PR43272. Additional VFS test failures will be fixed in separate patches. Differential Revision: https://reviews.llvm.org/D69958
2019-11-04VirtualFileSystem - fix uninitialized variable warnings. NFCI.Simon Pilgrim
2019-10-16RedirectingFileSystem::openFileForRead - replace bitwise & with boolean && ↵Simon Pilgrim
to fix warning Seems to be just a typo - now matches other instances which do something similar llvm-svn: 374995
2019-10-16RealFile - fix self-initialization warning in constructor.Simon Pilgrim
llvm-svn: 374994
2019-10-15[Reland][VirtualFileSystem] Support virtual working directory in the ↵Jonas Devlieghere
RedirectingFS Before this patch, changing the working directory of the RedirectingFS would just forward to its external file system. This prevented us from having a working directory that only existed in the VFS mapping. This patch adds support for a virtual working directory in the RedirectingFileSystem. It now keeps track of its own WD in addition to updating the WD of the external file system. This ensures that we can still fall through for relative paths. This change was originally motivated by the reproducer infrastructure in LLDB where we want to deal transparently with relative paths. Differential revision: https://reviews.llvm.org/D65677 llvm-svn: 374955
2019-10-15Revert "[VirtualFileSystem] Support virtual working directory in the ↵Jonas Devlieghere
RedirectingFS" This reverts the original commit and the follow up: Revert "[VirtualFileSystem] Support virtual working directory in the RedirectingFS" Revert "[test] Update YAML mapping in VirtualFileSystemTest" llvm-svn: 374935
2019-10-15[VirtualFileSystem] Support virtual working directory in the RedirectingFSJonas Devlieghere
Before this patch, changing the working directory of the RedirectingFS would just forward to its external file system. This prevented us from having a working directory that only existed in the VFS mapping. This patch adds support for a virtual working directory in the RedirectingFileSystem. It now keeps track of its own WD in addition to updating the WD of the external file system. This ensures that we can still fall through for relative paths. This change was originally motivated by the reproducer infrastructure in LLDB where we want to deal transparently with relative paths. Differential revision: https://reviews.llvm.org/D65677 llvm-svn: 374917
2019-10-01VirtualFileSystem - replace dyn_cast<>+assert with cast<> calls. NFCI.Simon Pilgrim
Silences a number of clang static analyzer null dereference warnings. llvm-svn: 373325
2019-09-13[Reproducer] Add reproducer dump command.Jonas Devlieghere
This adds a reproducer dump commands which makes it possible to inspect a reproducer from inside LLDB. Currently it supports the Files, Commands and Version providers. I'm planning to add support for the GDB Remote provider in a follow-up patch. Differential revision: https://reviews.llvm.org/D67474 llvm-svn: 371909
2019-08-15[llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. llvm-svn: 369013