migrate to winapi 0.3
authorSteffen Butzer <steffen.butzer@outlook.com>
Fri, 29 Dec 2017 22:32:39 +0000 (23:32 +0100)
committerSteffen Butzer <steffen.butzer@outlook.com>
Sat, 30 Dec 2017 17:39:42 +0000 (18:39 +0100)
Cargo.toml
src/cargo/core/shell.rs
src/cargo/util/job.rs
src/cargo/util/read2.rs
tests/death.rs

index 254bad04adc55f2eba060c468ded455585dc067d..85f487103489b51bf6641f7a749fd049c97c9aa9 100644 (file)
@@ -57,10 +57,9 @@ url = "1.1"
 core-foundation = { version = "0.4.4", features = ["mac_os_10_7_support"] }
 
 [target.'cfg(windows)'.dependencies]
-kernel32-sys = "0.2"
 miow = "0.2"
-psapi-sys = "0.1"
-winapi = "0.2"
+winapi = { version = "0.3", features = ["handleapi", "jobapi", "jobapi2", "minwindef", "ntdef", 
+    "processenv", "processthreadsapi", "psapi", "synchapi", "winerror", "winbase", "wincon", "winnt"] }
 
 [dev-dependencies]
 bufstream = "0.1"
index ade08505d57188f2f8820d8dd7be9b7a634b6844..16180fde66c022982d9b46aa0a4db3a177c9740f 100644 (file)
@@ -317,16 +317,16 @@ mod imp {
 
 #[cfg(windows)]
 mod imp {
-    use std::mem;
-
     extern crate winapi;
-    extern crate kernel32;
+
+    use std::mem;
+    use self::winapi::um::{processenv, winbase, wincon};
 
     pub fn stderr_width() -> Option<usize> {
         unsafe {
-            let stdout = kernel32::GetStdHandle(winapi::STD_ERROR_HANDLE);
-            let mut csbi: winapi::CONSOLE_SCREEN_BUFFER_INFO = mem::zeroed();
-            if kernel32::GetConsoleScreenBufferInfo(stdout, &mut csbi) == 0 {
+            let stdout = processenv::GetStdHandle(winbase::STD_ERROR_HANDLE);
+            let mut csbi: wincon::CONSOLE_SCREEN_BUFFER_INFO = mem::zeroed();
+            if wincon::GetConsoleScreenBufferInfo(stdout, &mut csbi) == 0 {
                 return None
             }
             Some((csbi.srWindow.Right - csbi.srWindow.Left) as usize)
index 06f51356d25076dd5e49ca080aa4cfd23210dacd..0f03c94b64109ebe57e9b75668da5b05763b61e5 100644 (file)
@@ -42,21 +42,21 @@ mod imp {
 
 #[cfg(windows)]
 mod imp {
-    extern crate kernel32;
     extern crate winapi;
-    extern crate psapi;
 
     use std::ffi::OsString;
     use std::io;
     use std::mem;
     use std::os::windows::prelude::*;
+    use self::winapi::shared::*;
+    use self::winapi::um::*;
 
     pub struct Setup {
         job: Handle,
     }
 
     pub struct Handle {
-        inner: winapi::HANDLE,
+        inner: ntdef::HANDLE,
     }
 
     fn last_err() -> io::Error {
@@ -73,7 +73,7 @@ mod imp {
         // use job objects, so we instead just ignore errors and assume that
         // we're otherwise part of someone else's job object in this case.
 
-        let job = kernel32::CreateJobObjectW(0 as *mut _, 0 as *const _);
+        let job = jobapi2::CreateJobObjectW(0 as *mut _, 0 as *const _);
         if job.is_null() {
             return None
         }
@@ -83,22 +83,22 @@ mod imp {
         // process in the object should be killed. Note that this includes our
         // entire process tree by default because we've added ourselves and and
         // our children will reside in the job once we spawn a process.
-        let mut info: winapi::JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
+        let mut info: winnt::JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
         info = mem::zeroed();
         info.BasicLimitInformation.LimitFlags =
-            winapi::JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
-        let r = kernel32::SetInformationJobObject(job.inner,
-                        winapi::JobObjectExtendedLimitInformation,
-                        &mut info as *mut _ as winapi::LPVOID,
-                        mem::size_of_val(&info) as winapi::DWORD);
+            winnt::JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
+        let r = jobapi2::SetInformationJobObject(job.inner,
+                        winnt::JobObjectExtendedLimitInformation,
+                        &mut info as *mut _ as minwindef::LPVOID,
+                        mem::size_of_val(&info) as minwindef::DWORD);
         if r == 0 {
             return None
         }
 
         // Assign our process to this job object, meaning that our children will
         // now live or die based on our existence.
-        let me = kernel32::GetCurrentProcess();
-        let r = kernel32::AssignProcessToJobObject(job.inner, me);
+        let me = processthreadsapi::GetCurrentProcess();
+        let r = jobapi2::AssignProcessToJobObject(job.inner, me);
         if r == 0 {
             return None
         }
@@ -126,13 +126,13 @@ mod imp {
                     info!("killed some, going for more");
                 }
 
-                let mut info: winapi::JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
+                let mut info: winnt::JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
                 info = mem::zeroed();
-                let r = kernel32::SetInformationJobObject(
+                let r = jobapi2::SetInformationJobObject(
                             self.job.inner,
-                            winapi::JobObjectExtendedLimitInformation,
-                            &mut info as *mut _ as winapi::LPVOID,
-                            mem::size_of_val(&info) as winapi::DWORD);
+                            winnt::JobObjectExtendedLimitInformation,
+                            &mut info as *mut _ as minwindef::LPVOID,
+                            mem::size_of_val(&info) as minwindef::DWORD);
                 if r == 0 {
                     info!("failed to configure job object to defaults: {}",
                           last_err());
@@ -145,16 +145,16 @@ mod imp {
         unsafe fn kill_remaining(&mut self) -> bool {
             #[repr(C)]
             struct Jobs {
-                header: winapi::JOBOBJECT_BASIC_PROCESS_ID_LIST,
-                list: [winapi::ULONG_PTR; 1024],
+                header: winnt::JOBOBJECT_BASIC_PROCESS_ID_LIST,
+                list: [basetsd::ULONG_PTR; 1024],
             }
 
             let mut jobs: Jobs = mem::zeroed();
-            let r = kernel32::QueryInformationJobObject(
+            let r = jobapi2::QueryInformationJobObject(
                             self.job.inner,
-                            winapi::JobObjectBasicProcessIdList,
-                            &mut jobs as *mut _ as winapi::LPVOID,
-                            mem::size_of_val(&jobs) as winapi::DWORD,
+                            winnt::JobObjectBasicProcessIdList,
+                            &mut jobs as *mut _ as minwindef::LPVOID,
+                            mem::size_of_val(&jobs) as minwindef::DWORD,
                             0 as *mut _);
             if r == 0 {
                 info!("failed to query job object: {}", last_err());
@@ -168,17 +168,17 @@ mod imp {
 
             let list = list.iter().filter(|&&id| {
                 // let's not kill ourselves
-                id as winapi::DWORD != kernel32::GetCurrentProcessId()
+                id as minwindef::DWORD != processthreadsapi::GetCurrentProcessId()
             }).filter_map(|&id| {
                 // Open the process with the necessary rights, and if this
                 // fails then we probably raced with the process exiting so we
                 // ignore the problem.
-                let flags = winapi::PROCESS_QUERY_INFORMATION |
-                            winapi::PROCESS_TERMINATE |
-                            winapi::SYNCHRONIZE;
-                let p = kernel32::OpenProcess(flags,
-                                              winapi::FALSE,
-                                              id as winapi::DWORD);
+                let flags = winnt::PROCESS_QUERY_INFORMATION |
+                            winnt::PROCESS_TERMINATE |
+                            winnt::SYNCHRONIZE;
+                let p = processthreadsapi::OpenProcess(flags,
+                                                       minwindef::FALSE,
+                                                       id as minwindef::DWORD);
                 if p.is_null() {
                     None
                 } else {
@@ -189,12 +189,12 @@ mod imp {
                 // If it's not then we likely raced with something else
                 // recycling this PID, so we just skip this step.
                 let mut res = 0;
-                let r = kernel32::IsProcessInJob(p.inner, self.job.inner, &mut res);
+                let r = jobapi::IsProcessInJob(p.inner, self.job.inner, &mut res);
                 if r == 0 {
                     info!("failed to test is process in job: {}", last_err());
                     return false
                 }
-                res == winapi::TRUE
+                res == minwindef::TRUE
             });
 
 
@@ -204,7 +204,7 @@ mod imp {
                 let mut buf = [0; 1024];
                 let r = psapi::GetProcessImageFileNameW(p.inner,
                                                         buf.as_mut_ptr(),
-                                                        buf.len() as winapi::DWORD);
+                                                        buf.len() as minwindef::DWORD);
                 if r == 0 {
                     info!("failed to get image name: {}", last_err());
                     continue
@@ -233,14 +233,14 @@ mod imp {
                 // Ok, this isn't mspdbsrv, let's kill the process. After we
                 // kill it we wait on it to ensure that the next time around in
                 // this function we're not going to see it again.
-                let r = kernel32::TerminateProcess(p.inner, 1);
+                let r = processthreadsapi::TerminateProcess(p.inner, 1);
                 if r == 0 {
                     info!("\tfailed to kill subprocess: {}", last_err());
                     info!("\tassuming subprocess is dead...");
                 } else {
                     info!("\tterminated subprocess");
                 }
-                let r = kernel32::WaitForSingleObject(p.inner, winapi::INFINITE);
+                let r = synchapi::WaitForSingleObject(p.inner, winbase::INFINITE);
                 if r != 0 {
                     info!("failed to wait for process to die: {}", last_err());
                     return false
@@ -254,7 +254,7 @@ mod imp {
 
     impl Drop for Handle {
         fn drop(&mut self) {
-            unsafe { kernel32::CloseHandle(self.inner); }
+            unsafe { handleapi::CloseHandle(self.inner); }
         }
     }
-}
+}
\ No newline at end of file
index b3aa7d8b2cc62a289da7358cfba6ba47d4d6aed7..74d6d67f271e5d3037c3c16f2b86abb63828533b 100644 (file)
@@ -84,7 +84,7 @@ mod imp {
     use self::miow::iocp::{CompletionPort, CompletionStatus};
     use self::miow::pipe::NamedPipe;
     use self::miow::Overlapped;
-    use self::winapi::ERROR_BROKEN_PIPE;
+    use self::winapi::shared::winerror::ERROR_BROKEN_PIPE;
 
     struct Pipe<'a> {
         dst: &'a mut Vec<u8>,
index 3d04a24ccc60e218d2ba1fd7d36833082eed6fc1..33d6f573d978df7c507c13a4ba1d2440519fedc2 100644 (file)
@@ -1,5 +1,7 @@
 extern crate cargotest;
 extern crate libc;
+#[cfg(windows)]
+extern crate winapi;
 
 use std::fs;
 use std::io::{self, Read};
@@ -23,16 +25,16 @@ fn enabled() -> bool {
 // can succeed or not.
 #[cfg(windows)]
 fn enabled() -> bool {
-    extern crate kernel32;
-    extern crate winapi;
+    use winapi::um::{handleapi, jobapi, jobapi2, processthreadsapi};
+
     unsafe {
         // If we're not currently in a job, then we can definitely run these
         // tests.
-        let me = kernel32::GetCurrentProcess();
+        let me = processthreadsapi::GetCurrentProcess();
         let mut ret = 0;
-        let r = kernel32::IsProcessInJob(me, 0 as *mut _, &mut ret);
+        let r = jobapi::IsProcessInJob(me, 0 as *mut _, &mut ret);
         assert!(r != 0);
-        if ret == winapi::FALSE {
+        if ret == winapi::shared::minwindef::FALSE {
             return true
         }
 
@@ -42,10 +44,10 @@ fn enabled() -> bool {
         //
         // If we can't be added to a nested job, then these tests will
         // definitely fail, and there's not much we can do about that.
-        let job = kernel32::CreateJobObjectW(0 as *mut _, 0 as *const _);
+        let job = jobapi2::CreateJobObjectW(0 as *mut _, 0 as *const _);
         assert!(!job.is_null());
-        let r = kernel32::AssignProcessToJobObject(job, me);
-        kernel32::CloseHandle(job);
+        let r = jobapi2::AssignProcessToJobObject(job, me);
+        handleapi::CloseHandle(job);
         r != 0
     }
 }