//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void AppendStringValue(CommandLineBuilder builder, BaseProperty property, string subtype, string value) { string switchName = property.SwitchPrefix; if (string.IsNullOrEmpty(property.SwitchPrefix)) { switchName = m_parsedBuildRule.SwitchPrefix; } switchName += property.Switch + property.Separator; if (subtype == "file" || subtype == "folder") { if (!string.IsNullOrWhiteSpace(switchName)) { builder.AppendSwitchIfNotNull(switchName, value); } else { builder.AppendTextUnquoted(" " + PathUtils.QuoteIfNeeded(value)); } } else if (!string.IsNullOrEmpty(property.Switch)) { builder.AppendSwitchUnquotedIfNotNull(switchName, value); } else if (!string.IsNullOrEmpty(value)) { builder.AppendTextUnquoted(" " + value); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// protected virtual int TrackedExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands) { // // Thread body. Generate required command line and launch tool. // int exitCode = -1; try { // // If response files arguments are used/supported, migrate shared flags to a file and strip them from the command line. // var commandLineSwitchesBuffer = new StringBuilder(commandLineCommands); var responseFileSwitchesBuffer = new StringBuilder(responseFileCommands); if (responseFileSwitchesBuffer.Length > 0) { commandLineSwitchesBuffer.Replace(responseFileSwitchesBuffer.ToString(), ""); } #if DEBUG Log.LogMessageFromText($"[{ToolName}] Tool: {pathToTool}", MessageImportance.High); Log.LogMessageFromText($"[{ToolName}] Command line: {commandLineSwitchesBuffer}", MessageImportance.High); Log.LogMessageFromText($"[{ToolName}] Response file commands: {responseFileSwitchesBuffer}", MessageImportance.High); #endif var trackerToolPath = FileTracker.GetTrackerPath(ExecutableType.Native64Bit); // @"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Tracker.exe"; var trackerCommandLineSwitches = FileTracker.TrackerCommandArguments(pathToTool, commandLineSwitchesBuffer.ToString()); if (!string.IsNullOrEmpty(trackerToolPath)) { var trackerRootingMarker = OutOfDateInputFiles.Length > 0 ? FileTracker.FormatRootingMarker(OutOfDateInputFiles) : null; var trackerResponseFileArguments = FileTracker.TrackerResponseFileArguments(FileTracker.GetFileTrackerPath(ExecutableType.Native64Bit), new TaskItemHelper(TrackerIntermediateDirectory).FullPath, trackerRootingMarker, null); var trackerResponseFile = Path.GetTempFileName(); File.WriteAllText(trackerResponseFile, trackerResponseFileArguments, ResponseFileEncoding); // /a : Enable extended tracking: GetFileAttributes, GetFileAttributesEx // /e : Enable extended tracking: GetFileAttributes, GetFileAttributesEx, RemoveDirectory, CreateDirectory // /k : Keep the full tool chain in tlog filenames. // /t : Track command lines (will expand response files specified with the '@filename' syntax) // (specifying /t will export *.command.*.tlog files) trackerCommandLineSwitches = $"{PathUtils.QuoteIfNeeded("@" + trackerResponseFile)} /k {trackerCommandLineSwitches}"; } #if DEBUG Log.LogMessageFromText($"[{ToolName}] Tracker tool: {trackerToolPath}", MessageImportance.High); Log.LogMessageFromText($"[{ToolName}] Tracker command line: {trackerCommandLineSwitches}", MessageImportance.High); #endif // // // responseFileSwitchesBuffer.Replace("\\", "\\\\"); responseFileSwitchesBuffer.Replace("\\\\\\\\ ", "\\\\ "); if (true) { exitCode = base.ExecuteTool(trackerToolPath, responseFileSwitchesBuffer.ToString(), trackerCommandLineSwitches); } #if false else { string responseFileSwitch = string.Empty; if (responseFileSwitchesBuffer.Length > 0) { string responseFilePath = Path.Combine(TrackerLogDirectory, string.Format("{0}_{1}.rsp", ToolName, Guid.NewGuid().ToString())); Directory.CreateDirectory(Path.GetDirectoryName(responseFilePath)); File.WriteAllText(responseFilePath, responseFileSwitchesBuffer.ToString(), ResponseFileEncoding); responseFileSwitch = GetResponseFileSwitch(responseFilePath); } using var trackedProcess = new Process(); trackedProcess.StartInfo = base.GetProcessStartInfo(trackerToolPath, trackerCommandLineSwitches, responseFileSwitch); trackedProcess.StartInfo.CreateNoWindow = true; trackedProcess.StartInfo.UseShellExecute = false; trackedProcess.StartInfo.ErrorDialog = false; trackedProcess.StartInfo.RedirectStandardOutput = true; trackedProcess.StartInfo.RedirectStandardError = true; trackedProcess.OutputDataReceived += (object sender, DataReceivedEventArgs args) => LogEventsFromTextOutput(args.Data, MessageImportance.Low); trackedProcess.ErrorDataReceived += (object sender, DataReceivedEventArgs args) => LogEventsFromTextOutput(args.Data, MessageImportance.Low); trackedProcess.EnableRaisingEvents = true; if (OutputCommandLine) { Log.LogMessageFromText(string.Format("[{0}] Process started: {1} {2}", ToolName, trackedProcess.StartInfo.FileName, trackedProcess.StartInfo.Arguments), MessageImportance.High); } if (!trackedProcess.Start()) { throw new InvalidOperationException("Could not start tracked child process."); } trackedProcess.BeginOutputReadLine(); trackedProcess.BeginErrorReadLine(); trackedProcess.WaitForExit(); exitCode = trackedProcess.ExitCode; } #endif } catch (Exception e) { Log.LogErrorFromException(e, true); exitCode = -1; } return(exitCode); }