Exemplo n.º 1
0
        public virtual bool ObsoleteBuild(uint vsopts, string config, IVsOutputWindowPane output, bool fCleanBuild)
        {
            if (fCleanBuild)
            {
                // we are done
                return true;
            }

            lock (Project.BuildLock)
            {
                ProjectOptions options = this.GetProjectOptions(config);
                CompilerResults results;
                ArrayList files = new ArrayList();
/*UNDONE: need to get this to use MSBuild
                foreach (XmlElement e in doc.SelectNodes("//Files/Include/File"))
                {
                    //TODO: Support other "BuildActions" like "EmbeddedResource"...
                    if (e.GetAttribute("BuildAction") == "Compile")
                    {
                        string rel = e.GetAttribute("RelPath");
                        Url url = new Url(new Url(doc.BaseURI), rel);
                        files.Add(url.AbsoluteUrl);
                    }
                }
*/
                try
                {
                    ICodeCompiler compiler = this.GetCompiler();
                    if (files.Count == 1)
                    {
                        string filename = (string)files[0];
                        results = compiler.CompileAssemblyFromFile(options, filename);
                    }
                    else
                    {
                        string[] fileNames = (string[])files.ToArray(typeof(string));
                        results = compiler.CompileAssemblyFromFileBatch(options, fileNames);
                    }
                }
                catch (Exception e)
                {
                    results = new CompilerResults(options.TempFiles);
                    results.Errors.Add(new CompilerError(options.OutputAssembly, 1, 1, "", "Internal Compiler Error: " + e.ToString() + "\n"));
                    results.NativeCompilerReturnValue = 1;
                }
                taskProvider.Tasks.Clear();

                int errorCount = 0;
                int warningCount = 0;

                foreach (CompilerError e in results.Errors)
                {
                    if (e.IsWarning) warningCount++;
                    else
                        errorCount++;

                    NativeMethods.ThrowOnFailure(output.OutputTaskItemString(GetFormattedErrorMessage(e, false) + "\n", VSTASKPRIORITY.TP_HIGH, VSTASKCATEGORY.CAT_BUILDCOMPILE, "", -1, e.FileName, (uint)e.Line - 1, e.ErrorText));
                }

                NativeMethods.ThrowOnFailure(output.OutputStringThreadSafe("Build complete -- " + errorCount + " errors, " + warningCount + " warnings")); //TODO: globalize
                NativeMethods.ThrowOnFailure(output.FlushToTaskList()); 
                return results.NativeCompilerReturnValue == 0;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Displays a diagnostic message in the error list window as well as in the output pane
 /// </summary>
 /// <param name="djangoDiagnostics"></param>
 /// <param name="filePath"></param>
 public void ShowDiagnostics(IVsOutputWindowPane djangoDiagnostics, string filePath)
 {
     if (node.ErrorMessage.Severity > 0)
     {
         ITextSnapshotLine line = snapshotSpan.Snapshot.GetLineFromPosition(node.Position);
         djangoDiagnostics.OutputTaskItemString(
             node.ErrorMessage.Message + "\n",
             VSTASKPRIORITY.TP_HIGH,
             VSTASKCATEGORY.CAT_BUILDCOMPILE,
             "",
             (int)_vstaskbitmap.BMP_COMPILE,
             filePath,
             (uint)line.LineNumber,
             node.ErrorMessage.Message + "\n"
             );
     }
     foreach (DesignerNode child in children)
         child.ShowDiagnostics(djangoDiagnostics, filePath);
 }
Exemplo n.º 3
0
    //////////////////////////////////////////////////////////////////////////////////////////////////    
    // This is called from the compiler background thread.
    //    fCleanBuild is not part of the vsopts, but passed down as the callpath is differently
    //
    //////////////////////////////////////////////////////////////////////////////////////////////////    
    /// <include file='doc\Project.uex' path='docs/doc[@for="Project.Build"]/*' />
    public virtual bool Build(uint vsopts, XmlElement config, IVsOutputWindowPane output, bool fCleanBuild){
      if (fCleanBuild){
        // we are done
        return true;
      }
      lock (Project.BuildLock){
#if LookForMemoryLeaks
        System.GC.Collect();
        System.GC.WaitForPendingFinalizers();
        System.GC.Collect();
        System.GC.WaitForPendingFinalizers();
        long usedMemoryBeforeBuild = System.GC.GetTotalMemory(true);
#endif        
        int errorCount = 0;
        int warningCount = 0;
        CompilerResults results = this.CompileProject(config);

#if WHIDBEY
        if (this.taskManager != null && this.taskManagerBuild != null) {
          taskManager.ClearTasksOnProject(this.Caption);
          taskManagerBuild.ClearTasksOnProject(this.Caption);
          bool runVerifierBuildOnly = this.GetBoolAttr(config, "RunProgramVerifier") && !this.GetBoolAttr(config, "RunProgramVerifierWhileEditing");
          string verifierCode = ((int)System.Compiler.Error.GenericWarning).ToString("0000");
          
          foreach (CompilerError e in results.Errors) {
            if (e.IsWarning)
              warningCount++;
            else
              errorCount++;

            // output.OutputTaskItemString(GetFormattedErrorMessage(e, false) + "\n", VSTASKPRIORITY.TP_HIGH, VSTASKCATEGORY.CAT_BUILDCOMPILE, "", -1, e.FileName, (uint)e.Line - 1, e.ErrorText);
            int endLine;
            int endColumn;
            if (e is System.Compiler.CompilerErrorEx) {
              System.Compiler.CompilerErrorEx errorEx = (System.Compiler.CompilerErrorEx)e;
              endLine = errorEx.EndLine;
              endColumn = errorEx.EndColumn;
            }
            else {
              endLine = e.Line;
              endColumn = e.Column + 1;
            }

            bool isBuildOnly = runVerifierBuildOnly && e.ErrorNumber == verifierCode;
            
            (isBuildOnly ? taskManagerBuild : taskManager).AddTask(e.ErrorText, null, e.ErrorNumber, "CS" + e.ErrorNumber,
              TaskPriority.Normal, (e.IsWarning ? TaskCategory.Warning : TaskCategory.Error),
              (isBuildOnly ? TaskMarker.Error : (e.IsWarning ? TaskMarker.Warning : TaskMarker.CodeSense)),
              TaskOutputPane.Build, this.Caption, e.FileName,
              e.Line, e.Column, endLine, endColumn, null);
          }
          taskManager.OutputString("Build complete -- " + errorCount + " errors, " + warningCount + " warnings\n", TaskOutputPane.Build);
          taskManager.Refresh();
          taskManagerBuild.Refresh();
        }
        else {
#endif        
          this.taskProvider.ClearErrors();
          foreach (CompilerError e in results.Errors) {
            if (e.IsWarning) warningCount++;
            else
              errorCount++;
            output.OutputTaskItemString(GetFormattedErrorMessage(e, false) + "\n", VSTASKPRIORITY.TP_HIGH, VSTASKCATEGORY.CAT_BUILDCOMPILE, "", -1, e.FileName, (uint)e.Line - 1, e.ErrorText);
          }
          output.OutputStringThreadSafe("Build complete -- " + errorCount + " errors, " + warningCount + " warnings\n"); //TODO: globalize
          output.FlushToTaskList();
#if WHIDBEY
        }
#endif
        bool success = results.NativeCompilerReturnValue == 0;
#if LookForMemoryLeaks
        results = null;
        System.GC.Collect();
        System.GC.WaitForPendingFinalizers();
        System.GC.Collect();
        System.GC.WaitForPendingFinalizers();
        long usedMemoryAfterBuild = System.GC.GetTotalMemory(true);
        output.OutputStringThreadSafe("Build leaked "+(usedMemoryAfterBuild-usedMemoryBeforeBuild)+" bytes");
#endif
        return success;
      }
    }