github.com/maruel/nin@v0.0.0-20220112143044-f35891e3ce7e/cmd/nin/msvc_helper_main_windows.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 ( 18 "fmt" 19 20 "github.com/maruel/nin" 21 ) 22 23 func msvcHelperUsage() { 24 fmt.Printf("usage: ninja -t msvc [options] -- cl.exe /showIncludes /otherArgs\noptions:\n -e ENVFILE load environment block from ENVFILE as environment\n -o FILE write output dependency information to FILE.d\n -p STRING localized prefix of msvc's /showIncludes output\n") 25 } 26 27 func pushPathIntoEnvironment(envBlock string) { 28 panic("TODO") 29 /* 30 asStr := envBlock 31 for asStr[0] { 32 if Strnicmp(asStr, "path=", 5) == 0 { 33 Putenv(asStr) 34 return 35 } else { 36 asStr = &asStr[strlen(asStr)+1] 37 } 38 } 39 */ 40 } 41 42 func writeDepFileOrDie(objectPath string, parse *nin.CLParser) { 43 panic("TODO") 44 /* 45 depfilePath := objectPath + ".d" 46 depfile, err := os.OpenFile(depfilePath, os.O_WRONLY, 0o666) 47 if depfile == nil { 48 os.Remove(objectPath) 49 Fatal("opening %s: %s", depfilePath, err) 50 } 51 if _, err := fmt.Fprintf(depfile, "%s: ", objectPath); err != nil { 52 os.Remove(objectPath) 53 depfile.Close() 54 os.Remove(depfilePath) 55 Fatal("writing %s", depfilePath) 56 } 57 headers := parse.includes 58 for i := range headers { 59 if _, err := fmt.Fprintf(depfile, "%s\n", EscapeForDepfile(i)); err != nil { 60 os.Remove(objectPath) 61 depfile.Close() 62 os.Remove(depfilePath) 63 Fatal("writing %s", depfilePath) 64 } 65 } 66 depfile.Close() 67 */ 68 } 69 70 func msvcHelperMain(arg []string) int { 71 panic("TODO") 72 /* 73 outputFilename := nil 74 envfile := nil 75 76 longOptions := {{ "help", noArgument, nil, 'h' }, { nil, 0, nil, 0 }} 77 depsPrefix := "" 78 for opt := getoptLong(argc, argv, "e:o:p:h", longOptions, nil); opt != -1; { 79 switch opt { 80 case 'e': 81 envfile = optarg 82 break 83 case 'o': 84 outputFilename = optarg 85 break 86 case 'p': 87 depsPrefix = optarg 88 break 89 case 'h': 90 default: 91 msvcHelperUsage() 92 return 0 93 } 94 } 95 96 var env []byte 97 if envfile != nil { 98 env, err2 := ReadFile(envfile) 99 if err2 != nil { 100 Fatal("couldn't open %s: %s", envfile, err2) 101 } 102 pushPathIntoEnvironment(env) 103 } 104 105 command := GetCommandLineA() 106 command = strstr(command, " -- ") 107 if command == nil { 108 Fatal("expected command line to end with \" -- command args\"") 109 } 110 command += 4 111 112 cl := NewCLWrapper() 113 if len(env) != 0 { 114 cl.SetEnvBlock(env) 115 } 116 output := "" 117 exitCode := cl.Run(command, &output) 118 119 if outputFilename { 120 parser := nin.NewCLParser() 121 if err := parser.Parse(output, depsPrefix, &output); err != nil { 122 Fatal("%s\n", err) 123 } 124 writeDepFileOrDie(outputFilename, parser) 125 } 126 127 if len(output) == 0 { 128 return exitCode 129 } 130 131 // CLWrapper's output already as \r\n line endings, make sure the C runtime 132 // doesn't expand this to \r\r\n. 133 Setmode(Fileno(stdout), _O_BINARY) 134 // Avoid printf and C strings, since the actual output might contain null 135 // bytes like UTF-16 does (yuck). 136 os.Stdout.Write(output) 137 138 return exitCode 139 */ 140 }