/// <summary> /// Cleans up intermediate files /// </summary> /// <param name="projectFiles"> /// The project's files /// <see cref="ProjectFileCollection"/> /// </param> /// <param name="configuration"> /// Project configuration /// <see cref="ValaProjectConfiguration"/> /// </param> /// <param name="monitor"> /// The progress monitor to be used /// <see cref="IProgressMonitor"/> /// </param> public void Clean(ProjectFileCollection projectFiles, ValaProjectConfiguration configuration, IProgressMonitor monitor) { /// Clean up intermediate files /// These should only be generated for libraries, but we'll check for them in all cases foreach (ProjectFile file in projectFiles) { if (file.BuildAction == BuildAction.Compile) { string cFile = Path.Combine(configuration.OutputDirectory, Path.GetFileNameWithoutExtension(file.Name) + ".c"); if (File.Exists(cFile)) { File.Delete(cFile); } string hFile = Path.Combine(configuration.OutputDirectory, Path.GetFileNameWithoutExtension(file.Name) + ".h"); if (File.Exists(hFile)) { File.Delete(hFile); } } } string vapiFile = Path.Combine(configuration.OutputDirectory, configuration.Output + ".vapi"); if (File.Exists(vapiFile)) { File.Delete(vapiFile); } }
/// <summary> /// Gets the files that get compiled into object code. /// </summary> /// <param name="projectFiles"> /// A <see cref="ProjectFileCollection"/> /// The project's files, extracts from here the files that get compiled into object code. /// </param> /// <param name="configuration"> /// A <see cref="CProjectConfiguration"/> /// The configuration to get the object files for... /// </param> /// <param name="withQuotes"> /// A <see cref="System.Boolean"/> /// If true, it will surround each object file with quotes /// so that gcc has no problem with paths that contain spaces. /// </param> /// <returns> /// An array of strings, each string is the name of a file /// that will get compiled into object code. The file name /// will already have the .o extension. /// </returns> private string[] ObjectFiles(ProjectFileCollection projectFiles, CProjectConfiguration configuration, bool withQuotes) { if (projectFiles.Count == 0) { return new string[] {} } ; List <string> objectFiles = new List <string> (); foreach (ProjectFile f in projectFiles) { if (f.BuildAction == BuildAction.Compile) { string PathName = Path.Combine(configuration.OutputDirectory, Path.GetFileNameWithoutExtension(f.Name) + ".o"); if (File.Exists(PathName) == false) { continue; } if (!withQuotes) { objectFiles.Add(PathName); } else { objectFiles.Add("\"" + PathName + "\""); } } } return(objectFiles.ToArray()); }
private void MakeStaticLibrary(Project project, ProjectFileCollection projectFiles, CProjectConfiguration configuration, ProjectPackageCollection packages, CompilerResults cr, ProgressMonitor monitor, string outputName) { if (!NeedsUpdate(projectFiles, configuration, outputName)) { return; } string objectFiles = string.Join(" ", ObjectFiles(projectFiles, configuration, true)); string args = string.Format("rcs \"{0}\" {1}", outputName, objectFiles); monitor.BeginTask(GettextCatalog.GetString("Generating static library {0} from object files", Path.GetFileName(outputName)), 1); string errorOutput; int exitCode = ExecuteCommand("ar", args, Path.GetDirectoryName(outputName), monitor, out errorOutput); if (exitCode == 0) { monitor.Step(1); } monitor.EndTask(); ParseCompilerOutput(errorOutput, cr); ParseLinkerOutput(errorOutput, cr); CheckReturnCode(exitCode, cr); }
void GetFolderContent (Project project, string folder, out ProjectFileCollection files, out ArrayList folders) { files = new ProjectFileCollection (); folders = new ArrayList (); string folderPrefix = folder + Path.DirectorySeparatorChar; foreach (ProjectFile file in project.Files) { string dir; if (file.Subtype != Subtype.Directory) { if (file.DependsOnFile != null) continue; dir = file.IsLink ? project.BaseDirectory.Combine (file.ProjectVirtualPath).ParentDirectory : file.FilePath.ParentDirectory; if (dir == folder) { files.Add (file); continue; } } else dir = file.Name; // add the directory if it isn't already present if (dir.StartsWith (folderPrefix)) { int i = dir.IndexOf (Path.DirectorySeparatorChar, folderPrefix.Length); if (i != -1) dir = dir.Substring (0,i); if (!folders.Contains (dir)) folders.Add (dir); } } }
public FakeDotNetProject(string fileName) : base(fileName) { References = new ProjectReferenceCollection(); Files = new ProjectFileCollection(); CreateEqualsAction(); }
public FakeDotNetProject() { References = new ProjectReferenceCollection(); Files = new ProjectFileCollection(); TargetFrameworkMoniker = new TargetFrameworkMoniker("v4.5"); CreateEqualsAction(); }
public Project () { FileService.FileChanged += OnFileChanged; files = new ProjectFileCollection (); Items.Bind (files); DependencyResolutionEnabled = true; }
public FakeDotNetProject () { References = new ProjectReferenceCollection (); Files = new ProjectFileCollection (); TargetFrameworkMoniker = new TargetFrameworkMoniker ("v4.5"); CreateEqualsAction (); }
private void PrecompileHeaders(ProjectFileCollection projectFiles, CProjectConfiguration configuration, string args) { foreach (ProjectFile file in projectFiles) { if (file.Subtype == Subtype.Code && CProject.IsHeaderFile(file.Name)) { string precomp = Path.Combine(configuration.SourceDirectory, ".prec"); precomp = Path.Combine(precomp, configuration.Name); precomp = Path.Combine(precomp, Path.GetFileName(file.Name) + ".ghc"); if (!File.Exists(precomp)) { DoPrecompileHeader(file, precomp, args); continue; } if (configuration.UseCcache || File.GetLastWriteTime(file.Name) > File.GetLastWriteTime(precomp)) { DoPrecompileHeader(file, precomp, args); } } } }
public FakeDotNetProject (string fileName) : base (fileName) { References = new ProjectReferenceCollection (); Files = new ProjectFileCollection (); CreateEqualsAction (); }
public override ICompilerResult Compile ( ProjectFileCollection projectFiles, ProjectPackageCollection packages, CProjectConfiguration configuration, IProgressMonitor monitor) { CompilerResults cr = new CompilerResults (new TempFileCollection ()); bool res = true; string args = GetCompilerFlags (configuration); string outputName = Path.Combine (configuration.OutputDirectory, configuration.CompiledOutputName); // Precompile header files and place them in .prec/<config_name>/ string precdir = Path.Combine (configuration.SourceDirectory, ".prec"); if (!Directory.Exists (precdir)) Directory.CreateDirectory (precdir); precdir = Path.Combine (precdir, configuration.Name); if (!Directory.Exists (precdir)) Directory.CreateDirectory (precdir); PrecompileHeaders (projectFiles, configuration, args); foreach (ProjectFile f in projectFiles) { if (f.Subtype == Subtype.Directory) continue; if (f.BuildAction == BuildAction.Compile) { if (configuration.UseCcache || NeedsCompiling (f)) res = DoCompilation (f, args, packages, monitor, cr, configuration.UseCcache); } else res = true; if (!res) break; } if (res) { switch (configuration.CompileTarget) { case CBinding.CompileTarget.Bin: MakeBin ( projectFiles, packages, configuration, cr, monitor, outputName); break; case CBinding.CompileTarget.StaticLibrary: MakeStaticLibrary ( projectFiles, monitor, outputName); break; case CBinding.CompileTarget.SharedLibrary: MakeSharedLibrary ( projectFiles, packages, configuration, cr, monitor, outputName); break; } } return new DefaultCompilerResult (cr, ""); }
void GetFolderContent(Project project, string folder, out ProjectFileCollection files, out List <string> folders) { string folderPrefix = folder + Path.DirectorySeparatorChar; files = new ProjectFileCollection(); folders = new List <string> (); foreach (ProjectFile file in project.Files) { string dir; if (!file.Visible || file.Flags.HasFlag(ProjectItemFlags.Hidden)) { continue; } if (file.Subtype != Subtype.Directory) { if (file.DependsOnFile != null) { continue; } dir = file.IsLink ? project.BaseDirectory.Combine(file.ProjectVirtualPath).ParentDirectory : file.FilePath.ParentDirectory; if (dir == folder) { files.Add(file); continue; } } else { dir = file.Name; } // add the directory if it isn't already present if (dir.StartsWith(folderPrefix, StringComparison.Ordinal)) { int i = dir.IndexOf(Path.DirectorySeparatorChar, folderPrefix.Length); if (i != -1) { dir = dir.Substring(0, i); } if (!folders.Contains(dir)) { folders.Add(dir); } } } }
private string[] ObjectFiles(ProjectFileCollection projectFiles) { List <string> objectFiles = new List <string> (); foreach (ProjectFile f in projectFiles) { if (f.BuildAction == BuildAction.Compile) { objectFiles.Add(Path.ChangeExtension(f.Name, ".o")); } } return(objectFiles.ToArray()); }
private bool NeedsUpdate(ProjectFileCollection projectFiles, CProjectConfiguration configuration, string target) { if (!File.Exists(target)) { return(true); } foreach (string obj in ObjectFiles(projectFiles, configuration, false)) { if (File.GetLastWriteTime(obj) > File.GetLastWriteTime(target)) { return(true); } } return(false); }
/// <summary> /// Parses a compiler output string into CompilerResults /// </summary> /// <param name="errorString"> /// The string output by the compiler /// <see cref="System.String"/> /// </param> /// <param name="cr"> /// The CompilerResults into which to parse errorString /// <see cref="CompilerResults"/> /// </param> protected void ParseCompilerOutput(string errorString, CompilerResults cr, ProjectFileCollection projectFiles) { TextReader reader = new StringReader(errorString); string next; while ((next = reader.ReadLine()) != null) { CompilerError error = CreateErrorFromErrorString(next, projectFiles); // System.Console.WriteLine ("Creating error from string \"{0}\"", next); if (error != null) { cr.Errors.Insert(0, error); // System.Console.WriteLine ("Adding error"); } } reader.Close(); }
/// <summary> /// Compile the project /// </summary> /// <param name="projectFiles"> /// Collection of project files /// <see cref="ProjectFileCollection"/> /// </param> /// <param name="packages"> /// Collection of depended packages /// <see cref="ProjectPackageCollection"/> /// </param> /// <param name="configuration"> /// Project configuration /// <see cref="ValaProjectConfiguration"/> /// </param> /// <param name="monitor"> /// Progress monitor to be used /// <see cref="IProgressMonitor"/> /// </param> /// <returns> /// Result of the compilation /// <see cref="ICompilerResult"/> /// </returns> public BuildResult Compile( ProjectFileCollection projectFiles, ProjectPackageCollection packages, ValaProjectConfiguration configuration, IProgressMonitor monitor) { if (!appsChecked) { appsChecked = true; compilerFound = CheckApp(compilerCommand); } /// Check for compiler if (!compilerFound) { BuildResult cres = new BuildResult(); cres.AddError("Compiler not found: " + compilerCommand); return(cres); } /// No compiler! CompilerResults cr = new CompilerResults(new TempFileCollection()); bool success = true; /// Build compiler params string string compilerArgs = GetCompilerFlags(configuration) + " " + GeneratePkgCompilerArgs(packages); /// Build executable name string outputName = Path.Combine(configuration.OutputDirectory, configuration.CompiledOutputName); monitor.BeginTask(GettextCatalog.GetString("Compiling source"), 1); success = DoCompilation(projectFiles, compilerArgs, outputName, monitor, cr); GenerateDepfile(configuration, packages); if (success) { monitor.Step(1); } monitor.EndTask(); return(new BuildResult(cr, "")); }
private bool PrecompileHeaders(ProjectFileCollection projectFiles, CProjectConfiguration configuration, string args, ProgressMonitor monitor, CompilerResults cr) { monitor.BeginTask(GettextCatalog.GetString("Precompiling headers"), 1); bool success = true; foreach (ProjectFile file in projectFiles) { if (file.Subtype == Subtype.Code && CProject.IsHeaderFile(file.Name)) { string precomp = Path.Combine(configuration.IntermediateOutputDirectory, "prec"); precomp = Path.Combine(precomp, configuration.Id); precomp = Path.Combine(precomp, Path.GetFileName(file.Name) + ".ghc"); if (file.BuildAction == BuildAction.Compile) { if (!File.Exists(precomp) || configuration.UseCcache || File.GetLastWriteTime(file.Name) > File.GetLastWriteTime(precomp)) { if (DoPrecompileHeader(file, precomp, args, monitor, cr) == false) { success = false; break; } } } else { //remove old files or they'll interfere with the build if (File.Exists(precomp)) { File.Delete(precomp); } } } } if (success) { monitor.Step(1); } monitor.EndTask(); return(success); }
public BuildResult Compile(ProjectFileCollection projectFiles, ProjectReferenceCollection projectReferences, DotNetProjectConfiguration configuration, IProgressMonitor monitor) { NemerleParameters cp = (NemerleParameters)configuration.CompilationParameters; if (cp == null) { cp = new NemerleParameters(); } string references = ""; string files = ""; foreach (ProjectReference lib in projectReferences) { foreach (string a in lib.GetReferencedFileNames()) { references += " -r \"" + a + "\""; } } foreach (ProjectFile f in projectFiles) { if (f.Subtype != Subtype.Directory) { switch (f.BuildAction) { case BuildAction.Compile: files += " \"" + f.Name + "\""; break; } } } if (!Directory.Exists(configuration.OutputDirectory)) { Directory.CreateDirectory(configuration.OutputDirectory); } string args = "-q -no-color " + GetOptionsString(configuration, cp) + references + files + " -o " + configuration.CompiledOutputName; return(DoCompilation(args)); }
private void MakeStaticLibrary(ProjectFileCollection projectFiles, IProgressMonitor monitor, string outputName) { if (!NeedsUpdate(projectFiles, outputName)) { return; } string objectFiles = StringArrayToSingleString(ObjectFiles(projectFiles)); monitor.Log.WriteLine("Generating static library..."); monitor.Log.WriteLine("using: ar rcs " + outputName + " " + objectFiles); Process p = Runtime.ProcessService.StartProcess( "ar", "rcs " + outputName + " " + objectFiles, null, null); p.WaitForExit(); p.Close(); }
public override void Clean(ProjectFileCollection projectFiles, CProjectConfiguration configuration, ProgressMonitor monitor) { //clean up object files foreach (string oFile in ObjectFiles(projectFiles, configuration, false)) { if (File.Exists(oFile)) { File.Delete(oFile); } string dFile = Path.ChangeExtension(oFile, ".d"); if (File.Exists(dFile)) { File.Delete(dFile); } } CleanPrecompiledHeaders(configuration); }
/// <summary> /// Creates a compiler error from an output string /// </summary> /// <param name="errorString"> /// The error string to be parsed /// <see cref="System.String"/> /// </param> /// <returns> /// A newly created CompilerError /// <see cref="CompilerError"/> /// </returns> private CompilerError CreateErrorFromErrorString(string errorString, ProjectFileCollection projectFiles) { Match errorMatch = null; foreach (Regex regex in new Regex[] { errorRegex, gccRegex }) { if ((errorMatch = regex.Match(errorString)).Success) { break; } } if (!errorMatch.Success) { return(null); } CompilerError error = new CompilerError(); foreach (ProjectFile pf in projectFiles) { if (Path.GetFileName(pf.Name) == errorMatch.Groups["file"].Value) { error.FileName = pf.FilePath; break; } } // check for fully pathed file if (string.Empty == error.FileName) { error.FileName = errorMatch.Groups["file"].Value; } // fallback to exact match error.Line = int.Parse(errorMatch.Groups["line"].Value); if (errorMatch.Groups["column"].Success) { error.Column = int.Parse(errorMatch.Groups["column"].Value); } error.IsWarning = !errorMatch.Groups["level"].Value.Equals(GettextCatalog.GetString("error"), StringComparison.Ordinal); error.ErrorText = errorMatch.Groups["message"].Value; return(error); }
/// <summary> /// Compiles the project /// </summary> private bool DoCompilation(ProjectFileCollection projectFiles, string args, string outputName, IProgressMonitor monitor, CompilerResults cr) { StringBuilder filelist = new StringBuilder(); foreach (ProjectFile f in projectFiles) { if (f.Subtype != Subtype.Directory && f.BuildAction == BuildAction.Compile) { filelist.AppendFormat("\"{0}\" ", f.FilePath); } } /// Build file list string compiler_args = string.Format("{0} {1} -o \"{2}\"", args, filelist.ToString(), Path.GetFileName(outputName)); string errorOutput = string.Empty; int exitCode = ExecuteCommand(compilerCommand, compiler_args, Path.GetDirectoryName(outputName), monitor, out errorOutput); ParseCompilerOutput(errorOutput, cr, projectFiles); return(exitCode == 0); }
/// <summary> /// Cleans up intermediate files /// </summary> /// <param name="projectFiles"> /// The project's files /// <see cref="ProjectFileCollection"/> /// </param> /// <param name="configuration"> /// Project configuration /// <see cref="ValaProjectConfiguration"/> /// </param> /// <param name="monitor"> /// The progress monitor to be used /// <see cref="IProgressMonitor"/> /// </param> public void Clean (ProjectFileCollection projectFiles, ValaProjectConfiguration configuration, IProgressMonitor monitor) { /// Clean up intermediate files /// These should only be generated for libraries, but we'll check for them in all cases foreach (ProjectFile file in projectFiles) { if (file.BuildAction == BuildAction.Compile) { string cFile = Path.Combine (configuration.OutputDirectory, Path.GetFileNameWithoutExtension (file.Name) + ".c"); if (File.Exists (cFile)){ File.Delete (cFile); } string hFile = Path.Combine (configuration.OutputDirectory, Path.GetFileNameWithoutExtension (file.Name) + ".h"); if (File.Exists (hFile)){ File.Delete (hFile); } } } string vapiFile = Path.Combine (configuration.OutputDirectory, configuration.Output + ".vapi"); if (File.Exists (vapiFile)){ File.Delete (vapiFile); } }
public abstract BuildResult Compile ( Project project, ProjectFileCollection projectFiles, ProjectPackageCollection packages, CProjectConfiguration configuration, IProgressMonitor monitor);
private bool NeedsUpdate (ProjectFileCollection projectFiles, CProjectConfiguration configuration, string target) { if (!File.Exists (target)) return true; foreach (string obj in ObjectFiles (projectFiles, configuration, false)) if (File.GetLastWriteTime (obj) > File.GetLastWriteTime (target)) return true; return false; }
/// <summary> /// Gets the files that get compiled into object code. /// </summary> /// <param name="projectFiles"> /// A <see cref="ProjectFileCollection"/> /// The project's files, extracts from here the files that get compiled into object code. /// </param> /// <param name="configuration"> /// A <see cref="CProjectConfiguration"/> /// The configuration to get the object files for... /// </param> /// <param name="withQuotes"> /// A <see cref="System.Boolean"/> /// If true, it will surround each object file with quotes /// so that gcc has no problem with paths that contain spaces. /// </param> /// <returns> /// An array of strings, each string is the name of a file /// that will get compiled into object code. The file name /// will already have the .o extension. /// </returns> private string[] ObjectFiles (ProjectFileCollection projectFiles, CProjectConfiguration configuration, bool withQuotes) { if(projectFiles.Count == 0) return new string[] {}; List<string> objectFiles = new List<string> (); foreach (ProjectFile f in projectFiles) { if (f.BuildAction == BuildAction.Compile) { string PathName = Path.Combine(configuration.OutputDirectory, Path.GetFileNameWithoutExtension(f.Name) + ".o"); if(File.Exists(PathName) == false) continue; if (!withQuotes) objectFiles.Add (PathName); else objectFiles.Add ("\"" + PathName + "\""); } } return objectFiles.ToArray (); }
private void MakeSharedLibrary(Project project, ProjectFileCollection projectFiles, CProjectConfiguration configuration, ProjectPackageCollection packages, CompilerResults cr, IProgressMonitor monitor, string outputName) { if (!NeedsUpdate (projectFiles, configuration, outputName)) return; string objectFiles = string.Join (" ", ObjectFiles (projectFiles, configuration, true)); string pkgargs = GeneratePkgLinkerArgs (packages); StringBuilder args = new StringBuilder (); if (configuration.ExtraLinkerArguments != null && configuration.ExtraLinkerArguments.Length > 0) { string extraLinkerArgs = ExpandBacktickedParameters(configuration.ExtraLinkerArguments.Replace ('\n', ' ')); args.Append (extraLinkerArgs + " "); } if (configuration.LibPaths != null) foreach (string libpath in configuration.LibPaths) args.Append ("-L\"" + StringParserService.Parse (libpath, GetStringTags (project)) + "\" "); if (configuration.Libs != null) { foreach (string lib in configuration.Libs) { string directory = Path.GetDirectoryName(lib); string library = Path.GetFileName(lib); // Is this a 'standard' (as in, uses an orthodox naming convention) library..? string link_lib = String.Empty; if(IsStandardLibrary(configuration, directory, library, ref link_lib)) args.Append ("-l\"" + link_lib + "\" "); // If not, reference the library by it's full pathname. else args.Append ("\"" + lib + "\" "); } } string linker_args = string.Format ("-shared -o \"{0}\" {1} {2} {3}", outputName, pkgargs, objectFiles, args.ToString ()); monitor.BeginTask (GettextCatalog.GetString ("Generating shared object \"{0}\" from object files", Path.GetFileName (outputName)), 1); string errorOutput; int exitCode = ExecuteCommand (linkerCommand , linker_args, Path.GetDirectoryName (outputName), monitor, out errorOutput); if (exitCode == 0) monitor.Step (1); monitor.EndTask (); ParseCompilerOutput (errorOutput, cr); ParseLinkerOutput (errorOutput, cr); CheckReturnCode (exitCode, cr); }
private bool PrecompileHeaders (ProjectFileCollection projectFiles, CProjectConfiguration configuration, string args, IProgressMonitor monitor, CompilerResults cr) { monitor.BeginTask (GettextCatalog.GetString ("Precompiling headers"), 1); bool success = true; foreach (ProjectFile file in projectFiles) { if (file.Subtype == Subtype.Code && CProject.IsHeaderFile (file.Name)) { string precomp = Path.Combine (configuration.SourceDirectory, ".prec"); precomp = Path.Combine (precomp, configuration.Id); precomp = Path.Combine (precomp, Path.GetFileName (file.Name) + ".ghc"); if (file.BuildAction == BuildAction.Compile) { if (!File.Exists (precomp) || configuration.UseCcache || File.GetLastWriteTime (file.Name) > File.GetLastWriteTime (precomp)) { if (DoPrecompileHeader (file, precomp, args, monitor, cr) == false) { success = false; break; } } } else { //remove old files or they'll interfere with the build if (File.Exists (precomp)) File.Delete (precomp); } } } if (success) monitor.Step (1); monitor.EndTask (); return success; }
/// <summary> /// Parses a compiler output string into CompilerResults /// </summary> /// <param name="errorString"> /// The string output by the compiler /// <see cref="System.String"/> /// </param> /// <param name="cr"> /// The CompilerResults into which to parse errorString /// <see cref="CompilerResults"/> /// </param> protected void ParseCompilerOutput (string errorString, CompilerResults cr, ProjectFileCollection projectFiles) { TextReader reader = new StringReader (errorString); string next; while ((next = reader.ReadLine ()) != null) { CompilerError error = CreateErrorFromErrorString (next, projectFiles); // System.Console.WriteLine ("Creating error from string \"{0}\"", next); if (error != null) { cr.Errors.Insert (0, error); // System.Console.WriteLine ("Adding error"); } } reader.Close (); }
public BuildResult Compile (ProjectFileCollection projectFiles, ProjectReferenceCollection references, DotNetProjectConfiguration configuration, IProgressMonitor monitor) { return compilerServices.Compile (projectFiles, references, configuration, monitor); }
/// <summary> /// Compile the project /// </summary> /// <param name="projectFiles"> /// Collection of project files /// <see cref="ProjectFileCollection"/> /// </param> /// <param name="packages"> /// Collection of depended packages /// <see cref="ProjectPackageCollection"/> /// </param> /// <param name="configuration"> /// Project configuration /// <see cref="ValaProjectConfiguration"/> /// </param> /// <param name="monitor"> /// Progress monitor to be used /// <see cref="IProgressMonitor"/> /// </param> /// <returns> /// Result of the compilation /// <see cref="ICompilerResult"/> /// </returns> public BuildResult Compile ( ProjectFileCollection projectFiles, ProjectPackageCollection packages, ValaProjectConfiguration configuration, IProgressMonitor monitor) { if (!appsChecked) { appsChecked = true; compilerFound = CheckApp (compilerCommand); }/// Check for compiler if (!compilerFound) { BuildResult cres = new BuildResult (); cres.AddError ("Compiler not found: " + compilerCommand); return cres; }/// No compiler! CompilerResults cr = new CompilerResults (new TempFileCollection ()); bool success = true; /// Build compiler params string string compilerArgs = GetCompilerFlags (configuration) + " " + GeneratePkgCompilerArgs (packages); /// Build executable name string outputName = Path.Combine (configuration.OutputDirectory, configuration.CompiledOutputName); monitor.BeginTask (GettextCatalog.GetString ("Compiling source"), 1); success = DoCompilation (projectFiles, compilerArgs, outputName, monitor, cr); GenerateDepfile (configuration, packages); if (success) monitor.Step (1); monitor.EndTask (); return new BuildResult (cr, ""); }
public abstract BuildResult Compile( Project project, ProjectFileCollection projectFiles, ProjectPackageCollection packages, CProjectConfiguration configuration, IProgressMonitor monitor);
/// <summary> /// Determines whether the target needs to be updated /// </summary> /// <param name="projectFiles"> /// The project's files /// <see cref="ProjectFileCollection"/> /// </param> /// <param name="target"> /// The target /// <see cref="System.String"/> /// </param> /// <returns> /// true if target needs to be updated /// <see cref="System.Boolean"/> /// </returns> private bool NeedsUpdate(ProjectFileCollection projectFiles, string target) { return(true); }
private void MakeSharedLibrary(ProjectFileCollection projectFiles, ProjectPackageCollection packages, CProjectConfiguration configuration, CompilerResults cr, IProgressMonitor monitor, string outputName) { if (!NeedsUpdate (projectFiles, outputName)) return; string objectFiles = StringArrayToSingleString (ObjectFiles (projectFiles)); string pkgargs = GeneratePkgLinkerArgs (packages); StringBuilder args = new StringBuilder (); CCompilationParameters cp = (CCompilationParameters)configuration.CompilationParameters; if (cp.ExtraLinkerArguments != null && cp.ExtraLinkerArguments.Length > 0) { string extraLinkerArgs = cp.ExtraLinkerArguments.Replace ('\n', ' '); args.Append (extraLinkerArgs + " "); } if (configuration.LibPaths != null) foreach (string libpath in configuration.LibPaths) args.Append ("-L" + libpath + " "); if (configuration.Libs != null) foreach (string lib in configuration.Libs) args.Append ("-l" + lib + " "); monitor.Log.WriteLine ("Generating shared object..."); string linker_args = string.Format ("-shared -o {0} {1} {2} {3}", outputName, objectFiles, args.ToString (), pkgargs); monitor.Log.WriteLine ("using: " + linkerCommand + " " + linker_args); ProcessWrapper p = Runtime.ProcessService.StartProcess (linkerCommand, linker_args, null, null); p.WaitForExit (); string line; StringWriter error = new StringWriter (); while ((line = p.StandardError.ReadLine ()) != null) error.WriteLine (line); monitor.Log.WriteLine (error.ToString ()); ParseCompilerOutput (error.ToString (), cr); error.Close (); p.Close (); ParseLinkerOutput (error.ToString (), cr); }
private string[] ObjectFiles (ProjectFileCollection projectFiles) { List<string> objectFiles = new List<string> (); foreach (ProjectFile f in projectFiles) { if (f.BuildAction == BuildAction.Compile) { objectFiles.Add (Path.ChangeExtension (f.Name, ".o")); } } return objectFiles.ToArray (); }
/// <summary> /// Compiles the project /// </summary> private bool DoCompilation (ProjectFileCollection projectFiles, string args, string outputName, IProgressMonitor monitor, CompilerResults cr) { StringBuilder filelist = new StringBuilder (); foreach (ProjectFile f in projectFiles) { if (f.Subtype != Subtype.Directory && f.BuildAction == BuildAction.Compile) { filelist.AppendFormat ("\"{0}\" ", f.FilePath); } }/// Build file list string compiler_args = string.Format ("{0} {1} -o \"{2}\"", args, filelist.ToString (), Path.GetFileName (outputName)); string errorOutput = string.Empty; int exitCode = ExecuteCommand (compilerCommand, compiler_args, Path.GetDirectoryName (outputName), monitor, out errorOutput); ParseCompilerOutput (errorOutput, cr, projectFiles); return exitCode == 0; }
public override ICompilerResult Compile( ProjectFileCollection projectFiles, ProjectPackageCollection packages, CProjectConfiguration configuration, IProgressMonitor monitor) { CompilerResults cr = new CompilerResults(new TempFileCollection()); bool res = true; string args = GetCompilerFlags(configuration); string outputName = Path.Combine(configuration.OutputDirectory, configuration.CompiledOutputName); // Precompile header files and place them in .prec/<config_name>/ string precdir = Path.Combine(configuration.SourceDirectory, ".prec"); if (!Directory.Exists(precdir)) { Directory.CreateDirectory(precdir); } precdir = Path.Combine(precdir, configuration.Name); if (!Directory.Exists(precdir)) { Directory.CreateDirectory(precdir); } PrecompileHeaders(projectFiles, configuration, args); foreach (ProjectFile f in projectFiles) { if (f.Subtype == Subtype.Directory) { continue; } if (f.BuildAction == BuildAction.Compile) { if (configuration.UseCcache || NeedsCompiling(f)) { res = DoCompilation(f, args, packages, monitor, cr, configuration.UseCcache); } } else { res = true; } if (!res) { break; } } if (res) { switch (configuration.CompileTarget) { case CBinding.CompileTarget.Bin: MakeBin( projectFiles, packages, configuration, cr, monitor, outputName); break; case CBinding.CompileTarget.StaticLibrary: MakeStaticLibrary( projectFiles, monitor, outputName); break; case CBinding.CompileTarget.SharedLibrary: MakeSharedLibrary( projectFiles, packages, configuration, cr, monitor, outputName); break; } } return(new DefaultCompilerResult(cr, "")); }
/// <summary> /// Compiles a D project. /// </summary> public static BuildResult Compile( DProject Project, ProjectFileCollection FilesToCompile, DProjectConfiguration BuildConfig, IProgressMonitor monitor) { var relObjDir = "objs"; var objDir = Path.Combine(Project.BaseDirectory, relObjDir); if (!Directory.Exists(objDir)) { Directory.CreateDirectory(objDir); } // List of created object files var BuiltObjects = new List <string>(); var compilerResults = new CompilerResults(new TempFileCollection()); var buildResult = new BuildResult(compilerResults, ""); bool succesfullyBuilt = true; bool modificationsDone = false; var Compiler = Project.Compiler; var Commands = Compiler.GetTargetConfiguration(Project.CompileTarget); var Arguments = Commands.GetArguments(BuildConfig.DebugMode); /// The target file to which all objects will be linked to var LinkTarget = BuildConfig.OutputDirectory.Combine(BuildConfig.CompiledOutputName); monitor.BeginTask("Build Project", FilesToCompile.Count + 1); var SourceIncludePaths = new List <string>(Compiler.GlobalParseCache.DirectoryPaths); SourceIncludePaths.AddRange(Project.LocalIncludeCache.DirectoryPaths); #region Compile sources to objects foreach (var f in FilesToCompile) { if (monitor.IsCancelRequested) { return(buildResult); } // If not compilable, skip it if (f.BuildAction != BuildAction.Compile || !File.Exists(f.FilePath)) { continue; } // a.Check if source file was modified and if object file still exists if (Project.LastModificationTimes.ContainsKey(f) && Project.LastModificationTimes[f] == File.GetLastWriteTime(f.FilePath) && File.Exists(f.LastGenOutput)) { // File wasn't edited since last build // but add the built object to the objs array BuiltObjects.Add(f.LastGenOutput); monitor.Step(1); continue; } else { modificationsDone = true; } #region Resource file if (f.Name.EndsWith(".rc", StringComparison.OrdinalIgnoreCase)) { var res = Path.Combine(objDir, Path.GetFileNameWithoutExtension(f.FilePath)) + ".res"; if (File.Exists(res)) { File.Delete(res); } // Build argument string var resCmpArgs = FillInMacros(Win32ResourceCompiler.Instance.Arguments, new Win32ResourceCompiler.ArgProvider { RcFile = f.FilePath.ToString(), ResFile = res }); // Execute compiler string output; int _exitCode = ExecuteCommand(Win32ResourceCompiler.Instance.Executable, resCmpArgs, Project.BaseDirectory, monitor, out output); // Error analysis if (!string.IsNullOrEmpty(output)) { compilerResults.Errors.Add(new CompilerError { FileName = f.FilePath, ErrorText = output }); } CheckReturnCode(_exitCode, compilerResults); monitor.Step(1); if (_exitCode != 0) { buildResult.FailedBuildCount++; succesfullyBuilt = false; break; } else { f.LastGenOutput = res; buildResult.BuildCount++; Project.LastModificationTimes[f] = File.GetLastWriteTime(f.FilePath); // Especially when compiling large projects, do only add the relative part of the r file due to command shortness if (res.StartsWith(Project.BaseDirectory)) { BuiltObjects.Add(res.Substring(Project.BaseDirectory.ToString().Length).TrimStart(Path.DirectorySeparatorChar)); } else { BuiltObjects.Add(res); } } continue; } #endregion // Create object file path var obj = Path.Combine(objDir, Path.GetFileNameWithoutExtension(f.FilePath)) + ObjectExtension; if (File.Exists(obj)) { File.Delete(obj); } // Prevent duplicates e.g. when having the samely-named source files in different sub-packages int i = 2; while (File.Exists(obj)) { // Simply add a number between the obj name and its extension obj = Path.Combine(objDir, Path.GetFileNameWithoutExtension(f.FilePath)) + i + ObjectExtension; i++; } // Create argument string for source file compilation. var dmdArgs = FillInMacros(Arguments.CompilerArguments + " " + BuildConfig.ExtraCompilerArguments, new DCompilerMacroProvider { IncludePathConcatPattern = Commands.IncludePathPattern, SourceFile = f.FilePath, ObjectFile = obj, Includes = SourceIncludePaths, }); // b.Execute compiler string dmdOutput; int exitCode = ExecuteCommand(Commands.Compiler, dmdArgs, Project.BaseDirectory, monitor, out dmdOutput); ParseCompilerOutput(dmdOutput, compilerResults); CheckReturnCode(exitCode, compilerResults); monitor.Step(1); if (exitCode != 0) { buildResult.FailedBuildCount++; succesfullyBuilt = false; break; } else { f.LastGenOutput = obj; buildResult.BuildCount++; Project.LastModificationTimes[f] = File.GetLastWriteTime(f.FilePath); // Especially when compiling large projects, do only add the relative part of the obj file due to command shortness if (obj.StartsWith(Project.BaseDirectory)) { BuiltObjects.Add(obj.Substring(Project.BaseDirectory.ToString().Length).TrimStart(Path.DirectorySeparatorChar)); } else { BuiltObjects.Add(obj); } } } #endregion #region Link files if (succesfullyBuilt) { // a. if ((!modificationsDone) && lastLinkerActionSuccessfull) { // Only return if build target is still existing if (File.Exists(LinkTarget)) { monitor.Step(1); return(new BuildResult(compilerResults, "")); } } // b.Build linker argument string // Build argument preparation /* * var libPaths=new List<string>(Compiler.DefaultLibPaths); * libPaths.AddRange(Project.LibraryPaths); */ var libs = new List <string>(Compiler.DefaultLibraries); libs.AddRange(Project.ExtraLibraries); var linkArgs = FillInMacros(Arguments.LinkerArguments + " " + BuildConfig.ExtraLinkerArguments, new DLinkerMacroProvider { ObjectsStringPattern = Commands.ObjectFileLinkPattern, Objects = BuiltObjects.ToArray(), TargetFile = LinkTarget, RelativeTargetDirectory = BuildConfig.OutputDirectory.ToRelative(Project.BaseDirectory), //LibraryPaths=libPaths, Libraries = libs }); var linkerOutput = ""; int exitCode = ExecuteCommand(Commands.Linker, linkArgs, Project.BaseDirectory, monitor, out linkerOutput); compilerResults.NativeCompilerReturnValue = exitCode; CheckReturnCode(exitCode, compilerResults); lastLinkerActionSuccessfull = (exitCode == 0); if (lastLinkerActionSuccessfull) { monitor.ReportSuccess("Build successful!"); monitor.Step(1); } } #endregion return(new BuildResult(compilerResults, "")); }
private void MakeStaticLibrary (ProjectFileCollection projectFiles, IProgressMonitor monitor, string outputName) { if (!NeedsUpdate (projectFiles, outputName)) return; string objectFiles = StringArrayToSingleString (ObjectFiles (projectFiles)); monitor.Log.WriteLine ("Generating static library..."); monitor.Log.WriteLine ("using: ar rcs " + outputName + " " + objectFiles); Process p = Runtime.ProcessService.StartProcess ( "ar", "rcs " + outputName + " " + objectFiles, null, null); p.WaitForExit (); p.Close (); }
protected void GetContents(MonoDevelop.Projects.Project project, MonoDevelop.Prj2Make.Schema.Csproj.File[] Include, ProjectFileCollection files, IProgressMonitor monitor) { if (Include == null || Include.Length == 0) { return; } // Iterate through the file collection of the csproj file foreach (MonoDevelop.Prj2Make.Schema.Csproj.File fl in Include) { ProjectFile flOut = new ProjectFile(); string name; if ((fl.Link == null) || (fl.Link.Length == 0)) { name = MapPath(project.BaseDirectory, fl.RelPath); } else { name = MapPath(null, fl.Link); } if (name == null) { monitor.ReportWarning(GettextCatalog.GetString("Can't import file: ") + fl.RelPath); continue; } flOut.Name = name; // Adding here as GetDefaultResourceIdInternal needs flOut.Project files.Add(flOut); switch (fl.SubType) { case "Code": flOut.Subtype = Subtype.Code; break; } switch (fl.BuildAction) { case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.Compile: flOut.BuildAction = BuildAction.Compile; break; case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.Content: flOut.BuildAction = BuildAction.Content; break; case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.EmbeddedResource: flOut.BuildAction = BuildAction.EmbeddedResource; break; case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.None: flOut.BuildAction = BuildAction.None; break; } // DependentUpon is relative to flOut flOut.DependsOn = MapPath(Path.GetDirectoryName(flOut.Name), fl.DependentUpon); flOut.Data = ""; } }
private void MakeSharedLibrary(Project project, ProjectFileCollection projectFiles, CProjectConfiguration configuration, ProjectPackageCollection packages, CompilerResults cr, ProgressMonitor monitor, string outputName) { if (!NeedsUpdate(projectFiles, configuration, outputName)) { return; } string objectFiles = string.Join(" ", ObjectFiles(projectFiles, configuration, true)); string pkgargs = GeneratePkgLinkerArgs(packages); StringBuilder args = new StringBuilder(); if (configuration.ExtraLinkerArguments != null && configuration.ExtraLinkerArguments.Length > 0) { string extraLinkerArgs = ExpandBacktickedParameters(configuration.ExtraLinkerArguments.Replace('\n', ' ')); args.Append(extraLinkerArgs + " "); } if (configuration.LibPaths != null) { foreach (string libpath in configuration.LibPaths) { args.Append("-L\"" + StringParserService.Parse(libpath, GetStringTags(project)) + "\" "); } } if (configuration.Libs != null) { foreach (string lib in configuration.Libs) { string directory = Path.GetDirectoryName(lib); string library = Path.GetFileName(lib); // Is this a 'standard' (as in, uses an orthodox naming convention) library..? string link_lib = String.Empty; if (IsStandardLibrary(configuration, directory, library, ref link_lib)) { args.Append("-l\"" + link_lib + "\" "); } // If not, reference the library by it's full pathname. else { args.Append("\"" + lib + "\" "); } } } string linker_args = string.Format("-shared -o \"{0}\" {1} {2} {3}", outputName, objectFiles, pkgargs, args.ToString()); monitor.BeginTask(GettextCatalog.GetString("Generating shared object \"{0}\" from object files", Path.GetFileName(outputName)), 1); string errorOutput; int exitCode = ExecuteCommand(linkerCommand, linker_args, Path.GetDirectoryName(outputName), monitor, out errorOutput); if (exitCode == 0) { monitor.Step(1); } monitor.EndTask(); ParseCompilerOutput(errorOutput, cr); ParseLinkerOutput(errorOutput, cr); CheckReturnCode(exitCode, cr); }
private void MakeStaticLibrary (Project project, ProjectFileCollection projectFiles, CProjectConfiguration configuration, ProjectPackageCollection packages, CompilerResults cr, IProgressMonitor monitor, string outputName) { if (!NeedsUpdate (projectFiles, configuration, outputName)) return; string objectFiles = string.Join (" ", ObjectFiles (projectFiles, configuration, true)); string args = string.Format ("rcs \"{0}\" {1}", outputName, objectFiles); monitor.BeginTask (GettextCatalog.GetString ("Generating static library {0} from object files", Path.GetFileName (outputName)), 1); string errorOutput; int exitCode = ExecuteCommand ("ar", args, Path.GetDirectoryName (outputName), monitor, out errorOutput); if (exitCode == 0) monitor.Step (1); monitor.EndTask (); ParseCompilerOutput (errorOutput, cr); ParseLinkerOutput (errorOutput, cr); CheckReturnCode (exitCode, cr); }
public override BuildResult Compile( Project project, ProjectFileCollection projectFiles, ProjectPackageCollection packages, CProjectConfiguration configuration, ProgressMonitor monitor) { if (!appsChecked) { appsChecked = true; compilerFound = CheckApp(compilerCommand); linkerFound = CheckApp(linkerCommand); } if (!compilerFound) { BuildResult cres = new BuildResult(); cres.AddError("Compiler not found: " + compilerCommand); return(cres); } if (!linkerFound) { BuildResult cres = new BuildResult(); cres.AddError("Linker not found: " + linkerCommand); return(cres); } CompilerResults cr = new CompilerResults(new TempFileCollection()); bool success = true; string compilerArgs = GetCompilerFlags(project, configuration) + " " + GeneratePkgCompilerArgs(packages); string outputName = Path.Combine(configuration.OutputDirectory, configuration.CompiledOutputName); // Precompile header files and place them in prec/<config_name>/ if (configuration.PrecompileHeaders) { string precDir = Path.Combine(configuration.IntermediateOutputDirectory, "prec"); string precConfigDir = Path.Combine(precDir, configuration.Id); if (!Directory.Exists(precDir)) { Directory.CreateDirectory(precDir); } if (!Directory.Exists(precConfigDir)) { Directory.CreateDirectory(precConfigDir); } if (!PrecompileHeaders(projectFiles, configuration, compilerArgs, monitor, cr)) { success = false; } } else { //old headers could interfere with the build CleanPrecompiledHeaders(configuration); } //compile source to object files monitor.BeginTask(GettextCatalog.GetString("Compiling source to object files"), 1); foreach (ProjectFile f in projectFiles) { if (!success) { break; } if (f.Subtype == Subtype.Directory || f.BuildAction != BuildAction.Compile || CProject.IsHeaderFile(f.FilePath)) { continue; } if (configuration.UseCcache || NeedsCompiling(f, configuration)) { success = DoCompilation(f, configuration, compilerArgs, monitor, cr, configuration.UseCcache); } } if (success) { monitor.Step(1); } monitor.EndTask(); if (success) { switch (configuration.CompileTarget) { case CBinding.CompileTarget.Bin: MakeBin(project, projectFiles, configuration, packages, cr, monitor, outputName); break; case CBinding.CompileTarget.StaticLibrary: MakeStaticLibrary(project, projectFiles, configuration, packages, cr, monitor, outputName); break; case CBinding.CompileTarget.SharedLibrary: MakeSharedLibrary(project, projectFiles, configuration, packages, cr, monitor, outputName); break; } } return(new BuildResult(cr, "")); }
public override BuildResult Compile ( Project project, ProjectFileCollection projectFiles, ProjectPackageCollection packages, CProjectConfiguration configuration, IProgressMonitor monitor) { if (!appsChecked) { appsChecked = true; compilerFound = CheckApp (compilerCommand); linkerFound = CheckApp (linkerCommand); } if (!compilerFound) { BuildResult cres = new BuildResult (); cres.AddError ("Compiler not found: " + compilerCommand); return cres; } if (!linkerFound) { BuildResult cres = new BuildResult (); cres.AddError ("Linker not found: " + linkerCommand); return cres; } CompilerResults cr = new CompilerResults (new TempFileCollection ()); bool success = true; string compilerArgs = GetCompilerFlags (project, configuration) + " " + GeneratePkgCompilerArgs (packages); string outputName = Path.Combine (configuration.OutputDirectory, configuration.CompiledOutputName); // Precompile header files and place them in .prec/<config_name>/ if (configuration.PrecompileHeaders) { string precDir = Path.Combine (configuration.SourceDirectory, ".prec"); string precConfigDir = Path.Combine (precDir, configuration.Id); if (!Directory.Exists (precDir)) Directory.CreateDirectory (precDir); if (!Directory.Exists (precConfigDir)) Directory.CreateDirectory (precConfigDir); if (!PrecompileHeaders (projectFiles, configuration, compilerArgs, monitor, cr)) success = false; } else { //old headers could interfere with the build CleanPrecompiledHeaders (configuration); } //compile source to object files monitor.BeginTask (GettextCatalog.GetString ("Compiling source to object files"), 1); foreach (ProjectFile f in projectFiles) { if (!success) break; if (f.Subtype == Subtype.Directory || f.BuildAction != BuildAction.Compile || CProject.IsHeaderFile (f.FilePath)) continue; if (configuration.UseCcache || NeedsCompiling (f, configuration)) success = DoCompilation (f, configuration, compilerArgs, monitor, cr, configuration.UseCcache); } if (success) monitor.Step (1); monitor.EndTask (); if (success) { switch (configuration.CompileTarget) { case CBinding.CompileTarget.Bin: MakeBin (project, projectFiles, configuration, packages, cr, monitor, outputName); break; case CBinding.CompileTarget.StaticLibrary: MakeStaticLibrary (project, projectFiles, configuration, packages, cr, monitor, outputName); break; case CBinding.CompileTarget.SharedLibrary: MakeSharedLibrary (project, projectFiles, configuration, packages, cr, monitor, outputName); break; } } return new BuildResult (cr, ""); }
private void PrecompileHeaders (ProjectFileCollection projectFiles, CProjectConfiguration configuration, string args) { foreach (ProjectFile file in projectFiles) { if (file.Subtype == Subtype.Code && CProject.IsHeaderFile (file.Name)) { string precomp = Path.Combine (configuration.SourceDirectory, ".prec"); precomp = Path.Combine (precomp, configuration.Name); precomp = Path.Combine (precomp, Path.GetFileName (file.Name) + ".ghc"); if (!File.Exists (precomp)) { DoPrecompileHeader (file, precomp, args); continue; } if (configuration.UseCcache || File.GetLastWriteTime (file.Name) > File.GetLastWriteTime (precomp)) { DoPrecompileHeader (file, precomp, args); } } } }
public override void Clean (ProjectFileCollection projectFiles, CProjectConfiguration configuration, IProgressMonitor monitor) { //clean up object files foreach (string oFile in ObjectFiles(projectFiles, configuration, false)) { if (File.Exists (oFile)) File.Delete (oFile); string dFile = Path.ChangeExtension (oFile, ".d"); if (File.Exists (dFile)) File.Delete (dFile); } CleanPrecompiledHeaders (configuration); }
private void MakeSharedLibrary(ProjectFileCollection projectFiles, ProjectPackageCollection packages, CProjectConfiguration configuration, CompilerResults cr, IProgressMonitor monitor, string outputName) { if (!NeedsUpdate(projectFiles, outputName)) { return; } string objectFiles = StringArrayToSingleString(ObjectFiles(projectFiles)); string pkgargs = GeneratePkgLinkerArgs(packages); StringBuilder args = new StringBuilder(); CCompilationParameters cp = (CCompilationParameters)configuration.CompilationParameters; if (cp.ExtraLinkerArguments != null && cp.ExtraLinkerArguments.Length > 0) { string extraLinkerArgs = cp.ExtraLinkerArguments.Replace('\n', ' '); args.Append(extraLinkerArgs + " "); } if (configuration.LibPaths != null) { foreach (string libpath in configuration.LibPaths) { args.Append("-L" + libpath + " "); } } if (configuration.Libs != null) { foreach (string lib in configuration.Libs) { args.Append("-l" + lib + " "); } } monitor.Log.WriteLine("Generating shared object..."); string linker_args = string.Format("-shared -o {0} {1} {2} {3}", outputName, objectFiles, args.ToString(), pkgargs); monitor.Log.WriteLine("using: " + linkerCommand + " " + linker_args); ProcessWrapper p = Runtime.ProcessService.StartProcess(linkerCommand, linker_args, null, null); p.WaitForExit(); string line; StringWriter error = new StringWriter(); while ((line = p.StandardError.ReadLine()) != null) { error.WriteLine(line); } monitor.Log.WriteLine(error.ToString()); ParseCompilerOutput(error.ToString(), cr); error.Close(); p.Close(); ParseLinkerOutput(error.ToString(), cr); }
/// <summary> /// Determines whether the target needs to be updated /// </summary> /// <param name="projectFiles"> /// The project's files /// <see cref="ProjectFileCollection"/> /// </param> /// <param name="target"> /// The target /// <see cref="System.String"/> /// </param> /// <returns> /// true if target needs to be updated /// <see cref="System.Boolean"/> /// </returns> private bool NeedsUpdate (ProjectFileCollection projectFiles, string target) { return true; }
/// <summary> /// Compiles a D project. /// </summary> public static BuildResult Compile( DProject Project, ProjectFileCollection FilesToCompile, DProjectConfiguration BuildConfig, IProgressMonitor monitor) { var relObjDir = "objs"; var objDir = Path.Combine(Project.BaseDirectory, relObjDir); if(!Directory.Exists(objDir)) Directory.CreateDirectory(objDir); // List of created object files var BuiltObjects = new List<string>(); var compilerResults = new CompilerResults(new TempFileCollection()); var buildResult = new BuildResult(compilerResults, ""); bool succesfullyBuilt = true; bool modificationsDone = false; var Compiler = Project.Compiler; var Commands = Compiler.GetTargetConfiguration(Project.CompileTarget); var Arguments= Commands.GetArguments(BuildConfig.DebugMode); /// The target file to which all objects will be linked to var LinkTarget = BuildConfig.OutputDirectory.Combine(BuildConfig.CompiledOutputName); monitor.BeginTask("Build Project", FilesToCompile.Count + 1); var SourceIncludePaths=new List<string>(Compiler.GlobalParseCache.DirectoryPaths); SourceIncludePaths.AddRange(Project.LocalIncludeCache.DirectoryPaths); #region Compile sources to objects foreach (var f in FilesToCompile) { if (monitor.IsCancelRequested) return buildResult; // If not compilable, skip it if (f.BuildAction != BuildAction.Compile || !File.Exists(f.FilePath)) continue; // a.Check if source file was modified and if object file still exists if (Project.LastModificationTimes.ContainsKey(f) && Project.LastModificationTimes[f] == File.GetLastWriteTime(f.FilePath) && File.Exists(f.LastGenOutput)) { // File wasn't edited since last build // but add the built object to the objs array BuiltObjects.Add(f.LastGenOutput); monitor.Step(1); continue; } else modificationsDone=true; #region Resource file if(f.Name.EndsWith(".rc",StringComparison.OrdinalIgnoreCase)) { var res = Path.Combine(objDir, Path.GetFileNameWithoutExtension(f.FilePath))+ ".res"; if(File.Exists(res)) File.Delete(res); // Build argument string var resCmpArgs = FillInMacros(Win32ResourceCompiler.Instance.Arguments, new Win32ResourceCompiler.ArgProvider{ RcFile=f.FilePath.ToString(), ResFile=res }); // Execute compiler string output; int _exitCode = ExecuteCommand(Win32ResourceCompiler.Instance.Executable, resCmpArgs, Project.BaseDirectory, monitor, out output); // Error analysis if(!string.IsNullOrEmpty(output)) compilerResults.Errors.Add(new CompilerError{ FileName=f.FilePath, ErrorText=output}); CheckReturnCode(_exitCode, compilerResults); monitor.Step(1); if (_exitCode != 0) { buildResult.FailedBuildCount++; succesfullyBuilt = false; break; } else { f.LastGenOutput = res; buildResult.BuildCount++; Project.LastModificationTimes[f] = File.GetLastWriteTime(f.FilePath); // Especially when compiling large projects, do only add the relative part of the r file due to command shortness if (res.StartsWith(Project.BaseDirectory)) BuiltObjects.Add(res.Substring(Project.BaseDirectory.ToString().Length).TrimStart(Path.DirectorySeparatorChar)); else BuiltObjects.Add(res); } continue; } #endregion // Create object file path var obj = Path.Combine(objDir, Path.GetFileNameWithoutExtension(f.FilePath)) + ObjectExtension; if (File.Exists(obj)) File.Delete(obj); // Prevent duplicates e.g. when having the samely-named source files in different sub-packages int i=2; while(File.Exists(obj)) { // Simply add a number between the obj name and its extension obj= Path.Combine(objDir, Path.GetFileNameWithoutExtension(f.FilePath))+i + ObjectExtension; i++; } // Create argument string for source file compilation. var dmdArgs = FillInMacros(Arguments.CompilerArguments + " " + BuildConfig.ExtraCompilerArguments, new DCompilerMacroProvider { IncludePathConcatPattern=Commands.IncludePathPattern, SourceFile = f.FilePath, ObjectFile = obj, Includes=SourceIncludePaths, }); // b.Execute compiler string dmdOutput; int exitCode = ExecuteCommand(Commands.Compiler, dmdArgs, Project.BaseDirectory, monitor, out dmdOutput); ParseCompilerOutput(dmdOutput, compilerResults); CheckReturnCode(exitCode, compilerResults); monitor.Step(1); if (exitCode != 0) { buildResult.FailedBuildCount++; succesfullyBuilt = false; break; } else { f.LastGenOutput = obj; buildResult.BuildCount++; Project.LastModificationTimes[f] = File.GetLastWriteTime(f.FilePath); // Especially when compiling large projects, do only add the relative part of the obj file due to command shortness if (obj.StartsWith(Project.BaseDirectory)) BuiltObjects.Add(obj.Substring(Project.BaseDirectory.ToString().Length).TrimStart(Path.DirectorySeparatorChar)); else BuiltObjects.Add(obj); } } #endregion #region Link files if (succesfullyBuilt) { // a. if ((!modificationsDone) && lastLinkerActionSuccessfull) { // Only return if build target is still existing if (File.Exists(LinkTarget)) { monitor.Step(1); return new BuildResult(compilerResults, ""); } } // b.Build linker argument string // Build argument preparation /* var libPaths=new List<string>(Compiler.DefaultLibPaths); libPaths.AddRange(Project.LibraryPaths); */ var libs=new List<string>(Compiler.DefaultLibraries); libs.AddRange(Project.ExtraLibraries); var linkArgs = FillInMacros(Arguments.LinkerArguments + " "+BuildConfig.ExtraLinkerArguments, new DLinkerMacroProvider { ObjectsStringPattern=Commands.ObjectFileLinkPattern, Objects=BuiltObjects.ToArray(), TargetFile=LinkTarget, RelativeTargetDirectory=BuildConfig.OutputDirectory.ToRelative(Project.BaseDirectory), //LibraryPaths=libPaths, Libraries=libs }); var linkerOutput = ""; int exitCode = ExecuteCommand(Commands.Linker,linkArgs,Project.BaseDirectory,monitor,out linkerOutput); compilerResults.NativeCompilerReturnValue = exitCode; CheckReturnCode(exitCode, compilerResults); lastLinkerActionSuccessfull = (exitCode == 0); if (lastLinkerActionSuccessfull) { monitor.ReportSuccess("Build successful!"); monitor.Step(1); } } #endregion return new BuildResult(compilerResults,""); }
public abstract void Clean (ProjectFileCollection projectFiles, CProjectConfiguration configuration, IProgressMonitor monitor);
public BuildResult Compile (ProjectFileCollection projectFiles, ProjectReferenceCollection projectReferences, DotNetProjectConfiguration configuration, IProgressMonitor monitor) { NemerleParameters cp = (NemerleParameters) configuration.CompilationParameters; if (cp == null) cp = new NemerleParameters (); string references = ""; string files = ""; foreach (ProjectReference lib in projectReferences) foreach (string a in lib.GetReferencedFileNames()) references += " -r \"" + a + "\""; foreach (ProjectFile f in projectFiles) if (f.Subtype != Subtype.Directory) switch (f.BuildAction) { case BuildAction.Compile: files += " \"" + f.Name + "\""; break; } if (!Directory.Exists (configuration.OutputDirectory)) Directory.CreateDirectory (configuration.OutputDirectory); string args = "-q -no-color " + GetOptionsString (configuration, cp) + references + files + " -o " + configuration.CompiledOutputName; return DoCompilation (args); }
public BuildResult Compile(ProjectFileCollection projectFiles, ProjectReferenceCollection references, DotNetProjectConfiguration configuration, IProgressMonitor monitor) { return(compilerServices.Compile(projectFiles, references, configuration, monitor)); }
/// <summary> /// Creates a compiler error from an output string /// </summary> /// <param name="errorString"> /// The error string to be parsed /// <see cref="System.String"/> /// </param> /// <returns> /// A newly created CompilerError /// <see cref="CompilerError"/> /// </returns> private CompilerError CreateErrorFromErrorString (string errorString, ProjectFileCollection projectFiles) { Match errorMatch = null; foreach (Regex regex in new Regex[]{errorRegex, gccRegex}) if ((errorMatch = regex.Match (errorString)).Success) break; if (!errorMatch.Success) return null; CompilerError error = new CompilerError (); foreach (ProjectFile pf in projectFiles) { if (Path.GetFileName (pf.Name) == errorMatch.Groups["file"].Value) { error.FileName = pf.FilePath; break; } }// check for fully pathed file if (string.Empty == error.FileName) { error.FileName = errorMatch.Groups["file"].Value; }// fallback to exact match error.Line = int.Parse (errorMatch.Groups["line"].Value); if (errorMatch.Groups["column"].Success) error.Column = int.Parse (errorMatch.Groups["column"].Value); error.IsWarning = !errorMatch.Groups["level"].Value.Equals (GettextCatalog.GetString ("error"), StringComparison.Ordinal); error.ErrorText = errorMatch.Groups["message"].Value; return error; }
public static void GetFolderContent (string folder, out ProjectFileCollection files, out List<string> folders) { string folderPrefix = folder + Path.DirectorySeparatorChar; files = new ProjectFileCollection (); folders = new List<string> (); foreach (ProjectFile file in AllFiles) { string dir; if (file.Subtype != Subtype.Directory) { if (file.DependsOnFile != null) continue; dir = //file.IsLink //? project.BaseDirectory.Combine (file.ProjectVirtualPath).ParentDirectory //: file.FilePath.ParentDirectory; if (dir == folder) { files.Add (file); continue; } } else dir = file.Name; // add the directory if it isn't already present if (dir.StartsWith (folderPrefix, StringComparison.Ordinal)) { int i = dir.IndexOf (Path.DirectorySeparatorChar, folderPrefix.Length); if (i != -1) dir = dir.Substring (0,i); if (!folders.Contains (dir)) folders.Add (dir); } } }
protected void GetContents (MonoDevelop.Projects.Project project, MonoDevelop.Prj2Make.Schema.Csproj.File[] Include, ProjectFileCollection files, IProgressMonitor monitor) { if (Include == null || Include.Length == 0) return; // Iterate through the file collection of the csproj file foreach(MonoDevelop.Prj2Make.Schema.Csproj.File fl in Include) { ProjectFile flOut = new ProjectFile (); string name; if ((fl.Link == null) || (fl.Link.Length == 0)) { name = MapPath (project.BaseDirectory, fl.RelPath); } else { name = MapPath (null, fl.Link); } if (name == null) { monitor.ReportWarning (GettextCatalog.GetString ("Can't import file: ") + fl.RelPath); continue; } flOut.Name = name; // Adding here as GetDefaultResourceIdInternal needs flOut.Project files.Add (flOut); switch (fl.SubType) { case "Code": flOut.Subtype = Subtype.Code; break; } switch (fl.BuildAction) { case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.Compile: flOut.BuildAction = BuildAction.Compile; break; case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.Content: flOut.BuildAction = BuildAction.Content; break; case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.EmbeddedResource: flOut.BuildAction = BuildAction.EmbeddedResource; break; case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.None: flOut.BuildAction = BuildAction.None; break; } // DependentUpon is relative to flOut flOut.DependsOn = MapPath (Path.GetDirectoryName (flOut.Name), fl.DependentUpon); flOut.Data = ""; } }
public abstract void Clean(ProjectFileCollection projectFiles, CProjectConfiguration configuration, IProgressMonitor monitor);
public BuildResult Compile(ProjectItemCollection items, DotNetProjectConfiguration configuration, IProgressMonitor monitor) { FSharpCompilerParameters compilerparameters = (FSharpCompilerParameters) configuration.CompilationParameters; if (compilerparameters == null) compilerparameters = new FSharpCompilerParameters (); string responseFileName = Path.GetTempFileName(); StringWriter writer = new StringWriter (); ArrayList gacRoots = new ArrayList (); AddOption(writer, "--fullpaths"); AddOption(writer, "--utf8output"); ProjectFileCollection projectFiles = new ProjectFileCollection(); ProjectReferenceCollection references = new ProjectReferenceCollection(); // FIXME: Plain guesswork foreach(ProjectItem item in items) { ProjectFile file = null; ProjectReference reference = null; if((file = item as ProjectFile) != null) { projectFiles.Add(file); } else if((reference = item as ProjectReference) != null) { references.Add(reference); } else { // Nada... } } if (references != null) { foreach (ProjectReference lib in references) { if ((lib.ReferenceType == ReferenceType.Project) && (!(lib.OwnerProject.ParentSolution.FindProjectByName (lib.Reference) is DotNetProject))) continue; foreach (string fileName in lib.GetReferencedFileNames (configuration.Id)) { switch (lib.ReferenceType) { case ReferenceType.Gac: SystemPackage[] pkgs = Runtime.SystemAssemblyService.GetPackagesFromFullName(lib.Reference); SystemPackage pkg = null; if(pkgs != null && pkgs.Length > 0) { // FIXME: Now handling only one package pkg = pkgs[0]; } if (pkg == null) { string msg = String.Format (GettextCatalog.GetString ("{0} could not be found or is invalid."), lib.Reference); monitor.ReportWarning (msg); continue; } else if (pkg.IsInternalPackage) { AddOption(writer,"-r \"" + fileName + "\""); } if (pkg.GacRoot != null && !gacRoots.Contains (pkg.GacRoot)) gacRoots.Add (pkg.GacRoot); break; default: AddOption(writer,"-r \"" + fileName + "\""); break; } } } } string exe = configuration.CompiledOutputName; AddOption(writer,"--out \"" + exe + '"'); if (configuration.SignAssembly) { if (File.Exists (configuration.AssemblyKeyFile)) AddOption(writer,"--keyfile \"" + configuration.AssemblyKeyFile + '"'); } if (configuration.DebugMode) { AddOption(writer,"--debug"); } else if (compilerparameters.Optimize) AddOption(writer,"--optimize"); if (compilerparameters.CodePage != 0) { AddOption(writer,"--codepage " + compilerparameters.CodePage); } if (compilerparameters.TreatWarningsAsErrors) { AddOption(writer,"--warnaserror"); } if (compilerparameters.DefineSymbols.Length > 0) { AddOption(writer,"--define " + compilerparameters.DefineSymbols); } switch (configuration.CompileTarget) { case CompileTarget.Exe: AddOption(writer,"--target exe"); break; case CompileTarget.WinExe: AddOption(writer,"--target winexe"); break; case CompileTarget.Library: AddOption(writer,"--target library"); break; case CompileTarget.Module: AddOption(writer,"--target module"); break; } if (compilerparameters.GenerateXmlDocumentation) { AddOption(writer,"-doc \"" + Path.ChangeExtension(exe, ".xml") + '"'); } if (!string.IsNullOrEmpty (compilerparameters.AdditionalArguments)) { AddOption(writer,compilerparameters.AdditionalArguments); } if (!string.IsNullOrEmpty (compilerparameters.NoWarnings)) { AddOption(writer, String.Format("--nowarn {0}", compilerparameters.NoWarnings)); } foreach (ProjectFile finfo in projectFiles) { if (finfo.Subtype == Subtype.Directory) continue; switch (finfo.BuildAction) { case BuildAction.Compile: AddOption(writer,'"' + finfo.Name + '"'); break; // case BuildAction.EmbedAsResource: // string fname = finfo.Name; // if (String.Compare (Path.GetExtension (fname), ".resx", true) == 0) // fname = Path.ChangeExtension (fname, ".resources"); // // AddOption(writer,@"""/res:{0},{1}""", fname, finfo.ResourceId); // break; default: continue; } } writer.Close(); string output = String.Empty; string error = String.Empty; File.WriteAllText (responseFileName, writer.ToString ()); string compilerName; try { compilerName = GetCompilerName (configuration.ClrVersion); } catch (Exception e) { string message = "Could not obtain F# compiler"; monitor.ReportError (message, e); return null; } //string outstr = compilerName + " @" + responseFileName; string outstr = compilerName + " "+ writer.ToString (); TempFileCollection tf = new TempFileCollection(); string workingDir = "."; if (projectFiles != null && projectFiles.Count > 0) { workingDir = projectFiles [0].Project.BaseDirectory; if (workingDir == null) // Dummy projects created for single files have no filename // and so no BaseDirectory. // This is a workaround for a bug in // ProcessStartInfo.WorkingDirectory - not able to handle null workingDir = "."; } LoggingService.LogInfo (compilerName + " " + writer.ToString ()); int exitCode = DoCompilation (outstr, tf, workingDir, gacRoots, ref output, ref error); BuildResult result = ParseOutput(tf, output, error); if (result.CompilerOutput.Trim ().Length != 0) monitor.Log.WriteLine (result.CompilerOutput); //if compiler crashes, output entire error string if (result.ErrorCount == 0 && exitCode != 0) { if (!string.IsNullOrEmpty (error)) result.AddError (error); else result.AddError ("The compiler appears to have crashed without any error output."); } FileService.DeleteFile (responseFileName); FileService.DeleteFile (output); FileService.DeleteFile (error); return result; }