summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/Path.cpp
Commit message (Collapse)AuthorAgeFilesLines
* 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
* Fix a relatively nasty bug with fs::getPathFromOpenFD() on Windows. The ↵Aaron Ballman2016-06-201-0/+33
| | | | | | GetFinalPathNameByHandle API does not behave as documented; if given a buffer that has enough space for the path but not the null terminator, the call will return the number of characters required *without* the null terminator (despite being documented otherwise) and it will not set GetLastError(). The result was that this function would return a bogus path and no error. Instead, ensure there is sufficient space for a null terminator (we already strip it off manually for compatibility with older versions of Windows). llvm-svn: 273195
* In openFileForRead, attempt to fetch the actual name of the file on disk -- ↵Taewook Oh2016-06-131-0/+57
| | | | | | | | | | | | | including case -- so that clang can later warn about non-portable #include and #import directives. Differential Revision: http://reviews.llvm.org/D19842 Corresponding clang patch: http://reviews.llvm.org/D19843 Re-commit after addressing issues with of generating too many warnings for Windows and asan test failures Patch by Eric Niebler llvm-svn: 272555
* Revert commit r271704, a patch that enables warnings for non-portable ↵Taewook Oh2016-06-041-57/+0
| | | | | | #include and #import paths (Corresponding clang patch has been reverted by r271761). Patches are reverted because they generate lots of unadressable warnings for windows and fail tests under ASAN. llvm-svn: 271764
* In openFileForRead, attempt to fetch the actual name of the file on disk -- ↵Taewook Oh2016-06-031-0/+57
| | | | | | | | | | including case -- so that clang can later warn about non-portable #include and #import directives. Differential Revision: http://reviews.llvm.org/D19842 Patch by Eric Niebler llvm-svn: 271704
* [ThinLTO] Option to control path of distributed backend filesTeresa Johnson2016-05-171-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Add support to control where files for a distributed backend (the individual index files and optional imports files) are created. This is invoked with a new thinlto-prefix-replace option in the gold plugin and llvm-lto. If specified, expects a string of the form "oldprefix:newprefix", and instead of generating these files in the same directory path as the corresponding bitcode file, will use a path formed by replacing the bitcode file's path prefix matching oldprefix with newprefix. Also add a new replace_path_prefix helper to Path.h in libSupport. Depends on D19636. Reviewers: joker.eph Subscribers: llvm-commits, joker.eph Differential Revision: http://reviews.llvm.org/D19644 llvm-svn: 269771
* [Support][Unittests] Add unittest for recursive_directory_iterator::level()Bruno Cardoso Lopes2016-05-131-0/+14
| | | | llvm-svn: 269488
* Unbreak building unit tests on Windows after r266595.Nico Weber2016-04-181-0/+1
| | | | llvm-svn: 266614
* [Support] Fix an invalid character escaping in string literal (unittest).Etienne Bergeron2016-04-051-1/+1
| | | | | | | | | | | | | | | | | | Summary: A character within a string literal is not escaped correctly. In this case, there is no semantic change because the invalid character turn out to be NUL anyway. note: "\0x12" is equivalent to {0, 'x', '1', '2'} and not { 12 }. This issue was found by clang-tidy. Reviewers: rnk Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D18747 llvm-svn: 265376
* Fix a -Wsign-compare in Support Path unittestsReid Kleckner2016-02-101-1/+1
| | | | llvm-svn: 260418
* Fix identify_magic() to check that a file that starts with MH_MAGIC isKevin Enderby2016-01-261-11/+19
| | | | | | | | | | | | at least as big as the mach header to be identified as a Mach-O file and make sure smaller files are not identified as a Mach-O files but as unknown files. Also fix identify_magic() so it looks at all 4 bytes of the filetype field when determining the type of the Mach-O file. Then fix the macho-invalid-header test case to check that it is an unknown file and make sure it does not get the error for object_error::parse_failed. And also update the unit tests. llvm-svn: 258883
* Fix -Wunused-function in a non-Win32 buildDavid Blaikie2015-11-171-1/+1
| | | | llvm-svn: 253373
* [Support] Tweak path::system_temp_directory() on Windows.Pawel Bylica2015-11-171-0/+70
| | | | | | | | | | | | | | | | | Summary: This patch changes the behavior of path::system_temp_directory() on Windows to be closer to GetTempPath Windows API call. Enforces path separator to be the native one, makes path absolute, etc. GetTempPath is not used directly because of limitations/implementation bugs on Windows 7. Windows specific unit tests are added. Most of them runs in separated process with modified environment variables. This change fixes FileSystemTest.CreateDir unittest that had been failing when run from Unix-like shell on Windows (Unix-like path separator (/) used in env variables). Reviewers: chapuni, rafael, aaron.ballman Subscribers: rafael, llvm-commits Differential Revision: http://reviews.llvm.org/D14231 llvm-svn: 253345
* Windows-specific test for sys::path::remove_dots.Mike Aizatsky2015-11-091-0/+13
| | | | | | Differential Revision: http://reviews.llvm.org/D14503 llvm-svn: 252504
* Moving FileManager::removeDotPaths to llvm::sys::path::remove_dotsMike Aizatsky2015-11-091-0/+20
| | | | | | Differential Revision: http://reviews.llvm.org/D14393 llvm-svn: 252499
* Revert r252366: [Support] Use GetTempDir to get the temporary dir path on ↵Pawel Bylica2015-11-061-70/+0
| | | | | | Windows. llvm-svn: 252367
* [Support] Use GetTempDir to get the temporary dir path on Windows.Pawel Bylica2015-11-061-0/+70
| | | | | | | | | | | | | | | Summary: In general GetTempDir follows the same logic as the replaced code: checks env variables TMP, TEMP, USERPROFILE in order. However, it also perform other checks like making separators native (\), making the path absolute, etc. This change fixes FileSystemTest.CreateDir unittest that had been failing when run from Unix-like shell on Windows (Unix-like path separator (/) used in env variables). Reviewers: chapuni, rafael, aaron.ballman Subscribers: rafael, llvm-commits Differential Revision: http://reviews.llvm.org/D14231 llvm-svn: 252366
OpenPOWER on IntegriCloud