aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2018-02-14 01:37:48 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-14 01:39:19 -0800
commit9bdb4d83e41170b573b602a8c2d3571a838fd153 (patch)
tree42d6972fed6a7b51a3367e91895aecbefb3a99ba /src
parentacfec5f2c069aa314c932910bedaeb8dbf61e8df (diff)
windows,singlejar: compile "token_stream"
We can now compile //src/tools/singlejar:token_stream on Windows. See https://github.com/bazelbuild/bazel/issues/2241 Change-Id: I98f86e608e5ebaf685e4de26b2dabe75fcca78d2 PiperOrigin-RevId: 185655986
Diffstat (limited to 'src')
-rw-r--r--src/tools/singlejar/diag.h20
-rw-r--r--src/tools/singlejar/token_stream.h7
2 files changed, 27 insertions, 0 deletions
diff --git a/src/tools/singlejar/diag.h b/src/tools/singlejar/diag.h
index 5dd4a7fb10..775ab05344 100644
--- a/src/tools/singlejar/diag.h
+++ b/src/tools/singlejar/diag.h
@@ -20,12 +20,32 @@
* for portability.
*/
#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__)
+
#include <err.h>
#define diag_err(...) err(__VA_ARGS__)
#define diag_errx(...) errx(__VA_ARGS__)
#define diag_warn(...) warn(__VA_ARGS__)
#define diag_warnx(...) warnx(__VA_ARGS__)
+
+#elif defined(COMPILER_MSVC)
+
+#include <stdio.h>
+#include <string.h>
+#include <windows.h>
+#define _diag_msg(prefix, msg, ...) \
+ { fprintf(stderr, prefix " [" __FILE__ ":%d]" msg, __LINE__, __VA_ARGS__); }
+#define _diag_msgx(eval, prefix, msg, ...) \
+ { \
+ _diag_msg(prefix, msg, __VA_ARGS__); \
+ ::ExitProcess(eval); \
+ }
+#define diag_err(eval, fmt, ...) _diag_msgx(eval, "ERROR", fmt, __VA_ARGS__)
+#define diag_errx(eval, ...) _diag_msgx(eval, "ERROR", "", __VA_ARGS__)
+#define diag_warn(...) _diag_msg("WARNING", __VA_ARGS__)
+#define diag_warnx(...) _diag_msg("WARNING")
+
#else
#error Unknown platform
#endif
+
#endif // BAZEL_SRC_TOOLS_SINGLEJAR_DIAG_H_
diff --git a/src/tools/singlejar/token_stream.h b/src/tools/singlejar/token_stream.h
index 23ee84d7ad..3bad0a883d 100644
--- a/src/tools/singlejar/token_stream.h
+++ b/src/tools/singlejar/token_stream.h
@@ -57,6 +57,13 @@ class ArgTokenStream {
class FileTokenStream {
public:
FileTokenStream(const char *filename) {
+ // TODO(laszlocsomor): use the fopen and related file handling API
+ // implementations from ProtoBuf, in order to support long paths:
+ // https://github.com/google/protobuf/blob/
+ // 47b7d2c7cadf74ceec90fc5042232819cd0dd557/
+ // src/google/protobuf/stubs/io_win32.cc
+ // Best would be to extract that library to a common location and use
+ // here, in ProtoBuf, and in Bazel itself.
if (!(fp_ = fopen(filename, "r"))) {
diag_err(1, "%s", filename);
}