Skip to content

Commit 33fed24

Browse files
hvadehracopybara-github
authored andcommitted
Fix launcher_maker to work with long paths on windows
Also changes error messages to print to stderr so that it's visible in the build log Fixes bazelbuild#17118 PiperOrigin-RevId: 503378489 Change-Id: I6860f3ec0f3a25502a3f96a3e028108c9953407d
1 parent ab71a10 commit 33fed24

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

src/tools/launcher/BUILD

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ win_cc_binary(
6969
"//src:__pkg__",
7070
"//tools/launcher:__pkg__",
7171
],
72+
deps = [
73+
"//src/main/cpp/util:filesystem",
74+
],
7275
)
7376

7477
launcher_maker_test(name = "launcher_maker_test")

src/tools/launcher/launcher_maker.cc

+27-10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <fstream>
1919
#include <string>
2020

21+
#include "src/main/cpp/util/path_platform.h"
22+
2123
// This is a replacement for
2224
// third_party/bazel/src/main/java/com/google/devtools/build/lib/analysis/actions/LauncherFileWriteAction.java
2325
//
@@ -30,31 +32,46 @@
3032
// appends each line of the launch info as a null-terminated string. At the
3133
// end, the size of the launch data written is appended as a long value (8
3234
// bytes).
35+
36+
std::wstring windows_path(char* path) {
37+
std::string error;
38+
std::wstring wpath;
39+
if (!blaze_util::AsAbsoluteWindowsPath(path, &wpath, &error)) {
40+
fprintf(stderr, "Failed to make absolute path for %s: %s\n", path,
41+
error.c_str());
42+
exit(1);
43+
}
44+
return wpath;
45+
}
46+
3347
int main(int argc, char** argv) {
3448
if (argc < 4) {
35-
printf("Expected 3 arguments, got %d\n", argc);
49+
fprintf(stderr, "Expected 3 arguments, got %d\n", argc);
3650
return 1;
3751
}
3852

39-
char* launcher_path = argv[1];
40-
char* info_params = argv[2];
41-
char* output_path = argv[3];
53+
std::wstring wlauncher_path = windows_path(argv[1]);
54+
std::wstring winfo_params = windows_path(argv[2]);
55+
std::wstring woutput_path = windows_path(argv[3]);
4256

43-
std::ifstream src(launcher_path, std::ios::binary);
57+
std::ifstream src(wlauncher_path, std::ios::binary);
4458
if (!src.good()) {
45-
printf("Failed to open %s: %s\n", launcher_path, strerror(errno));
59+
fprintf(stderr, "Failed to open %ls: %s\n", wlauncher_path.c_str(),
60+
strerror(errno));
4661
return 1;
4762
}
48-
std::ofstream dst(output_path, std::ios::binary);
63+
std::ofstream dst(woutput_path, std::ios::binary);
4964
if (!dst.good()) {
50-
printf("Failed to create %s: %s\n", output_path, strerror(errno));
65+
fprintf(stderr, "Failed to create %ls: %s\n", woutput_path.c_str(),
66+
strerror(errno));
5167
return 1;
5268
}
5369
dst << src.rdbuf();
5470

55-
std::ifstream info_file(info_params);
71+
std::ifstream info_file(winfo_params);
5672
if (!info_file.good()) {
57-
printf("Failed to open %s: %s\n", info_params, strerror(errno));
73+
fprintf(stderr, "Failed to open %ls: %s\n", winfo_params.c_str(),
74+
strerror(errno));
5875
return 1;
5976
}
6077
int64_t bytes = 0;

0 commit comments

Comments
 (0)