public static Process LaunchWithoutDebugger(string exe, string args, bool ShowConsole) { StopExecution(); if (!File.Exists(exe)) { ErrorLogger.Log(exe + " not found", ErrorType.Error, ErrorOrigin.Program); return(null); } IDEManager.Instance.MainWindow.LeftStatusText = "Launch " + Path.GetFileName(exe) + " without debugger"; // Make all documents read-only WorkbenchLogic.Instance.AllDocumentsReadOnly = true; try { if (ShowConsole) { CurrentProcess = FileExecution.ExecuteAsync(exe, args, Path.GetDirectoryName(exe), CurrentProcess_Exited); } else { CurrentProcess = FileExecution.ExecuteSilentlyAsync(exe, args, Path.GetDirectoryName(exe), CurrentProcess_OutputDataReceived, CurrentProcess_ErrorDataReceived, CurrentProcess_Exited); } } catch (Exception ex) { ErrorLogger.Log(ex, ErrorType.Error, ErrorOrigin.Program); } Instance.UpdateGUI(); return(CurrentProcess); }
public BuildResult CompileSource(SourceModule Module, DMDConfig dmd, bool DebugCompile, string objFile, string execDirectory) { var obj = Path.ChangeExtension(objFile, ".obj"); var br = new BuildResult() { SourceFile = Module.AbsoluteFileName, TargetFile = obj, Successful = true }; ErrorLogger.Log("Compile " + (Module.Project != null?Module.Project.ToRelativeFileName(Module.FileName):Module.FileName), ErrorType.Information, ErrorOrigin.Build); var dmd_exe = dmd.SoureCompiler; // Always enable it to use environment paths to find dmd.exe if (!Path.IsPathRooted(dmd_exe) && Directory.Exists(dmd.BaseDirectory)) { dmd_exe = Path.Combine(dmd.BaseDirectory, dmd.SoureCompiler); } TempPrc = FileExecution.ExecuteSilentlyAsync(dmd_exe, BuildDSourceCompileArgumentString(dmd.BuildArguments(DebugCompile).SoureCompiler, Module.AbsoluteFileName, obj, dmd.ImportDirectories), // Compile our program always in debug mode execDirectory, OnOutput, delegate(string s) { var err = ParseErrorMessage(s); if (Module.Project != null && Module.Project.ContainsFile(err.FileName)) { err.Project = Module.Project; } if (err.Type == GenericError.ErrorType.Error) { br.Successful = false; } br.BuildErrors.Add(err); }, OnExit); if (TempPrc != null && !TempPrc.HasExited) { TempPrc.WaitForExit(MaxCompilationTime); } br.Successful = br.Successful && TempPrc != null && TempPrc.ExitCode == 0 && File.Exists(obj); return(br); }
public override void BuildModule(SourceModule Module, string OutputDirectory, string ExecDirectory, bool DebugCompile, bool LinkToStandAlone) { var src = Module.AbsoluteFileName; var outputDir = Path.IsPathRooted(OutputDirectory) ? OutputDirectory : Path.Combine(Path.GetDirectoryName(src), OutputDirectory); // Ensure that target directory exists Util.CreateDirectoryRecursively(outputDir); // Compile .rc source file to res var res = Path.Combine(outputDir, Path.GetFileNameWithoutExtension(src) + ".res"); // Check if creation can be skipped if (GlobalProperties.Instance.EnableIncrementalBuild && !Module.Modified && File.Exists(res)) { Module.LastBuildResult = new BuildResult() { SourceFile = src, TargetFile = res, Successful = true, NoBuildNeeded = true }; return; } // Init returned BuildResult-object var br = new BuildResult() { SourceFile = src, TargetFile = res, Successful = true }; // Print verbose information message ErrorLogger.Log("Compile " + (Module.Project != null ? Module.Project.ToRelativeFileName(Module.FileName) : Module.FileName), ErrorType.Information, ErrorOrigin.Build); var resourceCompiler = ResConfig.Instance.ResourceCompilerPath; // Prefer the resource compiler located in D-IDE's bin root // Otherwise let the system search along the %PATH% environment variable to find the resource compiler if (!Path.IsPathRooted(resourceCompiler) && File.Exists(Path.Combine(Util.ApplicationStartUpPath, resourceCompiler))) { resourceCompiler = Path.Combine(Util.ApplicationStartUpPath, resourceCompiler); } TempPrc = FileExecution.ExecuteSilentlyAsync(resourceCompiler, BuildResArgumentString( ResConfig.Instance.ResourceCompilerArguments, src, res, outputDir), ExecDirectory, // Output handling delegate(string s) { var err = ParseErrorMessage(s); if (Module.Project != null && Module.Project.ContainsFile(err.FileName)) { err.Project = Module.Project; } br.BuildErrors.Add(err); br.Successful = false; if (!GlobalProperties.Instance.VerboseBuildOutput) { ErrorLogger.Log(s, ErrorType.Message, ErrorOrigin.Build); } }, // Error handling delegate(string s) { br.Successful = false; ErrorLogger.Log(s, ErrorType.Error, ErrorOrigin.Build); }, OnExit); if (TempPrc != null && !TempPrc.HasExited) { TempPrc.WaitForExit(MaxCompilationTime); } br.Successful = br.Successful && TempPrc != null && TempPrc.ExitCode == 0 && File.Exists(res); if (br.Successful) { Module.ResetModifiedTime(); } Module.LastBuildResult = br; }
/// <summary> /// Calls the cv2pdb program /// </summary> public BuildResult CreatePDBFromExe(string Executable) { var pdb = Path.ChangeExtension(Executable, ".pdb"); var br = new BuildResult() { SourceFile = Executable, TargetFile = pdb }; if (!File.Exists(Executable)) { br.BuildErrors.Add(new GenericError() { Message = "Debug information database creation failed - " + Executable + " does not exist" }); return(br); } if (File.Exists(pdb)) { File.Delete(pdb); // Enforce recreation of the database } string cv2pdb = DSettings.Instance.cv2pdb_exe; // By default, check if there's a cv2pdb.exe at the program's main directory if (!Path.IsPathRooted(cv2pdb) && File.Exists(Util.ApplicationStartUpPath + "\\" + cv2pdb)) { cv2pdb = Util.ApplicationStartUpPath + "\\" + cv2pdb; } ErrorLogger.Log("Create debug information database " + Path.GetFileName(pdb), ErrorType.Information, ErrorOrigin.Build); try { var prc = FileExecution.ExecuteSilentlyAsync(cv2pdb, "\"" + Executable + "\"", Path.GetDirectoryName(Executable), OnOutput, delegate(string s){ br.BuildErrors.Add(new GenericError() { Message = s }); }, delegate() { if (File.Exists(pdb)) { if (GlobalProperties.Instance.VerboseBuildOutput) { ErrorLogger.Log("Debug information database created successfully", ErrorType.Information, ErrorOrigin.Build); } br.Successful = true; } else { br.BuildErrors.Add(new GenericError() { Message = "Debug information database creation failed", Type = GenericError.ErrorType.Warning }); } }); if (prc != null && !prc.HasExited) { prc.WaitForExit(10000); // A time out of 10 seconds should be enough } } catch (Exception ex) { ErrorLogger.Log(ex); } return(br); }
/// <summary> /// Links several object files to an executable, dynamic or static library /// </summary> public BuildResult LinkFiles(DMDConfig dmd, string linkerExe, string linkerArgs, string startDirectory, string targetFile, bool CreatePDB, params string[] files) { var errList = new List <GenericError>(); var br = new BuildResult() { TargetFile = targetFile, Successful = true }; ErrorLogger.Log("Link files to " + Path.GetFileName(targetFile), ErrorType.Information, ErrorOrigin.Build); if (File.Exists(targetFile)) { try { File.Delete(targetFile); } catch (Exception ex) // Perhaps our targetFile is still in use { br.BuildErrors.Add(new GenericError() { Message = ex.Message }); return(br); } } // Ensure that target directory exists var tarDir = Path.GetDirectoryName(targetFile); try { Util.CreateDirectoryRecursively(tarDir); } catch (Exception ex) { ErrorLogger.Log(ex, ErrorType.Error, ErrorOrigin.Build); br.Successful = false; return(br); } // Always enable it to use environment paths to find dmd.exe if (!Path.IsPathRooted(linkerExe) && Directory.Exists(dmd.BaseDirectory)) { linkerExe = Path.Combine(dmd.BaseDirectory, linkerExe); } //CRITICAL: Execute linker exe TempPrc = FileExecution.ExecuteSilentlyAsync( linkerExe, BuildDLinkerArgumentString(linkerArgs, startDirectory, targetFile, dmd.ImportDirectories, files), startDirectory, OnOutput, delegate(string s) { var err = ParseErrorMessage(s); if (err.Type == GenericError.ErrorType.Error) { br.Successful = false; } br.BuildErrors.Add(err); }, OnExit); if (TempPrc != null && !TempPrc.HasExited) { TempPrc.WaitForExit(MaxCompilationTime); } br.Successful = br.Successful && TempPrc.ExitCode == 0 && File.Exists(targetFile); // If targetFile is executable or dynamic linked library, create PDB if (br.Successful && CreatePDB && (targetFile.EndsWith(".exe") || targetFile.EndsWith(".dll"))) { var br_ = CreatePDBFromExe(targetFile); br.BuildErrors.AddRange(br_.BuildErrors); br.AdditionalFiles = new[] { br_.TargetFile }; } return(br); }