(useLegacyBehavior: boolean, inputCompilerPath?: string, compilerArgs?: string[], cwd?: string)
| 1124 | * @param cwd - The directory used to resolve relative paths. |
| 1125 | */ |
| 1126 | export function extractCompilerPathAndArgs(useLegacyBehavior: boolean, inputCompilerPath?: string, compilerArgs?: string[], cwd?: string): CompilerPathAndArgs { |
| 1127 | let compilerPath: string | undefined = inputCompilerPath; |
| 1128 | let compilerName: string = ""; |
| 1129 | let compilerArgsFromCommandLineInPath: string[] = []; |
| 1130 | const trimLegacyQuotes = (compilerPath?: string): string | undefined => { |
| 1131 | if (compilerPath && useLegacyBehavior) { |
| 1132 | // Try to trim quotes from compiler path. |
| 1133 | const tempCompilerPath: string[] = extractArgs(compilerPath); |
| 1134 | if (tempCompilerPath.length > 0) { |
| 1135 | return tempCompilerPath[0]; |
| 1136 | } |
| 1137 | } |
| 1138 | return compilerPath; |
| 1139 | }; |
| 1140 | if (compilerPath) { |
| 1141 | compilerPath = compilerPath.trim(); |
| 1142 | if (isCl(compilerPath) || checkExecutableWithoutExtensionExistsSync(compilerPath)) { |
| 1143 | // If the path ends with cl, or if a file is found at that path, accept it without further validation. |
| 1144 | compilerName = path.basename(compilerPath); |
| 1145 | } else if (cwd && checkExecutableWithoutExtensionExistsSync(path.join(cwd, compilerPath))) { |
| 1146 | // If the path is relative and a file is found at that path, accept it without further validation. |
| 1147 | compilerPath = path.join(cwd, compilerPath); |
| 1148 | compilerName = path.basename(compilerPath); |
| 1149 | } else if (compilerPath.startsWith("\"") || (os.platform() !== 'win32' && compilerPath.startsWith("'"))) { |
| 1150 | // If the string starts with a quote, treat it as a command line. |
| 1151 | // Otherwise, a path with a leading quote would not be valid. |
| 1152 | compilerArgsFromCommandLineInPath = useLegacyBehavior ? legacyExtractArgs(compilerPath) : extractArgs(compilerPath); |
| 1153 | if (compilerArgsFromCommandLineInPath.length > 0) { |
| 1154 | compilerPath = trimLegacyQuotes(compilerArgsFromCommandLineInPath.shift()); |
| 1155 | compilerName = path.basename(compilerPath ?? ''); |
| 1156 | } |
| 1157 | } else { |
| 1158 | if (compilerPath.includes(' ')) { |
| 1159 | // There is no leading quote, but there is a space so we'll treat it as a command line. |
| 1160 | const potentialArgs: string[] = useLegacyBehavior ? legacyExtractArgs(compilerPath) : extractArgs(compilerPath); |
| 1161 | compilerPath = trimLegacyQuotes(potentialArgs.shift()); |
| 1162 | compilerArgsFromCommandLineInPath = potentialArgs; |
| 1163 | } |
| 1164 | compilerName = path.basename(compilerPath ?? ''); |
| 1165 | } |
| 1166 | } |
| 1167 | const allCompilerArgs: string[] = (compilerArgs ?? []).concat(compilerArgsFromCommandLineInPath); |
| 1168 | return { compilerPath, compilerName, compilerArgs, compilerArgsFromCommandLineInPath, allCompilerArgs }; |
| 1169 | } |
| 1170 | |
| 1171 | export function escapeForSquiggles(s: string): string { |
| 1172 | // Replace all \<escape character> with \\<character>, except for \" |
no test coverage detected