Skip to content

Commit

Permalink
Fix launcher_maker to work with long paths on windows
Browse files Browse the repository at this point in the history
Also changes error messages to print to stderr so that it's visible in the build log

Fixes #17118

PiperOrigin-RevId: 503378489
Change-Id: I6860f3ec0f3a25502a3f96a3e028108c9953407d
  • Loading branch information
hvadehra authored and copybara-github committed Jan 20, 2023
1 parent ab71a10 commit 33fed24
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/tools/launcher/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ win_cc_binary(
"//src:__pkg__",
"//tools/launcher:__pkg__",
],
deps = [
"//src/main/cpp/util:filesystem",
],
)

launcher_maker_test(name = "launcher_maker_test")
37 changes: 27 additions & 10 deletions src/tools/launcher/launcher_maker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <fstream>
#include <string>

#include "src/main/cpp/util/path_platform.h"

// This is a replacement for
// third_party/bazel/src/main/java/com/google/devtools/build/lib/analysis/actions/LauncherFileWriteAction.java
//
Expand All @@ -30,31 +32,46 @@
// appends each line of the launch info as a null-terminated string. At the
// end, the size of the launch data written is appended as a long value (8
// bytes).

std::wstring windows_path(char* path) {
std::string error;
std::wstring wpath;
if (!blaze_util::AsAbsoluteWindowsPath(path, &wpath, &error)) {
fprintf(stderr, "Failed to make absolute path for %s: %s\n", path,
error.c_str());
exit(1);
}
return wpath;
}

int main(int argc, char** argv) {
if (argc < 4) {
printf("Expected 3 arguments, got %d\n", argc);
fprintf(stderr, "Expected 3 arguments, got %d\n", argc);
return 1;
}

char* launcher_path = argv[1];
char* info_params = argv[2];
char* output_path = argv[3];
std::wstring wlauncher_path = windows_path(argv[1]);
std::wstring winfo_params = windows_path(argv[2]);
std::wstring woutput_path = windows_path(argv[3]);

std::ifstream src(launcher_path, std::ios::binary);
std::ifstream src(wlauncher_path, std::ios::binary);
if (!src.good()) {
printf("Failed to open %s: %s\n", launcher_path, strerror(errno));
fprintf(stderr, "Failed to open %ls: %s\n", wlauncher_path.c_str(),
strerror(errno));
return 1;
}
std::ofstream dst(output_path, std::ios::binary);
std::ofstream dst(woutput_path, std::ios::binary);
if (!dst.good()) {
printf("Failed to create %s: %s\n", output_path, strerror(errno));
fprintf(stderr, "Failed to create %ls: %s\n", woutput_path.c_str(),
strerror(errno));
return 1;
}
dst << src.rdbuf();

std::ifstream info_file(info_params);
std::ifstream info_file(winfo_params);
if (!info_file.good()) {
printf("Failed to open %s: %s\n", info_params, strerror(errno));
fprintf(stderr, "Failed to open %ls: %s\n", winfo_params.c_str(),
strerror(errno));
return 1;
}
int64_t bytes = 0;
Expand Down

0 comments on commit 33fed24

Please sign in to comment.