github.com/maruel/nin@v0.0.0-20220112143044-f35891e3ce7e/cmd/nin/msvc_helper-win32.go (about)

     1  // Copyright 2011 Google Inc. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package main
    16  
    17  import "strings"
    18  
    19  func escapeForDepfile(path string) string {
    20  	// Depfiles don't escape single \.
    21  	return strings.ReplaceAll(path, " ", "\\ ")
    22  }
    23  
    24  func (c *clWrapper) Run(command string, output *string) int {
    25  	panic("TODO")
    26  	/*
    27  		  SECURITY_ATTRIBUTES securityAttributes = {}
    28  		  securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES)
    29  		  securityAttributes.bInheritHandle = TRUE
    30  
    31  		  // Must be inheritable so subprocesses can dup to children.
    32  		  HANDLE nul =
    33  		      CreateFileA("NUL", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, &securityAttributes, OPEN_EXISTING, 0, nil)
    34  		  if nul == INVALID_HANDLE_VALUE {
    35  		    Fatal("couldn't open nul")
    36  		  }
    37  
    38  		  HANDLE stdoutRead, stdoutWrite
    39  		  if !CreatePipe(&stdoutRead, &stdoutWrite, &securityAttributes, 0) {
    40  		    Win32Fatal("CreatePipe")
    41  		  }
    42  
    43  		  if !SetHandleInformation(stdoutRead, HANDLE_FLAG_INHERIT, 0) {
    44  		    Win32Fatal("SetHandleInformation")
    45  		  }
    46  
    47  		  PROCESS_INFORMATION processInfo = {}
    48  		  STARTUPINFOA startupInfo = {}
    49  		  startupInfo.cb = sizeof(STARTUPINFOA)
    50  		  startupInfo.hStdInput = nul
    51  		  startupInfo.hStdError = ::GetStdHandle(STD_ERROR_HANDLE)
    52  		  startupInfo.hStdOutput = stdoutWrite
    53  		  startupInfo.dwFlags |= STARTF_USESTDHANDLES
    54  
    55  			// inherit handles = TRUE
    56  		  if !CreateProcessA(nil, (char*)command, nil, nil,  TRUE, 0, c.envBlock, nil, &startupInfo, &processInfo) {
    57  		    Win32Fatal("CreateProcess")
    58  		  }
    59  
    60  		  if !CloseHandle(nul) || !CloseHandle(stdoutWrite) {
    61  		    Win32Fatal("CloseHandle")
    62  		  }
    63  
    64  		  // Read all output of the subprocess.
    65  		  readLen := 1
    66  		  for readLen {
    67  		    char buf[64 << 10]
    68  		    readLen = 0
    69  		    if !::ReadFile(stdoutRead, buf, sizeof(buf), &readLen, nil) && GetLastError() != ERROR_BROKEN_PIPE {
    70  		      Win32Fatal("ReadFile")
    71  		    }
    72  		    output.append(buf, readLen)
    73  		  }
    74  
    75  		  // Wait for it to exit and grab its exit code.
    76  		  if WaitForSingleObject(processInfo.hProcess, INFINITE) == WAIT_FAILED {
    77  		    Win32Fatal("WaitForSingleObject")
    78  		  }
    79  		  exitCode := 0
    80  		  if !GetExitCodeProcess(processInfo.hProcess, &exitCode) {
    81  		    Win32Fatal("GetExitCodeProcess")
    82  		  }
    83  
    84  		  if !CloseHandle(stdoutRead) || !CloseHandle(processInfo.hProcess) || !CloseHandle(processInfo.hThread) {
    85  		    Win32Fatal("CloseHandle")
    86  		  }
    87  
    88  		  return exitCode
    89  	*/
    90  }