diff options
author | 2017-03-02 11:43:21 +0000 | |
---|---|---|
committer | 2017-03-02 13:32:42 +0000 | |
commit | 99b015430f4bfe42a6d116d42c638523752eeb18 (patch) | |
tree | 344b318fb70b77ccd568f3b452b8038e8a72d717 | |
parent | 9954ef0354bdd0a3e74fceb7725404437c4d0c98 (diff) |
Bazel client: fix broken compilation
Do not include <windows.h> in file_platform.h
because it #defines many symbols that later code,
particularly function definitions, conflict with,
e.g. GetUserName, SendMessage.
This was breaking the Bazel bootstrap project on
CI.
--
Change-Id: Ie4b59b00fc617bd3e7d0cbb967c1232798e055de
Reviewed-on: https://cr.bazel.build/9127
PiperOrigin-RevId: 148986922
MOS_MIGRATED_REVID=148986922
-rw-r--r-- | src/main/cpp/blaze_util_windows.cc | 6 | ||||
-rw-r--r-- | src/main/cpp/util/file_platform.h | 15 |
2 files changed, 13 insertions, 8 deletions
diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc index 839490b48e..a862fdaea6 100644 --- a/src/main/cpp/blaze_util_windows.cc +++ b/src/main/cpp/blaze_util_windows.cc @@ -1274,6 +1274,12 @@ void ReleaseLock(BlazeLock* blaze_lock) { #endif // COMPILER_MSVC } +#ifdef GetUserName +// By including <windows.h>, we have GetUserName defined either as +// GetUserNameA or GetUserNameW. +#undef GetUserName +#endif + string GetUserName() { WCHAR buffer[UNLEN + 1]; DWORD len = UNLEN + 1; diff --git a/src/main/cpp/util/file_platform.h b/src/main/cpp/util/file_platform.h index d8b254ecf4..02f5b8725b 100644 --- a/src/main/cpp/util/file_platform.h +++ b/src/main/cpp/util/file_platform.h @@ -15,13 +15,6 @@ #ifndef BAZEL_SRC_MAIN_CPP_UTIL_FILE_PLATFORM_H_ #define BAZEL_SRC_MAIN_CPP_UTIL_FILE_PLATFORM_H_ -#if defined(COMPILER_MSVC) || defined(__CYGWIN__) -#include <windows.h> -// Undef GetUserName defined by windows.h so we won't conflict with -// blaze_util::GetUserName -#undef GetUserName -#endif // defined(COMPILER_MSVC) || defined(__CYGWIN__) - #include <stdint.h> #include <time.h> @@ -61,7 +54,13 @@ IFileMtime *CreateFileMtime(); std::pair<std::string, std::string> SplitPath(const std::string &path); #if defined(COMPILER_MSVC) || defined(__CYGWIN__) -typedef HANDLE file_handle_type; +// We cannot include <windows.h> because it #defines many symbols that conflict +// with our function names, e.g. GetUserName, SendMessage. +// Instead of typedef'ing HANDLE, let's use the actual type, void*. If that ever +// changes in the future and HANDLE would no longer be compatible with void* +// (very unlikely, given how fundamental this type is in Windows), then we'd get +// a compilation error. +typedef /* HANDLE */ void *file_handle_type; #else // !(defined(COMPILER_MSVC) || defined(__CYGWIN__)) typedef int file_handle_type; #endif // defined(COMPILER_MSVC) || defined(__CYGWIN__) |