aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/cpp/util/file_windows_test.cc
Commit message (Collapse)AuthorAge
* Windows,JNI: use wstrings onlyGravatar Laszlo Csomor2017-10-20
| | | | | | | | | | | | | | | | | | | | In this commit: - fix the Windows JNI library to only use UTF-16 strings Converting between multi-byte strings (UTF-8) and wstrings (UTF-16) always carries the risk of incorrectly handling the strings. It also takes time, even if not much. Not converting the strings but using the raw Java strings (which are in fact UTF-16 strings) simplifies the code and allows using non-ASCII paths (at least in the JNI module, even if Bazel as a whole doesn't support non-ASCII characters). Change-Id: I827fbe92a1bbefac049a1e34ac1738c965ed2e9c PiperOrigin-RevId: 172715277
* Bazel client: add blaze_util::IsDevNullGravatar Laszlo Csomor2017-07-25
| | | | | | | | | | | | | | | | | | | | | | Add a method to test if a path is /dev/null (or case-insensitive "NUL" on Windows), and use it in blaze::MakeAbsolute. In this commit: - implement blaze_util::IsDevNull with POSIX and Windows semantics + add tests - blaze::MakeAbsolute calls blaze::ConvertPath on its input to convert MSYS paths on Windows - blaze_util::GetCwdW (thus GetCwd) always returns a lowercase path so that it is deterministic - blaze_util::GetCurrentDrive returns lowercase letter to be consisent with blaze::ConvertPath, which also returns a lowercase path Fixes https://github.com/bazelbuild/bazel/issues/3440 Change-Id: I3af5ba0a033d542fe64a676d67f27472298d1089 PiperOrigin-RevId: 163038503
* Windows: add blaze_util::AsAbsoluteWindowsPathGravatar laszlocsomor2017-07-24
| | | | | | | | | | | Replace blaze_util::AsWindowsPathWithUncPrefix with AsAbsoluteWindowsPath, which always returns an absolute path. Fixes https://github.com/bazelbuild/bazel/issues/2935 RELNOTES: none PiperOrigin-RevId: 162727218
* Windows: more robust path handling.Gravatar laszlocsomor2017-07-24
| | | | | | | | | | | | | | | In this change: - add support for absolute-on-current-drive paths (e.g. "\foo", meaning "c:\foo") - report error for relative-on-current-drive paths (e.g. "c:" and "c:foo") - report error for remote Windows paths (e.g. "\\servername\path\on\server") - update blaze_util::AsWindowsPath comments - update tests RELNOTES: none PiperOrigin-RevId: 162719763
* Windows, JNI: move around sourcesGravatar Laszlo Csomor2017-06-29
| | | | | | | | | | | | | | | | Move the Windows JNI C++ sources to a separate package and separate namespace. This no-op refactoring allows other build rules than Bazel's client library to depend on file I/O and/or JNI functionality. A follow-up commit will split the //src/main/native/windows:processes library into :jni-processes and :jni-file. Change-Id: I33c5f8ebd8961cc440db3b4a95ff78024d7c1d74 PiperOrigin-RevId: 160404298
* Bazel client, Windows: fix MSYS root computation Gravatar László Csomor2017-03-23
| | | | | | | | | | | | | | Make it more robust: it now works with Cygwin too, e.g. BAZEL_SH=c:/cygwin64/bin/bash.exe See https://github.com/bazelbuild/bazel/issues/2725 Related to https://github.com/bazelbuild/bazel/issues/2447 -- Change-Id: I911f09acd3e39c7cd0fe0750774fa0a900ffd844 Reviewed-on: https://cr.bazel.build/9510 PiperOrigin-RevId: 150885982 MOS_MIGRATED_REVID=150885982
* Bazel client, Windows: support "d:/" output rootGravatar Laszlo Csomor2017-03-16
| | | | | | | | | | | | | Support drive roots as --output_user_root values, so "d:\" and "d:/" will now work. However "d:" doesn't work yet because that's shorthand for the current working directory on "D:". See https://github.com/bazelbuild/bazel/issues/2683 -- PiperOrigin-RevId: 150203657 MOS_MIGRATED_REVID=150203657
* Bazel client, Windows: fix AsShortWindowsPathGravatar Laszlo Csomor2017-03-06
| | | | | | | | | | This method now works for non-existent paths too. See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 149284633 MOS_MIGRATED_REVID=149284633
* Bazel client, Windows: implement MakeCanonical Gravatar Laszlo Csomor2017-02-16
| | | | | | | | | | See https://github.com/bazelbuild/bazel/issues/2107 -- Change-Id: I27a97881e3e19cbb7913e1248a24e9e631bc4f40 Reviewed-on: https://cr.bazel.build/8951 PiperOrigin-RevId: 147719277 MOS_MIGRATED_REVID=147719277
* Bazel client: refactors, small bugfixes Gravatar Laszlo Csomor2017-02-15
| | | | | | | | | | | | | | | | | | | In this change: * Fix pdie and PrintError to acquire the last error string as the first thing the method does, otherwise we may display an error coming from pdie's/PrintError's own logic * Auto-close file handles in file_test in order to avoid leaking them in case an assertion fails (which means an early return from the function) -- Change-Id: Ia4392b42cbc93b931dcee76993db0ad264d0c147 Reviewed-on: https://cr.bazel.build/8932 PiperOrigin-RevId: 147610527 MOS_MIGRATED_REVID=147610527
* Bazel client, Windows, tests: use CreateJuction Gravatar Laszlo Csomor2017-02-15
| | | | | | | | | | | | | Use the JNI library's CreateJuction in file_windows_test. See https://github.com/bazelbuild/bazel/issues/2107 -- Change-Id: I4ef1536d43691fe7a2ae3ee457064d4e8f4ac6d7 Reviewed-on: https://cr.bazel.build/8895 PiperOrigin-RevId: 147594365 MOS_MIGRATED_REVID=147594365
* Bazel client, Windows, tests: remove cleanup code Gravatar Laszlo Csomor2017-02-15
| | | | | | | | | | | | | The TearDown method clears up after tests, so manual cleanup is unnecessary. See https://github.com/bazelbuild/bazel/issues/2107 -- Change-Id: Idf5d2b2bf012774171f1868d1341a7952015c35f Reviewed-on: https://cr.bazel.build/8894 PiperOrigin-RevId: 147591032 MOS_MIGRATED_REVID=147591032
* Windows JNI, refactor: move OpenDirectory to JNIGravatar Laszlo Csomor2017-02-14
| | | | | | | | | | | | Move the OpenDirectory helper method into the JNI library. We'll need it there; a subsequent change will make use of it there. See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 147448792 MOS_MIGRATED_REVID=147448792
* Bazel client, Windows, tests: `rm -rf TEST_TMPDIR`Gravatar Laszlo Csomor2017-02-10
| | | | | | | | | | | | Add test helpers to recursively delete the TEST_TMPDIR in the TearDown method of tests, to ensure each test sees a fresh temp directory. Also add tests for these test helpers. -- PiperOrigin-RevId: 147135561 MOS_MIGRATED_REVID=147135561
* Bazel client, Windows: use CreateFileWGravatar Laszlo Csomor2017-01-18
| | | | | | | | | | | | | | | | | | | | | | Use CreateFileW in blaze_util_windows.cc when opening the "jvm.out" file. This allows supporting long paths. Also use AsWindowsPathWithUncPrefix instead of just AsWindowsPath plus manually adding the UNC prefix. Also fix a compilation error in file_windows_test.cc, I'm surprised the CI system didn't catch this, maybe we aren't running this test there. See https://github.com/bazelbuild/bazel/issues/2107 See https://github.com/bazelbuild/bazel/issues/2181 -- PiperOrigin-RevId: 144813245 MOS_MIGRATED_REVID=144813245
* Bazel client, Windows: implement CanAccess methodsGravatar Laszlo Csomor2017-01-12
| | | | | | | | See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 144321891 MOS_MIGRATED_REVID=144321891
* Bazel client, Windows: implement MakeDirectoriesGravatar Laszlo Csomor2017-01-12
| | | | | | | | | See https://github.com/bazelbuild/bazel/issues/2107 See https://github.com/bazelbuild/bazel/issues/1744 -- PiperOrigin-RevId: 144313301 MOS_MIGRATED_REVID=144313301
* Bazel client, Windows: support /dev/nullGravatar Laszlo Csomor2017-01-11
| | | | | | | | | | | | | | | | | Support passing /dev/null and NUL as flag values for flags like --bazelrc. In particular, special-case these paths in methods like blaze_util::ReadFile, blaze_util::IsDirectory, etc. Fixes https://github.com/bazelbuild/bazel/issues/2354 RELNOTES[NEW]: Windows: "/dev/null" is now a supported path, e.g. --bazelrc=/dev/null now works -- PiperOrigin-RevId: 144195994 MOS_MIGRATED_REVID=144195994
* Bazel client, Windows: implement UnlinkPathGravatar Laszlo Csomor2017-01-11
| | | | | | | | | | | | | | | | This was committed and rolled back twice, once because I forgot to update file_posix.cc, and again because the roll-forward was somehow only partial. This is a clean attempt at submitting the same thing again. See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 144179954 MOS_MIGRATED_REVID=144179954
* Rollback of commit e1f8bbc1fe1d0a22736597dbd029155b01718b94.Gravatar Laszlo Csomor2017-01-10
| | | | | | | | | | | | | | | | | | | | | | | | *** Reason for rollback *** Bad rollback, was only partial. *** Original change description *** Automated [] rollback of commit 9a13899b1492738f8d1a9118cebc9ef9d90c6b34. *** Reason for rollback *** Fixed the problem with the CL. *** Original change description *** Bazel client, Windows: implement UnlinkPath See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 144115263 MOS_MIGRATED_REVID=144115263
* Rollback of commit 9a13899b1492738f8d1a9118cebc9ef9d90c6b34.Gravatar Laszlo Csomor2017-01-10
| | | | | | | | | | | | | | | | *** Reason for rollback *** Fixed the problem with the CL. *** Original change description *** Bazel client, Windows: implement UnlinkPath See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 144087552 MOS_MIGRATED_REVID=144087552
* Bazel client, Windows: implement IsDirectoryGravatar Laszlo Csomor2017-01-10
| | | | | | | | See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 144084379 MOS_MIGRATED_REVID=144084379
* Rollback of commit 9a13899b1492738f8d1a9118cebc9ef9d90c6b34.Gravatar Marcel Hlopko2017-01-10
| | | | | | | | | | | | | | | | | | | | *** Reason for rollback *** Breaks windows: bazel-out/local-fastbuild/bin/src/main/cpp/util/libfile.a(file_windows.o):file_windows.cc:(.text+0x11e2): multiple definition of `blaze_util::UnlinkPath(std::string const&)' bazel-out/local-fastbuild/bin/src/main/cpp/util/libfile.a(file_posix.o):file_posix.cc:(.text+0x3ff): first defined here *** Original change description *** Bazel client, Windows: implement UnlinkPath See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 144082937 MOS_MIGRATED_REVID=144082937
* Bazel client, Windows: implement UnlinkPathGravatar Laszlo Csomor2017-01-10
| | | | | | | | See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 144073888 MOS_MIGRATED_REVID=144073888
* Windows: implement and use AsShortWindowsPathGravatar Laszlo Csomor2017-01-10
| | | | | | | | | | | | | | | | | | Because CreateProcessW doesn't support long paths, not even with the "\\?\" prefix [1], we need to convert long paths to short ones to spawn processes. This change implements the corresponding function and uses it in blaze_util_windows. [1] https://github.com/bazelbuild/bazel/issues/2181#issuecomment-270696173 See https://github.com/bazelbuild/bazel/issues/2107 See https://github.com/bazelbuild/bazel/issues/2181 -- PiperOrigin-RevId: 144062404 MOS_MIGRATED_REVID=144062404
* Bazel client: move NormalizePath to Windows codeGravatar Laszlo Csomor2017-01-10
| | | | | | | | | | | | | | | | | | | | | | | | | | This method was only used by the Windows-specific code so move it there and adapt it to Windows paths. Update AsWindowsPath to normalize its output: this is necessary because AsWindowsPath's output is a widechar path string which we often prefix with the UNC prefix, but such paths must be normalized (the kernel won't do it if the path has an UNC prefix). Finally, add an AsWindowsPathWithUncPrefix method which does what the name suggests: converts the path to Windows path, makes it absolute, and adds the UNC prefix if necessary. (This is a very common operation when calling WinAPI functions and we'll use it a lot in subsequent changes.) See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 144060297 MOS_MIGRATED_REVID=144060297
* Bazel client: implement PathExists on WindowsGravatar Laszlo Csomor2017-01-05
| | | | | | | | | | | | | | | | | | | | Checking if a path exists is surprisingly hard on Windows. The most convenient API functions are PathFileExists and GetFileAttributes but neither of them follows junctions. To check if a junction is dangling, we have to resolve it all the way. This change adds a JunctionResolver class to file_windows, which can resolve junctions (if they aren't dangling) and non-junctions (in this case just checks their existence). See https://github.com/bazelbuild/bazel/issues/2107 See https://github.com/bazelbuild/bazel/issues/2181 -- PiperOrigin-RevId: 143645274 MOS_MIGRATED_REVID=143645274
* Bazel client, Windows: case-insensitive MSYS rootGravatar Laszlo Csomor2017-01-03
| | | | | | | | | | | | Make the MSYS root retrieval case-insensitive. While there, make the MSYS root resetable so we can test it. See https://github.com/bazelbuild/bazel/issues/2323 -- PiperOrigin-RevId: 143377137 MOS_MIGRATED_REVID=143377137
* Bazel client, Windows: fix MSYS root retrievalGravatar Laszlo Csomor2017-01-03
| | | | | | | | | | | | | | | | | | | | | The file_windows.cc:MsysRoot::Get() function was incorrectly assuming that bash.exe is usually under c:\tools\msys64\bin\bash.exe when in reality it's c:\tools\msys64\usr\bin\bash.exe, so we need to walk up one more directory. Unfortunately the test was assuming the same so the bug wasn't caught. The new code is a bit more foolproof in that it looks for an msys-looking final path segment and assumes that to be the msys root. Fixes https://github.com/bazelbuild/bazel/issues/2323 -- PiperOrigin-RevId: 143372193 MOS_MIGRATED_REVID=143372193
* Bazel client, Windows: implement AsWindowsPathGravatar Laszlo Csomor2016-12-20
| | | | | | | | | | | | | | | | | | | | This method converts MSYS paths to Windows path. It uses the BAZEL_SH envvar to obtain the MSYS root directory, to which all Unix paths (except for mounts) are relative. We cannot handle mounts because we don't want to read /etc/mtab every time there's a file operation so we simply apply a heuristic similar to https://github.com/bazelbuild/bazel/blob/cd4cc09fa6ef96380a3d0888f825dfd1dbada651/src/main/java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java#L52-L63 Also clean up the #ifdefs surrounding SyncFile. See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 142531986 MOS_MIGRATED_REVID=142531986
* Bazel client: generalize path handlingGravatar Laszlo Csomor2016-12-19
| | | | | | | | | | | | | | Use/implement utility methods to join paths, check if they are the root directory or are absolute, etc. Doing so (instead of say checking if a path starts with "/") allows for correct behavior on Windows. See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 142446027 MOS_MIGRATED_REVID=142446027
* Bazel client: SplitPath works with Windows pathsGravatar Laszlo Csomor2016-12-19
This allows correct behavior of Dirname and Basename on Windows. See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 142441234 MOS_MIGRATED_REVID=142441234