/// <summary> /// Deletes all ouput files of a build result /// </summary> static void DeleteTargets(BuildResult r) { if (r == null) return; try { if (File.Exists(r.TargetFile)) File.Delete(r.TargetFile); if (r.AdditionalFiles != null) foreach (var f in r.AdditionalFiles) if (File.Exists(f)) File.Delete(f); } catch (Exception ex) { ErrorLogger.Log(ex); } }
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; }
public static BuildResult BuildSingle() { AbstractEditorDocument ed = ed = Instance.CurrentEditor; if (ed == null) return null; // Save module ed.Save(); // Select appropriate language binding string file = ed.AbsoluteFilePath; bool IsProject = false; var lang = AbstractLanguageBinding.SearchBinding(file, out IsProject); // Check if binding supports building if (lang == null || IsProject || !lang.CanBuild || !lang.BuildSupport.CanBuildFile(file)) return null; // Set debug support if (lang.CanUseDebugging) DebugManagement.CurrentDebugSupport = lang.DebugSupport; else DebugManagement.CurrentDebugSupport = null; // Enable build menu IsBuilding = true; IDEManager.Instance.MainWindow.RefreshMenu(); // Clear build output Instance.MainWindow.ClearLog(); // Execute build var br = LastSingleBuildResult = lang.BuildSupport.BuildStandAlone(file); if (br.Successful && br.NoBuildNeeded) ErrorLogger.Log("File wasn't changed -- No compilation required", ErrorType.Information, ErrorOrigin.Build); // Update error list, Disable build menu ErrorManagement.RefreshErrorList(); IsBuilding = false; IDEManager.Instance.MainWindow.RefreshMenu(); return br; }
protected virtual void OnBuildFinished(BuildResult res) { if (BuildFinished != null) BuildFinished(res); }
/// <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; }
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; }