summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/Path.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Silence an MSVC C4189 warning about a local variable being initialized but ↵Aaron Ballman2018-07-041-1/+0
| | | | | | not used; NFC. llvm-svn: 336298
* [ThinLTO] Update ThinLTO cache file atimes when on WindowsAndrew Ng2018-07-041-0/+32
| | | | | | | | | | | | | | | | | | ThinLTO cache file access times are used for expiration based pruning and since Vista, file access times are not updated by Windows by default: https://blogs.technet.microsoft.com/filecab/2006/11/07/disabling-last-access-time-in-windows-vista-to-improve-ntfs-performance This means on Windows, cache files are currently being pruned from creation time. This change manually updates cache files that are accessed by ThinLTO, when on Windows. Patch by Owen Reynolds. Differential Revision: https://reviews.llvm.org/D47266 llvm-svn: 336276
* [FileSystem] Split up the OpenFlags enumeration.Zachary Turner2018-06-071-2/+225
| | | | | | | | | | | | | | | | | This breaks the OpenFlags enumeration into two separate enumerations: OpenFlags and CreationDisposition. The first controls the behavior of the API depending on whether or not the target file already exists, and is not a flags-based enum. The second controls more flags-like values. This yields a more easy to understand API, while also allowing flags to be passed to the openForRead api, where most of the values didn't make sense before. This also makes the apis more testable as it becomes easy to enumerate all the configurations which make sense, so I've added many new tests to exercise all the different values. llvm-svn: 334221
* Revert 332508 as it caused problems in the clang test suite.Greg Clayton2018-05-161-3/+2
| | | | llvm-svn: 332555
* Fix llvm::sys::path::remove_dots() to return "." instead of an empty path.Greg Clayton2018-05-161-2/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D46887 llvm-svn: 332508
* [Support/Path] Make handling of paths like "///" consistentPavel Labath2018-05-091-2/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Various path functions were not treating paths consisting of slashes alone consistently. For example, the iterator-based accessors decomposed the path "///" into two elements: "/" and ".". This is not too bad, but it is different from the behavior specified by posix: ``` A pathname that contains ***at least one non-slash character*** and that ends with one or more trailing slashes shall be resolved as if a single dot character ( '.' ) were appended to the pathname. ``` More importantly, this was different from how we treated the same path in the filename+parent_path functions, which decomposed this path into "." and "". This was completely wrong as it lost the information that this was an absolute path which referred to the root directory. This patch fixes this behavior by making sure all functions treat paths consisting of (back)slashes alone the same way as "/". I.e., the iterator-based functions will just report one component ("/"), and the filename+parent_path will decompose them into "/" and "". A slightly controversial topic here may be the treatment of "//". Posix says that paths beginning with "//" may have special meaning and indeed we have code which parses paths like "//net/foo/bar" specially. However, as we were already not being consistent in parsing the "//" string alone, and any special parsing for it would complicate the code further, I chose to treat it the same way as longer sequences of slashes (which are guaranteed to be the same as "/"). Another slight change of behavior is in the parsing of paths like "//net//". Previously the last component of this path was ".". However, as in our parsing the "//net" part in this path was the same as the "drive" part in "c:\" and the next slash was the "root directory", it made sense to treat "//net//" the same way as "//net/" (i.e., not to add the extra "." component at the end). Reviewers: zturner, rnk, dblaikie, Bigcheese Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D45942 llvm-svn: 331876
* IWYU for llvm-config.h in llvm, additions.Nico Weber2018-04-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | See r331124 for how I made a list of files missing the include. I then ran this Python script: for f in open('filelist.txt'): f = f.strip() fl = open(f).readlines() found = False for i in xrange(len(fl)): p = '#include "llvm/' if not fl[i].startswith(p): continue if fl[i][len(p):] > 'Config': fl.insert(i, '#include "llvm/Config/llvm-config.h"\n') found = True break if not found: print 'not found', f else: open(f, 'w').write(''.join(fl)) and then looked through everything with `svn diff | diffstat -l | xargs -n 1000 gvim -p` and tried to fix include ordering and whatnot. No intended behavior change. llvm-svn: 331184
* s/LLVM_ON_WIN32/_WIN32/, llvmNico Weber2018-04-291-9/+9
| | | | | | | | | | | | | | LLVM_ON_WIN32 is set exactly with MSVC and MinGW (but not Cygwin) in HandleLLVMOptions.cmake, which is where _WIN32 defined too. Just use the default macro instead of a reinvented one. See thread "Replacing LLVM_ON_WIN32 with just _WIN32" on llvm-dev and cfe-dev. No intended behavior change. This moves over all uses of the macro, but doesn't remove the definition of it in (llvm-)config.h yet. llvm-svn: 331127
* [Support/Path] Add more tests and improve failure messages of existing onesPavel Labath2018-04-241-102/+52
| | | | | | | | | | | | | | | | | | | | | | | | Summary: I am preparing a patch to the path function. While working on it, I noticed that some of the areas are lacking test coverage (e.g. filename and parent_path functions), so I add more tests to guard against regressions there. I have also found the failure messages hard to understand, so I rewrote some existing test to give more actionable messages when they fail: - for tests which run over multiple inputs, I use SCOPED_TRACE, to show which of the inputs caused the actual failure. - for comparisons of vectors, I use gmock's container matchers, which will print out the full container contents (and the elements that differ) when they fail to match. Reviewers: zturner, espindola Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D45941 llvm-svn: 330691
* [unittests] Change std::sort to llvm::sort in response to r327219Mandeep Singh Grang2018-04-071-6/+6
| | | | | | | | | | | | | | | r327219 added wrappers to std::sort which randomly shuffle the container before sorting. This will help in uncovering non-determinism caused due to undefined sorting order of objects having the same key. To make use of that infrastructure we need to invoke llvm::sort instead of std::sort. Note: This patch is one of a series of patches to replace *all* std::sort to llvm::sort. Refer the comments section in D44363 for a list of all the required patches. llvm-svn: 329475
* [llvm-cov] Prevent llvm-cov from hanging when a symblink doesn't exist.Max Moroz2018-04-051-40/+73
| | | | | | | | | | | | | | | | | | | | Summary: Previous code hangs indefinitely when trying to iterate through a symbol link file that points to an non-exist directory. This change fixes the bug to make the addCollectedPath function exit ealier and print out correct warning messages. Patch by Yuke Liao (@liaoyuke). Reviewers: Dor1s, vsk Reviewed By: vsk Subscribers: bruno, mgrang, llvm-commits Differential Revision: https://reviews.llvm.org/D44960 llvm-svn: 329338
* [Support] Use realpath(3) instead of trying to open a file.Davide Italiano2018-01-091-0/+19
| | | | | | | | | If we don't have read permissions on the directory the call would fail. <rdar://problem/35871293> llvm-svn: 322095
* Allow TempFile::discard to be called twice.Rafael Espindola2017-11-221-0/+21
| | | | | | | | | | We already allowed keep+discard. It is important to be able to discard a temporary if a rename fail. It is also convenient as it allows the use of RAII for discarding. Allow discarding twice for similar reasons. llvm-svn: 318867
* Support: Have directory_iterator::status() return ↵Peter Collingbourne2017-10-101-2/+2
| | | | | | | | | | | | | | | | | | FindFirstFileEx/FindNextFile results on Windows. This allows clients to avoid an unnecessary fs::status() call on each directory entry. Because the information returned by FindFirstFileEx is a subset of the information returned by a regular status() call, I needed to extract a base class from file_status that contains only that information. On my machine, this reduces the time required to enumerate a ThinLTO cache directory containing 520k files from almost 4 minutes to less than 2 seconds. Differential Revision: https://reviews.llvm.org/D38716 llvm-svn: 315378
* [Support, Windows] Handle long paths with unix separatorsPirama Arumuga Nainar2017-08-211-0/+15
| | | | | | | | | | | | | | | | | | Summary: The function widenPath() for Windows also normalizes long path names by iterating over the path's components and calling append(). The assumption during the iteration that separators are not returned by the iterator doesn't hold because the iterators do return a separator when the path has a drive name. Handle this case by ignoring separators during iteration. Reviewers: rnk Subscribers: danalbert, srhines Differential Revision: https://reviews.llvm.org/D36752 llvm-svn: 311382
* [Support] Remove getPathFromOpenFD, it was unusedReid Kleckner2017-08-041-90/+0
| | | | | | | | | | | | | | Summary: It was added to support clang warnings about includes with case mismatches, but it ended up not being necessary. Reviewers: twoh, rafael Subscribers: hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D36328 llvm-svn: 310078
* Move Object format code to lib/BinaryFormat.Zachary Turner2017-06-071-80/+1
| | | | | | | | | | | | This creates a new library called BinaryFormat that has all of the headers from llvm/Support containing structure and layout definitions for various types of binary formats like dwarf, coff, elf, etc as well as the code for identifying a file from its magic. Differential Revision: https://reviews.llvm.org/D33843 llvm-svn: 304864
* Re-sort #include lines for unittests. This uses a slightly modifiedChandler Carruth2017-06-061-1/+1
| | | | | | | | | | | | | | | clang-format (https://reviews.llvm.org/D33932) to keep primary headers at the top and handle new utility headers like 'gmock' consistently with other utility headers. No other change was made. I did no manual edits, all of this is clang-format. This should allow other changes to have more clear and focused diffs, and is especially motivated by moving some headers into more focused libraries. llvm-svn: 304786
* Make sure we have actually written what is expected by the test.Galina Kistanova2017-05-121-1/+1
| | | | llvm-svn: 302922
* Don't test setting sticky bits on files for modern BSDsDimitry Andric2017-04-241-0/+7
| | | | | | | | | | | | | | | | | | | Summary: In rL297945, jhenderson added methods for setting permissions to sys::fs, but some of the unittests that attempt to set sticky bits (01000) on files fail on modern BSDs, such as FreeBSD, NetBSD and OpenBSD. This is because those systems do not allow regular users to set sticky bits on files, only on directories. Fix it by disabling these particular tests on modern BSDs. Reviewers: emaste, brad, jhenderson Reviewed By: jhenderson Subscribers: joerg, krytarowski, llvm-commits Differential Revision: https://reviews.llvm.org/D32120 llvm-svn: 301220
* Make the home_directory test a little more resilient.Zachary Turner2017-03-221-10/+21
| | | | | | | | | | | | It's possible (albeit strange) for $HOME to intentionally point somewhere other than the user's home directory as reported by the password database. Our test shouldn't fail in this case. This patch updates the test to pull directly from the password database before unsetting $HOME, rather than comparing the return value of home_directory() to the original value of the environment variable. llvm-svn: 298514
* Make home_directory look in the password database in addition to $HOME.Zachary Turner2017-03-221-0/+20
| | | | | | | | | | | | | This is something of an edge case, but when the $HOME environment variable is not set, we can still look in the password database to get the current user's home directory. Added a test for this by getting the value of $HOME, then unsetting it, then calling home_directory() and verifying that it succeeds and that the value is the same as what we originally read from the environment. llvm-svn: 298513
* Add a function to MD5 a file's contents.Zachary Turner2017-03-201-0/+14
| | | | | | | | | | | | | | | In doing so, clean up the MD5 interface a little. Most existing users only care about the lower 8 bytes of an MD5, but for some users that care about the upper and lower, there wasn't a good interface. Furthermore, consumers of the MD5 checksum were required to handle endianness details on their own, so it seems reasonable to abstract this into a nicer interface that just gives you the right value. Differential Revision: https://reviews.llvm.org/D31105 llvm-svn: 298322
* SmallString doesn't have implicit conversion from const char*.Zachary Turner2017-03-171-2/+2
| | | | llvm-svn: 298019
* Don't rely on an implicit std::tuple constructor.Zachary Turner2017-03-171-4/+9
| | | | | | | Apparently it doesn't have one, so using an initializer list doesn't work correctly. llvm-svn: 298018
* Fix unit test.Zachary Turner2017-03-161-1/+1
| | | | llvm-svn: 298014
* [Support] Support both Windows and Posix paths on both platforms.Zachary Turner2017-03-161-87/+68
| | | | | | | | | | | | | | | | | | Previously which path syntax we supported dependend on what platform we were compiling LLVM on. While this is normally desirable, there are situations where we need to be able to handle a path that we know was generated on a remote host. Remote debugging, for example, or parsing debug info. 99% of the code in LLVM for handling paths was platform agnostic and literally just a few branches were gated behind pre-processor checks, so this changes those sites to use runtime checks instead, and adds a flag to every path API that allows one to override the host native syntax. Differential Revision: https://reviews.llvm.org/D30858 llvm-svn: 298004
* [Support] Add support for getting file system permissions on Windows and ↵James Henderson2017-03-161-0/+171
| | | | | | | | | | | | | | | | | | implement sys::fs::set/getPermissions to work with them This change adds support for functions to set and get file permissions, in a similar manner to the C++17 permissions() function in <filesystem>. The setter uses chmod on Unix systems and SetFileAttributes on Windows, setting the permissions as passed in. The getter simply uses the existing status() function. Prior to this change, status() would always return an unknown value for the permissions on a Windows file, making it impossible to test the new function on Windows. I have therefore added support for this as well. On Linux, prior to this change, the permissions included the file type, which should actually be accessed via a different member of the file_status class. Note that on Windows, only the *_write permission bits have any affect - if any are set, the file is writable, and if not, the file is read-only. This is in common with what MSDN describes for their behaviour of std::filesystem::permissions(), and also what boost::filesystem does. The motivation behind this change is so that we can easily test behaviour on read-only files in LLVM unit tests, but I am sure that others may find it useful in some situations. Reviewers: zturner, amccarth, aaron.ballman Differential Revision: https://reviews.llvm.org/D30736 llvm-svn: 297945
* [Support] Make the SystemZ bot happy by using make_error_code.Juergen Ributzka2017-03-141-1/+2
| | | | | | | This should fix the last issue on the SystemZ bot related to the broken symlink test. llvm-svn: 297767
* [Support] Follow-up for "Test directory iterators and recursive directory ↵Juergen Ributzka2017-03-131-1/+1
| | | | | | | | iterators with broken symlinks." Fix the test by sorting the result vector. llvm-svn: 297672
* [Support] Test directory iterators and recursive directory iterators with ↵Juergen Ributzka2017-03-131-0/+78
| | | | | | | | | | | broken symlinks. This commit adds a unit test to the file system tests to verify the behavior of the directory iterator and recursive directory iterator with broken symlinks. This test is Unix only. llvm-svn: 297669
* Reverting r297617 because it broke some bots:Aaron Ballman2017-03-131-182/+4
| | | | | | http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux/builds/49970 llvm-svn: 297618
* Add support for getting file system permissions and implement ↵Aaron Ballman2017-03-131-4/+182
| | | | | | | | sys::fs::permissions to set them. Patch by James Henderson. llvm-svn: 297617
* Fix test failure when Home directory cannot be found.Zachary Turner2017-03-101-9/+8
| | | | llvm-svn: 297484
* Add llvm::sys::fs::real_path.Zachary Turner2017-03-101-0/+36
| | | | | | | | | | | | | | | | | | | | | LLVM already has real_path like functionality, but it is cumbersome to use and involves clean up after (e.g. you have to call openFileForRead, then close the resulting FD). Furthermore, on Windows it doesn't work for directories since opening a directory and opening a file require slightly different flags. So I add a simple function `real_path` which works for all paths on all platforms and has a simple to use interface. In doing so, I add the ability to opt in to resolving tilde expressions (e.g. ~/foo), which are normally handled by the shell. Differential Revision: https://reviews.llvm.org/D30668 llvm-svn: 297483
* [Support] Add llvm::sys::fs::remove_directories.Zachary Turner2017-03-081-0/+33
| | | | | | | | | | | | | | | | | | | | | We already have a function create_directories() which can create an entire tree, and remove() which can remove an empty directory, but we do not have remove_directories() which can remove an entire tree. This patch adds such a function. Because removing a directory tree can have dangerous consequences when the tree contains a directory symlink, the patch here updates the existing directory_iterator construct to optionally not follow symlinks (previously it would always follow symlinks). The delete algorithm uses this flag so that for symlinks, only the links are removed, and not the targets. On Windows this is implemented with SHFileOperation, which also does not recurse into symbolic links or junctions. Differential Revision: https://reviews.llvm.org/D30676 llvm-svn: 297314
* [Support] Remove unit test for fs::is_localJonas Hahnfeld2017-03-081-55/+0
| | | | | | | | | rL295768 introduced this test that fails if LLVM is built and tested on an NFS share. Delete the test as discussed on the corresponing commit thread. The only feasible solution would have been to introduce environment variables and to en/disable the test conditionally. llvm-svn: 297260
* Process tilde in llvm::sys::path::nativeSerge Pavlov2017-03-011-0/+27
| | | | | | | | | | | | | Windows does not treat `~` as a reference to home directory, so the call to `llvm::sys::path::native` on, say, `~/somedir` produces `~\somedir`, which has different meaning than the original path. With this change tilde is expanded on Windows to user profile directory. Such behavior keeps original meaning of the path and is consistent with the algorithm of `llvm::sys::path::home_directory`. Differential Revision: https://reviews.llvm.org/D27527 llvm-svn: 296590
* [Support] XFAIL is_local for mipsSimon Dardis2017-02-221-0/+36
| | | | | | | is_local can't pass on some our buildbots as some of our buildbots use network shares for building and testing LLVM. llvm-svn: 295840
* [Support] Add a function to check if a file resides locally.Zachary Turner2017-02-211-0/+22
| | | | | | Differential Revision: https://reviews.llvm.org/D30010 llvm-svn: 295768
* Fix fs::set_current_path unit testPavel Labath2017-01-241-1/+5
| | | | | | | | The test fails when there is a symlink on the path because then the path returned by current_path will not match the one we have set. Instead of doing a string match check the unique id of the two files. llvm-svn: 292916
* [Support] Add sys::fs::set_current_path() (aka chdir)Pavel Labath2017-01-241-0/+19
| | | | | | | | | | | | | | | Summary: This adds a cross-platform way of setting the current working directory analogous to the existing current_path() function used for retrieving it. The function will be used in lldb. Reviewers: rafael, silvas, zturner Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29035 llvm-svn: 292907
* [Support] remove_dots: Remove windows test.Benjamin Kramer2016-10-171-2/+0
| | | | | | | Windows doesn't have roots, so I think this test doesn't make sense there. llvm-svn: 284386
* [Support] remove_dots: Remove .. from absolute paths.Benjamin Kramer2016-10-171-0/+4
| | | | | | | /../foo is still a proper path after removing the dotdot. This should now finally match https://9p.io/sys/doc/lexnames.html [Cleaning names]. llvm-svn: 284384
* unittests: Explicitly ignore some return values in crash testsJustin Bogner2016-10-161-16/+18
| | | | | | | | Ideally these would actually check that the results are reasonable, but given that we're looping over so many different kinds of path that isn't really practical. llvm-svn: 284350
* Do not delete leading ../ in remove_dots.Eric Liu2016-10-131-0/+4
| | | | | | | | | | Reviewers: bkramer Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25561 llvm-svn: 284129
* Fix a real temp file leak in FileOutputBufferReid Kleckner2016-09-021-0/+2
| | | | | | | | | | | | | If we failed to commit the buffer but did not die to a signal, the temp file would remain on disk on Windows. Having an open file mapping and file handle prevents the file from being deleted. I am choosing not to add an assertion of success on the temp file removal, since virus scanners and other environmental things can often cause removal to fail in real world tools. Also fix more temp file leaks in unit tests. llvm-svn: 280445
* Try to fix some temp file leaks in SupportTests, PR18335Reid Kleckner2016-09-021-13/+27
| | | | llvm-svn: 280443
* Use the range variant of find instead of unpacking begin/endDavid Majnemer2016-08-111-10/+10
| | | | | | | | | If the result of the find is only used to compare against end(), just use is_contained instead. No functionality change is intended. llvm-svn: 278433
* Switch to using an API that handles non-ASCII paths appropriately on Windows.Aaron Ballman2016-06-211-0/+26
| | | | llvm-svn: 273262
OpenPOWER on IntegriCloud