Skip to content

Commit

Permalink
Windows, build-runfiles: Fix bugs when dealing with long path
Browse files Browse the repository at this point in the history
We should make sure the path passing to Windows API has the \\?\ prefix.

Related bazelbuild#5807

RELNOTES: None
PiperOrigin-RevId: 211039921
  • Loading branch information
laszlocsomor committed Aug 31, 2018
1 parent fff72a7 commit 3950a27
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/create_embedded_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
('*tools/platforms/platforms.BUILD', lambda x: 'platforms/BUILD'),
('*tools/platforms/*', lambda x: 'platforms/' + os.path.basename(x)),
('*tools/cpp/runfiles/*',
lambda x: 'tools/cpp/runfiles/' + os.path.basename(x)),
lambda x: 'tools/cpp/runfiles/' + os.path.basename(x)[len('generated_'):]),
('*JavaBuilder*_deploy.jar', lambda x: 'tools/jdk/' + os.path.basename(x)),
('*JacocoCoverage*_deploy.jar',
lambda x: 'tools/jdk/JacocoCoverage_deploy.jar'),
Expand Down
8 changes: 5 additions & 3 deletions src/main/tools/build-runfiles-windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ class RunfilesCreator {
}

link = AsAbsoluteWindowsPath(link.c_str());
if (!target.empty()) {
target = AsAbsoluteWindowsPath(target.c_str());
}

manifest_file_map.insert(make_pair(link, target));
}
Expand Down Expand Up @@ -257,6 +260,7 @@ class RunfilesCreator {
do {
if (kDot != metadata.cFileName && kDotDot != metadata.cFileName) {
wstring subpath = path + L"\\" + metadata.cFileName;
subpath = AsAbsoluteWindowsPath(subpath.c_str());
bool is_dir =
(metadata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
bool is_symlink =
Expand All @@ -268,7 +272,6 @@ class RunfilesCreator {
GetLastErrorString().c_str());
}

subpath = AsAbsoluteWindowsPath(subpath.c_str());
target = AsAbsoluteWindowsPath(target.c_str());
ManifestFileMap::iterator expected_target =
manifest_file_map.find(subpath);
Expand All @@ -277,8 +280,7 @@ class RunfilesCreator {
expected_target->second.empty()
// Both paths are normalized paths in lower case, we can compare
// them directly.
|| target !=
AsAbsoluteWindowsPath(expected_target->second.c_str()) ||
|| target != expected_target->second.c_str() ||
blaze_util::IsDirectoryW(target) != is_dir) {
if (is_dir) {
RemoveDirectoryOrDie(subpath);
Expand Down
8 changes: 4 additions & 4 deletions tools/cpp/runfiles/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ genrule(
"runfiles_src.h",
],
outs = [
"runfiles.cc",
"runfiles.h",
"generated_runfiles.cc",
"generated_runfiles.h",
],
cmd = ("sed " +
" 's|^#include.*/runfiles_src.h.*|#include \"tools/cpp/runfiles/runfiles.h\"|' " +
" $(location runfiles_src.cc) > $(location runfiles.cc) && " +
"cp $(location runfiles_src.h) $(location runfiles.h)"),
" $(location runfiles_src.cc) > $(location generated_runfiles.cc) && " +
"cp $(location runfiles_src.h) $(location generated_runfiles.h)"),
)

cc_library(
Expand Down

0 comments on commit 3950a27

Please sign in to comment.