|
18 | 18 | #include <fstream>
|
19 | 19 | #include <string>
|
20 | 20 |
|
| 21 | +#include "src/main/cpp/util/path_platform.h" |
| 22 | + |
21 | 23 | // This is a replacement for
|
22 | 24 | // third_party/bazel/src/main/java/com/google/devtools/build/lib/analysis/actions/LauncherFileWriteAction.java
|
23 | 25 | //
|
|
30 | 32 | // appends each line of the launch info as a null-terminated string. At the
|
31 | 33 | // end, the size of the launch data written is appended as a long value (8
|
32 | 34 | // 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 | + |
33 | 47 | int main(int argc, char** argv) {
|
34 | 48 | if (argc < 4) {
|
35 |
| - printf("Expected 3 arguments, got %d\n", argc); |
| 49 | + fprintf(stderr, "Expected 3 arguments, got %d\n", argc); |
36 | 50 | return 1;
|
37 | 51 | }
|
38 | 52 |
|
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]); |
42 | 56 |
|
43 |
| - std::ifstream src(launcher_path, std::ios::binary); |
| 57 | + std::ifstream src(wlauncher_path, std::ios::binary); |
44 | 58 | 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)); |
46 | 61 | return 1;
|
47 | 62 | }
|
48 |
| - std::ofstream dst(output_path, std::ios::binary); |
| 63 | + std::ofstream dst(woutput_path, std::ios::binary); |
49 | 64 | 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)); |
51 | 67 | return 1;
|
52 | 68 | }
|
53 | 69 | dst << src.rdbuf();
|
54 | 70 |
|
55 |
| - std::ifstream info_file(info_params); |
| 71 | + std::ifstream info_file(winfo_params); |
56 | 72 | 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)); |
58 | 75 | return 1;
|
59 | 76 | }
|
60 | 77 | int64_t bytes = 0;
|
|
0 commit comments