diff options
-rw-r--r-- | src/main/native/BUILD | 7 | ||||
-rw-r--r-- | src/main/native/windows_processes.cc | 18 | ||||
-rw-r--r-- | src/main/native/windows_util.h | 16 | ||||
-rw-r--r-- | src/test/native/BUILD | 4 |
4 files changed, 25 insertions, 20 deletions
diff --git a/src/main/native/BUILD b/src/main/native/BUILD index ef4143a949..13775d04bd 100644 --- a/src/main/native/BUILD +++ b/src/main/native/BUILD @@ -63,10 +63,13 @@ cc_binary( ) cc_library( - name = "windows_jni_utils", + name = "windows_jni_lib", srcs = ["windows_util.cc"], hdrs = ["windows_util.h"], - visibility = ["//src/test/native:__pkg__"], + visibility = [ + "//src/main/cpp:__subpackages__", + "//src/test/native:__pkg__", + ], ) genrule( diff --git a/src/main/native/windows_processes.cc b/src/main/native/windows_processes.cc index 97f22b48be..284b4e8c60 100644 --- a/src/main/native/windows_processes.cc +++ b/src/main/native/windows_processes.cc @@ -79,16 +79,6 @@ struct NativeProcess { error_("") {} }; -struct AutoHandle { - AutoHandle() : handle(INVALID_HANDLE_VALUE) {} - ~AutoHandle() { - CloseHandle(handle); // handles INVALID_HANDLE_VALUE - handle = INVALID_HANDLE_VALUE; - } - - HANDLE handle; -}; - class JavaByteArray { public: JavaByteArray(JNIEnv* env, jbyteArray java_array) @@ -196,10 +186,10 @@ Java_com_google_devtools_build_lib_windows_WindowsProcesses_nativeCreateProcess( // created. If this was not so, operations on these file handles would not // return immediately if the process is terminated. // Therefore we make these handles auto-closing (by using AutoHandle). - AutoHandle stdin_process; - AutoHandle stdout_process; - AutoHandle stderr_process; - AutoHandle thread; + windows_util::AutoHandle stdin_process; + windows_util::AutoHandle stdout_process; + windows_util::AutoHandle stderr_process; + windows_util::AutoHandle thread; PROCESS_INFORMATION process_info = {0}; STARTUPINFOA startup_info = {0}; JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = {0}; diff --git a/src/main/native/windows_util.h b/src/main/native/windows_util.h index ac55d8948c..a2f09abc06 100644 --- a/src/main/native/windows_util.h +++ b/src/main/native/windows_util.h @@ -11,12 +11,12 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -// -// INTERNAL header file for use by C++ code in this package. #ifndef BAZEL_SRC_MAIN_NATIVE_WINDOWS_UTIL_H__ #define BAZEL_SRC_MAIN_NATIVE_WINDOWS_UTIL_H__ +#include <windows.h> + #include <functional> #include <memory> #include <string> @@ -28,6 +28,18 @@ using std::string; using std::unique_ptr; using std::wstring; +// A wrapper for the `HANDLE` type that calls CloseHandle in its d'tor. +struct AutoHandle { + AutoHandle(HANDLE _handle = INVALID_HANDLE_VALUE) : handle(_handle) {} + + ~AutoHandle() { + ::CloseHandle(handle); // succeeds if handle == INVALID_HANDLE_VALUE + handle = INVALID_HANDLE_VALUE; + } + + HANDLE handle; +}; + string GetLastErrorString(const string& cause); // Computes a path suitable as the executable part in CreateProcessA's cmdline. diff --git a/src/test/native/BUILD b/src/test/native/BUILD index 320f20e525..bd3f90d40b 100644 --- a/src/test/native/BUILD +++ b/src/test/native/BUILD @@ -17,11 +17,11 @@ cc_test( }), deps = select({ "//src:windows": [ - "//src/main/native:windows_jni_utils", + "//src/main/native:windows_jni_lib", "//third_party:gtest", ], "//src:windows_msvc": [ - "//src/main/native:windows_jni_utils", + "//src/main/native:windows_jni_lib", "//third_party:gtest", ], "//conditions:default": [], |